From e3625cb3066594bd8b9c9d09abf53ef147d6dc9b Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 12:29:40 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/TestTwoCalls.java --- .../FamilyOfGeneratedGenerics.java | 70 +++++++++++++------ .../java/insertGenerics/TestTwoCalls.java | 1 + 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 11c2a7c3..358c6d34 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -518,6 +518,7 @@ public class FamilyOfGeneratedGenerics { Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); List tcOfCs = buildTransitiveClosure(allConstraints); MethodAndTPH methAndTphs = methodAndTPH; + Set undCons = methAndTphs.constraints.getUndConstraints(); List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> orConsListConverted = new ArrayList<>(); //gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf ( @@ -567,9 +568,9 @@ public class FamilyOfGeneratedGenerics { } // dies ist das "R" aus dem ersten Teil, wird im zweiten Teil gebraucht - TypePlaceholder tphR = null; - Constraint extendsSetAllOfOr = new Constraint(); - Constraint equalSetAllOfOr = new Constraint(); +// TypePlaceholder tphR = null; +// Constraint extendsSetAllOfOr = new Constraint(); +// Constraint equalSetAllOfOr = new Constraint(); // Berechnung des ersten Teils der Regel for(int i=0; i itExtends = extendsSet.iterator(); @@ -595,7 +596,7 @@ public class FamilyOfGeneratedGenerics { Iterator itEqual = equalSet.iterator(); while(itEqual.hasNext()) { Pair pairEqual = itEqual.next(); - tphR = (TypePlaceholder) (pairEqual.TA2); +// tphR = (TypePlaceholder) (pairEqual.TA2); Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); Iterator itTC = tcOfoldConsSet.iterator(); while(itTC.hasNext()) { @@ -634,28 +635,55 @@ public class FamilyOfGeneratedGenerics { }*/ } + // Berechnung des zweiten Teils der Regel - Iterator itExtends2 = extendsSetAllOfOr.iterator(); - while(itExtends2.hasNext()) { - Pair pairExtends2 = itExtends2.next(); - Iterator itEqual2 = equalSetAllOfOr.iterator(); - while (itEqual2.hasNext()) { - Pair pairEqual2 = itEqual2.next(); - Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT); - boolean rEqRtilde = (tphR == pairEqual2.TA1 && checkForDuplicatesForSets(new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA2)).resolvedType, PairOperator.EQUALSDOT), equalSetAllOfOr)); - boolean rExRtilde = (tphR == pairExtends2.TA1 && checkForDuplicatesForSets(new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT), extendsSetAllOfOr)); - Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); - boolean isPairInTExTapostrophe = checkForDuplicatesForSets(rExRtildePair, extendsSetAllOfOr); - if (rEqRtilde || rExRtilde || !isPairInTExTapostrophe) { - if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA - if (!checkForDuplicatesForSets(newPair2, tempSet2)) { - tempSet2.add(newPair2); + for(int i=0; i extendsSet = new Constraint(); + Constraint equalSet = new Constraint(); + //für jede einzelne OrConstraint-Menge gehe durch + for (Constraint con : orCons.get(i)) { + Iterator it = con.iterator(); + while (it.hasNext()) { + Pair p = it.next(); + if (p.OperatorSmallerDot()) { + extendsSet.add(p); + } else if (p.OperatorEqual()) { + equalSet.add(p); + } + } + Iterator itExtends2 = extendsSet.iterator(); + while(itExtends2.hasNext()) { + Pair pairExtends2 = itExtends2.next(); + Iterator itEqual2 = equalSet.iterator(); + while (itEqual2.hasNext()) { + Pair pairEqual2 = itEqual2.next(); + Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT); + TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2; + Iterator itUndCons = undCons.iterator(); + while (itUndCons.hasNext()) { + Pair pairUndCons2 = itUndCons.next(); + boolean rEqRtilde = (tphR == pairUndCons2.TA1); + boolean rExRtilde = (tphR == pairUndCons2.TA1); + Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); + boolean isPairInTExTapostrophe = checkForDuplicatesForSets(rExRtildePair, extendsSet); + + if (rEqRtilde || rExRtilde || isPairInTExTapostrophe) { + if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA + if (!checkForDuplicatesForSets(newPair2, tempSet2)) { + tempSet2.add(pairExtends2); + tempSet2.add(newPair2); + } + } + } } + + } } } } + // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil Iterator itTemp = tempSet.iterator(); while(itTemp.hasNext()) { diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index a6157ecc..518ca0ad 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -65,6 +65,7 @@ public class TestTwoCalls { lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS)); lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg;