Fix warnings in JVM codegen tests
Add generics where needed, add nullability annotations, etc. Also delete some testcases from ArrayGenTest which will never be supported
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
class List<T>(len: Int) {
|
||||
val a = Array<T?>(len) { null }
|
||||
|
||||
fun reverse() {
|
||||
var i = 0
|
||||
var j = a.size-1
|
||||
while(i < j) {
|
||||
val x = a[i]
|
||||
a[i++] = a[j]
|
||||
a[j--] = x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val d = List<Int>(1)
|
||||
d.a[0] = 10
|
||||
checkEquals(d.a[0], 10)
|
||||
|
||||
val a = List<String>(1)
|
||||
a.a[0] = "1"
|
||||
checkEquals(a.a[0], "1")
|
||||
|
||||
val b = List<Int?>(1)
|
||||
b.a[0] = 10
|
||||
checkEquals(b.a[0], 10)
|
||||
|
||||
val c = List<Array<Int>>(1)
|
||||
c.a[0] = Array<Int>(4,{-1})
|
||||
checkEquals(c.a[0]?.size, 4)
|
||||
|
||||
val e = List<Int>(5)
|
||||
e.a[0] = 0
|
||||
e.a[1] = 1
|
||||
e.a[2] = 2
|
||||
e.a[3] = 3
|
||||
e.a[4] = 4
|
||||
e.reverse()
|
||||
for (i in 0..4)
|
||||
checkEquals(e.a[i], 4-i)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun checkEquals(a: Any?, b: Any?) {
|
||||
if (a != b) throw AssertionError("Expected: $b, actual: $a")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(box())
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase {
|
||||
}
|
||||
catch (Throwable e) {
|
||||
System.out.println(text);
|
||||
UtilsPackage.rethrow(e);
|
||||
throw UtilsPackage.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.OutputFile;
|
||||
import org.jetbrains.jet.OutputFileCollection;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.test.TestCaseWithTmpdir;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -68,7 +68,6 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
String text = FileUtil.loadFile(ktFile, true);
|
||||
|
||||
JetFile psiFile = JetTestUtils.createFile(ktFile.getName(), text, jetCoreEnvironment.getProject());
|
||||
assert psiFile != null;
|
||||
|
||||
OutputFileCollection outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
|
||||
|
||||
@@ -176,7 +175,7 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<LocalVariable> readLocalVariable(ClassReader cr, final String methodName) throws Exception {
|
||||
private static List<LocalVariable> readLocalVariable(ClassReader cr, final String methodName) throws Exception {
|
||||
class Visitor extends ClassVisitor {
|
||||
List<LocalVariable> readVariables = new ArrayList<LocalVariable>();
|
||||
|
||||
@@ -185,14 +184,17 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
public MethodVisitor visitMethod(
|
||||
int access, @NotNull String name, @NotNull String desc, String signature, String[] exceptions
|
||||
) {
|
||||
if (methodName.equals(name + desc)) {
|
||||
return new MethodVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
|
||||
public void visitLocalVariable(
|
||||
@NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index
|
||||
) {
|
||||
readVariables.add(new LocalVariable(name, desc, index));
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -27,26 +27,13 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
public void testKt326() {
|
||||
// Disabled: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
|
||||
/*
|
||||
blackBoxFile("regressions/kt326.kt");
|
||||
*/
|
||||
}
|
||||
|
||||
public void testCreateMultiInt() throws Exception {
|
||||
loadText("fun foo() = Array<Array<Int>> (5, { Array<Int>(it, {239}) })");
|
||||
Method foo = generateFunction();
|
||||
try {
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
assertEquals(invoke[2].length, 2);
|
||||
assertEquals(invoke[4].length, 4);
|
||||
assertEquals(invoke[4][2].intValue(), 239);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
throw ((e instanceof RuntimeException)) ? (RuntimeException) e : new RuntimeException(e);
|
||||
}
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
assertEquals(invoke[2].length, 2);
|
||||
assertEquals(invoke[4].length, 4);
|
||||
assertEquals(invoke[4][2].intValue(), 239);
|
||||
}
|
||||
|
||||
public void testCreateMultiIntNullable() throws Exception {
|
||||
@@ -64,17 +51,6 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
assertTrue(invoke instanceof Object[]);
|
||||
}
|
||||
|
||||
public void testCreateMultiGenerics() throws Exception {
|
||||
// Disabled: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
|
||||
/*
|
||||
loadText("class L<T>() { val a = Array<T?>(5) { null } } fun foo() = L<Int>().a");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
assertTrue(invoke.getClass() == Object[].class);
|
||||
*/
|
||||
}
|
||||
|
||||
public void testIntGenerics() throws Exception {
|
||||
loadText("class L<T>(var a : T) {} fun foo() = L<Int>(5).a");
|
||||
Method foo = generateFunction();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
public void testPSVMClass() {
|
||||
loadFile("classes/simpleClass.kt");
|
||||
|
||||
Class aClass = generateClass("SimpleClass");
|
||||
Class<?> aClass = generateClass("SimpleClass");
|
||||
Method[] methods = aClass.getDeclaredMethods();
|
||||
// public int SimpleClass.foo()
|
||||
assertEquals(1, methods.length);
|
||||
@@ -47,32 +47,36 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
|
||||
public void testArrayListInheritance() throws Exception {
|
||||
loadFile("classes/inheritingFromArrayList.kt");
|
||||
Class aClass = generateClass("Foo");
|
||||
Class<?> aClass = generateClass("Foo");
|
||||
assertInstanceOf(aClass.newInstance(), List.class);
|
||||
}
|
||||
|
||||
public void testDelegationToVal() throws Exception {
|
||||
loadFile("classes/delegationToVal.kt");
|
||||
GeneratedClassLoader loader = generateAndCreateClassLoader();
|
||||
Class aClass = loader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT));
|
||||
Class<?> aClass = loader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT));
|
||||
assertEquals("OK", aClass.getMethod("box").invoke(null));
|
||||
|
||||
Class test = loader.loadClass("Test");
|
||||
Class<?> test = loader.loadClass("Test");
|
||||
try {
|
||||
test.getDeclaredField("$delegate_0");
|
||||
fail("$delegate_0 field generated for class Test but should not");
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
catch (NoSuchFieldException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
Class test2 = loader.loadClass("Test2");
|
||||
Class<?> test2 = loader.loadClass("Test2");
|
||||
try {
|
||||
test2.getDeclaredField("$delegate_0");
|
||||
fail("$delegate_0 field generated for class Test2 but should not");
|
||||
}
|
||||
catch (NoSuchFieldException e) {}
|
||||
catch (NoSuchFieldException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
Class test3 = loader.loadClass("Test3");
|
||||
Class iActing = loader.loadClass("IActing");
|
||||
Class<?> test3 = loader.loadClass("Test3");
|
||||
Class<?> iActing = loader.loadClass("IActing");
|
||||
Object obj = test3.newInstance();
|
||||
assertTrue(iActing.isInstance(obj));
|
||||
Method iActingMethod = iActing.getMethod("act");
|
||||
@@ -89,14 +93,14 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
|
||||
public void testAbstractMethod() throws Exception {
|
||||
loadText("abstract class Foo { abstract fun x(): String; fun y(): Int = 0 }");
|
||||
Class aClass = generateClass("Foo");
|
||||
Class<?> aClass = generateClass("Foo");
|
||||
assertNotNull(aClass.getMethod("x"));
|
||||
assertNotNull(findDeclaredMethodByName(aClass, "y"));
|
||||
findDeclaredMethodByName(aClass, "y");
|
||||
}
|
||||
|
||||
public void testAbstractClass() throws Exception {
|
||||
loadText("abstract class SimpleClass() { }");
|
||||
Class aClass = generateClass("SimpleClass");
|
||||
Class<?> aClass = generateClass("SimpleClass");
|
||||
assertTrue((aClass.getModifiers() & Modifier.ABSTRACT) != 0);
|
||||
}
|
||||
|
||||
@@ -109,7 +113,7 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
|
||||
public void testEnumClass() throws Exception {
|
||||
loadText("enum class Direction { NORTH; SOUTH; EAST; WEST }");
|
||||
Class direction = generateClass("Direction");
|
||||
Class<?> direction = generateClass("Direction");
|
||||
Field north = direction.getField("NORTH");
|
||||
assertEquals(direction, north.getType());
|
||||
assertInstanceOf(north.get(null), direction);
|
||||
@@ -117,7 +121,7 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
|
||||
public void testEnumConstantConstructors() throws Exception {
|
||||
loadText("enum class Color(val rgb: Int) { RED: Color(0xFF0000); GREEN: Color(0x00FF00); }");
|
||||
Class colorClass = generateClass("Color");
|
||||
Class<?> colorClass = generateClass("Color");
|
||||
Field redField = colorClass.getField("RED");
|
||||
Object redValue = redField.get(null);
|
||||
Method rgbMethod = colorClass.getMethod("getRgb");
|
||||
|
||||
@@ -276,12 +276,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
|
||||
@NotNull
|
||||
protected Method generateFunction(@NotNull String name) {
|
||||
Class<?> aClass = generatePackageClass();
|
||||
Method method = findDeclaredMethodByName(aClass, name);
|
||||
if (method == null) {
|
||||
throw new IllegalArgumentException("Couldn't find method " + name + " in class " + aClass);
|
||||
}
|
||||
return method;
|
||||
return findDeclaredMethodByName(generatePackageClass(), name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -80,14 +80,14 @@ public class CodegenTestUtil {
|
||||
assertTrue(caught);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public static Method findDeclaredMethodByName(@NotNull Class<?> aClass, @NotNull String name) {
|
||||
for (Method method : aClass.getDeclaredMethods()) {
|
||||
if (method.getName().equals(name)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
throw new AssertionError("Method " + name + " is not found in class " + aClass);
|
||||
}
|
||||
|
||||
public static void assertIsCurrentTime(long returnValue) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.codegen;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
@@ -31,23 +30,23 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
public void testSuperclassIsEnum() throws NoSuchFieldException, IllegalAccessException {
|
||||
public void testSuperclassIsEnum() throws Exception {
|
||||
loadFile("enum/simple.kt");
|
||||
Class season = generateClass("Season");
|
||||
Class<?> season = generateClass("Season");
|
||||
assertEquals("java.lang.Enum", season.getSuperclass().getName());
|
||||
}
|
||||
|
||||
public void testEnumClassModifiers() throws NoSuchFieldException, IllegalAccessException {
|
||||
public void testEnumClassModifiers() throws Exception {
|
||||
loadFile("enum/simple.kt");
|
||||
Class season = generateClass("Season");
|
||||
Class<?> season = generateClass("Season");
|
||||
int modifiers = season.getModifiers();
|
||||
assertTrue((modifiers & 0x4000) != 0); // ACC_ENUM
|
||||
assertTrue((modifiers & Modifier.FINAL) != 0);
|
||||
}
|
||||
|
||||
public void testEnumFieldModifiers() throws NoSuchFieldException, IllegalAccessException {
|
||||
public void testEnumFieldModifiers() throws Exception {
|
||||
loadFile("enum/simple.kt");
|
||||
Class season = generateClass("Season");
|
||||
Class<?> season = generateClass("Season");
|
||||
Field summer = season.getField("SUMMER");
|
||||
int modifiers = summer.getModifiers();
|
||||
assertTrue((modifiers & 0x4000) != 0); // ACC_ENUM
|
||||
@@ -58,25 +57,23 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
|
||||
public void testEnumConstantConstructors() throws Exception {
|
||||
loadText("enum class Color(val rgb: Int) { RED: Color(0xFF0000); GREEN: Color(0x00FF00); }");
|
||||
Class colorClass = generateClass("Color");
|
||||
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 ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||
public void testNoClassForSimpleEnum() throws Exception {
|
||||
loadFile("enum/name.kt");
|
||||
Class cls = generateClass("State");
|
||||
Class<?> cls = generateClass("State");
|
||||
Field field = cls.getField("O");
|
||||
assertEquals("State", field.get(null).getClass().getName());
|
||||
}
|
||||
|
||||
public void testYesClassForComplexEnum()
|
||||
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||
public void testYesClassForComplexEnum() throws Exception {
|
||||
loadFile("enum/abstractmethod.kt");
|
||||
Class cls = generateClass("IssueState");
|
||||
Class<?> cls = generateClass("IssueState");
|
||||
Field field = cls.getField("DEFAULT");
|
||||
assertEquals("IssueState", field.get(null).getClass().getName());
|
||||
field = cls.getField("FIXED");
|
||||
@@ -88,6 +85,7 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
fail();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,11 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
|
||||
public void testNoRefToOuter() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
|
||||
loadText("class A() { fun f() : ()->String { val s = \"OK\"; return { -> s } } }");
|
||||
Class foo = generateClass("A");
|
||||
Class<?> foo = generateClass("A");
|
||||
Object obj = foo.newInstance();
|
||||
Method f = foo.getMethod("f");
|
||||
Object closure = f.invoke(obj);
|
||||
Class<? extends Object> aClass = closure.getClass();
|
||||
Class<?> aClass = closure.getClass();
|
||||
Field[] fields = aClass.getDeclaredFields();
|
||||
assertEquals(1, fields.length);
|
||||
assertEquals("$s", fields[0].getName());
|
||||
|
||||
@@ -18,10 +18,7 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.*;
|
||||
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
@@ -29,6 +26,10 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -167,7 +168,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
reader.accept(new ClassVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(
|
||||
int access, final String callerName, final String callerDesc, String signature, String[] exceptions
|
||||
int access, @NotNull final String callerName, @NotNull final String callerDesc, String signature, String[] exceptions
|
||||
) {
|
||||
return new MethodVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public class PackageGenTest extends CodegenTestCase {
|
||||
public void testReturnOne() throws Exception {
|
||||
loadText("fun f() : Int { return 42; }");
|
||||
Method main = generateFunction();
|
||||
Object returnValue = main.invoke(null, new Object[0]);
|
||||
Object returnValue = main.invoke(null);
|
||||
assertEquals(new Integer(42), returnValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testPrivateVal() throws Exception {
|
||||
loadFile();
|
||||
Class aClass = generateClass("PrivateVal");
|
||||
Class<?> aClass = generateClass("PrivateVal");
|
||||
Field[] fields = aClass.getDeclaredFields();
|
||||
assertEquals(1, fields.length); // prop
|
||||
Field field = fields[0];
|
||||
@@ -49,7 +49,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testPrivateVar() throws Exception {
|
||||
loadFile();
|
||||
Class aClass = generateClass("PrivateVar");
|
||||
Class<?> aClass = generateClass("PrivateVar");
|
||||
Object instance = aClass.newInstance();
|
||||
Method setter = findDeclaredMethodByName(aClass, "setValueOfX");
|
||||
setter.invoke(instance, 239);
|
||||
@@ -59,7 +59,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testPublicVar() throws Exception {
|
||||
loadText("class PublicVar() { public var foo : Int = 0; }");
|
||||
Class aClass = generateClass("PublicVar");
|
||||
Class<?> aClass = generateClass("PublicVar");
|
||||
Object instance = aClass.newInstance();
|
||||
Method setter = findDeclaredMethodByName(aClass, "setFoo");
|
||||
setter.invoke(instance, 239);
|
||||
@@ -69,14 +69,14 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testAccessorsInInterface() {
|
||||
loadText("class AccessorsInInterface() { public var foo : Int = 0; }");
|
||||
Class aClass = generateClass("AccessorsInInterface");
|
||||
Class<?> aClass = generateClass("AccessorsInInterface");
|
||||
assertNotNull(findDeclaredMethodByName(aClass, "getFoo"));
|
||||
assertNotNull(findDeclaredMethodByName(aClass, "setFoo"));
|
||||
}
|
||||
|
||||
public void testPrivatePropertyInPackage() throws Exception {
|
||||
loadText("private val x = 239");
|
||||
Class nsClass = generatePackagePartClass();
|
||||
Class<?> nsClass = generatePackagePartClass();
|
||||
Field[] fields = nsClass.getDeclaredFields();
|
||||
assertEquals(1, fields.length);
|
||||
Field field = fields[0];
|
||||
@@ -121,7 +121,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testAccessorsWithoutBody() throws Exception {
|
||||
loadText("class AccessorsWithoutBody() { protected var foo: Int = 349\n get\n private set\n fun setter() { foo = 610; } } ");
|
||||
Class aClass = generateClass("AccessorsWithoutBody");
|
||||
Class<?> aClass = generateClass("AccessorsWithoutBody");
|
||||
Object instance = aClass.newInstance();
|
||||
Method getFoo = findDeclaredMethodByName(aClass, "getFoo");
|
||||
getFoo.setAccessible(true);
|
||||
@@ -144,7 +144,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testPropertyReceiverOnStack() throws Exception {
|
||||
loadFile();
|
||||
Class aClass = generateClass("Evaluator");
|
||||
Class<?> aClass = generateClass("Evaluator");
|
||||
Constructor constructor = aClass.getConstructor(StringBuilder.class);
|
||||
StringBuilder sb = new StringBuilder("xyzzy");
|
||||
Object instance = constructor.newInstance(sb);
|
||||
@@ -155,7 +155,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testAbstractVal() throws Exception {
|
||||
loadText("abstract class Foo { public abstract val x: String }");
|
||||
Class aClass = generateClass("Foo");
|
||||
Class<?> aClass = generateClass("Foo");
|
||||
assertNotNull(aClass.getMethod("getX"));
|
||||
}
|
||||
|
||||
@@ -168,88 +168,76 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
|
||||
public void testKt1846() {
|
||||
loadFile("regressions/kt1846.kt");
|
||||
Class aClass = generateClass("A");
|
||||
Class<?> aClass = generateClass("A");
|
||||
try {
|
||||
Method v1 = aClass.getMethod("getV1");
|
||||
aClass.getMethod("getV1");
|
||||
System.out.println(generateToText());
|
||||
fail();
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
try {
|
||||
Method v1 = aClass.getMethod("setV1");
|
||||
aClass.getMethod("setV1");
|
||||
System.out.println(generateToText());
|
||||
fail();
|
||||
}
|
||||
catch (NoSuchMethodException ee) {
|
||||
//
|
||||
// ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testKt2589() {
|
||||
public void testKt2589() throws Exception {
|
||||
loadFile("regressions/kt2589.kt");
|
||||
Class aClass = generateClass("Foo");
|
||||
Class<?> aClass = generateClass("Foo");
|
||||
assertTrue((aClass.getModifiers() & Opcodes.ACC_FINAL) == 0);
|
||||
|
||||
try {
|
||||
Field foo = aClass.getDeclaredField("foo");
|
||||
assertTrue((foo.getModifiers() & Opcodes.ACC_PRIVATE) != 0);
|
||||
assertTrue((foo.getModifiers() & Opcodes.ACC_FINAL) == 0);
|
||||
Field foo = aClass.getDeclaredField("foo");
|
||||
assertTrue((foo.getModifiers() & Opcodes.ACC_PRIVATE) != 0);
|
||||
assertTrue((foo.getModifiers() & Opcodes.ACC_FINAL) == 0);
|
||||
|
||||
Field bar = aClass.getDeclaredField("bar");
|
||||
assertTrue((bar.getModifiers() & Opcodes.ACC_PRIVATE) != 0);
|
||||
assertTrue((bar.getModifiers() & Opcodes.ACC_FINAL) != 0);
|
||||
Field bar = aClass.getDeclaredField("bar");
|
||||
assertTrue((bar.getModifiers() & Opcodes.ACC_PRIVATE) != 0);
|
||||
assertTrue((bar.getModifiers() & Opcodes.ACC_FINAL) != 0);
|
||||
|
||||
Method getFoo = aClass.getDeclaredMethod("getFoo");
|
||||
assertTrue((getFoo.getModifiers() & Opcodes.ACC_PUBLIC) != 0);
|
||||
assertTrue((getFoo.getModifiers() & Opcodes.ACC_FINAL) != 0);
|
||||
Method getFoo = aClass.getDeclaredMethod("getFoo");
|
||||
assertTrue((getFoo.getModifiers() & Opcodes.ACC_PUBLIC) != 0);
|
||||
assertTrue((getFoo.getModifiers() & Opcodes.ACC_FINAL) != 0);
|
||||
|
||||
Method getBar = aClass.getDeclaredMethod("getBar");
|
||||
assertTrue((getBar.getModifiers() & Opcodes.ACC_PROTECTED) != 0);
|
||||
assertTrue((getBar.getModifiers() & Opcodes.ACC_FINAL) == 0);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Method getBar = aClass.getDeclaredMethod("getBar");
|
||||
assertTrue((getBar.getModifiers() & Opcodes.ACC_PROTECTED) != 0);
|
||||
assertTrue((getBar.getModifiers() & Opcodes.ACC_FINAL) == 0);
|
||||
}
|
||||
|
||||
public void testKt2677() {
|
||||
public void testKt2677() throws Exception {
|
||||
loadFile("regressions/kt2677.kt");
|
||||
Class aClass = generateClass("DerivedWeatherReport");
|
||||
Class bClass = aClass.getSuperclass();
|
||||
Class<?> derived = generateClass("DerivedWeatherReport");
|
||||
Class<?> weatherReport = derived.getSuperclass();
|
||||
|
||||
try {
|
||||
{
|
||||
Method get = aClass.getDeclaredMethod("getForecast");
|
||||
Type type = get.getGenericReturnType();
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
{
|
||||
Method get = derived.getDeclaredMethod("getForecast");
|
||||
Type type = get.getGenericReturnType();
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
|
||||
Method set = aClass.getDeclaredMethod("setForecast", (Class)parameterizedType.getRawType());
|
||||
type = set.getGenericParameterTypes()[0];
|
||||
parameterizedType = (ParameterizedType) type;
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
}
|
||||
{
|
||||
Method get = bClass.getDeclaredMethod("getForecast");
|
||||
Type type = get.getGenericReturnType();
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
|
||||
Method set = bClass.getDeclaredMethod("setForecast", (Class)parameterizedType.getRawType());
|
||||
type = set.getGenericParameterTypes()[0];
|
||||
parameterizedType = (ParameterizedType) type;
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
}
|
||||
Method set = derived.getDeclaredMethod("setForecast", (Class<?>) parameterizedType.getRawType());
|
||||
type = set.getGenericParameterTypes()[0];
|
||||
parameterizedType = (ParameterizedType) type;
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
throw new RuntimeException(e);
|
||||
{
|
||||
Method get = weatherReport.getDeclaredMethod("getForecast");
|
||||
Type type = get.getGenericReturnType();
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
|
||||
Method set = weatherReport.getDeclaredMethod("setForecast", (Class<?>) parameterizedType.getRawType());
|
||||
type = set.getGenericParameterTypes()[0];
|
||||
parameterizedType = (ParameterizedType) type;
|
||||
assertInstanceOf(type, ParameterizedType.class);
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider;
|
||||
@@ -26,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -106,7 +106,7 @@ public class ScriptGenTest extends CodegenTestCase {
|
||||
|
||||
public void testTopLevelFunction() throws Exception {
|
||||
blackBoxScript("script/topLevelFunction.kts");
|
||||
Method method = scriptInstance.getClass().getMethod("factorial", new Class<?>[]{ int.class });
|
||||
Method method = scriptInstance.getClass().getMethod("factorial", int.class);
|
||||
Object r = method.invoke(scriptInstance, 4);
|
||||
assertEquals(24, r);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public class ScriptGenTest extends CodegenTestCase {
|
||||
public void testLanguage() {
|
||||
JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(FIB_SCRIPT_DEFINITION);
|
||||
loadFile("script/fib.lang.kt");
|
||||
Class aClass = generateClass("Fib");
|
||||
Class<?> aClass = generateClass("Fib");
|
||||
try {
|
||||
Constructor constructor = aClass.getConstructor(int.class);
|
||||
Field result = aClass.getDeclaredField("result");
|
||||
@@ -170,7 +170,7 @@ public class ScriptGenTest extends CodegenTestCase {
|
||||
public void testLanguageWithPackage() {
|
||||
JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(FIB_SCRIPT_DEFINITION);
|
||||
loadFile("script/fibwp.lang.kt");
|
||||
Class aClass = generateClass("test.Fibwp");
|
||||
Class<?> aClass = generateClass("test.Fibwp");
|
||||
try {
|
||||
Constructor constructor = aClass.getConstructor(int.class);
|
||||
Field result = aClass.getDeclaredField("result");
|
||||
@@ -186,7 +186,7 @@ public class ScriptGenTest extends CodegenTestCase {
|
||||
public void testDependentScripts() {
|
||||
JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(FIB_SCRIPT_DEFINITION);
|
||||
loadFiles("script/fibwp.lang.kt", "script/fibwprunner.kts");
|
||||
Class aClass = generateClass("Fibwprunner");
|
||||
Class<?> aClass = generateClass("Fibwprunner");
|
||||
try {
|
||||
Constructor constructor = aClass.getConstructor();
|
||||
Field result = aClass.getDeclaredField("result");
|
||||
@@ -209,7 +209,7 @@ public class ScriptGenTest extends CodegenTestCase {
|
||||
public void testScriptWhereMethodHasClosure() {
|
||||
JetScriptDefinitionProvider.getInstance(myEnvironment.getProject()).addScriptDefinition(FIB_SCRIPT_DEFINITION);
|
||||
loadFile("script/methodWithClosure.lang.kt");
|
||||
Class aClass = generateClass("MethodWithClosure");
|
||||
Class<?> aClass = generateClass("MethodWithClosure");
|
||||
try {
|
||||
Constructor constructor = aClass.getConstructor(int.class);
|
||||
Object script = constructor.newInstance(239);
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.OutputFile;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.OutputFile;
|
||||
|
||||
public class SourceInfoGenTest extends CodegenTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class VarArgTest extends CodegenTestCase {
|
||||
public void testArrayAsVararg2() throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("private fun asList(vararg elems: String) = elems; fun test(ts1: Array<String>, ts2: String) = asList(*ts1, ts2); ");
|
||||
Method main = generateFunction("test");
|
||||
Object invoke = main.invoke(null, new Object[] {new String[] {"mama"}, "papa" });
|
||||
Object invoke = main.invoke(null, new String[] {"mama"}, "papa");
|
||||
assertInstanceOf(invoke, String[].class);
|
||||
assertEquals(2, Array.getLength(invoke));
|
||||
assertEquals("mama", Array.get(invoke, 0));
|
||||
|
||||
Reference in New Issue
Block a user