File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed
adapter/src/main/kotlin/org/javacs/ktda Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 1
1
package org.javacs.ktda.core.scope
2
2
3
+ import org.javacs.ktda.util.Identifiable
4
+
3
5
/* *
4
6
* A descriptor for a collection of child variables.
5
7
* (usually a scope or a variable's fields)
6
8
*/
7
- interface VariableTreeNode {
9
+ interface VariableTreeNode : Identifiable {
8
10
val name: String
9
11
val value: String?
10
12
get() = null
Original file line number Diff line number Diff line change @@ -11,12 +11,13 @@ import com.sun.jdi.Type
11
11
12
12
class JDIVariable (
13
13
override val name : String ,
14
- jdiValue : Value ? ,
14
+ private val jdiValue : Value ? ,
15
15
jdiType : Type ? = null
16
16
) : VariableTreeNode {
17
17
override val value: String = jdiValue?.toString() ? : " null" // TODO: Better string representation
18
18
override val type: String = (jdiType?.name() ? : jdiValue?.type()?.name()) ? : " Unknown type"
19
19
override val childs: List <VariableTreeNode >? by lazy { jdiValue?.let (::childrenOf) }
20
+ override val id: Long? = (jdiValue as ? ObjectReference )?.uniqueID() ? : (jdiValue as ? ArrayReference )?.uniqueID()
20
21
21
22
private fun childrenOf (jdiValue : Value ): List <VariableTreeNode > {
22
23
val jdiType = jdiValue.type()
Original file line number Diff line number Diff line change
1
+ package org.javacs.ktda.util
2
+
3
+ public interface Identifiable {
4
+ val id: Long?
5
+ get() = null
6
+ }
Original file line number Diff line number Diff line change 1
1
package org.javacs.ktda.util
2
2
3
+ import org.javacs.ktda.util.Identifiable
4
+
3
5
private data class ObjectKey <O >(
4
6
val id : Long ,
5
7
val owner : O
@@ -32,16 +34,14 @@ class ObjectPool<O, V> {
32
34
33
35
/* * Stores an object and returns its (unique) id */
34
36
fun store (owner : O , value : V ): Long {
35
- val id = currentID
37
+ val id = (value as ? Identifiable )?.id ? : nextID()
36
38
val key = ObjectKey (id, owner)
37
39
val mapping = ObjectMapping (key, value)
38
40
39
41
mappingsByID[id] = mapping
40
42
mappingsByOwner.putIfAbsent(owner, mutableSetOf ())
41
43
mappingsByOwner[owner]!! .add(mapping)
42
44
43
- currentID + = 1
44
-
45
45
return id
46
46
}
47
47
@@ -74,4 +74,14 @@ class ObjectPool<O, V> {
74
74
.orEmpty()
75
75
76
76
fun containsID (id : Long ) = mappingsByID.contains(id)
77
+
78
+ private fun nextID (): Long {
79
+ var id = currentID
80
+
81
+ while (containsID(id)) {
82
+ id + = 1
83
+ }
84
+
85
+ return id
86
+ }
77
87
}
You can’t perform that action at this time.
0 commit comments