diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 4a717879..5be20f2d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,7 +136,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); - + System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 03ea3f41..f5c06a0c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -35,12 +35,26 @@ public class FamilyOfGeneratedGenerics { cs_cl.add(cons); } } - List classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher - for (ClassConstraint cons: classConstraints2) { - if (!checkForDuplicates(cons, cs_cl)) { - cs_cl.add(cons); + boolean equalsConstraintsList = false; + List tempList = new ArrayList<>(); + do { + List classConstraints2 = new ArrayList<>(); + classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher + if (classConstraints2 == tempList) { + equalsConstraintsList = true; } - } + for (ClassConstraint cons: classConstraints2) { + if (!checkForDuplicates(cons, cs_cl)) { + cs_cl.add(cons); + } + } + tempList = new ArrayList<>(classConstraints2); + for (ClassConstraint cc : tempList) { + classConstraints2.remove(cc); + System.out.println(classConstraints2); + } + }while(!equalsConstraintsList); + List classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs); for (ClassConstraint cons: classConstraints3) { if (!checkForDuplicates(cons, cs_cl)) { @@ -113,7 +127,7 @@ public class FamilyOfGeneratedGenerics { */ public static List typeOfANodeOfAField(List allConstraints, HashMap> posOfTphs) { //RuntimeException re = new RuntimeException("enthält EQUALS-Relation"); - List tempCC= new ArrayList<>(); + List tempCC = new ArrayList<>(); for(TPHConstraint allCons: allConstraints){ if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { for(String tph: posOfTphs.keySet()) { @@ -137,15 +151,19 @@ public class FamilyOfGeneratedGenerics { * {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs } */ public static List transitiveSubtypeForClassTypes(List allConstraints, List cs_cl) { - List tempCC= new ArrayList<>(); + List tempCC = new ArrayList<>(); + ClassConstraint consToAdd; for(ClassConstraint cCons: cs_cl) { if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) { for(TPHConstraint allCons: allConstraints) { if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){ - ClassConstraint consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); + consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); } +// if (tempCC != null) { +// transitiveSubtypeForClassTypes(allConstraints, tempCC); +// } } } } @@ -279,12 +297,15 @@ public class FamilyOfGeneratedGenerics { * nimm die Menge cs_cl aus cs_m raus */ public static List methodTypesWithoutClassTypes(List cs_cl, List cs_m) { - //TODO: + // erstelle Kopie der Liste cs_cl List tempCC = new ArrayList<>(); for(ClassConstraint cc: cs_cl) { TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel()); tempCC.add(tphC); } + // Transitive Hülle von cs_cl + List tcOfCsCl = buildTransitiveClosure(tempCC); + List tempMC = new ArrayList<>(); for(MethodConstraint mc: cs_m) { TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel()); @@ -294,7 +315,7 @@ public class FamilyOfGeneratedGenerics { tempMC2.addAll(tempMC); List tempMCToReturn = new ArrayList<>(); - for(TPHConstraint cc: tempCC) { + for(TPHConstraint cc: tcOfCsCl) { for(TPHConstraint mc: tempMC) { if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) { tempMC2.remove(mc);