question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider replacing `KClass` with custom information class as DSL result

See original GitHub issue

The 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:closed
  • Created a year ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
nbirillocommented, May 20, 2022

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

0reactions
nbirillocommented, Jul 11, 2022

Next, we should make the same for objects and functions

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found