0

Can I get Problemes.NO from : Memes(Problemes.NO) during annotations processing somehow?

sealed class Memes(val pr: Problemes) {
    enum class Problemes { NO }
                                                 ↓↓↓
    data class Foo(val moo: String) : Memes(Problemes.NO)
}

Or java:

class Foo extends Memes {
   constructor(String moo) {
       super(Problemes.NO); // <- this bad boy
   }
}

What I tried:

*KotlinPoet metadata dark magic - couldn't find anything related to super type constructor call in it

*Java TreePathScanner with visitExpressionStatement and visitVariable overriden - no results at all

My thoughts:

Source file parsing, but during annotations processing it doesn't look like good idea.

  • For this to be possible, we would have to get the AST (abstract syntax tree) and then analyze it. As far as I know, it is possible to get the AST, but the API is not public, i.e. it could change without notice. – Turing85 Jul 30 '21 at 17:49
  • That's impossible as well as access to parameter [default value via reflection](https://discuss.kotlinlang.org/t/kotlin-reflection-and-default-values/2254), because it may involve _arbitrary expression which can only be represented as a chunk of bytecode_ – Михаил Нафталь Jul 30 '21 at 20:57
  • @МихаилНафталь ya, thought so. Hoped there is a workaround or something – PilotOfSparrow Aug 01 '21 at 04:10
  • @Turing85 Can you give me some links to check this out (repos, docs, etc), please? – PilotOfSparrow Aug 01 '21 at 04:17
  • See https://stackoverflow.com/questions/32664842/how-to-get-kotlin-ast – Михаил Нафталь Aug 01 '21 at 08:57

0 Answers0