diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index da114c2c..5dac990c 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -323,9 +323,13 @@ public class BytecodeGen implements ASTVisitor { tphsInRel.put(tphsInRel.size(), superTph); numOfVisitedPairs++; - + boolean isCycle = false; while(subAndSuperTph.containsKey(superTph)) { superTph = subAndSuperTph.get(superTph); + if(tphsInRel.containsValue(superTph)) { + isCycle = true; + break; + } tphsInRel.put(tphsInRel.size(), superTph); numOfVisitedPairs++; } @@ -361,7 +365,8 @@ public class BytecodeGen implements ASTVisitor { // Y muss durch Object ersetzt. // Zweite Operand für die Fälle wie in Lambda.jav (Paramtrisierte Typen) - if(methodTphs.contains(superTphRes) || !tphExtractor.allTPHS.containsKey(superTphRes)) { + if((methodTphs.contains(superTphRes) || !tphExtractor.allTPHS.containsKey(superTphRes)) + && !subTphRes.equals(superTphRes)) { GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes); simplifiedPairs.add(sPair); } diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index c049cac3..c06f7b38 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -112,12 +112,10 @@ public class Signature { // z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object if(!isConstructor) { String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()); - System.out.println("RET:::: " + ret); if(!ret.equals("V")) { // TODO TypeToSignature nochmal kontrollieren und schauen ob man dort wirklich // T... braucht und L ... if(ret.contains("$") && !ret.contains("$$")) { -// String g = ret.substring(4,ret.length())+"$"; if(genericsAndBounds.containsKey(ret)) { genericsAndBoundsMethod.put(ret.substring(1), genericsAndBounds.get(ret.substring(1))); }else { @@ -143,9 +141,7 @@ public class Signature { RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName); String pT = t.acceptTV(new TypeToSignature()); // S.o -// if(pT.substring(0,4).equals("TPH ")) { if(t instanceof TypePlaceholder) { -// String gP = pT.substring(4,pT.length())+"$"; String gP = t.acceptTV(new TypeToSignature()); if(!genericsAndBounds.containsKey(gP.substring(1)) && !genericsAndBoundsMethod.containsKey(gP.substring(1))) { sw.visitFormalTypeParameter(gP.substring(1)); @@ -393,16 +389,16 @@ public class Signature { // das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature()) // -// if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) { String sig2 = r.acceptTV(new TypeToSignature()); if(!(r instanceof TypePlaceholder)) { + if(sig2.contains("$$")) { + sv.visitInterface().visitClassType(sig2.substring(1, sig2.length())); + } else { + sv.visitClassType(sig2.substring(1, sig2.length())); + } -// sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature())); -// sv.visitClassType(r.acceptTV(new TypeToSignature())); - sv.visitClassType(sig2.substring(1, sig2.length())); } else { System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature())); -// sv.visitTypeVariable(r.acceptTV(new TypeToSignature()).substring(4)+"$"); sv.visitTypeVariable(sig2.substring(1, sig2.length())); } diff --git a/test/bytecode/MatrixTest.java b/test/bytecode/MatrixTest.java index 325cc1d8..cd0a20b7 100644 --- a/test/bytecode/MatrixTest.java +++ b/test/bytecode/MatrixTest.java @@ -69,7 +69,7 @@ public class MatrixTest { //Matrix m3 = m1.mul(vv1); Method mul = classToTest.getDeclaredMethod("mul", Vector.class); Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2); - System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString()); + System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString()); Vector> res = new Vector>(); Vector v5 = new Vector (); diff --git a/test/bytecode/Tph3Test.java b/test/bytecode/Tph3Test.java index d2cad1af..64bfa28f 100644 --- a/test/bytecode/Tph3Test.java +++ b/test/bytecode/Tph3Test.java @@ -30,7 +30,7 @@ public class Tph3Test { pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; compiler.generateBytecode(pathToClassFile); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass("Tph2"); + classToTest = loader.loadClass("Tph3"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); } diff --git a/test/bytecode/javFiles/Tph4.jav b/test/bytecode/javFiles/Tph4.jav new file mode 100644 index 00000000..1eb529de --- /dev/null +++ b/test/bytecode/javFiles/Tph4.jav @@ -0,0 +1,12 @@ +public class Tph4{ + m(a,b){ + var c = m2(b); + var d = m2(c); + return a; + } + + m2(b){ + return b + } + +} \ No newline at end of file