Skip to content

Commit 3be8897

Browse files
committed
Represent also derived Properties using PropertyDescription
1 parent e187eeb commit 3be8897

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

core/src/main/kotlin/com/strumenta/kolasu/model/Model.kt

-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ val <T : Any> Class<T>.nodeProperties: Collection<KProperty1<T, *>>
215215
val <T : Any> KClass<T>.nodeProperties: Collection<KProperty1<T, *>>
216216
get() = memberProperties.asSequence()
217217
.filter { it.visibility == KVisibility.PUBLIC }
218-
.filter { it.findAnnotation<Derived>() == null }
219218
.filter { it.findAnnotation<Internal>() == null }
220219
.filter { it.findAnnotation<Link>() == null }
221220
.toList()

core/src/main/kotlin/com/strumenta/kolasu/model/Reflection.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlin.reflect.KClassifier
99
import kotlin.reflect.KProperty1
1010
import kotlin.reflect.KType
1111
import kotlin.reflect.KTypeProjection
12+
import kotlin.reflect.full.findAnnotation
1213
import kotlin.reflect.full.isSubclassOf
1314
import kotlin.reflect.full.withNullability
1415

@@ -51,7 +52,8 @@ data class PropertyDescription(
5152
val provideNodes: Boolean,
5253
val multiplicity: Multiplicity,
5354
val value: Any?,
54-
val propertyType: PropertyType
55+
val propertyType: PropertyType,
56+
val derived: Boolean
5557
) {
5658

5759
fun valueToString(): String {
@@ -119,7 +121,8 @@ data class PropertyDescription(
119121
property.isReference() -> PropertyType.REFERENCE
120122
provideNodes -> PropertyType.CONTAINMENT
121123
else -> PropertyType.ATTRIBUTE
122-
}
124+
},
125+
derived = property.findAnnotation<Derived>() != null
123126
)
124127
}
125128
}

core/src/test/kotlin/com/strumenta/kolasu/model/PropertyDescriptionTest.kt

+12-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class PropertyDescriptionTest {
2525
false,
2626
Multiplicity.SINGULAR,
2727
"gino",
28-
PropertyType.ATTRIBUTE
28+
PropertyType.ATTRIBUTE,
29+
derived = false
2930
),
3031
list[0]
3132
)
@@ -45,7 +46,8 @@ class PropertyDescriptionTest {
4546
false,
4647
Multiplicity.MANY,
4748
listOf("gino", "pino"),
48-
PropertyType.ATTRIBUTE
49+
PropertyType.ATTRIBUTE,
50+
derived = false
4951
),
5052
list[0]
5153
)
@@ -65,7 +67,8 @@ class PropertyDescriptionTest {
6567
true,
6668
Multiplicity.SINGULAR,
6769
Foo1("gino"),
68-
PropertyType.CONTAINMENT
70+
PropertyType.CONTAINMENT,
71+
derived = false
6972
),
7073
list[0]
7174
)
@@ -85,7 +88,8 @@ class PropertyDescriptionTest {
8588
true,
8689
Multiplicity.MANY,
8790
listOf(Foo1("gino")),
88-
PropertyType.CONTAINMENT
91+
PropertyType.CONTAINMENT,
92+
derived = false
8993
),
9094
list[0]
9195
)
@@ -105,7 +109,8 @@ class PropertyDescriptionTest {
105109
true,
106110
Multiplicity.MANY,
107111
emptyList<Foo1>(),
108-
PropertyType.CONTAINMENT
112+
PropertyType.CONTAINMENT,
113+
derived = false
109114
),
110115
list[0]
111116
)
@@ -125,7 +130,8 @@ class PropertyDescriptionTest {
125130
true,
126131
Multiplicity.MANY,
127132
null,
128-
PropertyType.CONTAINMENT
133+
PropertyType.CONTAINMENT,
134+
derived = false
129135
),
130136
list[0]
131137
)

core/src/test/kotlin/com/strumenta/kolasu/serialization/JsonGenerationTest.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -338,28 +338,32 @@ class JsonGenerationTest {
338338
false,
339339
Multiplicity.SINGULAR,
340340
123,
341-
PropertyType.ATTRIBUTE
341+
PropertyType.ATTRIBUTE,
342+
derived = false
342343
),
343344
PropertyDescription(
344345
"someListAttr",
345346
false,
346347
Multiplicity.MANY,
347348
listOf("a", "b"),
348-
PropertyType.ATTRIBUTE
349+
PropertyType.ATTRIBUTE,
350+
derived = false
349351
),
350352
PropertyDescription(
351353
"someChild",
352354
true,
353355
Multiplicity.SINGULAR,
354356
BaseNode(456),
355-
PropertyType.CONTAINMENT
357+
PropertyType.CONTAINMENT,
358+
derived = false
356359
),
357360
PropertyDescription(
358361
"someChildren",
359362
true,
360363
Multiplicity.MANY,
361364
listOf(BaseNode(78), BaseNode(90)),
362-
PropertyType.CONTAINMENT
365+
PropertyType.CONTAINMENT,
366+
derived = false
363367
)
364368
)
365369
)

javalib/src/test/java/com/strumenta/kolasu/javalib/CompilationUnit.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public List<B> getBs() {
2020
@Override
2121
@Internal
2222
public List<PropertyDescription> getProperties() {
23-
return Arrays.asList(new PropertyDescription("bs", true, Multiplicity.MANY, getBs(), PropertyType.CONTAINMENT));
23+
return Arrays.asList(new PropertyDescription("bs", true, Multiplicity.MANY, getBs(), PropertyType.CONTAINMENT, false));
2424
}
2525
}
2626

@@ -38,6 +38,6 @@ public List<A> getAs() {
3838
@Override
3939
@Internal
4040
public List<PropertyDescription> getProperties() {
41-
return Arrays.asList(new PropertyDescription("as", true, Multiplicity.MANY, getAs(), PropertyType.CONTAINMENT));
41+
return Arrays.asList(new PropertyDescription("as", true, Multiplicity.MANY, getAs(), PropertyType.CONTAINMENT, false));
4242
}
4343
}

0 commit comments

Comments
 (0)