Skip to content

Commit

Permalink
[ML4SE-239] Repeat scenario.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 committed Dec 1, 2023
1 parent 198e46f commit 4adfd79
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ data class Scenario(
@Transient
private val logger: Logger = Logger.getInstance(javaClass)

@Transient
private var currentSteps = LinkedList(steps)

@Transient
private var currentStepIterator: Iterator<ScenarioUnit>? = null

private fun getNextStep(): ScenarioStep? {
var isValid: Boolean
var step: ScenarioStep
do {
if (steps.isEmpty()) {
if (currentSteps.isEmpty()) {
logger.warn("No steps found!")
return null
}

step = steps.poll()
step = currentSteps.poll()
isValid = step.isValid()
if (!isValid) {
logger.warn("Found useless step, all configs are null. Skip it")
Expand All @@ -42,21 +45,23 @@ data class Scenario(

@Suppress("ReturnCount")
fun getNextUnit(project: Project): ScenarioUnit? {
if (!currentStepIterator.notNullAndHasNext()) {
return null
}
cleanStepSettings()
val currentStep = getNextStep() ?: return null
currentStep.prepareSettings(project)
currentStepIterator = currentStep.getUnits().iterator()
return if (currentStepIterator.notNullAndHasNext()) {
currentStepIterator?.next()
} else {
null
if (currentStepIterator.notNullAndHasNext()) {
cleanStepSettings()
val currentStep = getNextStep() ?: return null
currentStep.prepareSettings(project)
currentStepIterator = currentStep.getUnits().iterator()
if (currentStepIterator.notNullAndHasNext()) {
return null
}
}
return currentStepIterator?.next()
}

fun reset() {
currentSteps = LinkedList(steps)
}

private fun Iterator<ScenarioUnit>?.notNullAndHasNext() = this?.hasNext() ?: false
private fun Iterator<ScenarioUnit>?.notNullAndHasNext() = this?.hasNext() != true

private fun cleanStepSettings() =
MainPanelStorage.activeIdeHandlers.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun Panel.agreementAcceptance() {
* Switches the panel to the plugin description window.
*/
fun Panel.welcomePage() {
loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", true)
loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", false)
setNextAction {
processScenario()
}
Expand Down Expand Up @@ -122,7 +122,7 @@ fun Panel.serverErrorPage() {
}

fun Panel.finalPage() {
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome")
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome", false)
setNextAction {
welcomePage()
}
Expand Down Expand Up @@ -162,6 +162,7 @@ fun Panel.processScenario() {
}

null -> {
scenario.reset()
finalPage()
}
}
Expand Down

0 comments on commit 4adfd79

Please sign in to comment.