Kapt3: Add tests for primitive values and NonExistentClass

This commit is contained in:
Yan Zhulanow
2016-11-18 22:17:14 +03:00
committed by Yan Zhulanow
parent 582f85f303
commit de0e4ac340
6 changed files with 192 additions and 8 deletions
@@ -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<JCCompilationUnit> {
val converter = ClassFileToSourceStubConverter(kaptRunner, typeMapper, generateNonExistentClass = false)
protected fun convert(kaptRunner: KaptContext, typeMapper: KotlinTypeMapper, generateNonExistentClass: Boolean): JavacList<JCCompilationUnit> {
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()),
@@ -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");
+12
View File
@@ -0,0 +1,12 @@
// NON_EXISTENT_CLASS
@Suppress("UNRESOLVED_REFERENCE")
object NonExistentType {
val a: ABCDEF? = null
val b: List<ABCDEF>? = null
val c: (ABCDEF) -> Unit = { f -> }
val d: ABCDEF<String, (List<ABCDEF>) -> Unit>? = null
fun a(a: ABCDEF, s: String): ABCDEF {}
fun b(s: String): ABCDEF {}
}
+47
View File
@@ -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<error.NonExistentClass> b = null;
private static final kotlin.jvm.functions.Function1<error.NonExistentClass, kotlin.Unit> 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<error.NonExistentClass> getB() {
return null;
}
public final kotlin.jvm.functions.Function1<error.NonExistentClass, kotlin.Unit> 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();
}
}
+41
View File
@@ -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"
}
+70
View File
@@ -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();
}
}