diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 30323d6e..5c2442b9 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -1,6 +1,5 @@ package de.dhbwstuttgart.bytecode.insertGenerics; -import com.ibm.icu.text.CurrencyMetaInfo; import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; @@ -23,7 +22,7 @@ public class FamilyOfGeneratedGenerics { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); - this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); +// this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); } @@ -58,7 +57,7 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs) { + public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { @@ -92,7 +91,7 @@ public class FamilyOfGeneratedGenerics { } } } while (addedToConstraintsListForMC3); - List methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs); + List methodConstraints4 = hasNoSupertypeForMethodTypes(cs, cs_m, posOfTphs, listOfMethodsAndTph); for (MethodConstraint cons: methodConstraints4) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); @@ -120,14 +119,35 @@ public class FamilyOfGeneratedGenerics { System.out.println(posOfTPHsForThisMethod); } } - listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod); + listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); System.out.println(tempMethodConstraintsWithPosition); } } + + for(String curMeth: tempMethodConstraintsWithPosition.keySet()){ + for(int i=0; i tempList = new ArrayList<>(list); + for(TPHConstraint tphC: tempList) { + if(tph == tphC.getLeft()) { + return true; + } + } + return false; + } + /** * Def. FGG: erste Zeile von cs_cl * {T < .T' | T is a type variable in a type of a node of a field} @@ -168,9 +188,6 @@ public class FamilyOfGeneratedGenerics { if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); } -// if (tempCC != null) { -// transitiveSubtypeForClassTypes(allConstraints, tempCC); -// } } } } @@ -191,7 +208,7 @@ public class FamilyOfGeneratedGenerics { boolean tvInField = posOfTphs.get(tph).fst == PositionFinder.Position.FIELD; boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null); if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) && - checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) { + !checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) { ClassConstraint consToAdd = new ClassConstraint(tph, "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempCC)){ tempCC.add(consToAdd); @@ -283,12 +300,12 @@ public class FamilyOfGeneratedGenerics { * {T <. Object | (T is a type variable in a type of a node of the method/constructor m in cl_\sigma), * (\existsnot T': T <. T') \in cs)} */ - public static List hasNoSupertypeForMethodTypes(List allConstraints, HashMap> posOfTphs) { + public static List hasNoSupertypeForMethodTypes(List allConstraints, List cs_m, HashMap> posOfTphs, List listOfMethodsAndTph) { //TODO: List tempMC= new ArrayList<>(); for(String tph: posOfTphs.keySet()) { for(TPHConstraint allCons: allConstraints) { - if((posOfTphs.get(tph).fst.equals(PositionFinder.Position.METHOD) || posOfTphs.get(tph).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && checkUpperBound(allConstraints,tph)) { + if((posOfTphs.get(tph).fst.equals(PositionFinder.Position.METHOD) || posOfTphs.get(tph).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) { MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempMC)) { tempMC.add(consToAdd); @@ -296,6 +313,22 @@ public class FamilyOfGeneratedGenerics { } } } + List tempMCObject1 = new ArrayList<>(cs_m); + String currentMethod = ""; + for(MethodAndTPH mat: listOfMethodsAndTph) { + if(mat.getId().equals(posOfTphs.get(tph).snd)) { + currentMethod = mat.getId(); + } + for(TPHConstraint mc1: tempMCObject1) { + if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) { + MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempMC)) { + tempMC.add(consToAdd); + System.out.println(consToAdd); + } + } + } + } } return tempMC; } @@ -374,10 +407,11 @@ public class FamilyOfGeneratedGenerics { public static boolean checkUpperBound(List cs, String tph) { for(int i=0; i methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); - assertTrue(methodConstraints.size() == 2); - assertTrue(methodConstraints.get(0).getLeft().equals("B")); - assertTrue(methodConstraints.get(0).getRight().equals("A")); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); +// assertTrue(methodConstraints.size() == 2); +// assertTrue(methodConstraints.get(0).getLeft().equals("B")); +// assertTrue(methodConstraints.get(0).getRight().equals("A")); } public void testClassField(){ @@ -110,12 +110,12 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); System.out.println(classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); - System.out.println(methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); +// System.out.println(methodConstraints); assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 6); - assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size() == 2); +// assertFalse(methodConstraints.isEmpty()); +// assertTrue(methodConstraints.size() == 2); } @@ -170,13 +170,13 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); System.out.println(classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); - System.out.println(methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); +// System.out.println(methodConstraints); assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 3); - assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size()==9); +// assertFalse(methodConstraints.isEmpty()); +// assertTrue(methodConstraints.size()==9); } diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java index 8d291a2d..127ddd59 100644 --- a/src/test/java/insertGenerics/TestExample42.java +++ b/src/test/java/insertGenerics/TestExample42.java @@ -54,8 +54,8 @@ public class TestExample42 { public void genericTest() { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); System.out.println("ClassConstraints: " + classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); - System.out.println("MethodConstraints: " + methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); +// System.out.println("MethodConstraints: " + methodConstraints); List testCons; } diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java index f6fa8d7f..1d355288 100644 --- a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java +++ b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java @@ -53,8 +53,8 @@ public class TestExample42_allInOneMethod { public void genericTest() { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); System.out.println("ClassConstraints: " + classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); - System.out.println("MethodConstraints: " + methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),); +// System.out.println("MethodConstraints: " + methodConstraints); List testCons; }