https://kotlinlang.org logo
Title
v

Vladimir Tagakov

08/03/2022, 7:10 AM
//Module A
public class MyJavaClass {
  public @interface MyAnnotation {}
}

//Module B with KSP Processor
class MyKotlinClass(@MyJavaClass.MyAnnotation val myProp: Any)
Hi! In my KSP Processor I’m trying to resolve
KSTypeReference
of annotation type
MyJavaClass.MyAnnotation
which I face during analysis of `MyKotlinClass`’s constructor and for some reason it could not be resolved (
KSType#isError
returns true). If I move
MyAnnotation
to the top-level everything works fine. I am not sure how I can debug this issue, any ideas? =\
cc: @Jiaxiang
At the same time if I try to get nested class via
resolver.getClassDeclarationByName
by its FQCN everything works just fine, so I think it means that theoretically it could be resolved
j

Jiaxiang

08/03/2022, 5:23 PM
sorry can you clarify your issue? It looks like in your snippet
MyAnnotation
is already at top level? Do you mean you are not able to resolve the type when the annotation is on the constructor parameter?
v

Vladimir Tagakov

08/03/2022, 5:56 PM
I am not able to resolve the type of annotation when it is being declared as a nested class. In the snippet above
MyAnnotation
is declared inside
MyJavaClass
. So it’s canonical name is
MyJavaClass$MyAnnotation
. When I declare
MyAnnotation
at the top-level, so its canonical name becomes just
MyAnnotation
(assuming I am using default empty package there) it could be resolved just fine.
j

Jiaxiang

08/03/2022, 6:28 PM
could be a known issue: https://github.com/google/ksp/issues/1034 which only happens with 1.7.0, can you try 1.6.21 to see if this issue goes away?
v

Vladimir Tagakov

08/03/2022, 6:44 PM
Yeah, sorry for not specifying the version, I’m on
1.6.21-1.0.5
updating :loading:
Nope, didn’t help =(
@Jiaxiang update, the same thing happens when nested annotation comes from kotlin file, so it looks like it has nothing to do with java 😞
j

Jiaxiang

08/04/2022, 7:01 PM
Thanks for the update. I’ll need another look then.