From 5e14acfa12ca39f5030c4d0dcf3d3b2ec9e5d5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 8 Aug 2018 18:12:24 +0200 Subject: [PATCH 1/3] modified: ../../test/bytecode/javFiles/Merge.jav modified: ../../test/bytecode/javFiles/OL.jav --- test/bytecode/javFiles/Merge.jav | 4 ++-- test/bytecode/javFiles/OL.jav | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/bytecode/javFiles/Merge.jav b/test/bytecode/javFiles/Merge.jav index 627e9f451..9240146e0 100644 --- a/test/bytecode/javFiles/Merge.jav +++ b/test/bytecode/javFiles/Merge.jav @@ -10,11 +10,11 @@ class Merge { } -/* + 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 b231e6a04..68650428e 100644 --- a/test/bytecode/javFiles/OL.jav +++ b/test/bytecode/javFiles/OL.jav @@ -14,7 +14,7 @@ public class OL { public class OLMain { - main(java.lang.Integer x) { + main(x) { var ol; ol = new OL(); return ol.m(x); From 9b131c48b01a9ad58b31585b242c291552b6bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 9 Aug 2018 15:32:48 +0200 Subject: [PATCH 2/3] modified: test/bytecode/LambdaTest.java modified: test/bytecode/javFiles/Lambda.jav aufgeraeumt new file: test/bytecode/LambdaVoidTest.java new file: test/bytecode/javFiles/LambdaVoid.jav FunVoidN-Tests --- test/bytecode/LambdaTest.java | 4 +-- test/bytecode/LambdaVoidTest.java | 47 +++++++++++++++++++++++++++ test/bytecode/javFiles/Lambda.jav | 7 ---- test/bytecode/javFiles/LambdaVoid.jav | 9 +++++ 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 test/bytecode/LambdaVoidTest.java create mode 100644 test/bytecode/javFiles/LambdaVoid.jav diff --git a/test/bytecode/LambdaTest.java b/test/bytecode/LambdaTest.java index 8a4abcd56..b79ed16eb 100644 --- a/test/bytecode/LambdaTest.java +++ b/test/bytecode/LambdaTest.java @@ -40,9 +40,9 @@ public class LambdaTest { apply.setAccessible(true); Integer i = 77; - // result = 77*77 = 5929 + Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); -// assertEquals(5929, result); + assertEquals(77, result); } diff --git a/test/bytecode/LambdaVoidTest.java b/test/bytecode/LambdaVoidTest.java new file mode 100644 index 000000000..ea83dbe09 --- /dev/null +++ b/test/bytecode/LambdaVoidTest.java @@ -0,0 +1,47 @@ +package bytecode; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class LambdaVoidTest { + 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/Lambda.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("Lambda"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + + Method m = classToTest.getDeclaredMethod("m"); + Class lambda = m.invoke(instanceOfClass).getClass(); + Method apply = lambda.getMethod("apply", Object.class); + + // Damit man auf die Methode zugreifen kann + apply.setAccessible(true); + + Integer i = 77; + apply.invoke(m.invoke(instanceOfClass), i); + } + + +} diff --git a/test/bytecode/javFiles/Lambda.jav b/test/bytecode/javFiles/Lambda.jav index bb7de0b46..ba466b180 100644 --- a/test/bytecode/javFiles/Lambda.jav +++ b/test/bytecode/javFiles/Lambda.jav @@ -6,13 +6,6 @@ public class Lambda { var lam1 = (x) -> { return x; }; -<<<<<<< HEAD return lam1; -======= - - return lam1.apply(new Apply()); - //return lam1; - //return new Vector(); ->>>>>>> 3fedbcc4a0e015ec8f5f6ccb77081f888135c850 } } diff --git a/test/bytecode/javFiles/LambdaVoid.jav b/test/bytecode/javFiles/LambdaVoid.jav new file mode 100644 index 000000000..dc16fcbf5 --- /dev/null +++ b/test/bytecode/javFiles/LambdaVoid.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; + +public class Lambda { + + m () { + var lam1 = (x) -> { }; + return lam1; + } +} From 5f89188d0074785d619cd3f2cd99b740fa780b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 13 Aug 2018 18:19:02 +0200 Subject: [PATCH 3/3] new file: ../../test/bytecode/Tph5Test.java new file: ../../test/bytecode/javFiles/Tph5.jav erzeugt Typfehler zur Laufzeit mit mport java.util.Vector; public class Tph5Use { public static void main(String[] args) { Tph5 tph5 = new Tph5(); Integer i = tph5.m(1,2,3); String s = tph5.m("xx",2,3); } } --- test/bytecode/Tph5Test.java | 44 +++++++++++++++++++++++++++++++++ test/bytecode/javFiles/Tph5.jav | 7 ++++++ 2 files changed, 51 insertions(+) create mode 100644 test/bytecode/Tph5Test.java create mode 100644 test/bytecode/javFiles/Tph5.jav diff --git a/test/bytecode/Tph5Test.java b/test/bytecode/Tph5Test.java new file mode 100644 index 000000000..7d44e5e52 --- /dev/null +++ b/test/bytecode/Tph5Test.java @@ -0,0 +1,44 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class Tph5Test { + + 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; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Tph5.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + compiler.generateBytecode(pathToClassFile); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("Tph5"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + + @Test + public void test() throws Exception { + Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class, Object.class); + Object result = m.invoke(instanceOfClass, "xx",2,3); + + //assertEquals(2,result); + } +} diff --git a/test/bytecode/javFiles/Tph5.jav b/test/bytecode/javFiles/Tph5.jav new file mode 100644 index 000000000..1772b7ce3 --- /dev/null +++ b/test/bytecode/javFiles/Tph5.jav @@ -0,0 +1,7 @@ +public class Tph5 { + m(a,b,c){ + a = c; + b = c; + return a; + } +}