diff --git a/resources/bytecode/javFiles/HelloWorld.jav b/resources/bytecode/javFiles/HelloWorld.jav new file mode 100644 index 00000000..ff3df087 --- /dev/null +++ b/resources/bytecode/javFiles/HelloWorld.jav @@ -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!"); + } +} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 9a36f871..c337dcd0 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -119,6 +119,10 @@ public class JavaTXCompiler { if (clazz.getClassName().equals(name)) return clazz; } } + try { + var clazz = classLoader.loadClass(name.toString()); + return ASTFactory.createClass(clazz); + } catch (ClassNotFoundException ignored) {} return null; } diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index e4e5849b..3b7386ec 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -754,4 +754,12 @@ public class TestComplete { var m = clazz.getDeclaredMethod("m"); 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); + } }