Skip to content

Commit 42fba5d

Browse files
committed
refactor: move CONDITION_EVALUATION
1 parent 2b86431 commit 42fba5d

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

common/src/main/kotlin/spp/jetbrains/artifact/model/IfArtifact.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
package spp.jetbrains.artifact.model
1818

1919
import com.intellij.psi.PsiElement
20+
import spp.jetbrains.SourceKey
2021

2122
/**
2223
* Represents if/elif/else control structures.
2324
*/
2425
abstract class IfArtifact(psiElement: PsiElement) : ControlStructureArtifact(psiElement) {
2526

27+
companion object {
28+
private val CONDITION_EVALUATION = SourceKey<Boolean>("CONDITION_EVALUATION")
29+
}
30+
2631
abstract val condition: ArtifactElement?
2732
abstract val thenBranch: ArtifactElement?
2833
abstract val elseBranch: ArtifactElement?
@@ -58,5 +63,27 @@ abstract class IfArtifact(psiElement: PsiElement) : ControlStructureArtifact(psi
5863
}
5964
}
6065

66+
fun setConditionEvaluation(value: Boolean) {
67+
data[CONDITION_EVALUATION] = value
68+
}
69+
70+
fun getConditionEvaluation(): Boolean? {
71+
return getData(CONDITION_EVALUATION)
72+
}
73+
74+
override fun toString(): String {
75+
return buildString {
76+
append("IfArtifact(conditionEvaluation=")
77+
append(getConditionEvaluation())
78+
append(", condition=")
79+
append(condition)
80+
append(", thenBranch=")
81+
append(thenBranch)
82+
append(", elseBranch=")
83+
append(elseBranch)
84+
append(")")
85+
}
86+
}
87+
6188
abstract override fun clone(): IfArtifact
6289
}

insight/src/main/kotlin/spp/jetbrains/insight/InsightKeys.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ object InsightKeys {
3434
val PATH_EXECUTION_PROBABILITY = SourceKey<InsightValue<Double>>(InsightType.PATH_EXECUTION_PROBABILITY.name)
3535
val PATH_DURATION = SourceKey<InsightValue<Double>>(InsightType.PATH_DURATION.name)
3636
val RECURSIVE_CALL = SourceKey<InsightValue<Boolean>>(InsightType.RECURSIVE_CALL.name)
37-
val CONDITION_EVALUATION = SourceKey<Boolean>("CONDITION_EVALUATION")
3837

3938
val ALL_INSIGHTS: List<SourceKey<out InsightValue<out Any>>> = listOf(
4039
FUNCTION_DURATION,

insight/src/main/kotlin/spp/jetbrains/insight/ProceduralAnalyzer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ProceduralAnalyzer {
118118

119119
if (artifactElement is IfArtifact) {
120120
val bool = boolIterator.next()
121-
artifactElement.data[InsightKeys.CONDITION_EVALUATION] = bool
121+
artifactElement.setConditionEvaluation(bool)
122122

123123
if (bool) {
124124
val childArtifacts = processArtifacts[index + 1] as List<Any>

insight/src/main/kotlin/spp/jetbrains/insight/pass/artifact/RandomConditionalPass.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RandomConditionalPass : ArtifactPass {
6363
else -> 0.0
6464
}.let { if (it > 1.0) 1.0 else if (it < 0.0) 0.0 else it }
6565

66-
val conditionEvaluation = ifArtifact.getData(InsightKeys.CONDITION_EVALUATION)!!
66+
val conditionEvaluation = ifArtifact.getConditionEvaluation()!!
6767
if (conditionEvaluation) {
6868
ifArtifact.data[InsightKeys.CONTROL_STRUCTURE_PROBABILITY] =
6969
InsightValue(InsightType.CONTROL_STRUCTURE_PROBABILITY, probability)

insight/src/main/kotlin/spp/jetbrains/insight/pass/multipath/StaticDfaMultiPathPass.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class StaticDfaMultiPathPass : ProceduralMultiPathPass {
6969
if (it is IfArtifact) {
7070
if (it.condition?.psiElement == expression) {
7171
val probability = if (value == ConstantValue.TRUE) 1.0 else 0.0
72-
val conditionEvaluation = it.getData(InsightKeys.CONDITION_EVALUATION)!!
72+
val conditionEvaluation = it.getConditionEvaluation()!!
7373
if (conditionEvaluation) {
7474
it.data[InsightKeys.CONTROL_STRUCTURE_PROBABILITY] =
7575
InsightValue(InsightType.CONTROL_STRUCTURE_PROBABILITY, probability)
@@ -90,7 +90,7 @@ class StaticDfaMultiPathPass : ProceduralMultiPathPass {
9090
if (it is IfArtifact) {
9191
if (it.condition?.psiElement == expression) {
9292
val probability = if (value == ConstantValue.TRUE) 1.0 else 0.0
93-
val conditionEvaluation = it.getData(InsightKeys.CONDITION_EVALUATION)!!
93+
val conditionEvaluation = it.getConditionEvaluation()!!
9494
if (conditionEvaluation) {
9595
it.data[InsightKeys.CONTROL_STRUCTURE_PROBABILITY] =
9696
InsightValue(InsightType.CONTROL_STRUCTURE_PROBABILITY, probability)

insight/src/main/kotlin/spp/jetbrains/insight/pass/path/PathProbabilityPass.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PathProbabilityPass : ProceduralPathPass {
3939
InsightValue.of(PATH_EXECUTION_PROBABILITY, 1.0)
4040

4141
if (it is IfArtifact) {
42-
analyze(it, it.getData(InsightKeys.CONDITION_EVALUATION)!!, 1.0)
42+
analyze(it, it.getConditionEvaluation()!!, 1.0)
4343
}
4444
}
4545
}
@@ -51,7 +51,7 @@ class PathProbabilityPass : ProceduralPathPass {
5151
InsightValue.of(PATH_EXECUTION_PROBABILITY, probability)
5252

5353
if (it is IfArtifact) {
54-
analyze(it, it.getData(InsightKeys.CONDITION_EVALUATION)!!, probability)
54+
analyze(it, it.getConditionEvaluation()!!, probability)
5555
}
5656
}
5757
}

insight/src/main/kotlin/spp/jetbrains/insight/path/ProceduralPath.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import spp.jetbrains.artifact.model.ArtifactElement
2020
import spp.jetbrains.artifact.model.CallArtifact
2121
import spp.jetbrains.artifact.model.FunctionArtifact
2222
import spp.jetbrains.artifact.model.IfArtifact
23-
import spp.jetbrains.insight.InsightKeys
2423
import spp.protocol.insight.InsightValue
2524

2625
/**
@@ -46,7 +45,7 @@ data class ProceduralPath(
4645
val conditionals = descendants.filterIsInstance<IfArtifact>()
4746
val conditions = mutableListOf<Pair<Boolean, IfArtifact>>()
4847
for (i in conditionals.indices) {
49-
conditions.add(Pair(conditionals[i].getData(InsightKeys.CONDITION_EVALUATION)!!, conditionals[i]))
48+
conditions.add(Pair(conditionals[i].getConditionEvaluation()!!, conditionals[i]))
5049
}
5150
return conditions
5251
}

0 commit comments

Comments
 (0)