diff --git a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt index 479572bc47b..9e092b60d5a 100644 --- a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt +++ b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt @@ -59,26 +59,28 @@ abstract class AbstractKotlinKapt3Test : CodegenTestCase() { val kaptContext = KaptContext(logger, classBuilderFactory.compiledClasses, classBuilderFactory.origins, processorOptions = emptyMap()) try { - check(kaptContext, typeMapper, txtFile) + check(kaptContext, typeMapper, txtFile, wholeFile) } finally { kaptContext.close() } } - protected fun convert(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper): JavacList { - val converter = ClassFileToSourceStubConverter(kaptRunner, typeMapper, generateNonExistentClass = false) + protected fun convert(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, generateNonExistentClass: Boolean): JavacList { + val converter = ClassFileToSourceStubConverter(kaptRunner, typeMapper, generateNonExistentClass) return converter.convert() } protected abstract fun check( kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, - txtFile: File) + txtFile: File, + wholeFile: File) } abstract class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test() { - override fun check(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, txtFile: File) { - val javaFiles = convert(kaptRunner, typeMapper) + override fun check(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, txtFile: File, wholeFile: File) { + val generateNonExistentClass = wholeFile.useLines { lines -> lines.any { it.trim() == "// NON_EXISTENT_CLASS" } } + val javaFiles = convert(kaptRunner, typeMapper, generateNonExistentClass) kaptRunner.compiler.enterTrees(javaFiles) val actualRaw = javaFiles.joinToString (FILE_SEPARATOR) @@ -93,8 +95,8 @@ abstract class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3T } abstract class AbstractKotlinKaptContextTest : AbstractKotlinKapt3Test() { - override fun check(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, txtFile: File) { - val compilationUnits = convert(kaptRunner, typeMapper) + override fun check(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, txtFile: File, wholeFile: File) { + val compilationUnits = convert(kaptRunner, typeMapper, generateNonExistentClass = false) val sourceOutputDir = Files.createTempDirectory("kaptRunner").toFile() try { kaptRunner.doAnnotationProcessing(emptyList(), listOf(JavaKaptContextTest.simpleProcessor()), diff --git a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index 4c2278199e1..789a1c63ef7 100644 --- a/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -120,6 +120,18 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi doTest(fileName); } + @TestMetadata("nonExistentClass.kt") + public void testNonExistentClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/nonExistentClass.kt"); + doTest(fileName); + } + + @TestMetadata("primitiveTypes.kt") + public void testPrimitiveTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/primitiveTypes.kt"); + doTest(fileName); + } + @TestMetadata("strangeNames.kt") public void testStrangeNames() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/strangeNames.kt"); diff --git a/plugins/kapt3/testData/converter/nonExistentClass.kt b/plugins/kapt3/testData/converter/nonExistentClass.kt new file mode 100644 index 00000000000..d1686384cf9 --- /dev/null +++ b/plugins/kapt3/testData/converter/nonExistentClass.kt @@ -0,0 +1,12 @@ +// NON_EXISTENT_CLASS + +@Suppress("UNRESOLVED_REFERENCE") +object NonExistentType { + val a: ABCDEF? = null + val b: List? = null + val c: (ABCDEF) -> Unit = { f -> } + val d: ABCDEF) -> Unit>? = null + + fun a(a: ABCDEF, s: String): ABCDEF {} + fun b(s: String): ABCDEF {} +} \ No newline at end of file diff --git a/plugins/kapt3/testData/converter/nonExistentClass.txt b/plugins/kapt3/testData/converter/nonExistentClass.txt new file mode 100644 index 00000000000..a89090fefb1 --- /dev/null +++ b/plugins/kapt3/testData/converter/nonExistentClass.txt @@ -0,0 +1,47 @@ +@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"}) +public final class NonExistentType { + private static final error.NonExistentClass a = null; + private static final java.util.List b = null; + private static final kotlin.jvm.functions.Function1 c = null; + private static final error.NonExistentClass d = null; + public static final NonExistentType INSTANCE = null; + + public final error.NonExistentClass getA() { + return null; + } + + public final java.util.List getB() { + return null; + } + + public final kotlin.jvm.functions.Function1 getC() { + return null; + } + + public final error.NonExistentClass getD() { + return null; + } + + public final error.NonExistentClass a(error.NonExistentClass a, java.lang.String s) { + return null; + } + + public final error.NonExistentClass b(java.lang.String s) { + return null; + } + + private NonExistentType() { + super(); + } +} + +//////////////////// + +package error; + +public final class NonExistentClass { + + public NonExistentClass() { + super(); + } +} diff --git a/plugins/kapt3/testData/converter/primitiveTypes.kt b/plugins/kapt3/testData/converter/primitiveTypes.kt new file mode 100644 index 00000000000..f6db55e43b5 --- /dev/null +++ b/plugins/kapt3/testData/converter/primitiveTypes.kt @@ -0,0 +1,41 @@ +object PrimitiveTypes { + const val booleanFalse: Boolean = false + const val booleanTrue: Boolean = true + + const val int0: Int = 0 + const val intMinus1000: Int = -1000 + const val intMinValue: Int = Int.MIN_VALUE + const val intMaxValue: Int = Int.MAX_VALUE + const val intHex: Int = 0xffffffff.toInt() + + const val byte0: Byte = 0.toByte() + const val byte50: Byte = 50.toByte() + + const val short5: Short = 5.toShort() + + const val charC: Char = 'C' + const val char0: Char = 0.toChar() + const val char10: Char = 10.toChar() + const val char13: Char = 13.toChar() + + const val long0: Long = 0L + const val longMaxValue: Long = Long.MAX_VALUE + const val longMinValue: Long = Long.MIN_VALUE + const val longHex: Long = 0xffffffff + + const val float54 = 5.4f + val floatMaxValue = Float.MAX_VALUE + val floatNan = Float.NaN + val floatPositiveInfinity = Float.POSITIVE_INFINITY + val floatNegativeInfinity = Float.NEGATIVE_INFINITY + + const val double54 = 5.4 + val doubleMaxValue = Double.MAX_VALUE + val doubleNan = Double.NaN + val doublePositiveInfinity = Double.POSITIVE_INFINITY + val doubleNegativeInfinity = Double.NEGATIVE_INFINITY + + const val stringHelloWorld: String = "Hello, world!" + const val stringQuotes: String = "quotes \" ''quotes" + const val stringRN: String = "\r\n" +} diff --git a/plugins/kapt3/testData/converter/primitiveTypes.txt b/plugins/kapt3/testData/converter/primitiveTypes.txt new file mode 100644 index 00000000000..9ed3cd231e3 --- /dev/null +++ b/plugins/kapt3/testData/converter/primitiveTypes.txt @@ -0,0 +1,70 @@ +public final class PrimitiveTypes { + public static final boolean booleanFalse = false; + public static final boolean booleanTrue = true; + public static final int int0 = 0; + public static final int intMinus1000 = -1000; + public static final int intMinValue = -2147483648; + public static final int intMaxValue = 2147483647; + public static final int intHex = -1; + public static final byte byte0 = "0"; + public static final byte byte50 = "50"; + public static final short short5 = "5"; + public static final char charC = 'C'; + public static final char char0 = '\u0000'; + public static final char char10 = '\n'; + public static final char char13 = '\r'; + public static final long long0 = 0L; + public static final long longMaxValue = 9223372036854775807L; + public static final long longMinValue = -9223372036854775808L; + public static final long longHex = 4294967295L; + public static final float float54 = 5.4F; + private static final float floatMaxValue = 0.0F; + private static final float floatNan = 0.0F; + private static final float floatPositiveInfinity = 0.0F; + private static final float floatNegativeInfinity = 0.0F; + public static final double double54 = 5.4; + private static final double doubleMaxValue = 0.0; + private static final double doubleNan = 0.0; + private static final double doublePositiveInfinity = 0.0; + private static final double doubleNegativeInfinity = 0.0; + public static final java.lang.String stringHelloWorld = "Hello, world!"; + public static final java.lang.String stringQuotes = "quotes \" \'\'quotes"; + public static final java.lang.String stringRN = "\r\n"; + public static final PrimitiveTypes INSTANCE = null; + + public final float getFloatMaxValue() { + return 0.0F; + } + + public final float getFloatNan() { + return 0.0F; + } + + public final float getFloatPositiveInfinity() { + return 0.0F; + } + + public final float getFloatNegativeInfinity() { + return 0.0F; + } + + public final double getDoubleMaxValue() { + return 0.0; + } + + public final double getDoubleNan() { + return 0.0; + } + + public final double getDoublePositiveInfinity() { + return 0.0; + } + + public final double getDoubleNegativeInfinity() { + return 0.0; + } + + private PrimitiveTypes() { + super(); + } +}