modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java

modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
	modified:   src/test/java/insertGenerics/TestExample42.java
	modified:   src/test/java/insertGenerics/TestExample42_allInOneMethod.java
This commit is contained in:
AluAli 2020-12-29 00:22:36 +01:00
parent 3b062de612
commit a04316f629
4 changed files with 75 additions and 36 deletions

View File

@ -4,7 +4,6 @@ import com.ibm.icu.text.CurrencyMetaInfo;
import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.TPHExtractor;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,6 +17,7 @@ public class FamilyOfGeneratedGenerics {
public List<ClassConstraint> classConstraints = new ArrayList<>(); public List<ClassConstraint> classConstraints = new ArrayList<>();
public List<MethodConstraint> methodConstraints = new ArrayList<>(); public List<MethodConstraint> methodConstraints = new ArrayList<>();
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) { public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
this.allConstraints = tphExtractor.allCons; this.allConstraints = tphExtractor.allCons;
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
@ -75,6 +75,8 @@ public class FamilyOfGeneratedGenerics {
cs_m.add(cons); cs_m.add(cons);
} }
} }
List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
// cs_m = methodConstraints5;
return cs_m; return cs_m;
} }
@ -155,20 +157,20 @@ public class FamilyOfGeneratedGenerics {
*/ */
public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma?? public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
//TODO: //TODO:
List<MethodConstraint> tempCC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints){ for(TPHConstraint allCons: allConstraints){
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
for(String tph: posOfTphs.keySet()) { for(String tph: posOfTphs.keySet()) {
if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) { if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) {
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
if (!checkForDuplicates(consToAdd, tempCC)) { if (!checkForDuplicates(consToAdd, tempMC)) {
tempCC.add(consToAdd); tempMC.add(consToAdd);
} }
} }
} }
} }
} }
return tempCC; return tempMC;
} }
@ -178,7 +180,7 @@ public class FamilyOfGeneratedGenerics {
*/ */
public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
//TODO: //TODO:
List<MethodConstraint> tempCC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints); List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
for(MethodConstraint mC1 : cs_m) { //(R <. R') for(MethodConstraint mC1 : cs_m) { //(R <. R')
for(MethodConstraint mC2 : cs_m) { //(S <. S') for(MethodConstraint mC2 : cs_m) { //(S <. S')
@ -187,14 +189,14 @@ public class FamilyOfGeneratedGenerics {
for(TPHConstraint tphC : tcOfCs) { for(TPHConstraint tphC : tcOfCs) {
if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S) if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S)
MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S) MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S)
if (!checkForDuplicates(consToAdd, tempCC)) { if (!checkForDuplicates(consToAdd, tempMC)) {
tempCC.add(consToAdd); tempMC.add(consToAdd);
} }
} }
} }
} }
} }
return tempCC; return tempMC;
} }
/** /**
@ -203,24 +205,25 @@ public class FamilyOfGeneratedGenerics {
*/ */
public static List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) { public static List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
//TODO: //TODO:
List<MethodConstraint> tempCC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints); List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
for(ClassConstraint cC : cs_cl) { for(ClassConstraint cC : cs_cl) {
for(MethodConstraint mC : cs_m) { for(MethodConstraint mC : cs_m) {
String rightSide = mC.getRight(); String leftSide = mC.getRight();
String leftSide = cC.getLeft(); String rightSide = cC.getLeft();
for(TPHConstraint tphC : tcOfCs) { for(TPHConstraint tphC : tcOfCs) {
if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) { if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) {
if (!checkForDuplicates(tphC, tempCC)) { MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
tempCC.add((MethodConstraint) tphC); if (!checkForDuplicates(consToAdd, tempMC)) {
System.out.println(tphC); tempMC.add(consToAdd);
System.out.println(consToAdd);
} }
} }
} }
} }
} }
return tempCC; return tempMC;
} }
/** /**
@ -230,26 +233,52 @@ public class FamilyOfGeneratedGenerics {
*/ */
public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//TODO: //TODO:
List<MethodConstraint> tempCC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
for(String tph: posOfTphs.keySet()) {
for(TPHConstraint allCons: allConstraints) { for(TPHConstraint allCons: allConstraints) {
for(TPHConstraint allCons2: allConstraints) { if((posOfTphs.get(tph).fst.equals(PositionFinder.Position.METHOD) || posOfTphs.get(tph).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && checkUpperBound(allConstraints,tph)) {
if(posOfTphs.containsKey(allCons.getRight()) && (posOfTphs.get(allCons.getRight()).fst.equals(PositionFinder.Position.METHOD) ||posOfTphs.get(allCons.getRight()).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && allCons.getRight()!=allCons2.getLeft()) { MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
MethodConstraint consToAdd = new MethodConstraint(allCons.getRight(), "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempMC)) {
if (!checkForDuplicates(consToAdd, tempCC)) { tempMC.add(consToAdd);
tempCC.add(consToAdd);
System.out.println(consToAdd); System.out.println(consToAdd);
} }
} }
} }
} }
return tempCC; return tempMC;
} }
/** /**
* nimm die Menge cs_cl aus cs_m raus * nimm die Menge cs_cl aus cs_m raus
*/ */
public static List<MethodConstraint> methodTypesWithoutClassTypes() { public static List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
//TODO: //TODO:
/*List<MethodConstraint> tempMCToReturn = new ArrayList<>();
List<TPHConstraint> tempMC = new ArrayList<TPHConstraint>();
for (int i=0; i < cs_m.size(); i++) {
TPHConstraint tphC = (TPHConstraint) cs_m.get(i);
tempMC.add((TPHConstraint) tphC);
}
List<TPHConstraint> tempCC = new ArrayList<TPHConstraint>(cs_cl);
for (TPHConstraint cc: cs_cl) {
TPHConstraint tphC = TPHConstraint.class.cast(cc);
tempCC.add(tphC);
}
for (TPHConstraint cc: tempCC) {
if(tempMC.contains(cc)) {
tempMC.remove(cc);
}
}
tempMCToReturn = List.class.cast(tempMC);
return tempMCToReturn;*/
List<MethodConstraint> tempMC = new ArrayList<>();
List<TPHConstraint> tempTphC = new ArrayList<>();
for(int i=0; i<cs_cl.size(); i++) {
TPHConstraint tphC = (TPHConstraint) cs_cl.get(i);
tempTphC.add(tphC);
}
return null; return null;
} }

