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