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 2021-01-22 23:49:25 +01:00
parent bb900af6bf
commit 3f4aa7bbd5
4 changed files with 63 additions and 29 deletions

View File

@ -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<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
List<MethodConstraint> cs_m = new ArrayList<>();
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
for (MethodConstraint cons: methodConstraints1) {
@ -92,7 +91,7 @@ public class FamilyOfGeneratedGenerics {
}
}
} while (addedToConstraintsListForMC3);
List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
List<MethodConstraint> 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<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
if(currentMC.getRight()!= "Object" && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), "Object", Relation.EXTENDS);
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
}
}
}
return tempMethodConstraintsWithPosition;
}
// Hilfsmethode um TPHs in den Methoden zu finden, die <. Object sein müssen
private static boolean compareTphsOfConstraints(String tph, List list) {
List<TPHConstraint> 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<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
//TODO:
List<MethodConstraint> 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<TPHConstraint> 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<TPHConstraint> cs, String tph) {
for(int i=0; i<cs.size(); i++) {
if(cs.get(i).getLeft() == tph) {
return false;
//has upper bound
return true;
}
}
return true;
return false;
}

View File

@ -32,10 +32,10 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
/*
MethodConstraints should be the same as the input constraint
*/
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions);
assertTrue(methodConstraints.size() == 2);
assertTrue(methodConstraints.get(0).getLeft().equals("B"));
assertTrue(methodConstraints.get(0).getRight().equals("A"));
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), 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<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
System.out.println(methodConstraints);
// List<MethodConstraint> 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<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
System.out.println(methodConstraints);
// List<MethodConstraint> 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);
}

View File

@ -54,8 +54,8 @@ public class TestExample42 {
public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
System.out.println("MethodConstraints: " + methodConstraints);
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
// System.out.println("MethodConstraints: " + methodConstraints);
List<TPHConstraint> testCons;
}

View File

@ -53,8 +53,8 @@ public class TestExample42_allInOneMethod {
public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
System.out.println("MethodConstraints: " + methodConstraints);
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),);
// System.out.println("MethodConstraints: " + methodConstraints);
List<TPHConstraint> testCons;
}