From 69a557f1f2240f8c91c574aac03296405cb9c23d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 18 Mar 2021 11:39:07 +0100 Subject: [PATCH] Fehlerhaften code entfernen --- .../FamilyOfGeneratedGenerics.java | 149 +----------------- .../FamilyOfGeneratedGenericsTest.java | 18 --- .../java/insertGenerics/TestExample42.java | 5 - .../TestExample42_allInOneMethod.java | 2 - 4 files changed, 3 insertions(+), 171 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index fbd66778..0625aa00 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; +import de.dhbwstuttgart.exceptions.NotImplementedException; import java.util.ArrayList; import java.util.HashMap; @@ -83,35 +84,7 @@ public class FamilyOfGeneratedGenerics { // } public static HashMap getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs) { - //TODO: Regeln - HashMap cs_m = new HashMap<>(); - HashMap methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); - for (MethodConstraint cons: methodConstraints1.keySet()) { - if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) { - cs_m.put(cons,); - } - } - HashMap methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m); - for (MethodConstraint cons: methodConstraints2.keySet()) { - if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) { - cs_m.add(cons); - } - } - HashMap methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m); - for (MethodConstraint cons: methodConstraints3.keySet()) { - if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) { - cs_m.add(cons); - } - } - HashMap methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs); - for (MethodConstraint cons: methodConstraints4.keySet()) { - if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) { - cs_m.add(cons); - } - } - HashMap methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m); - cs_m = methodConstraints5; - return cs_m; + throw new NotImplementedException(); } @@ -210,112 +183,6 @@ public class FamilyOfGeneratedGenerics { } - /** - * Def. FGG: zweite Zeile von cs_m - * {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs} - */ - public static HashMap firstTransitiveSubtypeForMethodTypes(List allConstraints, HashMap cs_m, HashMap> posOfTphs) { //transitive closure of cs - //TODO: - HashMap tempMC= new HashMap<>(); - List tcOfCs = buildTransitiveClosure(allConstraints); - for(MethodConstraint mC1 : cs_m.keySet()) { //(R <. R') - for(MethodConstraint mC2 : cs_m.keySet()) { //(S <. S') - String lSide = mC1.getRight(); //R' - String rSide = mC2.getLeft(); //S - for(TPHConstraint tphC : tcOfCs) { - 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 (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) { - tempMC.put(consToAdd, posOfTphs.get()); - } - } - } - } - } - return tempMC; - } - - /** - * Def. FGG: dritte Zeile von cs_m - * {R' <. S | (R <. R') \in cs_m, (S <. S') \in cs_cl and (R',S) is in the transitive closure of cs} - */ - public static HashMap secondTransitiveSubtypeForMethodTypes(List allConstraints, List cs_cl, HashMap cs_m, HashMap> posOfTphs) { - //TODO: - HashMap tempMC= new HashMap<>(); - List tcOfCs = buildTransitiveClosure(allConstraints); - for(ClassConstraint cC : cs_cl) { - for(MethodConstraint mC : cs_m.keySet()) { - String leftSide = mC.getRight(); - String rightSide = cC.getLeft(); - for(TPHConstraint tphC : tcOfCs) { - if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) { - MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel()); - if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) { - tempMC.put(consToAdd, posOfTphs.get()); -// System.out.println(consToAdd); - } - - } - } - } - } - return tempMC; - } - -/** - * Def. FGG: vierte Zeile von cs_m - * {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 HashMap hasNoSupertypeForMethodTypes(List allConstraints, HashMap> posOfTphs) { - //TODO: - HashMap tempMC= new HashMap<>(); - 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)) { - MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); - if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) { - tempMC.put(consToAdd, posOfTphs.get(tph).snd); -// System.out.println(consToAdd); - } - } - } - } - return tempMC; - } - -/** - * nimm die Menge cs_cl aus cs_m raus - */ - public static HashMap methodTypesWithoutClassTypes(List cs_cl, HashMap cs_m) { - //TODO: - List tempCC = new ArrayList<>(); - for(ClassConstraint cc: cs_cl) { - TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel()); - tempCC.add(tphC); - } - List tempMC = new ArrayList<>(); - for(MethodConstraint mc: cs_m.keySet()) { - TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel()); - tempMC.add(tphC); - } - List tempMC2 = new ArrayList<>(); - tempMC2.addAll(tempMC); - List tempMCToReturn = new ArrayList<>(); - - for(TPHConstraint cc: tempCC) { - for(TPHConstraint mc: tempMC) { - if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) { - tempMC2.remove(mc); - } - } - } - for(TPHConstraint tphC: tempMC2) { - MethodConstraint mCons = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel()); - tempMCToReturn.add(mCons); - } - return tempMCToReturn; - } public static boolean checkForDuplicates(TPHConstraint constraint, List list) { List tempList = list; @@ -331,17 +198,7 @@ public class FamilyOfGeneratedGenerics { } public static boolean checkForDuplicatesInMethods(TPHConstraint constraint, HashMap hashMap, HashMap> posOfTphs) { - HashMap tempMap = hashMap; - boolean hasSame = false; - for (TPHConstraint tphC: tempMap.keySet()) { - hasSame = constraint.getLeft() == tphC.getLeft() && - constraint.getRight() == tphC.getRight() && - constraint.getRel() == tphC.getRel() && - posOfTphs.get(); //constraint already in ArrayList if true - if (hasSame) - return true; - } - return false; + throw new NotImplementedException(); } public static List buildTransitiveClosure(List list) { diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java index 9d7689a0..1f5f00c3 100644 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -29,13 +29,6 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); assertTrue(classConstraints.isEmpty()); - /* - MethodConstraints should be the same as the input constraint - */ - 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(){ @@ -109,12 +102,8 @@ 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); assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 6); - assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size() == 2); } @@ -169,13 +158,6 @@ 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); - - assertFalse(classConstraints.isEmpty()); - assertTrue(classConstraints.size() == 3); - assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size()==9); } diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java index 57dad7b7..e3e800e3 100644 --- a/src/test/java/insertGenerics/TestExample42.java +++ b/src/test/java/insertGenerics/TestExample42.java @@ -54,11 +54,6 @@ 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); - for(MethodConstraint mC: methodConstraints) { - System.out.println(mC); - } List testCons; } diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java index f6fa8d7f..11c76f78 100644 --- a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java +++ b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java @@ -53,8 +53,6 @@ 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 testCons; }