forked from JavaTX/JavaCompilerCore
Fehlerhaften code entfernen
This commit is contained in:
parent
88175f8b48
commit
69a557f1f2
@ -5,6 +5,7 @@ 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.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -83,35 +84,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
public static HashMap<MethodConstraint, String> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, 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
|
throw new NotImplementedException();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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<MethodConstraint, String> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //transitive closure of cs
|
|
||||||
//TODO:
|
|
||||||
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
|
||||||
List<TPHConstraint> 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<MethodConstraint, String> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
||||||
//TODO:
|
|
||||||
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
|
||||||
List<TPHConstraint> 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<MethodConstraint, String> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
|
||||||
//TODO:
|
|
||||||
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 HashMap<MethodConstraint, String> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m) {
|
|
||||||
//TODO:
|
|
||||||
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) {
|
public static boolean checkForDuplicates(TPHConstraint constraint, List list) {
|
||||||
List<TPHConstraint> tempList = list;
|
List<TPHConstraint> tempList = list;
|
||||||
@ -331,17 +198,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkForDuplicatesInMethods(TPHConstraint constraint, HashMap<MethodConstraint, String> hashMap, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
public static boolean checkForDuplicatesInMethods(TPHConstraint constraint, HashMap<MethodConstraint, String> hashMap, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
HashMap<MethodConstraint, String> tempMap = hashMap;
|
throw new NotImplementedException();
|
||||||
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) {
|
public static List<TPHConstraint> buildTransitiveClosure(List list) {
|
||||||
|
@ -29,13 +29,6 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||||
assertTrue(classConstraints.isEmpty());
|
assertTrue(classConstraints.isEmpty());
|
||||||
|
|
||||||
/*
|
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassField(){
|
public void testClassField(){
|
||||||
@ -109,12 +102,8 @@ 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() == 2);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,13 +158,6 @@ 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());
|
|
||||||
assertTrue(classConstraints.size() == 3);
|
|
||||||
assertFalse(methodConstraints.isEmpty());
|
|
||||||
assertTrue(methodConstraints.size()==9);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,11 +54,6 @@ public class TestExample42 {
|
|||||||
public void genericTest() {
|
public void genericTest() {
|
||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
||||||
System.out.println("ClassConstraints: " + classConstraints);
|
System.out.println("ClassConstraints: " + classConstraints);
|
||||||
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
|
|
||||||
System.out.println("MethodConstraints: " + methodConstraints);
|
|
||||||
for(MethodConstraint mC: methodConstraints) {
|
|
||||||
System.out.println(mC);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TPHConstraint> testCons;
|
List<TPHConstraint> testCons;
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,6 @@ public class TestExample42_allInOneMethod {
|
|||||||
public void genericTest() {
|
public void genericTest() {
|
||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
||||||
System.out.println("ClassConstraints: " + classConstraints);
|
System.out.println("ClassConstraints: " + classConstraints);
|
||||||
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
|
|
||||||
System.out.println("MethodConstraints: " + methodConstraints);
|
|
||||||
|
|
||||||
List<TPHConstraint> testCons;
|
List<TPHConstraint> testCons;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user