From 89387d27184bc56b9df12fcb8e0e121eaacb1f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 6 Aug 2018 10:03:03 +0200 Subject: [PATCH 1/2] new file: ../../test/bytecode/MergeTest.java new file: ../../test/bytecode/javFiles/Merge.jav --- test/bytecode/MergeTest.java | 39 ++++++++++++++++++++++++++++++++ test/bytecode/javFiles/Merge.jav | 17 ++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/bytecode/MergeTest.java create mode 100644 test/bytecode/javFiles/Merge.jav diff --git a/test/bytecode/MergeTest.java b/test/bytecode/MergeTest.java new file mode 100644 index 000000000..c4da52ce3 --- /dev/null +++ b/test/bytecode/MergeTest.java @@ -0,0 +1,39 @@ +package bytecode; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class MergeTest { + private static String path; + private static File fileToTest; + private static JavaTXCompiler compiler; + private static ClassLoader loader; + private static Class classToTest; + private static String pathToClassFile; + private static Object instanceOfClass; + + @Test + public void generateBC() throws Exception { + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Merge.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/"); + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("Merge"); + //instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + + //Method m = classToTest.getDeclaredMethod("m"); + //Object result = m.invoke(instanceOfClass); + + //assertEquals(result.getClass(), loader.loadClass("Apply")); + } +} diff --git a/test/bytecode/javFiles/Merge.jav b/test/bytecode/javFiles/Merge.jav new file mode 100644 index 000000000..0c50b4434 --- /dev/null +++ b/test/bytecode/javFiles/Merge.jav @@ -0,0 +1,17 @@ +import java.util.List; +import java.lang.Integer; +import java.util.Collection; + +class Merge { + +merge(a, b) { + a.addAll(b); + return a; + } + + sort(in){ + var firstHalf = in.subList(1,2); + var secondHalf = in.subList(1,2); + return merge(sort(firstHalf), sort(secondHalf)); + } +} \ No newline at end of file From 6264d928b2ffa45e52f11443a37e5aa6748ab6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 6 Aug 2018 13:14:08 +0200 Subject: [PATCH 2/2] modified: test/bytecode/javFiles/Merge.jav modified: test/bytecode/javFiles/OL.jav --- test/bytecode/javFiles/Merge.jav | 3 ++- test/bytecode/javFiles/OL.jav | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/bytecode/javFiles/Merge.jav b/test/bytecode/javFiles/Merge.jav index 0c50b4434..1ac08f1d4 100644 --- a/test/bytecode/javFiles/Merge.jav +++ b/test/bytecode/javFiles/Merge.jav @@ -8,10 +8,11 @@ merge(a, b) { a.addAll(b); return a; } - +/* sort(in){ var firstHalf = in.subList(1,2); var secondHalf = in.subList(1,2); return merge(sort(firstHalf), sort(secondHalf)); } + */ } \ No newline at end of file diff --git a/test/bytecode/javFiles/OL.jav b/test/bytecode/javFiles/OL.jav index 263cf1ec4..e117f7dd6 100644 --- a/test/bytecode/javFiles/OL.jav +++ b/test/bytecode/javFiles/OL.jav @@ -13,9 +13,9 @@ public class OL { } -public class OLMain { +public class OLMain { - main(x) { + main(java.lang.Integer x) { var ol; ol = new OL(); return ol.m(x);