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
This commit is contained in:
AluAli 2020-12-28 00:29:08 +01:00
parent 5ed6a4617a
commit c32ef1e31f
3 changed files with 102 additions and 30 deletions

View File

@ -47,11 +47,6 @@ public class FamilyOfGeneratedGenerics {
return cs_cl; return cs_cl;
} }
public static List<MethodConstraint> getMethodConstraintsAlternative() {
List<GenericsGeneratorResult> ggRes = GenericsGeneratorResult.
return null;
}
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//TODO: Regeln //TODO: Regeln
List<MethodConstraint> cs_m = new ArrayList<>(); List<MethodConstraint> cs_m = new ArrayList<>();
@ -61,7 +56,13 @@ public class FamilyOfGeneratedGenerics {
cs_m.add(cons); cs_m.add(cons);
} }
} }
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(); List<MethodConstraint> 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; return cs_m;
} }
@ -178,13 +179,17 @@ public class FamilyOfGeneratedGenerics {
//TODO: //TODO:
List<MethodConstraint> tempCC= new ArrayList<>(); List<MethodConstraint> tempCC= new ArrayList<>();
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints); List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
for(MethodConstraint mC1 : cs_m) { for(MethodConstraint mC1 : cs_m) { //(R <. R')
for(MethodConstraint mC2 : cs_m) { for(MethodConstraint mC2 : cs_m) { //(S <. S')
String rightSide = mC1.getRight(); String lSide = mC1.getRight(); //R'
String leftSide = mC2.getLeft(); String rSide = mC2.getLeft(); //S
for(TPHConstraint tphC : tcOfCs) { for(TPHConstraint tphC : tcOfCs) {
if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) { if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S)
tempCC.add((MethodConstraint) tphC); MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S)
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
System.out.println(consToAdd);
}
} }
} }
} }

View File

@ -1,12 +1,8 @@
/*
package insertGenerics; package insertGenerics;
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.insertGenerics.ClassConstraint; import de.dhbwstuttgart.bytecode.insertGenerics.*;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.PositionFinder;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -26,18 +22,30 @@ public class TestExample42 {
return cs; return cs;
} }
public HashMap<String, PositionFinder.Position> fillPosOfTphs() { public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
HashMap<String, PositionFinder.Position> posOfTphs = new HashMap<>(); HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>();
posOfTphs.put("K", PositionFinder.Position.FIELD);
posOfTphs.put("L", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
posOfTphs.put("M", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
posOfTphs.put("N", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
posOfTphs.put("P", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
posOfTphs.put("Q", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA");
posOfTphs.put("U", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA");
posOfTphs.put("V", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
posOfTphs.put("W", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
posOfTphs.put("Z", PositionFinder.Position.METHOD); 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; return posOfTphs;
} }
@ -51,4 +59,3 @@ public class TestExample42 {
List<TPHConstraint> testCons; List<TPHConstraint> testCons;
} }
} }
*/

View File

@ -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<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<>();
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;
}
@Test
public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("MethodConstraints: " + methodConstraints);
List<TPHConstraint> testCons;
}
}