Skip to content

Commit

Permalink
[ML4SE-234] process new Scenario Units
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 committed Nov 16, 2023
1 parent 4137970 commit cf6bdaa
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig
import org.jetbrains.research.tasktracker.handler.scenario.ScenarioHandler

// Put into plugin.xml
class InitActivity : StartupActivity {
Expand All @@ -20,11 +19,11 @@ class InitActivity : StartupActivity {
override fun runActivity(project: Project) {
TaskTrackerPlugin.initializationHandler.setupEnvironment(project) // TODO: move to the start point of the task
TaskTrackerPlugin.mainConfig.scenarioConfig?.let { scenarioConf ->
scenarioConf.scenario.getNextStep()?.let { scenarioStep ->
with(ScenarioHandler(TaskTrackerPlugin.mainConfig)) {
scenarioStep.run()
}
} ?: logger.warn("Try to init the plugin, but the scenario is empty or invalid")
// scenarioConf.scenario.getNextStep()?.let { scenarioStep ->
// with(ScenarioHandler(TaskTrackerPlugin.mainConfig)) {
// scenarioStep.run()
// }
// } ?: logger.warn("Try to init the plugin, but the scenario is empty or invalid")
} ?: logger.warn("Please, provide a scenario for the plugin behaviour")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ data class Scenario(
@Transient
private val logger: Logger = Logger.getInstance(javaClass)

fun getNextStep(): ScenarioStep? {
@Transient
private var currentStepIterator: Iterator<ScenarioUnit>? = null

private fun getNextStep(): ScenarioStep? {
var isValid: Boolean
var step: ScenarioStep
do {
Expand All @@ -35,6 +38,18 @@ data class Scenario(
return step
}

@Suppress("ReturnCount")
fun getNextUnit(): ScenarioUnit? {
if (currentStepIterator?.hasNext() != true) {
val currentStep = getNextStep() ?: return null
currentStepIterator = currentStep.getUnits().iterator()
if (currentStepIterator?.hasNext() != true) {
return null
}
}
return currentStepIterator?.next()
}

private class QueueSerializer<T>(private val dataSerializer: KSerializer<T>) :
KSerializer<Queue<T>> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package org.jetbrains.research.tasktracker.config.scenario.models
import com.intellij.openapi.project.Project
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import org.jetbrains.research.tasktracker.config.BaseConfig
import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig
import org.jetbrains.research.tasktracker.handler.BaseProjectHandler

@Serializable
data class ScenarioStep(
private val ideConfig: MainIdeConfig?,
val units: List<BaseConfig>,
private val units: List<ScenarioUnit>,
val mode: ScenarioStepMode = ScenarioStepMode.ORDERED
) {

@Transient
private var mainIdeHandler: BaseProjectHandler? = null

Expand All @@ -21,8 +21,9 @@ data class ScenarioStep(
mainIdeHandler?.setup()
}

fun run() {
TODO()
fun getUnits() = when (mode) {
ScenarioStepMode.ORDERED -> units
ScenarioStepMode.SHUFFLED -> units.shuffled()
}

// TODO check if there are any config of specified type in units.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jetbrains.research.tasktracker.config.scenario.models

import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig
import org.jetbrains.research.tasktracker.config.survey.SurveyConfig

@Serializable
sealed interface ScenarioUnit

@Serializable
class TaskListUnit(val tasks: List<Int>) : ScenarioUnit

@Serializable
class TaskUnit(val id: Int) : ScenarioUnit

@Serializable
class IdeSettingUnit(val mainIdeConfig: MainIdeConfig) : ScenarioUnit

@Serializable
class SurveyUnit(val surveyConfig: SurveyConfig) : ScenarioUnit

@Serializable
class ExternalSourceUnit(val url: String) : ScenarioUnit

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jetbrains.research.tasktracker.ui.main.panel

import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig
import org.jetbrains.research.tasktracker.config.scenario.models.*
import org.jetbrains.research.tasktracker.ui.main.panel.models.ButtonState
import org.jetbrains.research.tasktracker.ui.main.panel.models.LinkType
import org.jetbrains.research.tasktracker.util.UIBundle
Expand Down Expand Up @@ -79,3 +81,33 @@ fun saveAgreements(agreementString: String) {
FileUtil.createIfDoesntExist(agreementFile)
agreementFile.writeText(agreementString)
}

fun processScenario() {
val scenario =
TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario ?: error("Unexpected error, Scenario config must exist!")
when (TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario?.getNextUnit()) {
is TaskListUnit -> {
TODO()
}

is TaskUnit -> {
TODO()
}

is IdeSettingUnit -> {
TODO()
}

is SurveyUnit -> {
TODO()
}

is ExternalSourceUnit -> {
TODO()
}

null -> {
TODO()
}
}
}

0 comments on commit cf6bdaa

Please sign in to comment.