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

This commit is contained in:
AluAli 2021-03-19 08:50:04 +01:00
parent 6e0e575524
commit 539cacef86

View File

@ -181,11 +181,11 @@ public class FamilyOfGeneratedGenerics {
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
}
}else if(pair.fst == PositionFinder.Position.FIELD){
/*}else if(pair.fst == PositionFinder.Position.FIELD){
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
}
}*/
}
}
}
@ -496,8 +496,10 @@ public class FamilyOfGeneratedGenerics {
r = Relation.EQUAL;
}
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
if(mc.getRel() != Relation.EQUAL) {
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
}
}
return tempMC;
@ -523,14 +525,17 @@ public class FamilyOfGeneratedGenerics {
if(p.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
tempMC.add(new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r));
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
/*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}*/
}
}
}
@ -586,8 +591,10 @@ public class FamilyOfGeneratedGenerics {
// if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) {
if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!)
// if (!checkForDuplicates(mc, tempMC)) {
if(!checkForDuplicatesForSets(newPair, tempSet)) {
tempSet.add(newPair);
if(newPair.TA1 != newPair.TA2) {
if (!checkForDuplicatesForSets(newPair, tempSet)) {
tempSet.add(newPair);
}
}
}
}
@ -608,8 +615,10 @@ public class FamilyOfGeneratedGenerics {
r = Relation.EQUAL;
}
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
if(mc.getRel() != Relation.EQUAL) {
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
}
}
@ -669,10 +678,33 @@ public class FamilyOfGeneratedGenerics {
return false;
}
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH) {
List<MethodConstraint> tempMC = new ArrayList<>();
List<TPHConstraint> allCons = allConstraints;
MethodAndTPH methAndTphs = methodAndTPH;
for(String tph: posOfTphs.keySet()) {
for(int i=0; i<posOfTphs.get(tph).size(); i++)
if(posOfTphs.get(tph).get(i).fst == PositionFinder.Position.METHOD && posOfTphs.get(tph).get(i).snd == methAndTphs.getId()) {
for(TPHConstraint ac: allCons) {
if(tph==ac.getRight() && !checkUpperBound(allCons,tph)) {
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
if(!checkForDuplicates(mc2, tempMC)) {
tempMC.add(mc2);
}
}
}
}
}
return tempMC;
}
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPositionNew(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
List<MethodConstraint> newMCList = new ArrayList<>();
List<MethodConstraint> newMCList2 = new ArrayList<>();
List<MethodConstraint> hasNoSupType = new ArrayList<>();
List<MethodConstraint> mcWithoutCc = new ArrayList<>();
List<String> methodsAddedToHashMap = new ArrayList<>();
for(MethodAndTPH method: listOfMethodsAndTph){
String currentMethod = method.getId();
@ -704,7 +736,25 @@ public class FamilyOfGeneratedGenerics {
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
}*/
tempMethodConstraintsWithPosition.put(currentMethod, listToAdd);
hasNoSupType = hasNoSupertypeForMethodTypesNew(cs,posOfTphs,method);
for (MethodConstraint cons: hasNoSupType) {
if (!checkForDuplicates(cons, listToAdd)) {
listToAdd.add(cons);
}
}
mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd);
tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc);
}
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
}
}
}
}