modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java
modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java modified: src/test/java/insertGenerics/TestContraVariant.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestTransitiveClosure.java Transitiv Closure auf new umgestellt
This commit is contained in:
parent
d1ad6e218a
commit
9be64e4905
@ -1,5 +1,10 @@
|
||||
package de.dhbwstuttgart.bytecode.constraint;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class TPHConstraint {
|
||||
protected String left;
|
||||
protected String right;
|
||||
@ -9,6 +14,12 @@ public class TPHConstraint {
|
||||
EXTENDS, EQUAL
|
||||
}
|
||||
|
||||
public TPHConstraint(Pair p) {
|
||||
this.left = ((TypePlaceholder)p.TA1).getName();
|
||||
this.right = ((TypePlaceholder)p.TA2).getName();
|
||||
this.rel = p.GetOperator().equals(PairOperator.SMALLERDOT) ? Relation.EXTENDS : Relation.EQUAL;
|
||||
}
|
||||
|
||||
public TPHConstraint(String left, String right, Relation rel) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
|
@ -21,6 +21,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
|
||||
public HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
|
||||
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
||||
private HashMap<String, MethodAndTPH> mapMethodsAndTph = new HashMap<>();
|
||||
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
||||
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
||||
public ResultSet resSet;
|
||||
@ -34,6 +35,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
this.allConstraints = tphExtractor.allCons;
|
||||
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
||||
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
||||
tphExtractor.ListOfMethodsAndTph.forEach(matph -> this.mapMethodsAndTph.put(matph.getId(), matph));
|
||||
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
||||
this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
|
||||
}
|
||||
@ -69,7 +71,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
return cs_cl;
|
||||
}
|
||||
|
||||
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
||||
public List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
||||
List<MethodConstraint> cs_m = new ArrayList<>();
|
||||
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||
for (MethodConstraint cons: methodConstraints1) {
|
||||
@ -114,7 +116,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
return cs_m;
|
||||
}
|
||||
|
||||
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
||||
public HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
||||
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
||||
for(MethodAndTPH method: listOfMethodsAndTph){
|
||||
List<String> methodsAddedToHashMap = new ArrayList<>();
|
||||
@ -281,7 +283,7 @@ 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 List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
||||
public List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
||||
//TODO:
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||
@ -306,7 +308,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
* 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) {
|
||||
public List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||
//TODO:
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||
@ -369,7 +371,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
/**
|
||||
* nimm die Menge cs_cl aus cs_m raus
|
||||
*/
|
||||
public static List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||
public List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||
// erstelle Kopie der Liste cs_cl
|
||||
List<TPHConstraint> tempCC = new ArrayList<>();
|
||||
for(ClassConstraint cc: cs_cl) {
|
||||
@ -415,7 +417,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<TPHConstraint> buildTransitiveClosure(List list) {
|
||||
public List<TPHConstraint> buildTransitiveClosure(List list) {
|
||||
List<TPHConstraint> iterList = new ArrayList<>(list);
|
||||
List<TPHConstraint> runList = new ArrayList<>(list);
|
||||
List<TPHConstraint> tcList = new ArrayList<>(list);
|
||||
@ -511,7 +513,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
public static List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
|
||||
public List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
|
||||
List<MethodConstraint> tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali)
|
||||
Set<Pair> tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils der Bedinung basierend auf der alten Datenstruktur
|
||||
Set<Pair> tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils der Bedingung basierend auf der alten Datenstruktur
|
||||
@ -572,6 +574,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
// Constraint<Pair> extendsSetAllOfOr = new Constraint<Pair>();
|
||||
// Constraint<Pair> equalSetAllOfOr = new Constraint<Pair>();
|
||||
|
||||
|
||||
// Berechnung des ersten Teils der Bedingung der Regel
|
||||
for(int i=0; i<orCons.size(); i++) {
|
||||
Constraint<Pair> extendsSet = new Constraint<Pair>();
|
||||
@ -660,9 +663,39 @@ public class FamilyOfGeneratedGenerics {
|
||||
Pair pairExtends2 = itExtends2.next();
|
||||
Iterator<Pair> itEqual2 = equalSet.iterator();
|
||||
while (itEqual2.hasNext()) {
|
||||
boolean transClo = false;
|
||||
Pair pairEqual2 = itEqual2.next();
|
||||
//TODO: Auf trans.FamilyOfGeneratedGenerics Huelle pruefen
|
||||
Pair newPairOld = new Pair(pairExtends2.TA2, pairEqual2.TA1);
|
||||
Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT);
|
||||
TPHConstraint newPairTPHConstraint = new TPHConstraint(newPair2);
|
||||
//if (!tcOfoldConsSet.contains(newPairOld)) { continue; }
|
||||
Iterator<TPHConstraint> itTC = tcOfCs.iterator(); //tcOfoldConsSet.iterator();
|
||||
/*
|
||||
buildTransitiveClosureForCP(
|
||||
mapMethodsAndTph.get(posOfTPHs.get(((TypePlaceholder)pairExtends2.TA2)
|
||||
.getName()).get(0).snd)
|
||||
.constraints.getAll(),
|
||||
resSet).iterator();
|
||||
*/
|
||||
//while(itTC.hasNext()) {//ueberpruefen ob newPair in transitiv closure
|
||||
//Pair pairTC = itTC.next();
|
||||
//if //((pairTC.TA1.equals(newPairOld.TA1))
|
||||
// ((resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType.equals(newPair2.TA1))
|
||||
// && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType.equals(newPair2.TA2)
|
||||
// //&& pairTC.OperatorSmallerDot()
|
||||
// //&& newPair2.OperatorSmallerDot()
|
||||
// )
|
||||
//TPHConstraint tPHCons = itTC.next();
|
||||
//if newPairTPHConstraint
|
||||
//{ //erst hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!)
|
||||
// transClo = true;
|
||||
// break;
|
||||
//}
|
||||
//}
|
||||
if (tcOfCs.contains(newPairTPHConstraint)) {
|
||||
transClo = true;
|
||||
}
|
||||
TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
|
||||
Iterator<Pair> itUndCons = undCons.iterator();
|
||||
while (itUndCons.hasNext()) {
|
||||
@ -686,9 +719,9 @@ public class FamilyOfGeneratedGenerics {
|
||||
}
|
||||
|
||||
|
||||
if (rEqExRtilde || isPairInTExTapostrophe) {
|
||||
if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA
|
||||
if (!checkForDuplicatesForSets(newPair2, tempSet2))
|
||||
if ((rEqExRtilde || isPairInTExTapostrophe)) {
|
||||
if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA
|
||||
if (transClo && !checkForDuplicatesForSets(newPair2, tempSet2))
|
||||
tempSet2.add(newPair2);
|
||||
}
|
||||
if (!checkForDuplicatesForSets(pairExtends2, tempSet2))
|
||||
@ -837,7 +870,7 @@ public class FamilyOfGeneratedGenerics {
|
||||
|
||||
|
||||
|
||||
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPositionNew(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
||||
public HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPositionNew(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
||||
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
||||
List<MethodConstraint> newMCList = new ArrayList<>();
|
||||
List<MethodConstraint> newMCList2 = new ArrayList<>();
|
||||
|
@ -47,4 +47,9 @@ public class MethodAndTPH {
|
||||
return localTphs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,8 @@ public class TestContraVariant {
|
||||
lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc);
|
||||
|
||||
|
@ -66,13 +66,17 @@ public class TestLocalVarLambda {
|
||||
lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
|
||||
}
|
||||
else {
|
||||
lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
|
||||
}
|
||||
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
|
||||
|
||||
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
@ -21,8 +21,8 @@ public class TestTransitiveClosure {
|
||||
|
||||
@Test
|
||||
public void genericTest() {
|
||||
List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList());
|
||||
System.out.println(testCons);
|
||||
//List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList());
|
||||
//System.out.println(testCons);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user