From dfddc44f292e9d34b88e5c40438f4dfa77a6c42a Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Fri, 12 Jul 2019 19:50:46 +0200 Subject: [PATCH] Separated the algorithm into two parts. Part 1 is the simplification of the constraints and part 2 is generation of generics. --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 2 +- .../bytecode/constraint/EqualConstraint.java | 4 +- .../constraint/ExtendsConstraint.java | 4 +- .../ConstraintsSimplifier.java | 92 +++++++++++++++++++ .../genericsGenerator/CyclesFinder.java | 15 +-- .../genericsGenerator/GenericsGenerator.java | 35 +------ .../GenericsGeneratorUtility.java | 70 +++++++++++++- .../bytecode/signature/Signature.java | 4 +- .../ConstraintsSimplierResult.java | 53 +++++++++++ .../bytecode/utilities/NameReplacer.java | 36 ++++++++ .../bytecode/utilities/Simplify.java | 37 ++++---- 11 files changed, 278 insertions(+), 74 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/ConstraintsSimplifier.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/ConstraintsSimplierResult.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 238f749e..9850d902 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -106,7 +106,7 @@ public class TPHExtractor extends AbstractASTWalker { if (inMethod) methodAndTph.getPairs().add(ag); allPairs.add(ag); - TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS); + TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName()); if(!containsConstraint(allCons,con)) allCons.add(con); // } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java index fb6cae20..69fb0b02 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java @@ -2,8 +2,8 @@ package de.dhbwstuttgart.bytecode.constraint; public class EqualConstraint extends TPHConstraint { - public EqualConstraint(String left, String right, Relation rel) { - super(left, right, rel); + public EqualConstraint(String left, String right) { + super(left, right, Relation.EQUAL); } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java index 6f28e24f..77007a3b 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java @@ -2,8 +2,8 @@ package de.dhbwstuttgart.bytecode.constraint; public class ExtendsConstraint extends TPHConstraint { - public ExtendsConstraint(String left, String right, Relation rel) { - super(left, right, rel); + public ExtendsConstraint(String left, String right) { + super(left, right, Relation.EXTENDS); } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/ConstraintsSimplifier.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/ConstraintsSimplifier.java new file mode 100644 index 00000000..9f85a483 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/ConstraintsSimplifier.java @@ -0,0 +1,92 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGenerator; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.bytecode.TPHExtractor; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.simplifyRes.ConstraintsSimplierResult; +import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResult; + +/** + * @author fayez + * + */ +public class ConstraintsSimplifier { + public static ConstraintsSimplierResult simplifyConstraints(TPHExtractor tphExtractor, List genericsGeneratorResults, List tphsClass) { + + List allCons = tphExtractor.allCons; + List equalCons = new ArrayList<>(); + List simpleCycles = findSimpleCycles(allCons); + + if(!simpleCycles.isEmpty()) { + handleSimpleCycles(allCons, simpleCycles); + equalCons.addAll(GenericsGeneratorUtility.getEqualConstraints(allCons)); + } + + /* Step 2 */ + List foundCons = GenericsGeneratorUtility.findConstraintsWithLeftSameLeftSide(allCons); + if(!foundCons.isEmpty()) { + List equalCons2 = GenericsGeneratorUtility.simplifyConstraintsWithSameLeftSide(foundCons,tphExtractor,tphsClass); + equalCons.addAll(equalCons2); + } + + List longCycles = findLongCycles(allCons); + + if(!longCycles.isEmpty()) { + handleLongCycle(genericsGeneratorResults, allCons, longCycles); + } + /* The right hand side of equal constraint is the new name in name replacement result */ + List nameReplacementResults = GenericsGeneratorUtility.createNameReplacementResultsFromEqualConstraints(equalCons); + ConstraintsSimplierResult result = new ConstraintsSimplierResult(genericsGeneratorResults, nameReplacementResults); + return result; + } + + /** + * @param genericsGeneratorResults + * @param allCons + * @param longCycles + */ + public static void handleLongCycle(List genericsGeneratorResults, + List allCons, List longCycles) { + GenericsGeneratorUtility.modifyRelationForConstraintsinLongCycle(longCycles); + List nameReplacementResults = GenericsGeneratorUtility.substituteTPHSFormLongCycle(allCons, longCycles); + GenericsGeneratorUtility.createResults(genericsGeneratorResults,nameReplacementResults); + GenericsGeneratorUtility.removeEqualConstraints(allCons); + } + + /** + * @param allCons + * @return + */ + public static List findLongCycles(List allCons) { + /* find all long cycles */ + CyclesFinder cyclesFinder = new CyclesFinder(allCons); + List longCycles = cyclesFinder.findLongCycles(); + return longCycles; + } + + /** + * @param allCons + * @param simpleCycles + */ + public static void handleSimpleCycles(List allCons, List simpleCycles) { + GenericsGeneratorUtility.modifyRelation(simpleCycles); + GenericsGeneratorUtility.removeAllReverseConstraints(allCons,simpleCycles); + GenericsGeneratorUtility.substituteTPH(allCons, simpleCycles); + } + + /** + * @param allCons + * @return + */ + public static List findSimpleCycles(List allCons) { + CyclesFinder cyclesFinder = new CyclesFinder(allCons); + /* find all simple cycles if they are exist */ + List simpleCycles = cyclesFinder.findSimpleCycles(); + return simpleCycles; + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/CyclesFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/CyclesFinder.java index dfeabae0..f2212843 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/CyclesFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/CyclesFinder.java @@ -4,10 +4,8 @@ package de.dhbwstuttgart.bytecode.genericsGenerator; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Optional; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; @@ -51,18 +49,17 @@ public class CyclesFinder { public List findLongCycles() { List vistedConstraints = new ArrayList<>(allCons.size()); List longCycles = new ArrayList<>(); - Map tableOfConstraints = createConstraintsTable(); for (TPHConstraint constraint : allCons) { if (!vistedConstraints.contains(constraint)) { vistedConstraints.add(constraint); - checkConstraint(constraint, vistedConstraints, longCycles, tableOfConstraints); + checkConstraint(constraint, vistedConstraints, longCycles); } } return longCycles; } private void checkConstraint(TPHConstraint constraint, List vistedConstraints, - List longCycles, Map tableOfConstraints) { + List longCycles) { List tphsInRelation = new LinkedList<>(); List maybeCycle = new ArrayList<>(); maybeCycle.add(constraint); @@ -119,14 +116,6 @@ public class CyclesFinder { return null; } - private Map createConstraintsTable() { - Map table = new HashMap<>(); - for (TPHConstraint constraint : allCons) { - table.put(constraint.getLeft(), constraint.getRight()); - } - return table; - } - private boolean isCycle(List tphsInRelation) { return tphsInRelation.get(0).equals(tphsInRelation.get(tphsInRelation.size() - 1)); } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGenerator.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGenerator.java index fc26ad03..25a27a02 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGenerator.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGenerator.java @@ -5,19 +5,12 @@ package de.dhbwstuttgart.bytecode.genericsGenerator; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; import de.dhbwstuttgart.bytecode.TPHExtractor; -import de.dhbwstuttgart.bytecode.constraint.EqualConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.simplifyRes.ConstraintsSimplierResult; import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResult; -import de.dhbwstuttgart.bytecode.utilities.ConstraintsFinder; -import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import de.dhbwstuttgart.bytecode.utilities.MethodUtility; -import de.dhbwstuttgart.bytecode.utilities.NameReplacer; import de.dhbwstuttgart.syntaxtree.Method; /** @@ -29,33 +22,13 @@ public class GenericsGenerator { public static List generateConstraintsForMethod(Method method, TPHExtractor tphExtractor, List tphsClass) { List genericsGeneratorResults = new ArrayList<>(); + + ConstraintsSimplierResult simplifiedConstraints = ConstraintsSimplifier.simplifyConstraints(tphExtractor, genericsGeneratorResults,tphsClass); + List allCons = tphExtractor.allCons; String methodID = MethodUtility.createID(tphExtractor.getResolver(), method); List methodTPHS = GenericsGeneratorUtility.getMethodTPHS(methodID ,tphExtractor.ListOfMethodsAndTph); - CyclesFinder cyclesFinder = new CyclesFinder(allCons); - /* find all simple cycles if they are exist */ - List simpleCycles = cyclesFinder.findSimpleCycles(); - - if(!simpleCycles.isEmpty()) { - GenericsGeneratorUtility.modifyRelation(simpleCycles); - GenericsGeneratorUtility.removeAllReverseConstraints(allCons,simpleCycles); - GenericsGeneratorUtility.substituteTPH(allCons, simpleCycles); - GenericsGeneratorUtility.removeEqualConstraints(allCons); - } - - /* Step 2 */ - List foundCons = GenericsGeneratorUtility.findConstraintsWithLeftSameLeftSide(allCons); - GenericsGeneratorUtility.simplifyConstraintsWithSameLeftSide(foundCons,allCons,methodTPHS); - - /* find all long cycles */ - List longCycles = cyclesFinder.findLongCycles(); - - if(!longCycles.isEmpty()) { - GenericsGeneratorUtility.modifyRelationForConstraintsinLongCycle(longCycles); - List nameReplacementResults = GenericsGeneratorUtility.substituteTPHSFormLongCycle(allCons, longCycles); - GenericsGeneratorUtility.createResults(genericsGeneratorResults,nameReplacementResults); - } return null; } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGeneratorUtility.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGeneratorUtility.java index b94c66fa..e5ad4ccc 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGeneratorUtility.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GenericsGeneratorUtility.java @@ -13,7 +13,9 @@ import java.util.stream.Collectors; import org.objectweb.asm.Type; +import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.EqualConstraint; +import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResult; @@ -60,7 +62,9 @@ public class GenericsGeneratorUtility { * @param newName The new name */ public static void substituteTPH(List allCons, String oldName, String newName) { - allCons.forEach(c->{ + allCons.stream() + .filter(c->c.getRel()==Relation.EXTENDS) + .forEach(c->{ if(c.getLeft().equals(oldName)) c.setLeft(newName); if(c.getRight().equals(oldName)) @@ -113,11 +117,35 @@ public class GenericsGeneratorUtility { } } + + public static List simplifyConstraintsWithSameLeftSide(List consWithSameLeftSide, + TPHExtractor tphExtractor, List tphsClass) { + List eqCons = new ArrayList<>(); + List allCons = tphExtractor.allCons; + + for (ConstraintsWithSameLeftSide list : consWithSameLeftSide) { + NameReplacementResult replRes = modifyNames(allCons, list, tphExtractor.ListOfMethodsAndTph,tphsClass); + createEqualConstraintsForNames(replRes.getName(), replRes.getOldNames(),eqCons); + + for (TPHConstraint c : allCons) { + if (c.getRel() == Relation.EQUAL && replRes.getName().equals(c.getRight())) { + eqCons.add(c); + } + } + updateEqualCons(replRes, eqCons); + + TPHConstraint c = list.getConstraints().get(0); + allCons.removeAll(list.getConstraints()); + allCons.add(c); + } + return eqCons; + + } private static void createEqualConstraintsForNames(String name, List equalNames, List eqCons) { // create an equal constraint for each value in repres for (String eName : equalNames) { - EqualConstraint ec = new EqualConstraint(eName, name, Relation.EQUAL); + EqualConstraint ec = new EqualConstraint(eName, name); eqCons.add(ec); } } @@ -138,6 +166,15 @@ public class GenericsGeneratorUtility { return replRes; } + public static NameReplacementResult modifyNames(List allCons, ConstraintsWithSameLeftSide list, List methodAndTPHs, List tphsClass) { + // generate a new name and replace the right hand side for each constraint + // in list with the new name + NameReplacer replacer = new NameReplacer(list.getConstraints(), allCons, methodAndTPHs, tphsClass); + // new name -> [all old names] + NameReplacementResult replRes = replacer.replaceNames(); + return replRes; + } + public static void updateEqualCons(NameReplacementResult nameReplacementResult, List eqCons) { List oldNames = nameReplacementResult.getOldNames(); String newName = nameReplacementResult.getName(); @@ -190,7 +227,7 @@ public class GenericsGeneratorUtility { List nameReplacementResults) { nameReplacementResults.forEach(n->{ Set equals = new HashSet<>(n.getOldNames()); - TPHConstraint cons = new EqualConstraint(n.getName(), Type.getInternalName(Object.class), Relation.EXTENDS); + TPHConstraint cons = new ExtendsConstraint(n.getName(), Type.getInternalName(Object.class)); GenericsGeneratorResult ggRes = new GenericsGeneratorResult(cons, equals); genericsGeneratorResults.add(ggRes); }); @@ -204,4 +241,31 @@ public class GenericsGeneratorUtility { public static List getEqualConstraints(List allCons) { return allCons.stream().filter(c->c.getRel()==Relation.EQUAL).collect(Collectors.toList()); } + + public static List createNameReplacementResultsFromEqualConstraints( + List equalCons) { + List nameReplacementResults = new ArrayList<>(); + equalCons.forEach(c->{ + if(isInNameReplacementResults(nameReplacementResults,c.getRight())) { + getNameReplacementByName(nameReplacementResults,c.getRight()).getOldNames().add(c.getLeft()); + } else { + List oldNames = new ArrayList<>(); + oldNames.add(c.getLeft()); + NameReplacementResult nrRes = new NameReplacementResult(c.getRight(), oldNames); + nameReplacementResults.add(nrRes); + } + }); + return nameReplacementResults; + } + + private static NameReplacementResult getNameReplacementByName(List nameReplacementResults, + String name) { + return nameReplacementResults.stream().filter(n->n.getName().equals(name)).findFirst().get(); + } + + public static boolean isInNameReplacementResults(List nameReplacementResults,String name){ + if(nameReplacementResults.isEmpty()) + return false; + return nameReplacementResults.stream().map(r->r.getName()).filter(n->name.equals(n)).findFirst().isPresent(); + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java index f9ab3d47..cb18e6b5 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -258,7 +258,7 @@ public class Signature { if(resolved instanceof TypePlaceholder) { //resType.getAdditionalGenerics().forEach(ag ->{ resultSet.genIns.forEach(ag ->{ - TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS); + TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName()); if(!contains(res,constr)) { res.add(constr); } @@ -270,7 +270,7 @@ public class Signature { if(resType2.resolvedType instanceof TypePlaceholder) { //resType2.getAdditionalGenerics().forEach(ag ->{ resultSet.genIns.forEach(ag ->{ - TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS); + TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName()); if(!contains(res,constr)) { res.add(constr); } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/ConstraintsSimplierResult.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/ConstraintsSimplierResult.java new file mode 100644 index 00000000..f99cdf2a --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/ConstraintsSimplierResult.java @@ -0,0 +1,53 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.simplifyRes; + +import java.util.List; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.genericsGenerator.NameReplacementResult; + +/** + * This class represents the result of the constraints simplifier. + * + * @author fayez + * + */ +public class ConstraintsSimplierResult { + private List genericsGenResults; + private List nameReplacementResults; + /** + * @param genericsGenResults + */ + public ConstraintsSimplierResult(List genericsGenResults, + List nameReplacementResults) { + this.genericsGenResults = genericsGenResults; + this.setNameReplacementResults(nameReplacementResults); + } + /** + * @return the genericsGenResults + */ + public List getGenericsGenResults() { + return genericsGenResults; + } + /** + * @param genericsGenResults the genericsGenResults to set + */ + public void setGenericsGenResults(List genericsGenResults) { + this.genericsGenResults = genericsGenResults; + } + /** + * @return the nameReplacementResults + */ + public List getNameReplacementResults() { + return nameReplacementResults; + } + /** + * @param nameReplacementResults the nameReplacementResults to set + */ + public void setNameReplacementResults(List nameReplacementResults) { + this.nameReplacementResults = nameReplacementResults; + } + +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/NameReplacer.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/NameReplacer.java index a37bea85..2b995b5f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/NameReplacer.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/NameReplacer.java @@ -10,8 +10,11 @@ import de.dhbwstuttgart.bytecode.genericsGenerator.NameReplacementResult; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; public class NameReplacer { + //TODO rename private List constraints; private List allConstraints; + private List methodAndTPHs; + // TODO rename into tphClass private List tphs; private List localTphs; @@ -30,11 +33,44 @@ public class NameReplacer { this.tphs = tphs; } + public NameReplacer(List constraints, List allConstraints) { + this.constraints = constraints; + this.allConstraints = allConstraints; + } + + public NameReplacer(List constraints, List allConstraints, List methodAndTPHs, + List tphsClass) { + this.constraints = constraints; + this.allConstraints = allConstraints; + this.methodAndTPHs = methodAndTPHs; + this.tphs = tphsClass; + } + public NameReplacementResult replaceNames() { String newName = NameGenerator.makeNewName(); List names = new ArrayList<>(); substituteRightSidesWithNewName(newName, names); + substituteNamesInAllConstraints(newName, names); + methodAndTPHs.stream().map(m->m.getTphs()).forEach(tphsMethod->{ + if(tphsMethod.removeAll(names)) + tphsMethod.add(newName); + }); + + + if(tphs.removeAll(names)) + tphs.add(newName); + + NameReplacementResult res = new NameReplacementResult(newName, names); + + return res; + } + + public NameReplacementResult replaceNamesLocal() { + String newName = NameGenerator.makeNewName(); + List names = new ArrayList<>(); + substituteRightSidesWithNewName(newName, names); + substituteNamesInAllConstraints(newName, names); tphs.removeAll(names); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java index c99d1f32..e0f9aa20 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java @@ -162,8 +162,7 @@ public class Simplify { eq.add(t); } // generate a new constraint (left < Object) - TPHConstraint constraint = new ExtendsConstraint(left, Type.getInternalName(Object.class), - Relation.EXTENDS); + TPHConstraint constraint = new ExtendsConstraint(left, Type.getInternalName(Object.class)); // put the generated constraint and its equal set into result set result.put(constraint, eq); constraints.clear(); @@ -217,8 +216,7 @@ public class Simplify { if (!result.containsKey(cons)) { result.put(cons, null); if (!cons.getRight().equals(Type.getInternalName(Object.class))) - result.put(new ExtendsConstraint(cons.getRight(), Type.getInternalName(Object.class), - Relation.EXTENDS), null); + result.put(new ExtendsConstraint(cons.getRight(), Type.getInternalName(Object.class)), null); } return result; @@ -248,7 +246,7 @@ public class Simplify { // create an equal constraint for each value in repres String key = replRes.getName(); for (String val : replRes.getOldNames()) { - EqualConstraint ec = new EqualConstraint(val, key, Relation.EQUAL); + EqualConstraint ec = new EqualConstraint(val, key); eqCons.add(ec); } for (TPHConstraint c : allCons) { @@ -391,18 +389,18 @@ public class Simplify { if (!containTPH(methodTphs, superTphRes)) { HashSet equals = getEqualsTphsFromEqualCons(eqCons, superTphRes); if (tphsClass.contains(superTphRes)/*classTPHSContainsTPH(tphsClass, superTphRes)*/) { - result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals); + result.put(new ExtendsConstraint(subTphRes, superTphRes), equals); } else { - result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), + result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class)), equals); } } else { HashSet equals = getEqualsTphsFromEqualCons(eqCons, subTphRes); - result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals); + result.put(new ExtendsConstraint(subTphRes, superTphRes), equals); if (!isTPHInConstraint(result, superTphRes) && !isTphInEqualSet(result, superTphRes)) { HashSet equals2 = getEqualsTphsFromEqualCons(eqCons, superTphRes); - result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), + result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class)), equals2); } } @@ -412,7 +410,7 @@ public class Simplify { for (String tph : localTphs) { if (!isTPHInConstraint(result, tph) && !isTphInEqualSet(result, tph)) { HashSet equals = getEqualsTphsFromEqualCons(eqCons, tph); - result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class), Relation.EXTENDS), equals); + result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class)), equals); } } @@ -583,8 +581,7 @@ public class Simplify { eq.add(t); } // generate a new constraint (left < Object) - TPHConstraint constraint = new ExtendsConstraint(left, Type.getInternalName(Object.class), - Relation.EXTENDS); + TPHConstraint constraint = new ExtendsConstraint(left, Type.getInternalName(Object.class)); // put the generated constraint and its equal set into result set result.put(constraint, eq); constraints.clear(); @@ -619,7 +616,7 @@ public class Simplify { TPHConstraint cons = allCons.get(0); if (!result.containsKey(cons)) { result.put(cons, null); - result.put(new ExtendsConstraint(cons.getRight(), Type.getInternalName(Object.class), Relation.EXTENDS), + result.put(new ExtendsConstraint(cons.getRight(), Type.getInternalName(Object.class)), null); } @@ -699,7 +696,7 @@ public class Simplify { subTphRes = tphInRel.getFirst(); HashSet equals = getEqualsTphsFromEqualCons(eqCons, superTphRes); - result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals); + result.put(new ExtendsConstraint(subTphRes, superTphRes), equals); } @@ -754,7 +751,7 @@ public class Simplify { substituteTPH(allCons, toSubs, tph); if (subAndSuper.containsKey(toSubs) && subAndSuper.containsKey(tph)) { toSubs = subAndSuper.remove(toSubs); - EqualConstraint eq = new EqualConstraint(subAndSuper.get(tph), toSubs, Relation.EQUAL); + EqualConstraint eq = new EqualConstraint(subAndSuper.get(tph), toSubs); eqCons.add(eq); substituteInMap(subAndSuper, allCons, eqCons, toSubs, subAndSuper.get(tph)); } else if (subAndSuper.containsKey(toSubs) && !subAndSuper.containsKey(tph)) { @@ -947,11 +944,11 @@ public class Simplify { i++; } if (superTphRes.equals(Type.getInternalName(Object.class))) { - result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), + result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class)), null); } else { - result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), null); - result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), + result.put(new ExtendsConstraint(subTphRes, superTphRes), null); + result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class)), null); } @@ -1023,7 +1020,7 @@ public class Simplify { return c; } - return new ExtendsConstraint(toFind.getRight(), Type.getInternalName(Object.class), Relation.EXTENDS); + return new ExtendsConstraint(toFind.getRight(), Type.getInternalName(Object.class)); } private static TPHConstraint getKeyConstraint(Map> result, @@ -1034,7 +1031,7 @@ public class Simplify { return c; } - return new ExtendsConstraint(toFind.getRight(), Type.getInternalName(Object.class), Relation.EXTENDS); + return new ExtendsConstraint(toFind.getRight(), Type.getInternalName(Object.class)); } private static Set getEqualsTPHs(Map> result, TPHConstraint toFind) {