modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java

modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
This commit is contained in:
AluAli 2021-03-05 20:18:48 +01:00
parent 2ca4aad07d
commit f208432c54
2 changed files with 64 additions and 33 deletions

View File

@ -56,7 +56,7 @@ public class TPHExtractor extends AbstractASTWalker {
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
// Alle Constraints in einer Menge (und- & Oder-Constraints)
// Alle Constraints in einer Menge (Und- & Oder-Constraints)
public Set<Pair> oldConstraints = new HashSet<>();
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();

View File

@ -13,10 +13,9 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.objectweb.asm.Type;
import javax.naming.ldap.PagedResultsResponseControl;
public class FamilyOfGeneratedGenerics {
public List<TPHConstraint> allConstraints = new ArrayList<>();
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
@ -24,19 +23,19 @@ public class FamilyOfGeneratedGenerics {
public List<ClassConstraint> classConstraints = new ArrayList<>();
public List<MethodConstraint> methodConstraints = new ArrayList<>();
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
// public List<MethodAndTPH> methodAndTPHList = new ArrayList<>(); //not necessary?
public ResultSet resSet;
public Set<Pair> oldCons = new HashSet<>();
private static final String objectType = Type.getInternalName(Object.class);
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor, ResultSet resultSet) {
this.resSet = resultSet;
this.oldCons = tphExtractor.oldConstraints;
this.allConstraints = tphExtractor.allCons;
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet);
// this.methodAndTPHList = tphExtractor.ListOfMethodsAndTph; //not necessary?
this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
}
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
@ -115,7 +114,7 @@ public class FamilyOfGeneratedGenerics {
return cs_m;
}
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet) {
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(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<>();
for(MethodAndTPH method: listOfMethodsAndTph){
List<String> methodsAddedToHashMap = new ArrayList<>();
@ -137,6 +136,7 @@ public class FamilyOfGeneratedGenerics {
tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod);
List<MethodConstraint> newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet);
List<MethodConstraint> newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
}
}
@ -481,41 +481,72 @@ public class FamilyOfGeneratedGenerics {
List<MethodConstraint> tempMC= new ArrayList<>();
MethodAndTPH methAndTphs = methodAndTPH;
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
List<Set<Pair>> orCons = methAndTphs.constraints.getOderConstraints();
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
Iterator<Pair> it = undCons.iterator();
while(it.hasNext()) {
Pair p = it.next();
String ta1 = ((TypePlaceholder) p.TA1).getName();
String ta2 = ((TypePlaceholder) p.TA2).getName();
System.out.println(p);
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 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<>();
MethodAndTPH methAndTphs = methodAndTPH;
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
List<List<Constraint<Pair>>> orConsList = new ArrayList<>();
List<List<List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
for(int i=0; i<orCons.size(); i++) {
List<List<TPHConstraint>> orConsInternal = new ArrayList<>();
List<TPHConstraint> orConsWithEQUAL = new ArrayList();
List<TPHConstraint> orConsWithEXTENDS = new ArrayList();
for(Constraint con: orCons.get(i)) {
Iterator<Pair> it = con.iterator();
while(it.hasNext()) {
Pair p = it.next();
Relation r = null;
if(p.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
}
}
}
orConsInternal.add(orConsWithEXTENDS);
orConsInternal.add(orConsWithEQUAL);
orConsListConverted.add(orConsInternal);
}
// Set res = resSet.results;
// Iterator it = res.iterator();
// System.out.println("res: " + res.size() + res);
// System.out.println("booooooooo");
// while(it.hasNext()) {
// System.out.println(it.next());
// }
// System.out.println("booooooooo2");
// for(TPHConstraint tphC: allConstraints) {
// }
// Predicate<Pair> filterUndConstraints = ab -> resSet.resolveType((TypePlaceholder)(ab.TA1)).resolvedType instanceof TypePlaceholder;
// System.out.println(filterUndConstraints);
// Predicate<Pair> the = x -> resSet.resolveType((TypePlaceholder)(x.TA1)).resolvedType instanceof TypePlaceholder;
// ResultPair rp = y -> resSet.resolveType((TypePlaceholder)(y.TA1)).getResultPair();
// (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder)
List<Pair> oldConsList = new ArrayList<>(oldCons);
List<TPHConstraint> oldConsListConverted = new ArrayList<>();
for(Pair pair: oldConsList) {
Relation r = null;
if(pair.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
} else if(pair.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
}
oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r));
}
List<TPHConstraint> tcOfoldCons = buildTransitiveClosure(oldConsListConverted);
return null;
return tempMC;
}
}