Kapt3: Support 'processors' option in Gradle plugin (KT-8558)

Also warn if kapt3 options are used without the "apply plugin: 'kotlin-kapt'" specified.
This commit is contained in:
Yan Zhulanow
2017-02-21 19:29:26 +03:00
parent 47ab47d6d1
commit 40fa5fb758
8 changed files with 86 additions and 1 deletions
@@ -6,6 +6,7 @@ import javax.annotation.processing.RoundEnvironment
import javax.lang.model.SourceVersion
import javax.lang.model.element.ElementKind
import javax.lang.model.element.TypeElement
import javax.tools.Diagnostic
import kotlin.reflect.KClass
class ExampleAnnotationProcessor : AbstractProcessor() {
@@ -18,6 +19,7 @@ class ExampleAnnotationProcessor : AbstractProcessor() {
val SUFFIX_OPTION = "suffix"
val GENERATE_KOTLIN_CODE_OPTION = "generate.kotlin.code"
val GENERATE_ERROR = "generate.error"
val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated"
}
@@ -57,11 +59,15 @@ class ExampleAnnotationProcessor : AbstractProcessor() {
}
}
}
if (options[GENERATE_ERROR] == "true") {
processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "Error from annotation processor!")
}
}
override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6
override fun getSupportedAnnotationTypes() = ANNOTATION_TO_PREFIX.keys.map { it.java.canonicalName }.toSet()
override fun getSupportedOptions() = setOf(SUFFIX_OPTION)
override fun getSupportedOptions() = setOf(SUFFIX_OPTION, GENERATE_KOTLIN_CODE_OPTION, GENERATE_ERROR)
}