google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.85k stars 268 forks source link

classes that inherit abstract classes w/ annotations always report validate() == false #912

Open TwoClocks opened 2 years ago

TwoClocks commented 2 years ago

In this case, all the annotations are on functions, but I want to generate one extension function per class that contains a function with an annotation. Ideally, the extension includes all the annotations for any implemented abstract classes.

A simple example:

abstract class Child {
  @MyAnno
  fun one() {...}
 ... other stuff ...
}

class Adult : Child {
  @MyAnno
  fun two() {...}
 ... other stuff ...
}

so for each annotation, I find out what class it's in via .parent. Then for each unique parent I generate my extension function by calling .getAllFunctions() and filtering by the @MyAnno annotation.

Two things I see that seem odd to me. 1 - .validate() on the Adult class always returns False. Even if I push it to the next round. 2 - When I iterate over the functions, the ones from the super class (fun one() in this case) always have parent and containingFile set to null

Is this expected? Am I using the library correctly?

micheljung commented 1 year ago

I have a similar issue:

@Mapper
interface PersonToPersonDtoMapper : Converter<Person, PersonDto>

This inherits the method Converter.convert(). While the function's parent is set to PersonToPersonDtoMapper, node.parent.containingFile unexpectedly returns null and node.parent.location is a NonExistLocation.