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

This commit is contained in:
AluAli 2021-03-19 14:23:07 +01:00
parent 539cacef86
commit 13144d0ac9

View File

@ -60,7 +60,7 @@ public class FamilyOfGeneratedGenerics {
}
} while (addedToConstraintsListForCC2);
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs);
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs_cl, posOfTphs);
for (ClassConstraint cons: classConstraints3) {
if (!checkForDuplicates(cons, cs_cl)) {
cs_cl.add(cons);
@ -224,28 +224,34 @@ public class FamilyOfGeneratedGenerics {
* {T <. Object | ((T is a type variable in a type of a node of a field
* or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)}
*/
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
List<ClassConstraint> tempCC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints) {
for(ClassConstraint cCons: cs_cl) {
for(String tph: posOfTphs.keySet()) {
for(PairTphMethod pair: posOfTphs.get(tph)) {
boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
!checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) {
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempCC)){
tempCC.add(consToAdd);
}
List<TPHConstraint> clCons = new ArrayList<>(cs_cl);
for(String tph: posOfTphs.keySet()) {
for(PairTphMethod pair: posOfTphs.get(tph)) {
boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
boolean hasSmallerTVInClCons = hasSmallerTVInClCons(tph, cs_cl);
if ((tvInField || hasSmallerTVInClCons) &&
!checkUpperBound(clCons, tph)) {
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
}
}
}
}
}
return tempCC;
}
public static boolean hasSmallerTVInClCons(String tph, List<ClassConstraint> cs_cl) {
for(ClassConstraint cC: cs_cl) {
if(tph == cC.getRight() && cC.getRel() == Relation.EXTENDS) {
return true;
}
}
return false;
}
/**
* Def. FGG: erste Zeile von cs_m
* {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs}
@ -496,7 +502,7 @@ public class FamilyOfGeneratedGenerics {
r = Relation.EQUAL;
}
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(mc.getRel() != Relation.EQUAL) {
if(mc.getRel() == Relation.EXTENDS) {
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
@ -678,20 +684,16 @@ public class FamilyOfGeneratedGenerics {
return false;
}
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH) {
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, List<MethodConstraint> cs_m) {
List<MethodConstraint> tempMC = new ArrayList<>();
List<TPHConstraint> allCons = allConstraints;
List<TPHConstraint> methCons = new ArrayList<>(cs_m);
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);
}
}
if(posOfTphs.get(tph).get(i).fst == PositionFinder.Position.METHOD && posOfTphs.get(tph).get(i).snd == methAndTphs.getId() && !checkUpperBound(methCons,tph)) {
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(mc2, tempMC)) {
tempMC.add(mc2);
}
}
}
@ -736,7 +738,7 @@ public class FamilyOfGeneratedGenerics {
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
}*/
hasNoSupType = hasNoSupertypeForMethodTypesNew(cs,posOfTphs,method);
hasNoSupType = hasNoSupertypeForMethodTypesNew(posOfTphs,method,listToAdd);
for (MethodConstraint cons: hasNoSupType) {
if (!checkForDuplicates(cons, listToAdd)) {
listToAdd.add(cons);