@@ -15,8 +15,8 @@ import org.jetbrains.kotlinx.jupyter.exceptions.ReplCompilerException
15
15
import org.jetbrains.kotlinx.jupyter.repl.ContextUpdater
16
16
import org.jetbrains.kotlinx.jupyter.repl.InternalEvalResult
17
17
import org.jetbrains.kotlinx.jupyter.repl.InternalEvaluator
18
- import kotlin. reflect.KMutableProperty1
19
- import kotlin. reflect.KProperty1
18
+ import java.lang. reflect.Field
19
+ import java.lang. reflect.Modifier
20
20
import kotlin.reflect.full.declaredMemberProperties
21
21
import kotlin.script.experimental.api.ResultValue
22
22
import kotlin.script.experimental.api.ResultWithDiagnostics
@@ -159,16 +159,21 @@ internal class InternalEvaluatorImpl(
159
159
val kClass = target.scriptClass ? : return emptyMap()
160
160
val cellClassInstance = target.scriptInstance!!
161
161
162
- val fields = kClass.declaredMemberProperties
162
+ val fields = kClass.java.declaredFields
163
+ // ignore implementation details of top level like script instance and result value
164
+ val memberKPropertiesNames = kClass.declaredMemberProperties.map {
165
+ it.name
166
+ }.toHashSet()
163
167
val ans = mutableMapOf<String , VariableStateImpl >()
164
168
fields.forEach { property ->
165
- @Suppress(" UNCHECKED_CAST" )
166
- property as KProperty1 <Any , * >
169
+ // if (property.name.startsWith("script$")) return@forEach
170
+ if (! memberKPropertiesNames.contains(property.name)) return @forEach
171
+
167
172
val state = VariableStateImpl (property, cellClassInstance)
168
173
variablesWatcher.addDeclaration(cellId, property.name)
169
174
170
175
// it was val, now it's var
171
- if (property is KMutableProperty1 ) {
176
+ if (isValField( property) ) {
172
177
variablesHolder.remove(property.name)
173
178
} else {
174
179
variablesHolder[property.name] = state
@@ -180,6 +185,10 @@ internal class InternalEvaluatorImpl(
180
185
return ans
181
186
}
182
187
188
+ private fun isValField (property : Field ): Boolean {
189
+ return property.modifiers and Modifier .FINAL != 0
190
+ }
191
+
183
192
private fun updateDataAfterExecution (lastExecutionCellId : Int , resultValue : ResultValue ) {
184
193
variablesWatcher.ensureStorageCreation(lastExecutionCellId)
185
194
variablesHolder + = getVisibleVariables(resultValue, lastExecutionCellId)
0 commit comments