|
|
|
@ -16,13 +16,15 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>();
|
|
|
|
|
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
|
|
|
|
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
|
|
|
|
public HashMap<MethodConstraint, String> methodsWithPosition = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
|
|
|
|
|
this.allConstraints = tphExtractor.allCons;
|
|
|
|
|
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
|
|
|
|
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
|
|
|
|
// this.methodConstraints =
|
|
|
|
|
// this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
|
|
|
|
@ -48,38 +50,72 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
return cs_cl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
// public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
// //TODO: Regeln
|
|
|
|
|
// List<MethodConstraint> cs_m = new ArrayList<>();
|
|
|
|
|
// List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
|
|
|
|
// for (MethodConstraint cons: methodConstraints1) {
|
|
|
|
|
// if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
// cs_m.add(cons);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
|
|
|
|
// for (MethodConstraint cons: methodConstraints2) {
|
|
|
|
|
// if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
// cs_m.add(cons);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
|
|
|
|
|
// for (MethodConstraint cons: methodConstraints3) {
|
|
|
|
|
// if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
// cs_m.add(cons);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
|
|
|
|
|
// for (MethodConstraint cons: methodConstraints4) {
|
|
|
|
|
// if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
// cs_m.add(cons);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
|
|
|
|
// cs_m = methodConstraints5;
|
|
|
|
|
// return cs_m;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public static HashMap<MethodConstraint, String> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
//TODO: Regeln
|
|
|
|
|
List<MethodConstraint> cs_m = new ArrayList<>();
|
|
|
|
|
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints1) {
|
|
|
|
|
if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
HashMap<MethodConstraint, String> cs_m = new HashMap<>();
|
|
|
|
|
HashMap<MethodConstraint, String> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints1.keySet()) {
|
|
|
|
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
|
|
|
|
cs_m.put(cons,);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HashMap<MethodConstraint, String> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints2.keySet()) {
|
|
|
|
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
|
|
|
|
cs_m.add(cons);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints2) {
|
|
|
|
|
if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
HashMap<MethodConstraint, String> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints3.keySet()) {
|
|
|
|
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
|
|
|
|
cs_m.add(cons);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints3) {
|
|
|
|
|
if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
HashMap<MethodConstraint, String> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints4.keySet()) {
|
|
|
|
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
|
|
|
|
cs_m.add(cons);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
|
|
|
|
|
for (MethodConstraint cons: methodConstraints4) {
|
|
|
|
|
if (!checkForDuplicates(cons, cs_m)) {
|
|
|
|
|
cs_m.add(cons);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
|
|
|
|
HashMap<MethodConstraint, String> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
|
|
|
|
cs_m = methodConstraints5;
|
|
|
|
|
return cs_m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Def. FGG: erste Zeile von cs_cl
|
|
|
|
|
* {T < .T' | T is a type variable in a type of a node of a field}
|
|
|
|
@ -155,16 +191,16 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
* 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}
|
|
|
|
|
*/
|
|
|
|
|
public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
|
|
|
|
|
public static HashMap<MethodConstraint, String> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
|
|
|
|
|
//TODO:
|
|
|
|
|
List<MethodConstraint> tempMC= new ArrayList<>();
|
|
|
|
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
|
|
|
|
for(TPHConstraint allCons: allConstraints){
|
|
|
|
|
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
|
|
|
|
|
for(String tph: posOfTphs.keySet()) {
|
|
|
|
|
if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) {
|
|
|
|
|
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
|
|
|
|
if (!checkForDuplicates(consToAdd, tempMC)) {
|
|
|
|
|
tempMC.add(consToAdd);
|
|
|
|
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
|
|
|
|
tempMC.put(consToAdd, posOfTphs.get(tph).snd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -178,19 +214,19 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
* Def. FGG: zweite Zeile von cs_m
|
|
|
|
|
* {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs}
|
|
|
|
|
*/
|
|
|
|
|
public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
|
|
|
|
public static HashMap<MethodConstraint, String> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //transitive closure of cs
|
|
|
|
|
//TODO:
|
|
|
|
|
List<MethodConstraint> tempMC= new ArrayList<>();
|
|
|
|
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
|
|
|
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
|
|
|
|
for(MethodConstraint mC1 : cs_m) { //(R <. R')
|
|
|
|
|
for(MethodConstraint mC2 : cs_m) { //(S <. S')
|
|
|
|
|
for(MethodConstraint mC1 : cs_m.keySet()) { //(R <. R')
|
|
|
|
|
for(MethodConstraint mC2 : cs_m.keySet()) { //(S <. S')
|
|
|
|
|
String lSide = mC1.getRight(); //R'
|
|
|
|
|
String rSide = mC2.getLeft(); //S
|
|
|
|
|
for(TPHConstraint tphC : tcOfCs) {
|
|
|
|
|
if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S)
|
|
|
|
|
MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S)
|
|
|
|
|
if (!checkForDuplicates(consToAdd, tempMC)) {
|
|
|
|
|
tempMC.add(consToAdd);
|
|
|
|
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
|
|
|
|
tempMC.put(consToAdd, posOfTphs.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -203,20 +239,20 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
* Def. FGG: dritte Zeile von cs_m
|
|
|
|
|
* {R' <. S | (R <. R') \in cs_m, (S <. S') \in cs_cl and (R',S) is in the transitive closure of cs}
|
|
|
|
|
*/
|
|
|
|
|
public static List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
|
|
|
|
public static HashMap<MethodConstraint, String> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
//TODO:
|
|
|
|
|
List<MethodConstraint> tempMC= new ArrayList<>();
|
|
|
|
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
|
|
|
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
|
|
|
|
for(ClassConstraint cC : cs_cl) {
|
|
|
|
|
for(MethodConstraint mC : cs_m) {
|
|
|
|
|
for(MethodConstraint mC : cs_m.keySet()) {
|
|
|
|
|
String leftSide = mC.getRight();
|
|
|
|
|
String rightSide = cC.getLeft();
|
|
|
|
|
for(TPHConstraint tphC : tcOfCs) {
|
|
|
|
|
if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) {
|
|
|
|
|
MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
|
|
|
|
|
if (!checkForDuplicates(consToAdd, tempMC)) {
|
|
|
|
|
tempMC.add(consToAdd);
|
|
|
|
|
System.out.println(consToAdd);
|
|
|
|
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
|
|
|
|
tempMC.put(consToAdd, posOfTphs.get());
|
|
|
|
|
// System.out.println(consToAdd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -231,16 +267,16 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
* {T <. Object | (T is a type variable in a type of a node of the method/constructor m in cl_\sigma),
|
|
|
|
|
* (\existsnot T': T <. T') \in cs)}
|
|
|
|
|
*/
|
|
|
|
|
public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
public static HashMap<MethodConstraint, String> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
//TODO:
|
|
|
|
|
List<MethodConstraint> tempMC= new ArrayList<>();
|
|
|
|
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
|
|
|
|
for(String tph: posOfTphs.keySet()) {
|
|
|
|
|
for(TPHConstraint allCons: allConstraints) {
|
|
|
|
|
if((posOfTphs.get(tph).fst.equals(PositionFinder.Position.METHOD) || posOfTphs.get(tph).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && checkUpperBound(allConstraints,tph)) {
|
|
|
|
|
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
|
|
|
|
|
if (!checkForDuplicates(consToAdd, tempMC)) {
|
|
|
|
|
tempMC.add(consToAdd);
|
|
|
|
|
System.out.println(consToAdd);
|
|
|
|
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
|
|
|
|
tempMC.put(consToAdd, posOfTphs.get(tph).snd);
|
|
|
|
|
// System.out.println(consToAdd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -251,7 +287,7 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
/**
|
|
|
|
|
* nimm die Menge cs_cl aus cs_m raus
|
|
|
|
|
*/
|
|
|
|
|
public static List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
|
|
|
|
public static HashMap<MethodConstraint, String> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m) {
|
|
|
|
|
//TODO:
|
|
|
|
|
List<TPHConstraint> tempCC = new ArrayList<>();
|
|
|
|
|
for(ClassConstraint cc: cs_cl) {
|
|
|
|
@ -259,7 +295,7 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
tempCC.add(tphC);
|
|
|
|
|
}
|
|
|
|
|
List<TPHConstraint> tempMC = new ArrayList<>();
|
|
|
|
|
for(MethodConstraint mc: cs_m) {
|
|
|
|
|
for(MethodConstraint mc: cs_m.keySet()) {
|
|
|
|
|
TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel());
|
|
|
|
|
tempMC.add(tphC);
|
|
|
|
|
}
|
|
|
|
@ -294,6 +330,20 @@ public class FamilyOfGeneratedGenerics {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean checkForDuplicatesInMethods(TPHConstraint constraint, HashMap<MethodConstraint, String> hashMap, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
|
|
|
HashMap<MethodConstraint, String> tempMap = hashMap;
|
|
|
|
|
boolean hasSame = false;
|
|
|
|
|
for (TPHConstraint tphC: tempMap.keySet()) {
|
|
|
|
|
hasSame = constraint.getLeft() == tphC.getLeft() &&
|
|
|
|
|
constraint.getRight() == tphC.getRight() &&
|
|
|
|
|
constraint.getRel() == tphC.getRel() &&
|
|
|
|
|
posOfTphs.get(); //constraint already in ArrayList if true
|
|
|
|
|
if (hasSame)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<TPHConstraint> buildTransitiveClosure(List list) {
|
|
|
|
|
List<TPHConstraint> iterList = new ArrayList<>(list);
|
|
|
|
|
List<TPHConstraint> runList = new ArrayList<>(list);
|
|
|
|
|