Add test checking that JVM_IR is enabled/disabled in kapt
#KT-53135
This commit is contained in:
committed by
Space Team
parent
62f2a09d70
commit
574b9b76cd
+30
@@ -92,6 +92,14 @@ class Kapt3ClassLoadersCacheIT : Kapt3IT() {
|
|||||||
override fun testKt33847(gradleVersion: GradleVersion) {
|
override fun testKt33847(gradleVersion: GradleVersion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled("classloaders cache is leaking file descriptors that prevents cleaning test project")
|
||||||
|
override fun testRepeatableAnnotations(gradleVersion: GradleVersion) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Disabled("classloaders cache is leaking file descriptors that prevents cleaning test project")
|
||||||
|
override fun testRepeatableAnnotationsWithOldJvmBackend(gradleVersion: GradleVersion) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun testAnnotationProcessorAsFqName(gradleVersion: GradleVersion) {
|
override fun testAnnotationProcessorAsFqName(gradleVersion: GradleVersion) {
|
||||||
project("annotationProcessorAsFqName".withPrefix, gradleVersion) {
|
project("annotationProcessorAsFqName".withPrefix, gradleVersion) {
|
||||||
//classloaders caching is not compatible with includeCompileClasspath
|
//classloaders caching is not compatible with includeCompileClasspath
|
||||||
@@ -1036,4 +1044,26 @@ open class Kapt3IT : Kapt3BaseIT() {
|
|||||||
build("assemble")
|
build("assemble")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("KT-53135: check that JVM IR backend is enabled by default by verifying that repeatable annotations are supported")
|
||||||
|
@GradleTest
|
||||||
|
open fun testRepeatableAnnotations(gradleVersion: GradleVersion) {
|
||||||
|
project("repeatableAnnotations".withPrefix, gradleVersion) {
|
||||||
|
build("build") {
|
||||||
|
assertKaptSuccessful()
|
||||||
|
assertTasksExecuted(":kaptGenerateStubsKotlin", ":kaptKotlin", ":compileKotlin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("KT-53135: check that JVM IR backend is disabled if kapt.use.jvm.ir=false is specified in gradle.properties")
|
||||||
|
@GradleTest
|
||||||
|
open fun testRepeatableAnnotationsWithOldJvmBackend(gradleVersion: GradleVersion) {
|
||||||
|
project("repeatableAnnotationsWithOldJvmBackend".withPrefix, gradleVersion) {
|
||||||
|
build("build") {
|
||||||
|
assertKaptSuccessful()
|
||||||
|
assertTasksExecuted(":kaptGenerateStubsKotlin", ":kaptKotlin", ":compileKotlin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id "java"
|
||||||
|
id "org.jetbrains.kotlin.jvm"
|
||||||
|
id "org.jetbrains.kotlin.kapt"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":processor"))
|
||||||
|
kapt(project(":processor"))
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin.kotlinOptions.allWarningsAsErrors = true
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
plugins {
|
||||||
|
id "java"
|
||||||
|
id "org.jetbrains.kotlin.jvm"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin.kotlinOptions.allWarningsAsErrors = true
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import javax.annotation.processing.AbstractProcessor
|
||||||
|
import javax.annotation.processing.RoundEnvironment
|
||||||
|
import javax.lang.model.SourceVersion
|
||||||
|
import javax.lang.model.element.TypeElement
|
||||||
|
import javax.tools.Diagnostic
|
||||||
|
|
||||||
|
class CheckAnnotationIsRepeated : AbstractProcessor() {
|
||||||
|
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
||||||
|
val element = processingEnv.elementUtils.getTypeElement("example.TestClass")
|
||||||
|
val containerAnnotation = element.annotationMirrors.singleOrNull {
|
||||||
|
it.annotationType.asElement().simpleName.contentEquals("Container") &&
|
||||||
|
it.annotationType.asElement().enclosingElement.simpleName.contentEquals("Anno")
|
||||||
|
}
|
||||||
|
if (containerAnnotation == null) {
|
||||||
|
processingEnv.messager.printMessage(
|
||||||
|
Diagnostic.Kind.ERROR,
|
||||||
|
"Repeatable container annotation class example.Anno.Container is not found. " +
|
||||||
|
"The problem is likely in the fact that JVM IR is NOT enabled for kapt stub generation.",
|
||||||
|
element,
|
||||||
|
)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val expected = "{value()={@example.Anno(\"1\"), @example.Anno(\"2\")}}"
|
||||||
|
val actual = containerAnnotation.elementValues.toString()
|
||||||
|
if (actual != expected) {
|
||||||
|
processingEnv.messager.printMessage(
|
||||||
|
Diagnostic.Kind.ERROR,
|
||||||
|
"Repeatable annotation values are incorrect: $actual"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSupportedSourceVersion(): SourceVersion =
|
||||||
|
SourceVersion.RELEASE_6
|
||||||
|
|
||||||
|
override fun getSupportedAnnotationTypes(): Set<String> =
|
||||||
|
setOf("example.ToBeChecked")
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
processor.CheckAnnotationIsRepeated
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
include "processor"
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
annotation class ToBeChecked
|
||||||
|
|
||||||
|
@Repeatable
|
||||||
|
annotation class Anno(val value: String)
|
||||||
|
|
||||||
|
@ToBeChecked
|
||||||
|
@Anno("1")
|
||||||
|
@Anno("2")
|
||||||
|
public class TestClass
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id "java"
|
||||||
|
id "org.jetbrains.kotlin.jvm"
|
||||||
|
id "org.jetbrains.kotlin.kapt"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":processor"))
|
||||||
|
kapt(project(":processor"))
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin.kotlinOptions.allWarningsAsErrors = true
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
kapt.use.jvm.ir=false
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
plugins {
|
||||||
|
id "java"
|
||||||
|
id "org.jetbrains.kotlin.jvm"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin.kotlinOptions.allWarningsAsErrors = true
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import javax.annotation.processing.AbstractProcessor
|
||||||
|
import javax.annotation.processing.RoundEnvironment
|
||||||
|
import javax.lang.model.SourceVersion
|
||||||
|
import javax.lang.model.element.TypeElement
|
||||||
|
import javax.tools.Diagnostic
|
||||||
|
|
||||||
|
class CheckAnnotationIsNotRepeated : AbstractProcessor() {
|
||||||
|
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
||||||
|
val element = processingEnv.elementUtils.getTypeElement("example.TestClass")
|
||||||
|
val containerAnnotation = element.annotationMirrors.singleOrNull {
|
||||||
|
it.annotationType.asElement().simpleName.contentEquals("Container") &&
|
||||||
|
it.annotationType.asElement().enclosingElement.simpleName.contentEquals("Anno")
|
||||||
|
}
|
||||||
|
if (containerAnnotation != null) {
|
||||||
|
processingEnv.messager.printMessage(
|
||||||
|
Diagnostic.Kind.ERROR,
|
||||||
|
"Repeatable container annotation class example.Anno.Container is found. " +
|
||||||
|
"The problem is likely in the fact that JVM IR is NOT DISABLED for kapt stub generation " +
|
||||||
|
"even though kapt.use.jvm.ir=false is specified in gradle.properties.",
|
||||||
|
element,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSupportedSourceVersion(): SourceVersion =
|
||||||
|
SourceVersion.RELEASE_6
|
||||||
|
|
||||||
|
override fun getSupportedAnnotationTypes(): Set<String> =
|
||||||
|
setOf("example.ToBeChecked")
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
processor.CheckAnnotationIsNotRepeated
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
include "processor"
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
annotation class ToBeChecked
|
||||||
|
|
||||||
|
@Repeatable
|
||||||
|
annotation class Anno(val value: String)
|
||||||
|
|
||||||
|
@ToBeChecked
|
||||||
|
@Anno("1")
|
||||||
|
@Anno("2")
|
||||||
|
public class TestClass
|
||||||
Reference in New Issue
Block a user