Skip to content

Commit

Permalink
[ML4SE-160] Divided configs into 2 types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 committed Oct 15, 2023
1 parent 389f80e commit cc4fe7c
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.tasktracker.config

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

interface BaseProjectConfig : BaseConfig {
fun buildHandler(project: Project): BaseProjectHandler?
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.jetbrains.research.tasktracker.config.ide

import com.intellij.openapi.diagnostic.Logger
import org.jetbrains.research.tasktracker.config.BaseConfig
import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.ide.inspection.InspectionConfig
import org.jetbrains.research.tasktracker.config.ide.settings.SettingsConfig
import org.jetbrains.research.tasktracker.config.util.buildBaseConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler
import org.jetbrains.research.tasktracker.handler.ide.IdeHandler
import java.io.File

class MainIdeConfig : BaseConfig {
class MainIdeConfig : BaseProjectConfig {
var inspectionConfig: InspectionConfig? = null
var settingsConfig: SettingsConfig? = null
override val configName: String
get() = "main_ide"

override fun buildHandler(): BaseHandler = IdeHandler(this)
override fun buildHandler(project: Project): BaseProjectHandler = IdeHandler(this, project)

companion object {
private val logger = Logger.getInstance(MainIdeConfig::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jetbrains.research.tasktracker.config.ide.inspection

import com.intellij.openapi.project.Project
import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.BaseConfig
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.YamlConfigLoadStrategy
import org.jetbrains.research.tasktracker.handler.ide.InspectionHandler
import java.io.File
Expand All @@ -14,12 +15,12 @@ data class InspectionConfig(
* in accordance with the selected mode.
*/
val inspectionNames: List<String> = emptyList()
) : BaseConfig {
) : BaseProjectConfig {

override val configName: String
get() = "inspection"

override fun buildHandler() = InspectionHandler(this)
override fun buildHandler(project: Project) = InspectionHandler(this, project)

companion object {
const val CONFIG_FILE_PREFIX: String = "inspection"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jetbrains.research.tasktracker.config.ide.settings

import com.intellij.openapi.project.Project
import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.BaseConfig
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.YamlConfigLoadStrategy
import org.jetbrains.research.tasktracker.handler.ide.SettingsHandler
import java.io.File
Expand All @@ -11,12 +12,12 @@ data class SettingsConfig(
val enableCodeCompletion: SettingMode,
val enableZenMode: SettingMode,
val theme: Theme
) : BaseConfig {
) : BaseProjectConfig {

override val configName: String
get() = "settings"

override fun buildHandler() = SettingsHandler(this)
override fun buildHandler(project: Project) = SettingsHandler(this, project)

companion object {
const val CONFIG_FILE_PREFIX: String = "settings"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package org.jetbrains.research.tasktracker.config.tracking

import com.intellij.openapi.project.Project
import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.BaseConfig
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.YamlConfigLoadStrategy
import org.jetbrains.research.tasktracker.handler.tracking.ActivityTrackingHandler
import java.io.File

@Serializable
data class ActivityTrackingConfig(
override val trackingDeltaSec: Double = BaseTrackingConfig.DEFAULT_TRACKING_DELTA,
) : BaseTrackingConfig, BaseConfig {
) : BaseTrackingConfig, BaseProjectConfig {

override val configName: String
get() = "activity_tracking"

override fun buildHandler() = ActivityTrackingHandler(this)
override fun buildHandler(project: Project) = ActivityTrackingHandler(this, project)

companion object {
const val CONFIG_FILE_PREFIX: String = "activity_tracking"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jetbrains.research.tasktracker.config.tracking

import com.intellij.openapi.project.Project
import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.BaseConfig
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.YamlConfigLoadStrategy
import org.jetbrains.research.tasktracker.config.tracking.BaseTrackingConfig.Companion.DEFAULT_TRACKING_DELTA
import org.jetbrains.research.tasktracker.handler.tracking.CodeTrackingHandler
Expand All @@ -19,12 +20,12 @@ data class CodeTrackingConfig(
val granularity: CodeTrackingGranularity = CodeTrackingGranularity.ALL_CHANGES,
// Additional files to track
val filesPathToTrack: List<String> = emptyList(),
) : BaseTrackingConfig, BaseConfig {
) : BaseTrackingConfig, BaseProjectConfig {

override val configName: String
get() = "code_tracking"

override fun buildHandler() = CodeTrackingHandler(this)
override fun buildHandler(project: Project) = CodeTrackingHandler(this, project)

companion object {
const val CONFIG_FILE_PREFIX: String = "code_tracking"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jetbrains.research.tasktracker.config.tracking

import com.intellij.openapi.project.Project
import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.BaseConfig
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.YamlConfigLoadStrategy
import org.jetbrains.research.tasktracker.handler.tracking.WebCamTrackingHandler
import java.io.File
Expand All @@ -14,11 +15,11 @@ enum class WebCamTrackingGranularity {
data class WebCamTrackingConfig(
override val trackingDeltaSec: Double = BaseTrackingConfig.DEFAULT_TRACKING_DELTA,
val granularity: WebCamTrackingGranularity = WebCamTrackingGranularity.ALWAYS,
) : BaseConfig, BaseTrackingConfig {
) : BaseProjectConfig, BaseTrackingConfig {
override val configName: String
get() = "webcam_tracking"

override fun buildHandler() = WebCamTrackingHandler(this)
override fun buildHandler(project: Project) = WebCamTrackingHandler(this, project)

companion object {
const val CONFIG_FILE_PREFIX: String = "webcam_tracking"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.jetbrains.research.tasktracker.handler

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.BaseConfig

interface BaseHandler {
val config: BaseConfig

fun setup(project: Project) = run { }
fun setup() = run { }

fun destroy() = run { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.jetbrains.research.tasktracker.handler

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.BaseConfig

interface BaseProjectHandler : BaseHandler {
override val config: BaseConfig

val project: Project
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.jetbrains.research.tasktracker.handler.content

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.content.TaskContentConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.ui.main.panel.storage.MainPanelStorage

// TODO: add hierarchy for different types of tasks
class TaskContentHandler(override val config: TaskContentConfig) : BaseHandler {

override fun setup(project: Project) {
override fun setup() {
MainPanelStorage.taskIdTask = config.tasks.associateBy { it.id }.toMutableMap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package org.jetbrains.research.tasktracker.handler.ide

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

class IdeHandler(override val config: MainIdeConfig) : BaseHandler {
private val childHandlers: List<BaseHandler?>
class IdeHandler(override val config: MainIdeConfig, override val project: Project) : BaseProjectHandler {
private val childHandlers: List<BaseProjectHandler?>

init {
with(config) {
childHandlers = listOfNotNull(inspectionConfig, settingsConfig).map { it.buildHandler() }
childHandlers = listOfNotNull(inspectionConfig, settingsConfig).map { it.buildHandler(project) }
}
}

override fun setup(project: Project) {
override fun setup() {
childHandlers.forEach {
it?.setup(project)
it?.setup()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import com.intellij.openapi.util.Disposer
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
import org.jetbrains.research.tasktracker.config.ide.inspection.InspectionConfig
import org.jetbrains.research.tasktracker.config.ide.inspection.InspectionMode
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

class InspectionHandler(override val config: InspectionConfig) : BaseHandler {
class InspectionHandler(override val config: InspectionConfig, override val project: Project) : BaseProjectHandler {
private var inspectionDisposable: Disposable? = null
private val logger: Logger = Logger.getInstance(InspectionHandler::class.java)

override fun setup(project: Project) {
override fun setup() {
// creating a new profile to make changes only in the current project
val profile = initTaskProfile(project)
applyConfig(profile, project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.ide.settings.SettingMode
import org.jetbrains.research.tasktracker.config.ide.settings.SettingsConfig
import org.jetbrains.research.tasktracker.config.ide.settings.Theme
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler
import javax.swing.UIManager.LookAndFeelInfo

class SettingsHandler(override val config: SettingsConfig) : BaseHandler {
class SettingsHandler(override val config: SettingsConfig, override val project: Project) : BaseProjectHandler {
private val settings: CodeInsightSettings = CodeInsightSettings.getInstance()
private val defaultUserCompletion: Boolean = settings.AUTO_POPUP_COMPLETION_LOOKUP
private val lafManager = LafManager.getInstance()
private val defaultUserLookAndFeel: LookAndFeelInfo? = LafManager.getInstance().currentLookAndFeel

override fun setup(project: Project) {
override fun setup() {
setupCodeCompletion()
setupZenMode(project)
setupTheme()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.research.tasktracker.handler.init

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.BaseProjectConfig
import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler

Expand All @@ -23,8 +24,14 @@ class InitializationHandler(private val mainConfig: MainTaskTrackerConfig) {
destroyHandlers()

handlers.addAll(
mainConfig.getAllConfigs().mapNotNull { it?.buildHandler() }
mainConfig.getAllConfigs().mapNotNull {
when (it) {
is BaseProjectConfig -> it.buildHandler(project)
is BaseHandler -> it.buildHandler()
else -> null
}
}
)
handlers.forEach { it.setup(project) }
handlers.forEach { it.setup() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package org.jetbrains.research.tasktracker.handler.tracking

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.tracking.ActivityTrackingConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

class ActivityTrackingHandler(override val config: ActivityTrackingConfig) : BaseHandler {
override fun setup(project: Project) {
class ActivityTrackingHandler(
override val config: ActivityTrackingConfig,
override val project: Project
) : BaseProjectHandler {
override fun setup() {
// TODO(
// "Setup activity tracking according to the config"
// )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package org.jetbrains.research.tasktracker.handler.tracking

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.tracking.CodeTrackingConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

class CodeTrackingHandler(override val config: CodeTrackingConfig) : BaseHandler {
override fun setup(project: Project) {
class CodeTrackingHandler(override val config: CodeTrackingConfig, override val project: Project) : BaseProjectHandler {
override fun setup() {
// TODO(
// "Setup code tracking according to the config: " +
// "create files for tasks, add listeners for them and for filesToTrack, etc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package org.jetbrains.research.tasktracker.handler.tracking

import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.config.tracking.WebCamTrackingConfig
import org.jetbrains.research.tasktracker.handler.BaseHandler
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

class WebCamTrackingHandler(override val config: WebCamTrackingConfig) : BaseHandler {
override fun setup(project: Project) {
class WebCamTrackingHandler(
override val config: WebCamTrackingConfig,
override val project: Project
) : BaseProjectHandler {
override fun setup() {
// TODO(
// "Setup webcam tracking according to the config"
// )
Expand Down

0 comments on commit cc4fe7c

Please sign in to comment.