diff --git a/src/test/java/targetast/TphTest.java b/src/test/java/targetast/TphTest.java index c2bb9835..a1a1a214 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,7 +14,7 @@ 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()); @@ -22,10 +24,67 @@ public class TphTest { @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 diff --git a/src/test/resources/bytecode/javFiles/Inf.jav b/src/test/resources/bytecode/javFiles/Inf.jav index 3c785a6e..788fca8d 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: +*/ +