Consider replacing `KClass` with custom information class as DSL result
See original GitHub issueThe idea is that WithX.toList
should return not a KClass
, which assumes further runtime reflection, but an information class storing all the information about the class available to Reflekt plus the old KClass
reference.
This is particularly useful to implement #71, because actually KClass
has the sealedSubclasses
property that does that thing; however, this data can be collected at compile time, and it’s helpful in cases where run-time reflection isn’t available or too slow.
Rough API:
class ReflektClass<T> {
val kotlin: KClass<T>
val qualifiledName: String
val simpleName: String
val sealedSubclasses: List<ReflektClass<*>>
val isOpen: Boolean
...
}
Possible usage:
Reflekt.classes().withSuperType<B1>().toList().map { /* it: ReflektClass<B1> */ it.qualifiedName }.forEach { println(it) }
Also, to not bloat the ReflektImpl
file, there must be a registry of such classes to have them available in many DSL calls simultaneously (basically, val classData: HashMap<String, ReflektClass<*>>
).
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:8
Top Results From Across the Web
Chapter 10. Annotations and reflection - Kotlin in Action
Applying and defining annotations; Using reflection to introspect classes at ... Annotations let you customize how specific classes and properties are ...
Read more >How to get Class<java.lang.Long> in Kotlin? - Stack Overflow
Try using KClass 's javaObjectType property instead of java , e.g.: 1L::class.java // returns long 1L::class.
Read more >Practical JFixture - TWiStErRob
Tests need data, let's see how can we create them using JFixture. In this article we'll go through some practical usage patterns of...
Read more >Language Support - Spring
The Spring Framework provides first-class support for Kotlin that allows ... This DSL is programmatic, thus it allows custom registration ...
Read more >Fragment | Android Developers
State information that has been retrieved from a fragment instance ... replacement of setFragmentResultListener and setFragmentResult , consider using ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We use KtObjectDeclaration in lamda bodies to access its fields, next we run KotlinScript. In this case, we would like to use our wrappers and don’t use some internal compiler classes
Next, we should make the same for objects and functions