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