modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java

This commit is contained in:
AluAli 2021-03-13 01:26:20 +01:00
parent bb5692da8e
commit 8e89c9b5e8

View File

@ -503,7 +503,9 @@ public class FamilyOfGeneratedGenerics {
}
public static List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
List<MethodConstraint> tempMC= new ArrayList<>();
List<MethodConstraint> tempMC = new ArrayList<>();
Set<Pair> tempSet = new HashSet<>();
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet);
MethodAndTPH methAndTphs = methodAndTPH;
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
List<List<Constraint<Pair>>> orConsList = new ArrayList<>();
@ -542,29 +544,73 @@ public class FamilyOfGeneratedGenerics {
}
oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r));
}
List<TPHConstraint> tcOfoldCons = buildTransitiveClosure(oldConsListConverted);
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons);
// List<TPHConstraint> tcOfoldCons = buildTransitiveClosure(oldConsListConverted);
// Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons);
for(int i=0; i<orConsListConverted.size(); i++) {
List<TPHConstraint> extendsList = orConsListConverted.get(i).get(Relation.EXTENDS);
List<TPHConstraint> 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<orConsListConverted.size(); i++) {
for(int i=0; i<orCons.size(); i++) {
Constraint<Pair> extendsSet = new Constraint<Pair>();
Constraint<Pair> equalSet = new Constraint<Pair>();
for(Constraint con: orCons.get(i)) {
Iterator<Pair> it = con.iterator();
while (it.hasNext()) {
Pair p = it.next();
// List<TPHConstraint> extendsList = orConsListConverted.get(i).get(Relation.EXTENDS);
// List<TPHConstraint> 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<Pair> itExtends = extendsSet.iterator();
while(itExtends.hasNext()) {
Pair pairExtends = itExtends.next();
// for (TPHConstraint eq : equalList) {
Iterator<Pair> 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<Pair> 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<Pair> 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<Pair> buildTransitiveClosureForCP(Set constraint) {
public static Set<Pair> buildTransitiveClosureForCP(Set constraint, ResultSet resSet) {
Set<Pair> iterSet = new HashSet<>(constraint);
Set<Pair> runSet = new HashSet<>(constraint);
Set<Pair> 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<Pair> tempSet = set;
boolean hasSame = false;
// for (TPHConstraint tphC: tempList) {
Iterator<Pair> it = set.iterator();
Iterator<Pair> 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)