From fa5a29c682430a45d2d8aa4d92b7c34547236c69 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 6 Aug 2022 14:10:25 +0200 Subject: [PATCH 1/2] modified: src/test/resources/bytecode/javFiles/Inf.jav Kommentare erweitert --- src/test/resources/bytecode/javFiles/Inf.jav | 46 +++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/test/resources/bytecode/javFiles/Inf.jav b/src/test/resources/bytecode/javFiles/Inf.jav index 3c785a6ee..788fca8d0 100644 --- a/src/test/resources/bytecode/javFiles/Inf.jav +++ b/src/test/resources/bytecode/javFiles/Inf.jav @@ -12,8 +12,44 @@ public class Inf { b=a; } } -// v w -// \ / -// z y b -// \ / \ / -// x a \ No newline at end of file + +/* +TPH M m(TPH N x, TPH O y, TPH P a)({ + TPH Q z; + TPH R v; + TPH S w; + TPH T b; + (y)::TPH O = (x)::TPH N; + (z)::TPH Q = (x)::TPH N; + (v)::TPH R = (y)::TPH O; + (w)::TPH S = (y)::TPH O; + (y)::TPH O = (a)::TPH P; + (b)::TPH T = (a)::TPH P; + return; + })::TPH U + + Inf()({ + super(()); + })::TPH X + +} +// v::R w::S +// \ / +// z::Q y::O b::T +// \ / \ / +// x::N a::P + +RESULT Final: [[(TPH O < TPH S), (TPH P < TPH O), (TPH O < TPH R), (TPH P < TPH T), (TPH M = void), (TPH N < TPH O), (TPH N < TPH Q)]] +Simplified constraints: [(TPH O < TPH S), (TPH P < TPH O), (TPH O < TPH R), (TPH P < TPH T), (TPH N < TPH O), (TPH N < TPH Q)] +m: [(TPH DDV = java.lang.Object), (TPH DDX = java.lang.Object), (TPH DDX < TPH DDV), (TPH N < TPH DDX), (TPH P < TPH DDX)] +Class Inf: [] +Inf: [] + +Unify nach Oder-Constraints-Anpassung: +UND:[(void =. M, , -1 WC: false, IT: false), (N <. O, 1 WC: false, IT: false, 1 WC: false, IT: false), (P <. O, 1 WC: false, IT: false, 1 WC: false, IT: false), (N <. Q, 1 WC: false, IT: false, 0 WC: true, IT: false), (O <. S, 1 WC: false, IT: false, 0 WC: true, IT: false), (O <. R, 1 WC: false, IT: false, 0 WC: true, IT: false), (P <. T, 1 WC: false, IT: false, 0 WC: true, IT: false)] +isInherited = false +isStatement = false + +ODER: +*/ + From 092d066774deefc598e1b0555bf1df189fd0b879 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 6 Aug 2022 22:17:49 +0200 Subject: [PATCH 2/2] modified: ../../java/targetast/TphTest.java Test fuer Tph7 so angepasst, dass ueberprueft wird ob die richtigen Typvariablen generiert werden --- src/test/java/targetast/TphTest.java | 70 +++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/src/test/java/targetast/TphTest.java b/src/test/java/targetast/TphTest.java index 198bea5bc..a1a1a2143 100644 --- a/src/test/java/targetast/TphTest.java +++ b/src/test/java/targetast/TphTest.java @@ -5,6 +5,8 @@ import org.junit.BeforeClass; import org.junit.Test; import java.lang.reflect.Method; +import java.lang.reflect.TypeVariable; +import java.util.Arrays; import static org.junit.Assert.assertEquals; @@ -12,23 +14,77 @@ public class TphTest { private static Class classToTest; private static Object instanceOfClass; - + @BeforeClass public static void setUpBeforeClass() throws Exception { var classFiles = TestCodegen.generateClassFiles("Tph.jav", new ByteArrayClassLoader()); classToTest = classFiles.get("Tph"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader()); - classToTest = classFiles.get("Tph7"); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); } @Test public void test1() throws Exception { + var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader()); + classToTest = classFiles.get("Tph7"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + + //public DZU m(DZL, DZM); Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class); - Object result = m.invoke(instanceOfClass, 1,2); - - assertEquals(1,result); + + //System.out.println(m.toString()); + + //Argumenttypes of the method m + var paraTypes = m.getGenericParameterTypes(); + + //Typeparameters of the method m + var typeParaTypes = m.getTypeParameters(); + + //Typeparameters are extracted from the argumenttypes + //Conditions for the extracted typeparameters are set + + //paraTypes[0] = DLZ + var boundFstArg = Arrays.stream(typeParaTypes) + .filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds(); + + //Bound of DLZ has to be Object + assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get()); + + //paraTypes[0] = DZM + var boundSndArg = Arrays.stream(typeParaTypes) + .filter(x -> x.equals(paraTypes[1])).findFirst().get().getBounds(); + + //Bound of DZM has to be the return type of m + assertEquals(Arrays.stream(boundSndArg).findFirst().get(), m.getGenericReturnType()); + + //Bound of the bound of DZM + var boundBoundSndArg = Arrays.stream(typeParaTypes).filter(x -> x.equals(Arrays.stream(boundSndArg) + .findFirst().get())).findFirst().get().getBounds(); + + //boundBoundSndArg have to be a type variable (type of the local variable c) + assertEquals(true, Arrays.stream(boundBoundSndArg).findFirst().get() instanceof TypeVariable); + m.getGenericParameterTypes(); + + //public DZU m2(DZU); + Method m2 = classToTest.getDeclaredMethod("m2", Object.class); + + //Argumenttypes of the method m2 + var paraTypesm2 = m2.getGenericParameterTypes(); + + //Typeparameters of the method m2 + var typeParaTypesm2 = m2.getTypeParameters(); + + //Typeparameters are extracted from the argumenttypes + //Conditions for the extracted typeparameters are set + + //paraTypes[0] = DZU + var fstArgm2 = Arrays.stream(typeParaTypesm2) + .filter(x -> x.equals(paraTypesm2[0])).findFirst().get(); + + //Bound of DZU has to be Object + assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get()); + + //DZU has to be the return type of m + assertEquals(fstArgm2, m2.getGenericReturnType()); } @Test