diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index c1b44353..3901963a 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -503,7 +503,9 @@ public class FamilyOfGeneratedGenerics { } public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { - List tempMC= new ArrayList<>(); + List tempMC = new ArrayList<>(); + Set tempSet = new HashSet<>(); + Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); MethodAndTPH methAndTphs = methodAndTPH; List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> orConsList = new ArrayList<>(); @@ -542,29 +544,73 @@ public class FamilyOfGeneratedGenerics { } oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); } - List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); - Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons); +// List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); +// Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons); - for(int i=0; i extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); - List equalList = orConsListConverted.get(i).get(Relation.EQUAL); - for(TPHConstraint ex: extendsList) { - for(TPHConstraint eq: equalList) { - MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS); - for(TPHConstraint tc: tcOfoldCons) { - if(tc.getLeft()==mc.getLeft() && tc.getRight()==mc.getRight() && tc.getRel()==mc.getRel()) { - if(!checkForDuplicates(mc, tempMC)) { - tempMC.add(mc); +// for(int i=0; i extendsSet = new Constraint(); + Constraint equalSet = new Constraint(); + for(Constraint con: orCons.get(i)) { + Iterator it = con.iterator(); + while (it.hasNext()) { + Pair p = it.next(); +// List extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); +// List equalList = orConsListConverted.get(i).get(Relation.EQUAL); + if (p.OperatorSmallerDot()) { + extendsSet.add(p); + } else if (p.OperatorEqual()) { + equalSet.add(p); + } + } +// for (TPHConstraint ex : extendsList) { + Iterator itExtends = extendsSet.iterator(); + while(itExtends.hasNext()) { + Pair pairExtends = itExtends.next(); +// for (TPHConstraint eq : equalList) { + Iterator itEqual = equalSet.iterator(); + while(itEqual.hasNext()) { + Pair pairEqual = itEqual.next(); +// MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS); + Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); +// for (TPHConstraint tc : tcOfoldCons) { + Iterator itTC = tcOfoldConsSet.iterator(); + while(itTC.hasNext()) { + Pair pairTC = itTC.next(); +// if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) { + if(pairTC.TA1 == newPair.TA1 && pairTC.TA2 == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { +// if (!checkForDuplicates(mc, tempMC)) { + if(!checkForDuplicatesForSets(newPair, tempSet)) { + tempSet.add(newPair); + } } } } } } } + + Iterator itTemp = tempSet.iterator(); + while(itTemp.hasNext()) { + Pair p = itTemp.next(); + String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(); + String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(); + Relation r = null; + if(p.GetOperator() == PairOperator.SMALLERDOT) { + r = Relation.EXTENDS; + } else if(p.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + } + MethodConstraint mc = new MethodConstraint(ta1, ta2, r); + System.out.println(mc); + tempMC.add(mc); + } + return tempMC; } - public static Set buildTransitiveClosureForCP(Set constraint) { + + public static Set buildTransitiveClosureForCP(Set constraint, ResultSet resSet) { Set iterSet = new HashSet<>(constraint); Set runSet = new HashSet<>(constraint); Set tcSet = new HashSet<>(constraint); @@ -580,14 +626,14 @@ public class FamilyOfGeneratedGenerics { // if(cons.getRight() == cons2.getLeft()) { if(pairIterSet.TA2 == pairRunSet.TA1 && pairIterSet.OperatorSmallerDot() && pairRunSet.OperatorSmallerDot()) { // TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS); - Pair p = new Pair(pairIterSet.TA1, pairRunSet.TA2, PairOperator.SMALLERDOT); + Pair p = new Pair(resSet.resolveType((TypePlaceholder)(pairIterSet.TA1)).resolvedType, resSet.resolveType((TypePlaceholder)(pairRunSet.TA2)).resolvedType, PairOperator.SMALLERDOT); // if (!checkForDuplicates(consToAdd,tcList)) { - if(!tcSet.contains(p)) { + if(!checkForDuplicatesForSets(p, tcSet)) { // tcList.add(consToAdd); tcSet.add(p); addedConToList = true; if (addedConToList) { - return buildTransitiveClosureForCP(tcSet); + return buildTransitiveClosureForCP(tcSet, resSet); } } } @@ -601,13 +647,13 @@ public class FamilyOfGeneratedGenerics { Set tempSet = set; boolean hasSame = false; // for (TPHConstraint tphC: tempList) { - Iterator it = set.iterator(); + Iterator it = tempSet.iterator(); while (it.hasNext()) { Pair p = it.next(); // hasSame = constraint.getLeft() == tphC.getLeft() && // constraint.getRight() == tphC.getRight() && // constraint.getRel() == tphC.getRel(); //constraint already in ArrayList if true - hasSame = pair.TA1 == pair.TA1 && + hasSame = pair.TA1 == p.TA1 && pair.TA2 == p.TA2 && pair.OperatorSmallerDot() && p.OperatorSmallerDot(); //constraint already in Set if true if (hasSame)