From f208432c545dec59cad20fb4db189073a0c1e660 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 5 Mar 2021 20:18:48 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 2 +- .../FamilyOfGeneratedGenerics.java | 95 ++++++++++++------- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index d74ecad8..3154c931 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -56,7 +56,7 @@ public class TPHExtractor extends AbstractASTWalker { public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); - // Alle Constraints in einer Menge (und- & Oder-Constraints) + // Alle Constraints in einer Menge (Und- & Oder-Constraints) public Set oldConstraints = new HashSet<>(); final ArrayList> allPairs = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 6b3cd99b..8ea4638a 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -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 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 classConstraints = new ArrayList<>(); public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); -// public List methodAndTPHList = new ArrayList<>(); //not necessary? public ResultSet resSet; + public Set 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 getClassConstraints(List cs, HashMap>> posOfTphs) { //Inputparameter List constraintsSet weg @@ -115,7 +114,7 @@ public class FamilyOfGeneratedGenerics { return cs_m; } - public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet) { + public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); for(MethodAndTPH method: listOfMethodsAndTph){ List methodsAddedToHashMap = new ArrayList<>(); @@ -137,6 +136,7 @@ public class FamilyOfGeneratedGenerics { tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); List newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet); + List newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons); } } @@ -481,41 +481,72 @@ public class FamilyOfGeneratedGenerics { List tempMC= new ArrayList<>(); MethodAndTPH methAndTphs = methodAndTPH; Set undCons = methAndTphs.constraints.getUndConstraints(); - List> orCons = methAndTphs.constraints.getOderConstraints(); + List>> orCons = methAndTphs.constraints.getOderConstraints(); Iterator 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 secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { + List tempMC= new ArrayList<>(); + MethodAndTPH methAndTphs = methodAndTPH; + List>> orCons = methAndTphs.constraints.getOderConstraints(); + List>> orConsList = new ArrayList<>(); + List>> orConsListConverted = new ArrayList<>(); + for(int i=0; i> orConsInternal = new ArrayList<>(); + List orConsWithEQUAL = new ArrayList(); + List orConsWithEXTENDS = new ArrayList(); + for(Constraint con: orCons.get(i)) { + Iterator 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 filterUndConstraints = ab -> resSet.resolveType((TypePlaceholder)(ab.TA1)).resolvedType instanceof TypePlaceholder; -// System.out.println(filterUndConstraints); -// Predicate 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 oldConsList = new ArrayList<>(oldCons); + List 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 tcOfoldCons = buildTransitiveClosure(oldConsListConverted); - return null; + + + return tempMC; } - - - }