From 7a5f94129c473ae6edbeef7342de384861181e94 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 17 Feb 2017 16:15:02 +0300 Subject: [PATCH] Add ClassBuilderMode.KAPT3 tests --- compiler/testData/codegen/kapt/dataClass.kt | 1 + compiler/testData/codegen/kapt/dataClass.txt | 15 ++++ compiler/testData/codegen/kapt/errorTypes.kt | 4 + compiler/testData/codegen/kapt/errorTypes.txt | 7 ++ .../testData/codegen/kapt/innerClasses.kt | 26 ++++++ .../testData/codegen/kapt/innerClasses.txt | 52 ++++++++++++ .../testData/codegen/kapt/interfaceImpls.kt | 8 ++ .../testData/codegen/kapt/interfaceImpls.txt | 17 ++++ .../testData/codegen/kapt/jvmOverloads.kt | 6 ++ .../testData/codegen/kapt/jvmOverloads.txt | 9 +++ compiler/testData/codegen/kapt/lambdas.kt | 5 ++ compiler/testData/codegen/kapt/lambdas.txt | 5 ++ compiler/testData/codegen/kapt/simple.kt | 1 + compiler/testData/codegen/kapt/simple.txt | 4 + ...stractKapt3BuilderModeBytecodeShapeTest.kt | 46 +++++++++++ ...BuilderModeBytecodeShapeTestGenerated.java | 80 +++++++++++++++++++ .../kotlin/generators/tests/GenerateTests.kt | 4 + 17 files changed, 290 insertions(+) create mode 100644 compiler/testData/codegen/kapt/dataClass.kt create mode 100644 compiler/testData/codegen/kapt/dataClass.txt create mode 100644 compiler/testData/codegen/kapt/errorTypes.kt create mode 100644 compiler/testData/codegen/kapt/errorTypes.txt create mode 100644 compiler/testData/codegen/kapt/innerClasses.kt create mode 100644 compiler/testData/codegen/kapt/innerClasses.txt create mode 100644 compiler/testData/codegen/kapt/interfaceImpls.kt create mode 100644 compiler/testData/codegen/kapt/interfaceImpls.txt create mode 100644 compiler/testData/codegen/kapt/jvmOverloads.kt create mode 100644 compiler/testData/codegen/kapt/jvmOverloads.txt create mode 100644 compiler/testData/codegen/kapt/lambdas.kt create mode 100644 compiler/testData/codegen/kapt/lambdas.txt create mode 100644 compiler/testData/codegen/kapt/simple.kt create mode 100644 compiler/testData/codegen/kapt/simple.txt create mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/AbstractKapt3BuilderModeBytecodeShapeTest.kt create mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/Kapt3BuilderModeBytecodeShapeTestGenerated.java diff --git a/compiler/testData/codegen/kapt/dataClass.kt b/compiler/testData/codegen/kapt/dataClass.kt new file mode 100644 index 00000000000..75ba4c11e57 --- /dev/null +++ b/compiler/testData/codegen/kapt/dataClass.kt @@ -0,0 +1 @@ +data class User(val name: String, val age: Int) \ No newline at end of file diff --git a/compiler/testData/codegen/kapt/dataClass.txt b/compiler/testData/codegen/kapt/dataClass.txt new file mode 100644 index 00000000000..f7f0553904f --- /dev/null +++ b/compiler/testData/codegen/kapt/dataClass.txt @@ -0,0 +1,15 @@ +@kotlin.Metadata +public final class User { + private final field age: int + private final @org.jetbrains.annotations.NotNull field name: java.lang.String + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: int): void + public final @org.jetbrains.annotations.NotNull method component1(): java.lang.String + public final method component2(): int + public synthetic static @org.jetbrains.annotations.NotNull method copy$default(p0: User, p1: java.lang.String, p2: int, p3: int, p4: java.lang.Object): User + public final @org.jetbrains.annotations.NotNull method copy(@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: int): User + public method equals(p0: java.lang.Object): boolean + public final method getAge(): int + public final @org.jetbrains.annotations.NotNull method getName(): java.lang.String + public method hashCode(): int + public method toString(): java.lang.String +} diff --git a/compiler/testData/codegen/kapt/errorTypes.kt b/compiler/testData/codegen/kapt/errorTypes.kt new file mode 100644 index 00000000000..4cdc751f02b --- /dev/null +++ b/compiler/testData/codegen/kapt/errorTypes.kt @@ -0,0 +1,4 @@ +@Suppress("UNRESOLVED_REFERENCE") +class A { + val a: ABC = null +} \ No newline at end of file diff --git a/compiler/testData/codegen/kapt/errorTypes.txt b/compiler/testData/codegen/kapt/errorTypes.txt new file mode 100644 index 00000000000..4c520aed8a4 --- /dev/null +++ b/compiler/testData/codegen/kapt/errorTypes.txt @@ -0,0 +1,7 @@ +@kotlin.Metadata +@kotlin.Suppress +public final class A { + private final @org.jetbrains.annotations.NotNull field a: error.NonExistentClass + public method (): void + public final @org.jetbrains.annotations.NotNull method getA(): error.NonExistentClass +} diff --git a/compiler/testData/codegen/kapt/innerClasses.kt b/compiler/testData/codegen/kapt/innerClasses.kt new file mode 100644 index 00000000000..3d29236fb71 --- /dev/null +++ b/compiler/testData/codegen/kapt/innerClasses.kt @@ -0,0 +1,26 @@ +// WITH_RUNTIME + +package test + +class TopLevel { + companion object { + fun a() {} + + @JvmStatic + val q = "A" + } + + fun b() {} + + val x: String + + val y = 5 + + class NestedClass { + inner class NestedInnerClass + } + + object InnerObject + + interface InnerInterface +} \ No newline at end of file diff --git a/compiler/testData/codegen/kapt/innerClasses.txt b/compiler/testData/codegen/kapt/innerClasses.txt new file mode 100644 index 00000000000..67452ed0579 --- /dev/null +++ b/compiler/testData/codegen/kapt/innerClasses.txt @@ -0,0 +1,52 @@ +@kotlin.Metadata +public final class test/TopLevel { + public final static field Companion: test.TopLevel.Companion + private final static @org.jetbrains.annotations.NotNull field q: java.lang.String + private final @org.jetbrains.annotations.NotNull field x: java.lang.String + private final field y: int + inner class test/TopLevel/Companion + inner class test/TopLevel/InnerInterface + inner class test/TopLevel/InnerObject + inner class test/TopLevel/NestedClass + public method (): void + public final method b(): void + public final static @org.jetbrains.annotations.NotNull method getQ(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getX(): java.lang.String + public final method getY(): int +} + +@kotlin.Metadata +public final class test/TopLevel/Companion { + inner class test/TopLevel/Companion + private method (): void + public final method a(): void + public final @org.jetbrains.annotations.NotNull method getQ(): java.lang.String + public synthetic deprecated static @kotlin.jvm.JvmStatic method q$annotations(): void +} + +@kotlin.Metadata +public interface test/TopLevel/InnerInterface { + inner class test/TopLevel/InnerInterface +} + +@kotlin.Metadata +public final class test/TopLevel/InnerObject { + public final static field INSTANCE: test.TopLevel.InnerObject + inner class test/TopLevel/InnerObject + private method (): void +} + +@kotlin.Metadata +public final class test/TopLevel/NestedClass { + inner class test/TopLevel/NestedClass + inner class test/TopLevel/NestedClass/NestedInnerClass + public method (): void +} + +@kotlin.Metadata +public final class test/TopLevel/NestedClass/NestedInnerClass { + synthetic final field this$0: test.TopLevel.NestedClass + inner class test/TopLevel/NestedClass + inner class test/TopLevel/NestedClass/NestedInnerClass + public method (p0: test.TopLevel.NestedClass): void +} diff --git a/compiler/testData/codegen/kapt/interfaceImpls.kt b/compiler/testData/codegen/kapt/interfaceImpls.kt new file mode 100644 index 00000000000..6e4decb0c35 --- /dev/null +++ b/compiler/testData/codegen/kapt/interfaceImpls.kt @@ -0,0 +1,8 @@ +interface A { + fun a() {} + fun b() +} + +interface B { + fun b() +} \ No newline at end of file diff --git a/compiler/testData/codegen/kapt/interfaceImpls.txt b/compiler/testData/codegen/kapt/interfaceImpls.txt new file mode 100644 index 00000000000..f4be136a40a --- /dev/null +++ b/compiler/testData/codegen/kapt/interfaceImpls.txt @@ -0,0 +1,17 @@ +@kotlin.Metadata +public interface A { + inner class A/DefaultImpls + public abstract method a(): void + public abstract method b(): void +} + +@kotlin.Metadata +public final class A/DefaultImpls { + inner class A/DefaultImpls + public static method a(p0: A): void +} + +@kotlin.Metadata +public interface B { + public abstract method b(): void +} diff --git a/compiler/testData/codegen/kapt/jvmOverloads.kt b/compiler/testData/codegen/kapt/jvmOverloads.kt new file mode 100644 index 00000000000..c2a91274f9e --- /dev/null +++ b/compiler/testData/codegen/kapt/jvmOverloads.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME + +class Test { + @JvmOverloads + fun b(s: String = "A", i: Int = 5, c: Char = 'c') {} +} \ No newline at end of file diff --git a/compiler/testData/codegen/kapt/jvmOverloads.txt b/compiler/testData/codegen/kapt/jvmOverloads.txt new file mode 100644 index 00000000000..a057da8c866 --- /dev/null +++ b/compiler/testData/codegen/kapt/jvmOverloads.txt @@ -0,0 +1,9 @@ +@kotlin.Metadata +public final class Test { + public method (): void + public synthetic static @kotlin.jvm.JvmOverloads method b$default(p0: Test, p1: java.lang.String, p2: int, p3: char, p4: int, p5: java.lang.Object): void + public final @kotlin.jvm.JvmOverloads @synthetic.kotlin.jvm.GeneratedByJvmOverloads method b(): void + public final @kotlin.jvm.JvmOverloads @synthetic.kotlin.jvm.GeneratedByJvmOverloads method b(@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final @kotlin.jvm.JvmOverloads @synthetic.kotlin.jvm.GeneratedByJvmOverloads method b(@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: int): void + public final @kotlin.jvm.JvmOverloads method b(@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: int, p2: char): void +} diff --git a/compiler/testData/codegen/kapt/lambdas.kt b/compiler/testData/codegen/kapt/lambdas.kt new file mode 100644 index 00000000000..fa2000dd0e9 --- /dev/null +++ b/compiler/testData/codegen/kapt/lambdas.kt @@ -0,0 +1,5 @@ +fun a() = run { + "" +} + +fun run(block: () -> R): R = block() diff --git a/compiler/testData/codegen/kapt/lambdas.txt b/compiler/testData/codegen/kapt/lambdas.txt new file mode 100644 index 00000000000..c12543c99c7 --- /dev/null +++ b/compiler/testData/codegen/kapt/lambdas.txt @@ -0,0 +1,5 @@ +@kotlin.Metadata +public final class LambdasKt { + public final static @org.jetbrains.annotations.NotNull method a(): java.lang.String + public final static method run(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object +} diff --git a/compiler/testData/codegen/kapt/simple.kt b/compiler/testData/codegen/kapt/simple.kt new file mode 100644 index 00000000000..a6dfbc16ea5 --- /dev/null +++ b/compiler/testData/codegen/kapt/simple.kt @@ -0,0 +1 @@ +class Simple \ No newline at end of file diff --git a/compiler/testData/codegen/kapt/simple.txt b/compiler/testData/codegen/kapt/simple.txt new file mode 100644 index 00000000000..f496652d88b --- /dev/null +++ b/compiler/testData/codegen/kapt/simple.txt @@ -0,0 +1,4 @@ +@kotlin.Metadata +public final class Simple { + public method (): void +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/AbstractKapt3BuilderModeBytecodeShapeTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/AbstractKapt3BuilderModeBytecodeShapeTest.kt new file mode 100644 index 00000000000..435efd7d8f1 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/codegen/AbstractKapt3BuilderModeBytecodeShapeTest.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.codegen + +import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension +import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension +import org.jetbrains.kotlin.test.KotlinTestUtils +import java.io.File + +abstract class AbstractKapt3BuilderModeBytecodeShapeTest : CodegenTestCase() { + private companion object { + var TEST_LIGHT_ANALYSIS: ClassBuilderFactory = object : ClassBuilderFactories.TestClassBuilderFactory(false) { + override fun getClassBuilderMode() = ClassBuilderMode.KAPT3 + } + } + + override fun doMultiFileTest(wholeFile: File, files: MutableList, javaFilesDir: File?) { + val txtFile = File(wholeFile.parentFile, wholeFile.nameWithoutExtension + ".txt") + KotlinTestUtils.assertEqualsToFile(txtFile, compile(files, javaFilesDir)) + } + + private fun compile(files: List, javaFilesDir: File?): String { + val classFileFactory = AbstractBytecodeListingTest.compileClasses( + testRootDisposable, files, javaFilesDir, + TEST_LIGHT_ANALYSIS, + setupEnvironment = { env -> AnalysisHandlerExtension.registerExtension(env.project, PartialAnalysisHandlerExtension()) } + ) + + return BytecodeListingTextCollectingVisitor.getText(classFileFactory) + } + +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/Kapt3BuilderModeBytecodeShapeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/Kapt3BuilderModeBytecodeShapeTestGenerated.java new file mode 100644 index 00000000000..2aa4eaf5fe7 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/codegen/Kapt3BuilderModeBytecodeShapeTestGenerated.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.codegen; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/codegen/kapt") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class Kapt3BuilderModeBytecodeShapeTestGenerated extends AbstractKapt3BuilderModeBytecodeShapeTest { + public void testAllFilesPresentInKapt() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/kapt"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("dataClass.kt") + public void testDataClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/dataClass.kt"); + doTest(fileName); + } + + @TestMetadata("errorTypes.kt") + public void testErrorTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/errorTypes.kt"); + doTest(fileName); + } + + @TestMetadata("innerClasses.kt") + public void testInnerClasses() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/innerClasses.kt"); + doTest(fileName); + } + + @TestMetadata("interfaceImpls.kt") + public void testInterfaceImpls() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/interfaceImpls.kt"); + doTest(fileName); + } + + @TestMetadata("jvmOverloads.kt") + public void testJvmOverloads() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/jvmOverloads.kt"); + doTest(fileName); + } + + @TestMetadata("lambdas.kt") + public void testLambdas() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/lambdas.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/kapt/simple.kt"); + doTest(fileName); + } +} diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 53004e40bd4..a2091ed4ecc 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -242,6 +242,10 @@ fun main(args: Array) { model("codegen/box", targetBackend = TargetBackend.JVM) } + testClass { + model("codegen/kapt", targetBackend = TargetBackend.JVM) + } + testClass("IrOnlyBoxCodegenTestGenerated") { model("ir/box", targetBackend = TargetBackend.JVM) }