Make System.out.println work

This commit is contained in:
Daniel Holle 2023-10-27 15:28:46 +02:00
parent e31f1c59e1
commit 837317c84c
3 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,9 @@
import java.lang.System;
import java.lang.String;
import java.io.PrintStream;
public class HelloWorld {
static hello() {
System.out.println("Hello World!");
}
}

View File

@ -119,6 +119,10 @@ public class JavaTXCompiler {
if (clazz.getClassName().equals(name)) return clazz; if (clazz.getClassName().equals(name)) return clazz;
} }
} }
try {
var clazz = classLoader.loadClass(name.toString());
return ASTFactory.createClass(clazz);
} catch (ClassNotFoundException ignored) {}
return null; return null;
} }

View File

@ -754,4 +754,12 @@ public class TestComplete {
var m = clazz.getDeclaredMethod("m"); var m = clazz.getDeclaredMethod("m");
assertEquals(m.invoke(instance), 5); assertEquals(m.invoke(instance), 5);
} }
@Test
public void testHelloWorld() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "HelloWorld.jav");
var clazz = classFiles.get("HelloWorld");
var hello = clazz.getDeclaredMethod("hello");
hello.invoke(null);
}
} }