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