Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

How Can I use Kapt to append annotation to a field #121

Open
caiqfrog opened this issue Dec 30, 2019 · 0 comments
Open

How Can I use Kapt to append annotation to a field #121

caiqfrog opened this issue Dec 30, 2019 · 0 comments

Comments

@caiqfrog
Copy link

I Use APT to append annotation to a field. When I used in kotlin. It not work.

@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
annotation class Inject(
    val value: String = ""
)

When It annotation on a field, I want to replace it to javax.inject.Inject.
so I extends AbstractProcessor and init context.

override fun init(processingEnv: ProcessingEnvironment) {
  val trees = JavacTrees.instance(processingEnv as JavacProcessingEnvironment)
}

It throws

[ERROR] [kapt] An exception occurred: java.lang.ClassCastException: com.sun.tools.javac.processing.JavacProcessingEnvironment cannot be cast to com.sun.tools.javac.processing.JavacProcessingEnvironment
[ERROR] 	at com.meitu.rec.starter.annotation.processor.InjectProcessor.init(InjectProcessor.kt:73)
[ERROR] 	at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.init(incrementalProcessors.kt:31)
[ERROR] 	at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.init(annotationProcessing.kt:156)
[ERROR] 	at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:500)

I don't know how to solve it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant