diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 50170cdf5..fc30ab085 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -47,11 +47,6 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraintsAlternative() { - List ggRes = GenericsGeneratorResult. - return null; - } - public static List getMethodConstraints(List cs, HashMap> posOfTphs) { //TODO: Regeln List cs_m = new ArrayList<>(); @@ -61,7 +56,13 @@ public class FamilyOfGeneratedGenerics { cs_m.add(cons); } } - List methodConstraints2 = firstTransitiveSubtypeForMethodTypes(); + List methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m, posOfTphs); + for (MethodConstraint cons: methodConstraints2) { + if (!checkForDuplicates(cons, cs_m)) { + cs_m.add(cons); + } + } + System.out.println("sdfsdf" + methodConstraints2); return cs_m; } @@ -178,13 +179,17 @@ public class FamilyOfGeneratedGenerics { //TODO: List tempCC= new ArrayList<>(); List tcOfCs = buildTransitiveClosure(allConstraints); - for(MethodConstraint mC1 : cs_m) { - for(MethodConstraint mC2 : cs_m) { - String rightSide = mC1.getRight(); - String leftSide = mC2.getLeft(); + for(MethodConstraint mC1 : cs_m) { //(R <. R') + for(MethodConstraint mC2 : cs_m) { //(S <. S') + String lSide = mC1.getRight(); //R' + String rSide = mC2.getLeft(); //S for(TPHConstraint tphC : tcOfCs) { - if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) { - tempCC.add((MethodConstraint) tphC); + if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S) + MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S) + if (!checkForDuplicates(consToAdd, tempCC)) { + tempCC.add(consToAdd); + System.out.println(consToAdd); + } } } } diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java index eddc53419..f8f059568 100644 --- a/src/test/java/insertGenerics/TestExample42.java +++ b/src/test/java/insertGenerics/TestExample42.java @@ -1,12 +1,8 @@ -/* package insertGenerics; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.PositionFinder; +import de.dhbwstuttgart.bytecode.insertGenerics.*; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -26,18 +22,30 @@ public class TestExample42 { return cs; } - public HashMap fillPosOfTphs() { - HashMap posOfTphs = new HashMap<>(); - posOfTphs.put("K", PositionFinder.Position.FIELD); - posOfTphs.put("L", PositionFinder.Position.METHOD); - posOfTphs.put("M", PositionFinder.Position.METHOD); - posOfTphs.put("N", PositionFinder.Position.METHOD); - posOfTphs.put("P", PositionFinder.Position.METHOD); - posOfTphs.put("Q", PositionFinder.Position.METHOD); - posOfTphs.put("U", PositionFinder.Position.METHOD); - posOfTphs.put("V", PositionFinder.Position.METHOD); - posOfTphs.put("W", PositionFinder.Position.METHOD); - posOfTphs.put("Z", PositionFinder.Position.METHOD); + public HashMap> fillPosOfTphs() { + HashMap> posOfTphs = new HashMap<>(); + + PairTphMethod posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); + PairTphMethod posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); + PairTphMethod posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); + PairTphMethod posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); + PairTphMethod posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); + PairTphMethod posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); + PairTphMethod posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + + posOfTphs.put("K", posOfK); + posOfTphs.put("L", posOfL); + posOfTphs.put("M", posOfM); + posOfTphs.put("N", posOfN); + posOfTphs.put("P", posOfP); + posOfTphs.put("Q", posOfQ); + posOfTphs.put("U", posOfU); + posOfTphs.put("V", posOfV); + posOfTphs.put("W", posOfW); + posOfTphs.put("Z", posOfZ); return posOfTphs; } @@ -51,4 +59,3 @@ public class TestExample42 { List testCons; } } -*/ diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java new file mode 100644 index 000000000..6da2c0d80 --- /dev/null +++ b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java @@ -0,0 +1,60 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.insertGenerics.*; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class TestExample42_allInOneMethod { + public List fillConstraintsList() { + List cs = new ArrayList<>(); + cs.add(new TPHConstraint("M", "N", Relation.EXTENDS)); + cs.add(new TPHConstraint("N", "Z", Relation.EXTENDS)); + cs.add(new TPHConstraint("Q", "K", Relation.EXTENDS)); + cs.add(new TPHConstraint("K", "P", Relation.EXTENDS)); + cs.add(new TPHConstraint("W", "M", Relation.EXTENDS)); + cs.add(new TPHConstraint("Z", "V", Relation.EXTENDS)); + return cs; + } + + public HashMap> fillPosOfTphs() { + HashMap> posOfTphs = new HashMap<>(); + + PairTphMethod posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); + PairTphMethod posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); + PairTphMethod posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); + PairTphMethod posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); + PairTphMethod posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); + PairTphMethod posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); + PairTphMethod posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + + posOfTphs.put("K", posOfK); + posOfTphs.put("L", posOfL); + posOfTphs.put("M", posOfM); + posOfTphs.put("N", posOfN); + posOfTphs.put("P", posOfP); + posOfTphs.put("Q", posOfQ); + posOfTphs.put("U", posOfU); + posOfTphs.put("V", posOfV); + posOfTphs.put("W", posOfW); + posOfTphs.put("Z", posOfZ); + return posOfTphs; + } + + @Test + public void genericTest() { + List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); + System.out.println("ClassConstraints: " + classConstraints); + List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),fillPosOfTphs()); + System.out.println("MethodConstraints: " + methodConstraints); + + List testCons; + } +}