Compare commits

...

5 Commits

Author SHA1 Message Date
88175f8b48 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
	modified:   src/test/java/insertGenerics/TestExample42.java
2021-01-08 15:44:07 +01:00
2f37bb7313 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
2020-12-29 01:03:55 +01:00
a04316f629 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
2020-12-29 00:22:36 +01:00
3b062de612 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
2020-12-28 15:37:45 +01:00
c32ef1e31f modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/TestExample42.java
	new file:   src/test/java/insertGenerics/TestExample42_allInOneMethod.java
2020-12-28 00:29:08 +01:00
4 changed files with 262 additions and 76 deletions

@ -1,9 +1,9 @@
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;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import java.util.ArrayList;
@ -16,12 +16,15 @@ public class FamilyOfGeneratedGenerics {
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>();
public List<ClassConstraint> classConstraints = new ArrayList<>();
public List<MethodConstraint> methodConstraints = new ArrayList<>();
public HashMap<MethodConstraint, String> methodsWithPosition = new HashMap<>();
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
this.allConstraints = tphExtractor.allCons;
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
// this.methodConstraints =
// this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs);
}
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
@ -47,24 +50,72 @@ public class FamilyOfGeneratedGenerics {
return cs_cl;
}
public static List<MethodConstraint> getMethodConstraintsAlternative() {
List<GenericsGeneratorResult> ggRes = GenericsGeneratorResult.
return null;
}
// public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
// //TODO: Regeln
// List<MethodConstraint> cs_m = new ArrayList<>();
// List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
// for (MethodConstraint cons: methodConstraints1) {
// if (!checkForDuplicates(cons, cs_m)) {
// cs_m.add(cons);
// }
// }
// List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
// for (MethodConstraint cons: methodConstraints2) {
// if (!checkForDuplicates(cons, cs_m)) {
// cs_m.add(cons);
// }
// }
// List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
// for (MethodConstraint cons: methodConstraints3) {
// if (!checkForDuplicates(cons, cs_m)) {
// cs_m.add(cons);
// }
// }
// List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
// for (MethodConstraint cons: methodConstraints4) {
// if (!checkForDuplicates(cons, cs_m)) {
// cs_m.add(cons);
// }
// }
// List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
// cs_m = methodConstraints5;
// return cs_m;
// }
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
public static HashMap<MethodConstraint, String> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//TODO: Regeln
List<MethodConstraint> cs_m = new ArrayList<>();
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, cs_m, posOfTphs);
for (MethodConstraint cons: methodConstraints1) {
if (!checkForDuplicates(cons, cs_m)) {
HashMap<MethodConstraint, String> cs_m = new HashMap<>();
HashMap<MethodConstraint, String> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
for (MethodConstraint cons: methodConstraints1.keySet()) {
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
cs_m.put(cons,);
}
}
HashMap<MethodConstraint, String> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
for (MethodConstraint cons: methodConstraints2.keySet()) {
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
cs_m.add(cons);
}
}
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes();
HashMap<MethodConstraint, String> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
for (MethodConstraint cons: methodConstraints3.keySet()) {
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
cs_m.add(cons);
}
}
HashMap<MethodConstraint, String> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
for (MethodConstraint cons: methodConstraints4.keySet()) {
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
cs_m.add(cons);
}
}
HashMap<MethodConstraint, String> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
cs_m = methodConstraints5;
return cs_m;
}
/**
* Def. FGG: erste Zeile von cs_cl
* {T < .T' | T is a type variable in a type of a node of a field}
@ -136,83 +187,79 @@ public class FamilyOfGeneratedGenerics {
return tempCC;
}
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;
}
}
return true;
}
/**
/**
* Def. FGG: erste Zeile von cs_m
* {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs}
*/
public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
public static HashMap<MethodConstraint, String> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
//TODO:
List<MethodConstraint> tempCC= new ArrayList<>();
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
for(TPHConstraint allCons: allConstraints){
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
for(String tph: posOfTphs.keySet()) {
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());
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
tempMC.put(consToAdd, posOfTphs.get(tph).snd);
}
}
}
}
}
return tempCC;
return tempMC;
}
/**
/**
* 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 List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //transitive closure of cs
public static HashMap<MethodConstraint, String> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //transitive closure of cs
//TODO:
List<MethodConstraint> tempCC= new ArrayList<>();
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
List<TPHConstraint> 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.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(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 (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
tempMC.put(consToAdd, posOfTphs.get());
}
}
}
}
}
return tempCC;
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 List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
public static HashMap<MethodConstraint, String> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//TODO:
List<MethodConstraint> tempCC= new ArrayList<>();
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
for(ClassConstraint cC : cs_cl) {
for(MethodConstraint mC : cs_m) {
String rightSide = mC.getRight();
String leftSide = cC.getLeft();
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)) {
tempCC.add((MethodConstraint) tphC);
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 tempCC;
return tempMC;
}
/**
@ -220,18 +267,54 @@ 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() {
public static HashMap<MethodConstraint, String> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//TODO:
return null;
HashMap<MethodConstraint, String> 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 List<MethodConstraint> methodTypesWithoutClassTypes() {
public static HashMap<MethodConstraint, String> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m) {
//TODO:
return null;
List<TPHConstraint> tempCC = new ArrayList<>();
for(ClassConstraint cc: cs_cl) {
TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel());
tempCC.add(tphC);
}
List<TPHConstraint> tempMC = new ArrayList<>();
for(MethodConstraint mc: cs_m.keySet()) {
TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel());
tempMC.add(tphC);
}
List<TPHConstraint> tempMC2 = new ArrayList<>();
tempMC2.addAll(tempMC);
List<MethodConstraint> 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) {
@ -247,6 +330,20 @@ public class FamilyOfGeneratedGenerics {
return false;
}
public static boolean checkForDuplicatesInMethods(TPHConstraint constraint, HashMap<MethodConstraint, String> hashMap, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
HashMap<MethodConstraint, String> 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;
}
public static List<TPHConstraint> buildTransitiveClosure(List list) {
List<TPHConstraint> iterList = new ArrayList<>(list);
List<TPHConstraint> runList = new ArrayList<>(list);
@ -269,6 +366,15 @@ public class FamilyOfGeneratedGenerics {
return tcList;
}
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;
}
}
return true;
}
public static HashMap<String, PairTphMethod<PositionFinder.Position, String>> positionConverter(HashMap<String, Boolean> allTphs, List<MethodAndTPH> listOfMethodsAndTphs) {
HashMap<String, PairTphMethod<PositionFinder.Position, String>> convertedPositions = new HashMap<>();

@ -15,7 +15,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
/*
Example method:
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<>();
@ -32,8 +32,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
/*
MethodConstraints should be the same as the input constraint
*/
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions);
assertTrue(methodConstraints.size() == 1);
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"));
}
@ -46,7 +46,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
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<>();
@ -109,8 +109,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);
assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 6);
assertFalse(methodConstraints.isEmpty());
assertTrue(methodConstraints.size() == 2);
}
@ -165,9 +169,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);
assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 3);
assertFalse(methodConstraints.isEmpty());
assertTrue(methodConstraints.size()==9);
}

@ -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,31 @@ public class TestExample42 {
return cs;
}
public HashMap<String, PositionFinder.Position> fillPosOfTphs() {
HashMap<String, PositionFinder.Position> 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<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
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> posOfL = 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> posOfP = 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> posOfV = 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");
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;
}
@ -45,10 +54,12 @@ public class TestExample42 {
public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),fillPosOfTphs());
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
System.out.println("MethodConstraints: " + methodConstraints);
for(MethodConstraint mC: methodConstraints) {
System.out.println(mC);
}
List<TPHConstraint> testCons;
}
}
*/

@ -0,0 +1,61 @@
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<TPHConstraint> fillConstraintsList() {
List<TPHConstraint> 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<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
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> posOfL = 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> posOfP = 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> posOfV = 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");
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<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<TPHConstraint> testCons;
}
}