View File

@ -15,7 +15,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
/* /*
Example method: Example method:
A id(B i) return i; A id(B i) return i;
gives constraint: B <. A, which is a method constraint gives constraint: B <. A and A <. Object, which are method constraints
*/ */
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
@ -33,7 +33,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
MethodConstraints should be the same as the input constraint MethodConstraints should be the same as the input constraint
*/ */
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions); List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions);
assertTrue(methodConstraints.size() == 1); assertTrue(methodConstraints.size() == 2);
assertTrue(methodConstraints.get(0).getLeft().equals("B")); assertTrue(methodConstraints.get(0).getLeft().equals("B"));
assertTrue(methodConstraints.get(0).getRight().equals("A")); assertTrue(methodConstraints.get(0).getRight().equals("A"));
} }
@ -46,7 +46,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return f; return f;
} }
} }
gives constraint: A <. B, which is a class constraint gives constraint: A <. B and B <. Object which are class constraints
*/ */
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
@ -109,8 +109,12 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
System.out.println(methodConstraints);
assertFalse(classConstraints.isEmpty()); assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 6); assertTrue(classConstraints.size() == 6);
assertFalse(methodConstraints.isEmpty());
assertTrue(methodConstraints.size() == 5);
} }
@ -165,9 +169,13 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
System.out.println(methodConstraints);
assertFalse(classConstraints.isEmpty()); assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 3); assertTrue(classConstraints.size() == 3);
assertFalse(methodConstraints.isEmpty());
assertTrue(methodConstraints.size()==11);
} }

View File

@ -25,24 +25,25 @@ public class TestExample42 {
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() { public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>(); HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>();
// TPHs "U" und "L" auskommentiert, da nach Vorgaben L zu Z umbenannt und U als void interpretiert wird
PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); // PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA");
PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA");
PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); // PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
PairTphMethod<PositionFinder.Position, String> posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); PairTphMethod<PositionFinder.Position, String> posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
PairTphMethod<PositionFinder.Position, String> posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); PairTphMethod<PositionFinder.Position, String> posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
posOfTphs.put("K", posOfK); posOfTphs.put("K", posOfK);
posOfTphs.put("L", posOfL); // posOfTphs.put("L", posOfL);
posOfTphs.put("M", posOfM); posOfTphs.put("M", posOfM);
posOfTphs.put("N", posOfN); posOfTphs.put("N", posOfN);
posOfTphs.put("P", posOfP); posOfTphs.put("P", posOfP);
posOfTphs.put("Q", posOfQ); posOfTphs.put("Q", posOfQ);
posOfTphs.put("U", posOfU); // posOfTphs.put("U", posOfU);
posOfTphs.put("V", posOfV); posOfTphs.put("V", posOfV);
posOfTphs.put("W", posOfW); posOfTphs.put("W", posOfW);
posOfTphs.put("Z", posOfZ); posOfTphs.put("Z", posOfZ);

View File

@ -24,24 +24,25 @@ public class TestExample42_allInOneMethod {
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() { public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>(); HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>();
// TPHs "U" und "L" auskommentiert, da nach Vorgaben L zu Z umbenannt und U als void interpretiert wird
PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); // PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); // PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
PairTphMethod<PositionFinder.Position, String> posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); PairTphMethod<PositionFinder.Position, String> posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
posOfTphs.put("K", posOfK); posOfTphs.put("K", posOfK);
posOfTphs.put("L", posOfL); // posOfTphs.put("L", posOfL);
posOfTphs.put("M", posOfM); posOfTphs.put("M", posOfM);
posOfTphs.put("N", posOfN); posOfTphs.put("N", posOfN);
posOfTphs.put("P", posOfP); posOfTphs.put("P", posOfP);
posOfTphs.put("Q", posOfQ); posOfTphs.put("Q", posOfQ);
posOfTphs.put("U", posOfU); // posOfTphs.put("U", posOfU);
posOfTphs.put("V", posOfV); posOfTphs.put("V", posOfV);
posOfTphs.put("W", posOfW); posOfTphs.put("W", posOfW);
posOfTphs.put("Z", posOfZ); posOfTphs.put("Z", posOfZ);