blackBox() infrastructure
This commit is contained in:
@@ -9,3 +9,7 @@ class P1(x : Int, y : Y) : Abstract, X(x), Y by y {}
|
|||||||
class P2(x : Int, y : Y) : X(x), Abstract, Y by y {}
|
class P2(x : Int, y : Y) : X(x), Abstract, Y by y {}
|
||||||
class P3(x : Int, y : Y) : X(x), Y by y, Abstract {}
|
class P3(x : Int, y : Y) : X(x), Y by y, Abstract {}
|
||||||
class P4(x : Int, y : Y) : Y by y, Abstract, X(x) {}
|
class P4(x : Int, y : Y) : Y by y, Abstract, X(x) {}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
"OK"
|
||||||
|
}
|
||||||
@@ -23,14 +23,12 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
final Class aClass = loadClass("Foo", generateClassesInFile());
|
final Class aClass = loadClass("Foo", generateClassesInFile());
|
||||||
checkInterface(aClass, List.class);
|
checkInterface(aClass, List.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayInheritance() throws Exception {
|
public void testArrayInheritance() throws Exception {
|
||||||
loadFile("inheritance.jet");
|
loadFile("inheritance.jet");
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
|
|
||||||
/*
|
assertEquals("OK", blackBox());
|
||||||
final Class aClass = loadClass("Foo", generateClassesInFile());
|
|
||||||
checkInterface(aClass, List.class);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkInterface(Class aClass, Class ifs) {
|
private static void checkInterface(Class aClass, Class ifs) {
|
||||||
|
|||||||
@@ -40,6 +40,18 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
|||||||
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String blackBox() throws Exception {
|
||||||
|
Codegens codegens = generateClassesInFile();
|
||||||
|
CodegensClassLoader loader = new CodegensClassLoader(codegens);
|
||||||
|
|
||||||
|
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||||
|
final JetNamespace namespace = jetFile.getRootNamespace();
|
||||||
|
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
|
||||||
|
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||||
|
Method method = namespaceClass.getMethod("box");
|
||||||
|
return (String) method.invoke(null);
|
||||||
|
}
|
||||||
|
|
||||||
protected String generateToText() {
|
protected String generateToText() {
|
||||||
Codegens state = new Codegens(getProject(), true);
|
Codegens state = new Codegens(getProject(), true);
|
||||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||||
@@ -144,6 +156,25 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class CodegensClassLoader extends ClassLoader {
|
||||||
|
private final Codegens state;
|
||||||
|
|
||||||
|
public CodegensClassLoader(Codegens state) {
|
||||||
|
super(CodegenTestCase.class.getClassLoader());
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
|
String file = name.replace('.', '/') + ".class";
|
||||||
|
if (state.files().contains(file)) {
|
||||||
|
byte[] bytes = state.asBytes(file);
|
||||||
|
return defineClass(name, bytes, 0, bytes.length);
|
||||||
|
}
|
||||||
|
return super.findClass(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected LightProjectDescriptor getProjectDescriptor() {
|
protected LightProjectDescriptor getProjectDescriptor() {
|
||||||
|
|||||||
Reference in New Issue
Block a user