diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 3154c9319..2db52ec3f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -195,7 +195,7 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(Method method) { inMethod = true; String id = MethodUtility.createID(resolver,method); - Predicate filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) && + Predicate filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) && (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) && (resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder)); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index c361f154e..d293fe6ce 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -505,9 +505,11 @@ public class FamilyOfGeneratedGenerics { } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); if(mc.getRel() == Relation.EXTENDS) { - if(!checkForDuplicates(mc, tempMC)) { - tempMC.add(mc); - } + if (!mc.getLeft().equals(mc.getRight())) { //eliminieren der Fälle wie AA<.AA + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } + } } } return tempMC; @@ -611,7 +613,7 @@ public class FamilyOfGeneratedGenerics { if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA if (!checkForDuplicatesForSets(newPair, tempSet)) { //TODO: evtl. pairExtends hinzufuegen - tempSet.add(newPair); + //tempSet.add(newPair); } } } @@ -662,6 +664,7 @@ public class FamilyOfGeneratedGenerics { while(itExtends2.hasNext()) { Pair pairExtends2 = itExtends2.next(); Iterator itEqual2 = equalSet.iterator(); + while (itEqual2.hasNext()) { boolean transClo = false; Pair pairEqual2 = itEqual2.next(); @@ -693,15 +696,17 @@ public class FamilyOfGeneratedGenerics { // break; //} //} - if (tcOfCs.contains(newPairTPHConstraint)) { + if (tcOfCs.contains(newPairTPHConstraint)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) { transClo = true; } TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2; Iterator itUndCons = undCons.iterator(); + boolean rEqExRtilde = false; while (itUndCons.hasNext()) { Pair pairUndCons2 = itUndCons.next(); - boolean rEqExRtilde = (tphR == pairUndCons2.TA1); + rEqExRtilde = rEqExRtilde || (tphR == pairUndCons2.TA1); // Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); + } boolean isPairInTExTapostrophe = false; // Constraint allOfOr = new Constraint(); for(Set> scp: orCons) { @@ -716,10 +721,10 @@ public class FamilyOfGeneratedGenerics { } } } + } - - - if ((rEqExRtilde || isPairInTExTapostrophe)) { + + if (transClo && (rEqExRtilde || isPairInTExTapostrophe)) { if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA if (transClo && !checkForDuplicatesForSets(newPair2, tempSet2)) tempSet2.add(newPair2); @@ -727,10 +732,13 @@ public class FamilyOfGeneratedGenerics { if (!checkForDuplicatesForSets(pairExtends2, tempSet2)) tempSet2.add(pairExtends2); } - } - - } + String key = ((TypePlaceholder)pairExtends2.TA2).getName(); + if (posOfTphs.containsKey(key)) { + if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { + tempSet2.add(pairExtends2); + } + } } } } diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index eb220f4ff..1b3e67c4b 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -102,6 +102,7 @@ public class JavaTXCompiler { } classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader()); environment = new CompilationEnvironment(sources); + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); for (File s : sources) { sourceFiles.put(s, parse(s)); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java index f20ea0cd5..1c8dee420 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java @@ -4,6 +4,16 @@ public class NameGenerator { private static String strNextName = "A"; + /** + * Setzt den zu Beginn der Typinferenz auf "A" zurueck. + * Dies ist beio den JUnit-Test noetig + * TypePlaceholder.
Author: Martin Pluemicke + * @return void + */ + public static void reset() { + strNextName = "A"; + } + /** * Berechnet einen neuen, eindeutigen Namen f�r eine neue * TypePlaceholder.
Author: J�rg B�uerle diff --git a/src/test/java/insertGenerics/TestContraVariant.java b/src/test/java/insertGenerics/TestContraVariant.java index f220f3d59..328044fac 100644 --- a/src/test/java/insertGenerics/TestContraVariant.java +++ b/src/test/java/insertGenerics/TestContraVariant.java @@ -57,8 +57,8 @@ public class TestContraVariant { lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc); lmc = new HashSet<>(); - lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS)); - lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS)); + lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index ff99b2cbc..870d8c962 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -70,9 +70,9 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); @@ -89,9 +89,9 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); @@ -108,9 +108,9 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS)); diff --git a/src/test/java/insertGenerics/TestThreeArgs.java b/src/test/java/insertGenerics/TestThreeArgs.java index 75e505800..dd93724f6 100644 --- a/src/test/java/insertGenerics/TestThreeArgs.java +++ b/src/test/java/insertGenerics/TestThreeArgs.java @@ -59,8 +59,9 @@ public class TestThreeArgs { HashMap> methodConstraintsWithPositionTest = new HashMap<>(); Set lmc; lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "R", Relation.EXTENDS)); - lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS)); @@ -84,7 +85,8 @@ public class TestThreeArgs { compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + //liefert Fehler, da Variable "a" nicht initialisiert ist. + //instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); return new TestResultSet(); } }