From bab127ad33fa8483b11176f2a50947ac295f40e9 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 7 Mar 2016 20:57:09 +0300 Subject: [PATCH] Remove some legacy codegen tests, move some to generated --- .../load/kotlin/PackagePartClassUtils.kt | 11 +- .../codegen/box/closures/noRefToOuter.kt | 19 +++ .../controlStructures/continueInWhile.kt} | 8 +- .../box/controlStructures/factorialTest.kt | 44 ++++++ .../codegen/box/delegation/delegationToVal.kt | 46 ++++++ .../codegen/box/enum/classForEnumEntry.kt | 32 ++++ .../codegen/box/enum/modifierFlags.kt | 27 ++++ compiler/testData/codegen/box/enum/name.kt | 6 - .../codegen/box/enum/noClassForSimpleEnum.kt | 14 ++ .../testData/codegen/box/enum/openMethod.kt | 10 -- .../testData/codegen/box/typeMapping/kt309.kt | 12 ++ .../codegen/box/when/exceptionOnNoMatch.kt | 14 ++ .../codegen/box/when/multipleEntries.kt | 12 ++ .../stringOperations/nonNullableStringPlus.kt | 3 + .../stringOperations/nullableStringPlus.kt | 3 + .../codegen/classes/classObjectInterface.kt | 9 -- .../classes/classObjectIsInnerClass.kt | 3 - .../codegen/classes/delegationToVal.kt | 25 --- .../classes/inheritingFromArrayList.kt | 1 - .../classes/newInstanceDefaultConstructor.kt | 8 - .../testData/codegen/classes/simpleClass.kt | 5 - .../codegen/controlStructures/break.kt | 10 -- .../codegen/controlStructures/doWhile.kt | 9 -- .../testData/codegen/controlStructures/for.kt | 9 -- .../codegen/controlStructures/forInArray.kt | 7 - .../testData/codegen/controlStructures/if.kt | 1 - .../codegen/controlStructures/ifBlock.kt | 10 -- .../codegen/controlStructures/ifNoElse.kt | 5 - .../controlStructures/singleBranchIf.kt | 4 - .../codegen/controlStructures/tryCatch.kt | 9 -- .../codegen/controlStructures/tryFinally.kt | 9 -- .../codegen/controlStructures/while.kt | 9 -- compiler/testData/codegen/enum/name.kt | 6 - compiler/testData/codegen/enum/openMethod.kt | 10 -- compiler/testData/codegen/enum/simple.kt | 12 -- compiler/testData/codegen/junit/kt1592.kt | 3 - compiler/testData/codegen/junit/kt2344.kt | 12 -- .../codegen/patternMatching/constant.kt | 4 - .../patternMatching/exceptionOnNoMatch.kt | 4 - .../codegen/patternMatching/inrange.kt | 9 -- .../codegen/patternMatching/pattern.kt | 4 - .../codegen/patternMatching/rangeChar.kt | 4 - .../testData/codegen/regressions/kt1213.kt | 11 -- .../testData/codegen/regressions/kt297.kt | 4 - .../testData/codegen/regressions/kt799.kt | 8 - .../kotlin/codegen/AnnotationGenTest.java | 41 ++--- .../codegen/BlackBoxCodegenTestGenerated.java | 75 +++++++-- .../codegen/BytecodeTextTestGenerated.java | 12 ++ .../kotlin/codegen/ClassGenTest.java | 148 ------------------ .../kotlin/codegen/CodegenTestCase.java | 6 - .../kotlin/codegen/ControlStructuresTest.java | 97 ------------ .../jetbrains/kotlin/codegen/EnumGenTest.java | 91 ----------- .../kotlin/codegen/FunctionGenTest.java | 57 ------- .../kotlin/codegen/JUnitUsageGenTest.java | 69 -------- .../kotlin/codegen/PatternMatchingTest.java | 104 ------------ .../kotlin/codegen/PrimitiveTypesTest.java | 2 +- .../kotlin/codegen/PropertyGenTest.java | 2 +- .../jetbrains/kotlin/codegen/StringsTest.java | 67 -------- 58 files changed, 326 insertions(+), 930 deletions(-) create mode 100644 compiler/testData/codegen/box/closures/noRefToOuter.kt rename compiler/testData/codegen/{controlStructures/continue.kt => box/controlStructures/continueInWhile.kt} (55%) create mode 100644 compiler/testData/codegen/box/controlStructures/factorialTest.kt create mode 100644 compiler/testData/codegen/box/delegation/delegationToVal.kt create mode 100644 compiler/testData/codegen/box/enum/classForEnumEntry.kt create mode 100644 compiler/testData/codegen/box/enum/modifierFlags.kt delete mode 100644 compiler/testData/codegen/box/enum/name.kt create mode 100644 compiler/testData/codegen/box/enum/noClassForSimpleEnum.kt delete mode 100644 compiler/testData/codegen/box/enum/openMethod.kt create mode 100644 compiler/testData/codegen/box/typeMapping/kt309.kt create mode 100644 compiler/testData/codegen/box/when/exceptionOnNoMatch.kt create mode 100644 compiler/testData/codegen/box/when/multipleEntries.kt create mode 100644 compiler/testData/codegen/bytecodeText/stringOperations/nonNullableStringPlus.kt create mode 100644 compiler/testData/codegen/bytecodeText/stringOperations/nullableStringPlus.kt delete mode 100644 compiler/testData/codegen/classes/classObjectInterface.kt delete mode 100644 compiler/testData/codegen/classes/classObjectIsInnerClass.kt delete mode 100644 compiler/testData/codegen/classes/delegationToVal.kt delete mode 100644 compiler/testData/codegen/classes/inheritingFromArrayList.kt delete mode 100644 compiler/testData/codegen/classes/newInstanceDefaultConstructor.kt delete mode 100644 compiler/testData/codegen/classes/simpleClass.kt delete mode 100644 compiler/testData/codegen/controlStructures/break.kt delete mode 100644 compiler/testData/codegen/controlStructures/doWhile.kt delete mode 100644 compiler/testData/codegen/controlStructures/for.kt delete mode 100644 compiler/testData/codegen/controlStructures/forInArray.kt delete mode 100644 compiler/testData/codegen/controlStructures/if.kt delete mode 100644 compiler/testData/codegen/controlStructures/ifBlock.kt delete mode 100644 compiler/testData/codegen/controlStructures/ifNoElse.kt delete mode 100644 compiler/testData/codegen/controlStructures/singleBranchIf.kt delete mode 100644 compiler/testData/codegen/controlStructures/tryCatch.kt delete mode 100644 compiler/testData/codegen/controlStructures/tryFinally.kt delete mode 100644 compiler/testData/codegen/controlStructures/while.kt delete mode 100644 compiler/testData/codegen/enum/name.kt delete mode 100644 compiler/testData/codegen/enum/openMethod.kt delete mode 100644 compiler/testData/codegen/enum/simple.kt delete mode 100644 compiler/testData/codegen/junit/kt1592.kt delete mode 100644 compiler/testData/codegen/junit/kt2344.kt delete mode 100644 compiler/testData/codegen/patternMatching/constant.kt delete mode 100644 compiler/testData/codegen/patternMatching/exceptionOnNoMatch.kt delete mode 100644 compiler/testData/codegen/patternMatching/inrange.kt delete mode 100644 compiler/testData/codegen/patternMatching/pattern.kt delete mode 100644 compiler/testData/codegen/patternMatching/rangeChar.kt delete mode 100644 compiler/testData/codegen/regressions/kt1213.kt delete mode 100644 compiler/testData/codegen/regressions/kt297.kt delete mode 100644 compiler/testData/codegen/regressions/kt799.kt delete mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/ClassGenTest.java delete mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/EnumGenTest.java delete mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/FunctionGenTest.java delete mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/JUnitUsageGenTest.java delete mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/PatternMatchingTest.java delete mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/StringsTest.java diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/PackagePartClassUtils.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/PackagePartClassUtils.kt index 39ca7f76b2f..f0229ad32a4 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/PackagePartClassUtils.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/PackagePartClassUtils.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtScript -import org.jetbrains.kotlin.resolve.jvm.JvmClassName import java.util.* object PackagePartClassUtils { @@ -58,14 +57,6 @@ object PackagePartClassUtils { return packageFqName.child(Name.identifier(partClassName)) } - @Deprecated("Migrate to JvmFileClassesProvider") - @JvmStatic fun getPackagePartInternalName(file: KtFile): String = - JvmClassName.byFqNameWithoutInnerClasses(getPackagePartFqName(file)).internalName - - @Deprecated("Migrate to JvmFileClassesProvider") - @JvmStatic fun getPackagePartFqName(file: KtFile): FqName = - getPackagePartFqName(file.packageFqName, file.name) - @JvmStatic fun getFilesWithCallables(files: Collection): List = files.filter { fileHasTopLevelCallables(it) } @@ -79,4 +70,4 @@ object PackagePartClassUtils { @JvmStatic fun getFilePartShortName(fileName: String): String = getPartClassName(FileUtil.getNameWithoutExtension(fileName)) -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/closures/noRefToOuter.kt b/compiler/testData/codegen/box/closures/noRefToOuter.kt new file mode 100644 index 00000000000..d153a6639f1 --- /dev/null +++ b/compiler/testData/codegen/box/closures/noRefToOuter.kt @@ -0,0 +1,19 @@ +// WITH_RUNTIME + +class A { + fun f(): () -> String { + val s = "OK" + return { -> s } + } +} + +fun box(): String { + val lambdaClass = A().f().javaClass + val fields = lambdaClass.getDeclaredFields().toList() + if (fields.size != 1) return "Fail: lambda should only capture 's': $fields" + + val fieldName = fields[0].getName() + if (fieldName != "\$s") return "Fail: captured variable should be named '\$s': $fields" + + return "OK" +} diff --git a/compiler/testData/codegen/controlStructures/continue.kt b/compiler/testData/codegen/box/controlStructures/continueInWhile.kt similarity index 55% rename from compiler/testData/codegen/controlStructures/continue.kt rename to compiler/testData/codegen/box/controlStructures/continueInWhile.kt index 6716e7ef20b..79b4ea623ff 100644 --- a/compiler/testData/codegen/controlStructures/continue.kt +++ b/compiler/testData/codegen/box/controlStructures/continueInWhile.kt @@ -1,4 +1,4 @@ -fun continue_test(i: Int): Int { +fun foo(i: Int): Int { var count = i; var result = 0; while(count > 0) { @@ -8,3 +8,9 @@ fun continue_test(i: Int): Int { } return result; } + +fun box(): String { + if (foo(4) != 3) return "Fail 1" + if (foo(5) != 7) return "Fail 2" + return "OK" +} diff --git a/compiler/testData/codegen/box/controlStructures/factorialTest.kt b/compiler/testData/codegen/box/controlStructures/factorialTest.kt new file mode 100644 index 00000000000..fdb108f8bdc --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/factorialTest.kt @@ -0,0 +1,44 @@ +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun facWhile(i: Int): Int { + var count = 1; + var result = 1; + while(count < i) { + count = count + 1; + result = result * count; + } + return result; +} + +fun facBreak(i: Int): Int { + var count = 1; + var result = 1; + while(true) { + count = count + 1; + result = result * count; + if (count == i) break; + } + return result; +} + +fun facDoWhile(i: Int): Int { + var count = 1; + var result = 1; + do { + count = count + 1; + result = result * count; + } while(count != i); + return result; +} + +fun box(): String { + assertEquals(6, facWhile(3)) + assertEquals(6, facBreak(3)) + assertEquals(6, facDoWhile(3)) + assertEquals(120, facWhile(5)) + assertEquals(120, facBreak(5)) + assertEquals(120, facDoWhile(5)) + return "OK" +} diff --git a/compiler/testData/codegen/box/delegation/delegationToVal.kt b/compiler/testData/codegen/box/delegation/delegationToVal.kt new file mode 100644 index 00000000000..7bba0acab37 --- /dev/null +++ b/compiler/testData/codegen/box/delegation/delegationToVal.kt @@ -0,0 +1,46 @@ +// WITH_RUNTIME +// FULL_JDK + +interface IActing { + fun act(): String +} + +class CActing(val value: String = "OK") : IActing { + override fun act(): String = value +} + +// final so no need in delegate field +class Test(val acting: CActing = CActing()) : IActing by acting { +} + +// even if open so we don't need delegate field +open class Test2(open val acting: CActing = CActing()) : IActing by acting { +} + +// even if open the backing field is final, so we don't need delegate field +class Test3() : Test2() { + override val acting = CActing("OKOK") +} + +fun box(): String { + try { + Test::class.java.getDeclaredField("\$delegate_0") + return "\$delegate_0 field generated for class Test but should not" + } + catch (e: NoSuchFieldException) { + // ok + } + + try { + Test2::class.java.getDeclaredField("\$delegate_0") + return "\$delegate_0 field generated for class Test but should not" + } + catch (e: NoSuchFieldException) { + // ok + } + + if (Test3().acting.act() != "OKOK") return "Fail Test3" + + val test = Test() + return test.act() +} diff --git a/compiler/testData/codegen/box/enum/classForEnumEntry.kt b/compiler/testData/codegen/box/enum/classForEnumEntry.kt new file mode 100644 index 00000000000..88ea6789018 --- /dev/null +++ b/compiler/testData/codegen/box/enum/classForEnumEntry.kt @@ -0,0 +1,32 @@ +// WITH_RUNTIME + +enum class IssueState { + DEFAULT, + FIXED { + override fun ToString() = "K" + }; + + open fun ToString(): String = "O" +} + +fun box(): String { + val field = IssueState::class.java.getField("FIXED") + + val typeName = field.type.name + if (typeName != "IssueState") return "Fail type name: $typeName" + + val className = field.get(null).javaClass.name + if (className != "IssueState\$FIXED") return "Fail class name: $className" + + val classLoader = IssueState::class.java.classLoader + classLoader.loadClass("IssueState\$FIXED") + try { + classLoader.loadClass("IssueState\$DEFAULT") + return "Fail: no class should have been generated for DEFAULT" + } + catch (e: Exception) { + // ok + } + + return IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString() +} diff --git a/compiler/testData/codegen/box/enum/modifierFlags.kt b/compiler/testData/codegen/box/enum/modifierFlags.kt new file mode 100644 index 00000000000..4184e77982f --- /dev/null +++ b/compiler/testData/codegen/box/enum/modifierFlags.kt @@ -0,0 +1,27 @@ +// WITH_RUNTIME +// FULL_JDK + +import java.lang.reflect.Modifier + +enum class En { + Y +} + +fun box(): String { + val klass = En::class.java + val superclass = klass.superclass.name + if (superclass != "java.lang.Enum") "Fail superclass: $superclass" + + val enumModifiers = klass.modifiers + if ((enumModifiers and 0x4000) == 0) return "Fail ACC_ENUM on class" + if ((enumModifiers and Modifier.FINAL) == 0) return "Fail FINAL on class" + + val entry = klass.getField("Y") + val entryModifiers = entry.modifiers + if ((entryModifiers and 0x4000) == 0) return "Fail ACC_ENUM on entry" + if ((entryModifiers and Modifier.FINAL) == 0) return "Fail FINAL on entry" + if ((entryModifiers and Modifier.STATIC) == 0) return "Fail FINAL on entry" + if ((entryModifiers and Modifier.PUBLIC) == 0) return "Fail FINAL on entry" + + return "OK" +} diff --git a/compiler/testData/codegen/box/enum/name.kt b/compiler/testData/codegen/box/enum/name.kt deleted file mode 100644 index 6e0227199a1..00000000000 --- a/compiler/testData/codegen/box/enum/name.kt +++ /dev/null @@ -1,6 +0,0 @@ -enum class State { - O, - K -} - -fun box() = "${State.O.name}${State.K.name}" diff --git a/compiler/testData/codegen/box/enum/noClassForSimpleEnum.kt b/compiler/testData/codegen/box/enum/noClassForSimpleEnum.kt new file mode 100644 index 00000000000..4c1cb7e9be9 --- /dev/null +++ b/compiler/testData/codegen/box/enum/noClassForSimpleEnum.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME + +enum class State { + O, + K +} + +fun box(): String { + val field = State::class.java.getField("O") + val className = field.get(null).javaClass.name + if (className != "State") return "Fail: $className" + + return "${State.O.name}${State.K.name}" +} diff --git a/compiler/testData/codegen/box/enum/openMethod.kt b/compiler/testData/codegen/box/enum/openMethod.kt deleted file mode 100644 index 010d6e40ad4..00000000000 --- a/compiler/testData/codegen/box/enum/openMethod.kt +++ /dev/null @@ -1,10 +0,0 @@ -fun box() = IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString() - -enum class IssueState { - DEFAULT, - FIXED { - override fun ToString() = "K" - }; - - open fun ToString() : String = "O" -} diff --git a/compiler/testData/codegen/box/typeMapping/kt309.kt b/compiler/testData/codegen/box/typeMapping/kt309.kt new file mode 100644 index 00000000000..cbfebcfcc46 --- /dev/null +++ b/compiler/testData/codegen/box/typeMapping/kt309.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME + +class N { + fun foo() = null +} + +fun box(): String { + val method = N::class.java.getDeclaredMethod("foo") + if (method.returnType.name != "java.lang.Void") return "Fail: Nothing should be mapped to Void" + + return "OK" +} diff --git a/compiler/testData/codegen/box/when/exceptionOnNoMatch.kt b/compiler/testData/codegen/box/when/exceptionOnNoMatch.kt new file mode 100644 index 00000000000..15a1b759082 --- /dev/null +++ b/compiler/testData/codegen/box/when/exceptionOnNoMatch.kt @@ -0,0 +1,14 @@ +fun isZero(x: Int) = when(x) { + 0 -> true + else -> throw Exception() +} + +fun box(): String { + try { + isZero(1) + } + catch (e: Exception) { + return "OK" + } + return "Fail" +} diff --git a/compiler/testData/codegen/box/when/multipleEntries.kt b/compiler/testData/codegen/box/when/multipleEntries.kt new file mode 100644 index 00000000000..65c20b334d2 --- /dev/null +++ b/compiler/testData/codegen/box/when/multipleEntries.kt @@ -0,0 +1,12 @@ +fun foo(x: Any) = + when (x) { + 0, 1 -> "bit" + else -> "something" + } + +fun box(): String { + if (foo(0) != "bit") return "Fail 0" + if (foo(1) != "bit") return "Fail 1" + if (foo(2) != "something") return "Fail 2" + return "OK" +} diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/nonNullableStringPlus.kt b/compiler/testData/codegen/bytecodeText/stringOperations/nonNullableStringPlus.kt new file mode 100644 index 00000000000..bff25b39339 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/nonNullableStringPlus.kt @@ -0,0 +1,3 @@ +fun foo(x: String, y: Any?) = x + y + 120 + +// 0 stringPlus diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/nullableStringPlus.kt b/compiler/testData/codegen/bytecodeText/stringOperations/nullableStringPlus.kt new file mode 100644 index 00000000000..ef37d600c13 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/nullableStringPlus.kt @@ -0,0 +1,3 @@ +fun foo(x: String?, y: Any?) = x + y + +// 1 stringPlus diff --git a/compiler/testData/codegen/classes/classObjectInterface.kt b/compiler/testData/codegen/classes/classObjectInterface.kt deleted file mode 100644 index 76b5614275c..00000000000 --- a/compiler/testData/codegen/classes/classObjectInterface.kt +++ /dev/null @@ -1,9 +0,0 @@ -class C() { - fun getInstance(): Runnable = C - - companion object: Runnable { - override fun run(): Unit { } - } -} - -fun foo() = C().getInstance() diff --git a/compiler/testData/codegen/classes/classObjectIsInnerClass.kt b/compiler/testData/codegen/classes/classObjectIsInnerClass.kt deleted file mode 100644 index 3ce218107d0..00000000000 --- a/compiler/testData/codegen/classes/classObjectIsInnerClass.kt +++ /dev/null @@ -1,3 +0,0 @@ -class A { - companion object -} diff --git a/compiler/testData/codegen/classes/delegationToVal.kt b/compiler/testData/codegen/classes/delegationToVal.kt deleted file mode 100644 index 0a4558ae4b7..00000000000 --- a/compiler/testData/codegen/classes/delegationToVal.kt +++ /dev/null @@ -1,25 +0,0 @@ -interface IActing { - fun act(): String -} - -class CActing(val value: String = "OK"): IActing { - override fun act(): String = value -} - -// final so no need in delegate field -class Test(val acting: CActing = CActing()): IActing by acting { -} - -// even if open so we don't need delegate field -open class Test2(open val acting: CActing = CActing()): IActing by acting { -} - -// even if open the backing field is final, so we don't need delegate field -class Test3() : Test2() { - override val acting = CActing("OKOK") -} - -fun box(): String { - val test = Test() - return test.act() -} diff --git a/compiler/testData/codegen/classes/inheritingFromArrayList.kt b/compiler/testData/codegen/classes/inheritingFromArrayList.kt deleted file mode 100644 index d0ee9df62d0..00000000000 --- a/compiler/testData/codegen/classes/inheritingFromArrayList.kt +++ /dev/null @@ -1 +0,0 @@ -class Foo() : java.util.ArrayList() \ No newline at end of file diff --git a/compiler/testData/codegen/classes/newInstanceDefaultConstructor.kt b/compiler/testData/codegen/classes/newInstanceDefaultConstructor.kt deleted file mode 100644 index 2e91e8ea973..00000000000 --- a/compiler/testData/codegen/classes/newInstanceDefaultConstructor.kt +++ /dev/null @@ -1,8 +0,0 @@ -class SimpleClass() { - fun foo() = 610 -} - -fun test() : Int { - val c = SimpleClass() - return c.foo() -} diff --git a/compiler/testData/codegen/classes/simpleClass.kt b/compiler/testData/codegen/classes/simpleClass.kt deleted file mode 100644 index e860e6e0e0b..00000000000 --- a/compiler/testData/codegen/classes/simpleClass.kt +++ /dev/null @@ -1,5 +0,0 @@ -class SimpleClass { - fun foo() : Int { - return 0; - } -} diff --git a/compiler/testData/codegen/controlStructures/break.kt b/compiler/testData/codegen/controlStructures/break.kt deleted file mode 100644 index c2b0073d4e4..00000000000 --- a/compiler/testData/codegen/controlStructures/break.kt +++ /dev/null @@ -1,10 +0,0 @@ -fun fac(i: Int): Int { - var count = 1; - var result = 1; - while(true) { - count = count + 1; - result = result * count; - if (count == i) break; - } - return result; -} \ No newline at end of file diff --git a/compiler/testData/codegen/controlStructures/doWhile.kt b/compiler/testData/codegen/controlStructures/doWhile.kt deleted file mode 100644 index 1ffc78729ef..00000000000 --- a/compiler/testData/codegen/controlStructures/doWhile.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun fac(i: Int): Int { - var count = 1; - var result = 1; - do { - count = count + 1; - result = result * count; - } while(count != i); - return result; -} diff --git a/compiler/testData/codegen/controlStructures/for.kt b/compiler/testData/codegen/controlStructures/for.kt deleted file mode 100644 index 588baba360e..00000000000 --- a/compiler/testData/codegen/controlStructures/for.kt +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.* - -fun concat(l: List): String? { - val sb = StringBuilder() - for(s in l) { - sb.append(s) - } - return sb.toString() -} diff --git a/compiler/testData/codegen/controlStructures/forInArray.kt b/compiler/testData/codegen/controlStructures/forInArray.kt deleted file mode 100644 index 70c508458ab..00000000000 --- a/compiler/testData/codegen/controlStructures/forInArray.kt +++ /dev/null @@ -1,7 +0,0 @@ -fun concat(l: Array): String? { - val sb = StringBuilder() - for(s in l) { - sb.append(s) - } - return sb.toString() -} diff --git a/compiler/testData/codegen/controlStructures/if.kt b/compiler/testData/codegen/controlStructures/if.kt deleted file mode 100644 index 282a87e267b..00000000000 --- a/compiler/testData/codegen/controlStructures/if.kt +++ /dev/null @@ -1 +0,0 @@ -fun foo(b: Boolean): Int { return if (b) 15 else 20 } \ No newline at end of file diff --git a/compiler/testData/codegen/controlStructures/ifBlock.kt b/compiler/testData/codegen/controlStructures/ifBlock.kt deleted file mode 100644 index 9afdccdc69b..00000000000 --- a/compiler/testData/codegen/controlStructures/ifBlock.kt +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.* - -fun concat(l: List): String? { - val sb = StringBuilder() - for(s in l) { - val x = if(l.size > 1) { "T" } else { "F" }; - sb.append(x) - } - return sb.toString() -} diff --git a/compiler/testData/codegen/controlStructures/ifNoElse.kt b/compiler/testData/codegen/controlStructures/ifNoElse.kt deleted file mode 100644 index 920ca2956b8..00000000000 --- a/compiler/testData/codegen/controlStructures/ifNoElse.kt +++ /dev/null @@ -1,5 +0,0 @@ -fun f(x: Int, b: Boolean): Int { - var result = x; - if (b) else result = result + 5; - return result; -} diff --git a/compiler/testData/codegen/controlStructures/singleBranchIf.kt b/compiler/testData/codegen/controlStructures/singleBranchIf.kt deleted file mode 100644 index 29001194b38..00000000000 --- a/compiler/testData/codegen/controlStructures/singleBranchIf.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun foo(b: Boolean) : Int { - if (b) return 15; - return 20; -} diff --git a/compiler/testData/codegen/controlStructures/tryCatch.kt b/compiler/testData/codegen/controlStructures/tryCatch.kt deleted file mode 100644 index b3410a183a7..00000000000 --- a/compiler/testData/codegen/controlStructures/tryCatch.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun foo(s: String): String? { - try { - Integer.parseInt(s); - return "no message"; - } - catch(e: NumberFormatException) { - return e.message // Work around an overload-resolution bug - } -} diff --git a/compiler/testData/codegen/controlStructures/tryFinally.kt b/compiler/testData/codegen/controlStructures/tryFinally.kt deleted file mode 100644 index 2108c83b5c0..00000000000 --- a/compiler/testData/codegen/controlStructures/tryFinally.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun f(sb: StringBuilder, s: String): Unit { - try { - sb.append("foo"); - sb.append(Integer.parseInt(s)); - } - finally { - sb.append("bar"); - } -} \ No newline at end of file diff --git a/compiler/testData/codegen/controlStructures/while.kt b/compiler/testData/codegen/controlStructures/while.kt deleted file mode 100644 index 1324c79c0b9..00000000000 --- a/compiler/testData/codegen/controlStructures/while.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun fac(i: Int): Int { - var count = 1; - var result = 1; - while(count < i) { - count = count + 1; - result = result * count; - } - return result; -} \ No newline at end of file diff --git a/compiler/testData/codegen/enum/name.kt b/compiler/testData/codegen/enum/name.kt deleted file mode 100644 index 6e0227199a1..00000000000 --- a/compiler/testData/codegen/enum/name.kt +++ /dev/null @@ -1,6 +0,0 @@ -enum class State { - O, - K -} - -fun box() = "${State.O.name}${State.K.name}" diff --git a/compiler/testData/codegen/enum/openMethod.kt b/compiler/testData/codegen/enum/openMethod.kt deleted file mode 100644 index 010d6e40ad4..00000000000 --- a/compiler/testData/codegen/enum/openMethod.kt +++ /dev/null @@ -1,10 +0,0 @@ -fun box() = IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString() - -enum class IssueState { - DEFAULT, - FIXED { - override fun ToString() = "K" - }; - - open fun ToString() : String = "O" -} diff --git a/compiler/testData/codegen/enum/simple.kt b/compiler/testData/codegen/enum/simple.kt deleted file mode 100644 index ed48d29a5d9..00000000000 --- a/compiler/testData/codegen/enum/simple.kt +++ /dev/null @@ -1,12 +0,0 @@ -enum class Season { - WINTER, - SPRING, - SUMMER, - AUTUMN -} - -fun foo(): Season = Season.SPRING - -fun box() = - if (foo() == Season.SPRING) "OK" - else "fail" diff --git a/compiler/testData/codegen/junit/kt1592.kt b/compiler/testData/codegen/junit/kt1592.kt deleted file mode 100644 index 8a07229118f..00000000000 --- a/compiler/testData/codegen/junit/kt1592.kt +++ /dev/null @@ -1,3 +0,0 @@ -import org.junit.Test - -@Test fun foo(m : java.lang.reflect.Method) = "OK" diff --git a/compiler/testData/codegen/junit/kt2344.kt b/compiler/testData/codegen/junit/kt2344.kt deleted file mode 100644 index d33451eaf65..00000000000 --- a/compiler/testData/codegen/junit/kt2344.kt +++ /dev/null @@ -1,12 +0,0 @@ -import kotlin.test.* -import org.junit.Test as test - -public class Test { - @test fun f(): Unit { - assertEquals(true, !false) - } -} - -fun foo() { - Test().f() -} diff --git a/compiler/testData/codegen/patternMatching/constant.kt b/compiler/testData/codegen/patternMatching/constant.kt deleted file mode 100644 index e74aa2568a2..00000000000 --- a/compiler/testData/codegen/patternMatching/constant.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun isZero(x: Int) = when(x) { - 0 -> true - else -> false -} diff --git a/compiler/testData/codegen/patternMatching/exceptionOnNoMatch.kt b/compiler/testData/codegen/patternMatching/exceptionOnNoMatch.kt deleted file mode 100644 index 2c98ded9809..00000000000 --- a/compiler/testData/codegen/patternMatching/exceptionOnNoMatch.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun isZero(x: Int) = when(x) { - 0 -> true - else -> throw Exception() -} diff --git a/compiler/testData/codegen/patternMatching/inrange.kt b/compiler/testData/codegen/patternMatching/inrange.kt deleted file mode 100644 index e883e5dbb9c..00000000000 --- a/compiler/testData/codegen/patternMatching/inrange.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun isDigit(a: Int) : String { - val aa = java.util.ArrayList () - aa.add(239) - - if(a in aa) return "array list" - if(a in 0..9) return "digit" - if(a !in 0..100) return "not small" - return "something" -} diff --git a/compiler/testData/codegen/patternMatching/pattern.kt b/compiler/testData/codegen/patternMatching/pattern.kt deleted file mode 100644 index e87965a0fc8..00000000000 --- a/compiler/testData/codegen/patternMatching/pattern.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun isString(x: Any) = when(x) { - is String -> "string" - else -> "something" -} diff --git a/compiler/testData/codegen/patternMatching/rangeChar.kt b/compiler/testData/codegen/patternMatching/rangeChar.kt deleted file mode 100644 index 7ab6b77512f..00000000000 --- a/compiler/testData/codegen/patternMatching/rangeChar.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun isDigit(a: Char) = when(a) { - in '0'..'9' -> "digit" - else -> "something" -} diff --git a/compiler/testData/codegen/regressions/kt1213.kt b/compiler/testData/codegen/regressions/kt1213.kt deleted file mode 100644 index 6f95ec93515..00000000000 --- a/compiler/testData/codegen/regressions/kt1213.kt +++ /dev/null @@ -1,11 +0,0 @@ -package interactive - -class Shape(var height : Double = 1.0, var fillColor : String = "#AAAAAA") { - -} - -fun box() : String { - var a : Shape? = Shape() - a?.height = 1.0 - return "OK" -} diff --git a/compiler/testData/codegen/regressions/kt297.kt b/compiler/testData/codegen/regressions/kt297.kt deleted file mode 100644 index 255848588f3..00000000000 --- a/compiler/testData/codegen/regressions/kt297.kt +++ /dev/null @@ -1,4 +0,0 @@ -// KT-297 Overload resolution ambiguity with required in interface -interface ALE : java.util.ArrayList { - fun getOrValue(index: Int, value : T) : T = if(index >= 0 && index < size) get(index) else value -} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt799.kt b/compiler/testData/codegen/regressions/kt799.kt deleted file mode 100644 index 93254b17f6f..00000000000 --- a/compiler/testData/codegen/regressions/kt799.kt +++ /dev/null @@ -1,8 +0,0 @@ -package kt799 - -fun foo(b: Boolean) : String { - val a = if (b) true else return "false" - return "$a" -} - -fun box() = if (foo(true) == "true" && foo(false) == "false") "OK" else "fail" diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/AnnotationGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/AnnotationGenTest.java index c03c745cd6b..f42faa237ec 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/AnnotationGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/AnnotationGenTest.java @@ -18,29 +18,18 @@ package org.jetbrains.kotlin.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; import org.jetbrains.kotlin.test.ConfigurationKind; import java.lang.annotation.*; import java.lang.reflect.*; public class AnnotationGenTest extends CodegenTestCase { - @Override protected void setUp() throws Exception { super.setUp(); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL); } - private ClassLoader loadFileGetClassLoader(@NotNull String text) { - loadText(text); - return generateAndCreateClassLoader(); - } - - private Class getPackageSrcClass(@NotNull ClassLoader loader) throws ClassNotFoundException { - return loader.loadClass(PackagePartClassUtils.getPackagePartInternalName(myFiles.getPsiFile())); - } - public void testVolatileProperty() throws Exception { loadText("abstract class Foo { @Volatile public var x: String = \"\"; }"); Class aClass = generateClass("Foo"); @@ -49,34 +38,34 @@ public class AnnotationGenTest extends CodegenTestCase { } public void testPropField() throws Exception { - ClassLoader loader = loadFileGetClassLoader("@[java.lang.Deprecated] var x = 0"); - Class srcClass = getPackageSrcClass(loader); + loadText("@[java.lang.Deprecated] var x = 0"); + Class srcClass = generateFacadeClass(); assertNull(srcClass.getDeclaredMethod("getX").getAnnotation(Deprecated.class)); assertNull(srcClass.getDeclaredMethod("setX", int.class).getAnnotation(Deprecated.class)); assertNotNull(srcClass.getDeclaredField("x").getAnnotation(Deprecated.class)); } public void testPropGetter() throws Exception { - ClassLoader loader = loadFileGetClassLoader("var x = 0\n" + + loadText("var x = 0\n" + "@[java.lang.Deprecated] get"); - Class srcClass = getPackageSrcClass(loader); + Class srcClass = generateFacadeClass(); assertNotNull(srcClass.getDeclaredMethod("getX").getAnnotation(Deprecated.class)); assertNull(srcClass.getDeclaredMethod("setX", int.class).getAnnotation(Deprecated.class)); assertNull(srcClass.getDeclaredField("x").getAnnotation(Deprecated.class)); } public void testPropSetter() throws Exception { - ClassLoader loader = loadFileGetClassLoader("var x = 0\n" + + loadText("var x = 0\n" + "@[java.lang.Deprecated] set"); - Class scrClass = getPackageSrcClass(loader); + Class scrClass = generateFacadeClass(); assertNull(scrClass.getDeclaredMethod("getX").getAnnotation(Deprecated.class)); assertNotNull(scrClass.getDeclaredMethod("setX", int.class).getAnnotation(Deprecated.class)); assertNull(scrClass.getDeclaredField("x").getAnnotation(Deprecated.class)); } public void testAnnotationForParamInTopLevelFunction() throws Exception { - ClassLoader loader = loadFileGetClassLoader("fun x(@[java.lang.Deprecated] i: Int) {}"); - Class srcClass = getPackageSrcClass(loader); + loadText("fun x(@[java.lang.Deprecated] i: Int) {}"); + Class srcClass = generateFacadeClass(); Method srcClassMethod = srcClass.getMethod("x", int.class); assertNotNull(srcClassMethod); assertNotNull(getDeprecatedAnnotationFromList(srcClassMethod.getParameterAnnotations()[0])); @@ -147,18 +136,13 @@ public class AnnotationGenTest extends CodegenTestCase { } public void testAnnotationWithParamForParamInFunction() throws Exception { - ClassLoader loader = loadFileGetClassLoader("import java.lang.annotation.*\n" + + loadText("import java.lang.annotation.*\n" + "@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" + "fun x(@A(\"239\") i: Int) {}"); - Class packageClass = getPackageSrcClass(loader); + Class packageClass = generateFacadeClass(); Method packageClassMethod = packageClass.getMethod("x", int.class); assertNotNull(packageClassMethod); assertNotNull(getAnnotationByName(packageClassMethod.getParameterAnnotations()[0], "A")); - - Class srcClass = getPackageSrcClass(loader); - Method srcClassMethod = srcClass.getMethod("x", int.class); - assertNotNull(srcClassMethod); - assertNotNull(getAnnotationByName(srcClassMethod.getParameterAnnotations()[0], "A")); } @Nullable @@ -189,11 +173,10 @@ public class AnnotationGenTest extends CodegenTestCase { } public void testMethod() throws Exception { - ClassLoader loader = loadFileGetClassLoader("@[java.lang.Deprecated] fun x () {}"); - Class srcClass = getPackageSrcClass(loader); + loadText("@[java.lang.Deprecated] fun x () {}"); + Class srcClass = generateFacadeClass(); Method srcClassMethod = srcClass.getDeclaredMethod("x"); assertNotNull(srcClassMethod.getAnnotation(Deprecated.class)); - } public void testClass() throws NoSuchFieldException, NoSuchMethodException { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 96303e970e0..a742d90e6ea 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -3124,6 +3124,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("noRefToOuter.kt") + public void testNoRefToOuter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/noRefToOuter.kt"); + doTest(fileName); + } + @TestMetadata("recursiveClosure.kt") public void testRecursiveClosure() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/recursiveClosure.kt"); @@ -3433,6 +3439,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("continueInWhile.kt") + public void testContinueInWhile() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/continueInWhile.kt"); + doTest(fileName); + } + @TestMetadata("continueToLabelInFor.kt") public void testContinueToLabelInFor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/continueToLabelInFor.kt"); @@ -3475,6 +3487,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("factorialTest.kt") + public void testFactorialTest() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/factorialTest.kt"); + doTest(fileName); + } + @TestMetadata("finallyOnEmptyReturn.kt") public void testFinallyOnEmptyReturn() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/finallyOnEmptyReturn.kt"); @@ -4892,6 +4910,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/delegation") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Delegation extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInDelegation() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/delegation"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("delegationToVal.kt") + public void testDelegationToVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegation/delegationToVal.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/diagnostics") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -5296,6 +5329,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("classForEnumEntry.kt") + public void testClassForEnumEntry() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/classForEnumEntry.kt"); + doTest(fileName); + } + @TestMetadata("companionObjectInEnum.kt") public void testCompanionObjectInEnum() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/companionObjectInEnum.kt"); @@ -5380,9 +5419,15 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("name.kt") - public void testName() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/name.kt"); + @TestMetadata("modifierFlags.kt") + public void testModifierFlags() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/modifierFlags.kt"); + doTest(fileName); + } + + @TestMetadata("noClassForSimpleEnum.kt") + public void testNoClassForSimpleEnum() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/noClassForSimpleEnum.kt"); doTest(fileName); } @@ -5392,12 +5437,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("openMethod.kt") - public void testOpenMethod() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/openMethod.kt"); - doTest(fileName); - } - @TestMetadata("ordinal.kt") public void testOrdinal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/ordinal.kt"); @@ -13906,6 +13945,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt309.kt") + public void testKt309() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typeMapping/kt309.kt"); + doTest(fileName); + } + @TestMetadata("kt3286.kt") public void testKt3286() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typeMapping/kt3286.kt"); @@ -14140,6 +14185,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("exceptionOnNoMatch.kt") + public void testExceptionOnNoMatch() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/when/exceptionOnNoMatch.kt"); + doTest(fileName); + } + @TestMetadata("exhaustiveBoolean.kt") public void testExhaustiveBoolean() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/when/exhaustiveBoolean.kt"); @@ -14212,6 +14263,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("multipleEntries.kt") + public void testMultipleEntries() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/when/multipleEntries.kt"); + doTest(fileName); + } + @TestMetadata("noElseExhaustive.kt") public void testNoElseExhaustive() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/when/noElseExhaustive.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 3d24b9e41c8..c3fb80bb835 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1159,6 +1159,18 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("nonNullableStringPlus.kt") + public void testNonNullableStringPlus() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/nonNullableStringPlus.kt"); + doTest(fileName); + } + + @TestMetadata("nullableStringPlus.kt") + public void testNullableStringPlus() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/nullableStringPlus.kt"); + doTest(fileName); + } + @TestMetadata("plusAssign.kt") public void testPlusAssign() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/plusAssign.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/ClassGenTest.java deleted file mode 100644 index 3703c9fc7da..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ClassGenTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2010-2015 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.annotations.NotNull; -import org.jetbrains.kotlin.name.SpecialNames; -import org.jetbrains.kotlin.test.ConfigurationKind; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.List; - -import static org.jetbrains.kotlin.codegen.CodegenTestUtil.findDeclaredMethodByName; - -public class ClassGenTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - @NotNull - @Override - protected String getPrefix() { - return "classes"; - } - - public void testSimpleClass() { - loadFile(); - Class aClass = generateClass("SimpleClass"); - Method[] methods = aClass.getDeclaredMethods(); - // public int SimpleClass.foo() - assertEquals(1, methods.length); - } - - public void testInheritingFromArrayList() throws Exception { - loadFile(); - Class aClass = generateClass("Foo"); - assertInstanceOf(aClass.newInstance(), List.class); - } - - public void testDelegationToVal() throws Exception { - loadFile(); - GeneratedClassLoader loader = generateAndCreateClassLoader(); - Class aClass = loader.loadClass("DelegationToValKt"); - assertEquals("OK", aClass.getMethod("box").invoke(null)); - - Class test = loader.loadClass("Test"); - try { - test.getDeclaredField("$delegate_0"); - fail("$delegate_0 field generated for class Test but should not"); - } - catch (NoSuchFieldException e) { - // ok - } - - Class test2 = loader.loadClass("Test2"); - try { - test2.getDeclaredField("$delegate_0"); - fail("$delegate_0 field generated for class Test2 but should not"); - } - catch (NoSuchFieldException e) { - // ok - } - - Class test3 = loader.loadClass("Test3"); - Class iActing = loader.loadClass("IActing"); - Object obj = test3.newInstance(); - assertTrue(iActing.isInstance(obj)); - Method iActingMethod = iActing.getMethod("act"); - assertEquals("OK", iActingMethod.invoke(obj)); - assertEquals("OKOK", iActingMethod.invoke(test3.getMethod("getActing").invoke(obj))); - } - - public void testNewInstanceDefaultConstructor() throws Exception { - loadFile(); - Method method = generateFunction("test"); - Integer returnValue = (Integer) method.invoke(null); - assertEquals(610, returnValue.intValue()); - } - - public void testAbstractMethod() throws Exception { - loadText("abstract class Foo { abstract fun x(): String; fun y(): Int = 0 }"); - Class aClass = generateClass("Foo"); - assertNotNull(aClass.getMethod("x")); - findDeclaredMethodByName(aClass, "y"); - } - - public void testAbstractClass() throws Exception { - loadText("abstract class SimpleClass() { }"); - Class aClass = generateClass("SimpleClass"); - assertTrue((aClass.getModifiers() & Modifier.ABSTRACT) != 0); - } - - public void testClassObjectInterface() throws Exception { - loadFile(); - Method method = generateFunction(); - Object result = method.invoke(null); - assertInstanceOf(result, Runnable.class); - } - - public void testEnumClass() throws Exception { - loadText("enum class Direction { NORTH, SOUTH, EAST, WEST; }"); - Class direction = generateClass("Direction"); - Field north = direction.getField("NORTH"); - assertEquals(direction, north.getType()); - assertInstanceOf(north.get(null), direction); - } - - public void testEnumConstantConstructors() throws Exception { - loadText("enum class Color(val rgb: Int) { RED(0xFF0000), GREEN(0x00FF00); }"); - Class colorClass = generateClass("Color"); - Field redField = colorClass.getField("RED"); - Object redValue = redField.get(null); - Method rgbMethod = colorClass.getMethod("getRgb"); - assertEquals(0xFF0000, rgbMethod.invoke(redValue)); - } - - public void testKt309() { - loadText("fun box() = null"); - Method method = generateFunction("box"); - assertEquals(method.getReturnType().getName(), "java.lang.Void"); - } - - public void testClassObjectIsInnerClass() throws Exception { - loadFile(); - GeneratedClassLoader loader = generateAndCreateClassLoader(); - Class a = loader.loadClass("A"); - Class companionObject = loader.loadClass("A$" + SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.asString()); - assertSameElements(a.getDeclaredClasses(), companionObject); - assertEquals(a, companionObject.getDeclaringClass()); - } -} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 713b919be8d..87256cd802a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -231,12 +231,6 @@ public abstract class CodegenTestCase extends UsefulTestCase { return generateClass(facadeClassFqName.asString()); } - @NotNull - protected Class generateFileClass() { - FqName fileClassFqName = JvmFileClassUtil.getFileClassInfoNoResolve(myFiles.getPsiFile()).getFileClassFqName(); - return generateClass(fileClassFqName.asString()); - } - @NotNull protected Class generateClass(@NotNull String name) { try { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/ControlStructuresTest.java index b9073a269ec..8179ca5784c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ControlStructuresTest.java @@ -16,12 +16,9 @@ package org.jetbrains.kotlin.codegen; -import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.test.ConfigurationKind; import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; import static org.jetbrains.kotlin.codegen.CodegenTestUtil.assertThrows; @@ -32,59 +29,6 @@ public class ControlStructuresTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); } - @NotNull - @Override - protected String getPrefix() { - return "controlStructures"; - } - - public void testIf() throws Exception { - loadFile(); - Method main = generateFunction(); - assertEquals(15, main.invoke(null, true)); - assertEquals(20, main.invoke(null, false)); - } - - public void testSingleBranchIf() throws Exception { - loadFile(); - Method main = generateFunction(); - assertEquals(15, main.invoke(null, true)); - assertEquals(20, main.invoke(null, false)); - } - - public void testWhile() throws Exception { - factorialTest(); - } - - public void testDoWhile() throws Exception { - factorialTest(); - } - - public void testBreak() throws Exception { - factorialTest(); - } - - private void factorialTest() throws Exception { - loadFile(); - Method main = generateFunction(); - assertEquals(6, main.invoke(null, 3)); - assertEquals(120, main.invoke(null, 5)); - } - - public void testContinue() throws Exception { - loadFile(); - Method main = generateFunction(); - assertEquals(3, main.invoke(null, 4)); - assertEquals(7, main.invoke(null, 5)); - } - - public void testIfNoElse() throws Exception { - loadFile(); - Method main = generateFunction(); - assertEquals(5, main.invoke(null, 5, true)); - assertEquals(10, main.invoke(null, 5, false)); - } - public void testCondJumpOnStack() throws Exception { loadText("import java.lang.Boolean as jlBoolean; fun foo(a: String): Int = if (jlBoolean.parseBoolean(a)) 5 else 10"); Method main = generateFunction(); @@ -92,29 +36,6 @@ public class ControlStructuresTest extends CodegenTestCase { assertEquals(10, main.invoke(null, "false")); } - public void testFor() throws Exception { - loadFile(); - Method main = generateFunction(); - List args = Arrays.asList("IntelliJ", " ", "IDEA"); - assertEquals("IntelliJ IDEA", main.invoke(null, args)); - } - - public void testIfBlock() throws Exception { - loadFile(); - Method main = generateFunction(); - List args = Arrays.asList("IntelliJ", " ", "IDEA"); - assertEquals("TTT", main.invoke(null, args)); - args = Arrays.asList("JetBrains"); - assertEquals("F", main.invoke(null, args)); - } - - public void testForInArray() throws Exception { - loadFile(); - Method main = generateFunction(); - String[] args = new String[] { "IntelliJ", " ", "IDEA" }; - assertEquals("IntelliJ IDEA", main.invoke(null, new Object[] { args })); - } - public void testForInRange() throws Exception { loadText("fun foo(sb: StringBuilder) { for(x in 1..4) sb.append(x) }"); Method main = generateFunction(); @@ -129,24 +50,6 @@ public class ControlStructuresTest extends CodegenTestCase { assertThrows(main, Exception.class, null); } - public void testTryCatch() throws Exception { - loadFile(); - Method main = generateFunction(); - assertEquals("no message", main.invoke(null, "0")); - assertEquals("For input string: \"a\"", main.invoke(null, "a")); - } - - public void testTryFinally() throws Exception { - loadFile(); - Method main = generateFunction(); - StringBuilder sb = new StringBuilder(); - main.invoke(null, sb, "9"); - assertEquals("foo9bar", sb.toString()); - sb = new StringBuilder(); - assertThrows(main, NumberFormatException.class, null, sb, "x"); - assertEquals("foobar", sb.toString()); - } - public void testCompareToZero() throws Exception { loadText("fun foo(a: Int, b: Int): Boolean = a == 0 && b != 0 && 0 == a && 0 != b"); String text = generateToText(); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/EnumGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/EnumGenTest.java deleted file mode 100644 index 824bb200259..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/EnumGenTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2010-2015 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.test.ConfigurationKind; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -public class EnumGenTest extends CodegenTestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - public void testSuperclassIsEnum() throws Exception { - loadFile("enum/simple.kt"); - Class season = generateClass("Season"); - assertEquals("java.lang.Enum", season.getSuperclass().getName()); - } - - public void testEnumClassModifiers() throws Exception { - loadFile("enum/simple.kt"); - Class season = generateClass("Season"); - int modifiers = season.getModifiers(); - assertTrue((modifiers & 0x4000) != 0); // ACC_ENUM - assertTrue((modifiers & Modifier.FINAL) != 0); - } - - public void testEnumFieldModifiers() throws Exception { - loadFile("enum/simple.kt"); - Class season = generateClass("Season"); - Field summer = season.getField("SUMMER"); - int modifiers = summer.getModifiers(); - assertTrue((modifiers & 0x4000) != 0); // ACC_ENUM - assertTrue((modifiers & Modifier.FINAL) != 0); - assertTrue((modifiers & Modifier.STATIC) != 0); - assertTrue((modifiers & Modifier.PUBLIC) != 0); - } - - public void testEnumConstantConstructors() throws Exception { - loadText("enum class Color(val rgb: Int) { RED(0xFF0000), GREEN(0x00FF00); }"); - Class colorClass = generateClass("Color"); - Field redField = colorClass.getField("RED"); - Object redValue = redField.get(null); - Method rgbMethod = colorClass.getMethod("getRgb"); - assertEquals(0xFF0000, rgbMethod.invoke(redValue)); - } - - public void testNoClassForSimpleEnum() throws Exception { - loadFile("enum/name.kt"); - Class cls = generateClass("State"); - Field field = cls.getField("O"); - assertEquals("State", field.get(null).getClass().getName()); - } - - public void testYesClassForComplexEnum() throws Exception { - loadFile("enum/openMethod.kt"); - Class cls = generateClass("IssueState"); - Field field = cls.getField("DEFAULT"); - assertEquals("IssueState", field.get(null).getClass().getName()); - field = cls.getField("FIXED"); - assertEquals("IssueState", field.getType().getName()); - assertEquals("IssueState$FIXED", field.get(null).getClass().getName()); - assertNotNull(cls.getClassLoader().loadClass("IssueState$FIXED")); - try { - cls.getClassLoader().loadClass("IssueState$DEFAULT"); - fail(); - } - catch (ClassNotFoundException e) { - // ok - } - } -} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/FunctionGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/FunctionGenTest.java deleted file mode 100644 index de9a043e702..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/FunctionGenTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2010-2015 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.test.ConfigurationKind; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class FunctionGenTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - public void testAnyEqualsNullable() throws InvocationTargetException, IllegalAccessException { - loadText("fun foo(x: Any?) = x?.equals(\"lala\")"); - Method foo = generateFunction(); - assertTrue((Boolean) foo.invoke(null, "lala")); - assertFalse((Boolean) foo.invoke(null, "mama")); - } - - public void testNoRefToOuter() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { - loadText("class A() { fun f() : ()->String { val s = \"OK\"; return { -> s } } }"); - Class foo = generateClass("A"); - Object obj = foo.newInstance(); - Method f = foo.getMethod("f"); - Object closure = f.invoke(obj); - Class aClass = closure.getClass(); - Field[] fields = aClass.getDeclaredFields(); - assertEquals(1, fields.length); - assertEquals("$s", fields[0].getName()); - } - - public void testAnyEquals() throws InvocationTargetException, IllegalAccessException { - loadText("fun foo(x: Any) = x.equals(\"lala\")"); - Method foo = generateFunction(); - assertTrue((Boolean) foo.invoke(null, "lala")); - assertFalse((Boolean) foo.invoke(null, "mama")); - } -} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/JUnitUsageGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/JUnitUsageGenTest.java deleted file mode 100644 index 3dbcecd8480..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/JUnitUsageGenTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2010-2015 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.annotations.NotNull; -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; -import org.jetbrains.kotlin.test.ConfigurationKind; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TestJdkKind; -import org.junit.Test; - -import java.io.File; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -public class JUnitUsageGenTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - File junitJar = new File("libraries/lib/junit-4.11.jar"); - - if (!junitJar.exists()) { - throw new AssertionError("JUnit jar wasn't found"); - } - - myEnvironment = KotlinCoreEnvironment.createForTests( - getTestRootDisposable(), - KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, junitJar), - EnvironmentConfigFiles.JVM_CONFIG_FILES); - } - - @NotNull - @Override - protected String getPrefix() { - return "junit"; - } - - public void testKt2344() throws Exception { - loadFile(); - generateFunction().invoke(null); - } - - public void testKt1592() throws Exception { - loadFile(); - Class packageClass = generateFacadeClass(); - Method method = packageClass.getMethod("foo", Method.class); - method.setAccessible(true); - Annotation annotation = method.getAnnotation(loadAnnotationClassQuietly(Test.class.getName())); - assertEquals(CodegenTestUtil.getAnnotationAttribute(annotation, "timeout"), Long.valueOf(0)); - Class expected = (Class) CodegenTestUtil.getAnnotationAttribute(annotation, "expected"); - assertNotNull(expected); - assertEquals(Test.None.class.getName(), expected.getName()); - } -} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PatternMatchingTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PatternMatchingTest.java deleted file mode 100644 index 7825e5f50ad..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PatternMatchingTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2010-2015 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.annotations.NotNull; -import org.jetbrains.kotlin.test.ConfigurationKind; - -import java.lang.reflect.Method; - -import static org.jetbrains.kotlin.codegen.CodegenTestUtil.assertThrows; - -public class PatternMatchingTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - @NotNull - @Override - protected String getPrefix() { - return "patternMatching"; - } - - public void testConstant() throws Exception { - loadFile(); - Method foo = generateFunction(); - assertTrue((Boolean) foo.invoke(null, 0)); - assertFalse((Boolean) foo.invoke(null, 1)); - } - - public void testExceptionOnNoMatch() throws Exception { - loadFile(); - Method foo = generateFunction(); - assertTrue((Boolean) foo.invoke(null, 0)); - assertThrows(foo, Exception.class, null, 1); - } - - public void testPattern() throws Exception { - loadFile(); - Method foo = generateFunction(); - assertEquals("string", foo.invoke(null, "")); - assertEquals("something", foo.invoke(null, new Object())); - } - - public void testInrange() throws Exception { - loadFile(); - Method foo = generateFunction(); - assertEquals("array list", foo.invoke(null, 239)); - assertEquals("digit", foo.invoke(null, 0)); - assertEquals("digit", foo.invoke(null, 9)); - assertEquals("digit", foo.invoke(null, 5)); - assertEquals("not small", foo.invoke(null, 190)); - assertEquals("something", foo.invoke(null, 19)); - } - - public void testRangeChar() throws Exception { - loadFile(); - Method foo = generateFunction(); - assertEquals("digit", foo.invoke(null, '0')); - assertEquals("something", foo.invoke(null, 'A')); - } - - public void testWildcardPattern() throws Exception { - loadText("fun foo(x: String) = when(x) { else -> \"something\" }"); - Method foo = generateFunction(); - assertEquals("something", foo.invoke(null, "")); - } - - public void testNoReturnType() throws Exception { - loadText("fun foo(x: String) = when(x) { else -> \"x\" }"); - Method foo = generateFunction(); - assertEquals("x", foo.invoke(null, "")); - } - - public void testCall() throws Exception { - loadText("fun foo(s: String) = when { s[0] == 'J' -> \"JetBrains\"; else -> \"something\" }"); - Method foo = generateFunction(); - assertEquals("JetBrains", foo.invoke(null, "Java")); - assertEquals("something", foo.invoke(null, "C#")); - } - - public void testMultipleConditions() throws Exception { - loadText("fun foo(x: Any) = when(x) { 0, 1 -> \"bit\"; else -> \"something\" }"); - Method foo = generateFunction(); - assertEquals("bit", foo.invoke(null, 0)); - assertEquals("bit", foo.invoke(null, 1)); - assertEquals("something", foo.invoke(null, 2)); - } -} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java index 8dee84698da..824aec6f283 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java @@ -159,7 +159,7 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testCastOnStack() throws Exception { loadText("fun foo(l: Long): Double = l.toDouble()"); - Class mainClass = generateFileClass(); + Class mainClass = generateFacadeClass(); Method main = mainClass.getDeclaredMethod("foo", long.class); double result = (Double) main.invoke(null, 42L); assertTrue(Math.abs(42L - result) <= 1e-9); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java index 7293f9c408a..579b45cb27f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java @@ -73,7 +73,7 @@ public class PropertyGenTest extends CodegenTestCase { public void testPrivatePropertyInPackage() throws Exception { loadText("private val x = 239"); - Class nsClass = generateFileClass(); + Class nsClass = generateFacadeClass(); Field[] fields = nsClass.getDeclaredFields(); assertEquals(1, fields.length); Field field = fields[0]; diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/StringsTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/StringsTest.java deleted file mode 100644 index f2541634090..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/StringsTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010-2015 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.test.ConfigurationKind; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class StringsTest extends CodegenTestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - public void testAnyToString () throws InvocationTargetException, IllegalAccessException { - loadText("fun foo(x: Any) = x.toString()"); - Method foo = generateFunction(); - assertEquals("something", foo.invoke(null, "something")); - } - - public void testNullableAnyToString () throws InvocationTargetException, IllegalAccessException { - loadText("fun foo(x: Any?) = x.toString()"); - Method foo = generateFunction(); - assertEquals("something", foo.invoke(null, "something")); - assertEquals("null", foo.invoke(null, new Object[]{null})); - - } - - public void testNullableStringPlus () throws InvocationTargetException, IllegalAccessException { - loadText("fun foo(x: String?, y: Any?) = x + y"); - String text = generateToText(); - assertTrue(text.contains(".stringPlus")); - Method foo = generateFunction(); - assertEquals("something239", foo.invoke(null, "something", 239)); - assertEquals("null239", foo.invoke(null, null, 239)); - assertEquals("239null", foo.invoke(null, "239", null)); - assertEquals("nullnull", foo.invoke(null, null, null)); - - } - - public void testNonNullableStringPlus () throws InvocationTargetException, IllegalAccessException { - loadText("fun foo(x: String, y: Any?) = x + y + 120"); - String text = generateToText(); - assertFalse(text.contains(".stringPlus")); - Method foo = generateFunction(); - assertEquals("something239120", foo.invoke(null, "something", 239)); - assertEquals("239null120", foo.invoke(null, "239", null)); - - } -}