Expose collected superclass properties/methods in pkl:reflect (#1106)

This commit is contained in:
Jen Basch
2025-09-19 12:23:57 -07:00
committed by GitHub
parent d1171db3d5
commit 63f89fb679
7 changed files with 2997 additions and 16 deletions
@@ -0,0 +1,88 @@
amends ".../snippetTest.pkl"
import "pkl:reflect"
local class MyAnn extends Annotation
open local class A {
inheritedFromA: String
overriddenInBFromA: String
overriddenInCFromA: String
overriddenInBCFromA: String
fixed modA: String = ""
fixed modAOverrideB: String = ""
fixed modAOverrideC: String = ""
fixed modAOverrideBC: String = ""
fixed modAOverrideCB: String = ""
@Unlisted
annA: String
@Unlisted
annAOverrideB: String
@Unlisted
annAOverrideC: String
@Unlisted
annAOverrideBC: String
}
open local class B extends A {
inheritedFromB: String
overriddenInBFromA: Int
overriddenInCFromB: String
overriddenInBCFromA: Int
fixed modB: String = ""
hidden fixed modAOverrideB: Int = 0
hidden fixed modAOverrideBC: Int = 0
fixed modAOverrideCB: Int = 0
@Unlisted
annB: String
@MyAnn
annAOverrideB: String
@MyAnn
annAOverrideBC: String
}
local class C extends B {
fromC: String
overriddenInCFromA: Int
overriddenInCFromB: Int
overriddenInBCFromA: Boolean
fixed modC: String = ""
hidden fixed modAOverrideC: Int = 0
fixed modAOverrideBC: Boolean = false
hidden fixed modAOverrideCB: Boolean = false
@Unlisted
annC: String
@MyAnn
annAOverrideC: String
@AlsoKnownAs { names { "mergedAnnotations" } }
annAOverrideBC: String
}
local class DisplayProperty {
hidden property: reflect.Property
fixed name = property.name
fixed annotations = property.annotations.map((it) -> it.toString()).toListing()
fixed allAnnotations = property.allAnnotations.map((it) -> it.toString()).toListing()
fixed modifiers = property.modifiers.toListing()
fixed allModifiers = property.allModifiers.toListing()
fixed type = property.type.getPropertyOrNull("referent")?.getPropertyOrNull("name") ?? "unknown"
}
examples {
["C"] {
reflect.Class(C).allProperties.mapValues((_, it) -> new DisplayProperty { property = it }).toMapping()
}
["module"] {
new DisplayProperty { property = reflect.Class(module.getClass()).properties["output"] }
}
}
output { // override to test example "module", allModifiers should contain "hidden"
text = super.text + "\n// hello world"
}
@@ -0,0 +1,243 @@
examples {
["C"] {
new {
["inheritedFromA"] {
name = "inheritedFromA"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "String"
}
["overriddenInBFromA"] {
name = "overriddenInBFromA"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "Int"
}
["overriddenInCFromA"] {
name = "overriddenInCFromA"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "Int"
}
["overriddenInBCFromA"] {
name = "overriddenInBCFromA"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "Boolean"
}
["modA"] {
name = "modA"
annotations {}
allAnnotations {}
modifiers {
"fixed"
}
allModifiers {
"fixed"
}
type = "String"
}
["modAOverrideB"] {
name = "modAOverrideB"
annotations {}
allAnnotations {}
modifiers {
"hidden"
"fixed"
}
allModifiers {
"hidden"
"fixed"
}
type = "Int"
}
["modAOverrideC"] {
name = "modAOverrideC"
annotations {}
allAnnotations {}
modifiers {
"hidden"
"fixed"
}
allModifiers {
"hidden"
"fixed"
}
type = "Int"
}
["modAOverrideBC"] {
name = "modAOverrideBC"
annotations {}
allAnnotations {}
modifiers {
"fixed"
}
allModifiers {
"hidden"
"fixed"
}
type = "Boolean"
}
["modAOverrideCB"] {
name = "modAOverrideCB"
annotations {}
allAnnotations {}
modifiers {
"hidden"
"fixed"
}
allModifiers {
"hidden"
"fixed"
}
type = "Boolean"
}
["annA"] {
name = "annA"
annotations {
"new Unlisted {}"
}
allAnnotations {
"new Unlisted {}"
}
modifiers {}
allModifiers {}
type = "String"
}
["annAOverrideB"] {
name = "annAOverrideB"
annotations {
"new MyAnn {}"
}
allAnnotations {
"new MyAnn {}"
"new Unlisted {}"
}
modifiers {}
allModifiers {}
type = "String"
}
["annAOverrideC"] {
name = "annAOverrideC"
annotations {
"new MyAnn {}"
}
allAnnotations {
"new MyAnn {}"
"new Unlisted {}"
}
modifiers {}
allModifiers {}
type = "String"
}
["annAOverrideBC"] {
name = "annAOverrideBC"
annotations {
"new AlsoKnownAs { names { \"mergedAnnotations\" } }"
}
allAnnotations {
"new AlsoKnownAs { names { \"mergedAnnotations\" } }"
"new MyAnn {}"
"new Unlisted {}"
}
modifiers {}
allModifiers {}
type = "String"
}
["inheritedFromB"] {
name = "inheritedFromB"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "String"
}
["overriddenInCFromB"] {
name = "overriddenInCFromB"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "Int"
}
["modB"] {
name = "modB"
annotations {}
allAnnotations {}
modifiers {
"fixed"
}
allModifiers {
"fixed"
}
type = "String"
}
["annB"] {
name = "annB"
annotations {
"new Unlisted {}"
}
allAnnotations {
"new Unlisted {}"
}
modifiers {}
allModifiers {}
type = "String"
}
["fromC"] {
name = "fromC"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {}
type = "String"
}
["modC"] {
name = "modC"
annotations {}
allAnnotations {}
modifiers {
"fixed"
}
allModifiers {
"fixed"
}
type = "String"
}
["annC"] {
name = "annC"
annotations {
"new Unlisted {}"
}
allAnnotations {
"new Unlisted {}"
}
modifiers {}
allModifiers {}
type = "String"
}
}
}
["module"] {
new {
name = "output"
annotations {}
allAnnotations {}
modifiers {}
allModifiers {
"hidden"
}
type = "unknown"
}
}
}
// hello world
File diff suppressed because it is too large Load Diff