modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java

modified:   src/test/java/insertGenerics/TestTwoCalls.java
This commit is contained in:
AluAli 2021-03-26 12:29:40 +01:00
parent d276c7c044
commit e3625cb306
2 changed files with 50 additions and 21 deletions

View File

@ -518,6 +518,7 @@ public class FamilyOfGeneratedGenerics {
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet);
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints); List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
MethodAndTPH methAndTphs = methodAndTPH; MethodAndTPH methAndTphs = methodAndTPH;
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints(); List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>(); List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
//gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf ( //gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf (
@ -567,9 +568,9 @@ public class FamilyOfGeneratedGenerics {
} }
// dies ist das "R" aus dem ersten Teil, wird im zweiten Teil gebraucht // dies ist das "R" aus dem ersten Teil, wird im zweiten Teil gebraucht
TypePlaceholder tphR = null; // TypePlaceholder tphR = null;
Constraint<Pair> extendsSetAllOfOr = new Constraint<Pair>(); // Constraint<Pair> extendsSetAllOfOr = new Constraint<Pair>();
Constraint<Pair> equalSetAllOfOr = new Constraint<Pair>(); // Constraint<Pair> equalSetAllOfOr = new Constraint<Pair>();
// Berechnung des ersten Teils der Regel // Berechnung des ersten Teils der Regel
for(int i=0; i<orCons.size(); i++) { for(int i=0; i<orCons.size(); i++) {
@ -583,10 +584,10 @@ public class FamilyOfGeneratedGenerics {
Pair p = it.next(); Pair p = it.next();
if (p.OperatorSmallerDot()) { if (p.OperatorSmallerDot()) {
extendsSet.add(p); extendsSet.add(p);
extendsSetAllOfOr.add(p); // extendsSetAllOfOr.add(p);
} else if (p.OperatorEqual()) { } else if (p.OperatorEqual()) {
equalSet.add(p); equalSet.add(p);
equalSetAllOfOr.add(p); // equalSetAllOfOr.add(p);
} }
} }
Iterator<Pair> itExtends = extendsSet.iterator(); Iterator<Pair> itExtends = extendsSet.iterator();
@ -595,7 +596,7 @@ public class FamilyOfGeneratedGenerics {
Iterator<Pair> itEqual = equalSet.iterator(); Iterator<Pair> itEqual = equalSet.iterator();
while(itEqual.hasNext()) { while(itEqual.hasNext()) {
Pair pairEqual = itEqual.next(); Pair pairEqual = itEqual.next();
tphR = (TypePlaceholder) (pairEqual.TA2); // tphR = (TypePlaceholder) (pairEqual.TA2);
Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT);
Iterator<Pair> itTC = tcOfoldConsSet.iterator(); Iterator<Pair> itTC = tcOfoldConsSet.iterator();
while(itTC.hasNext()) { while(itTC.hasNext()) {
@ -634,27 +635,54 @@ public class FamilyOfGeneratedGenerics {
}*/ }*/
} }
// Berechnung des zweiten Teils der Regel // Berechnung des zweiten Teils der Regel
Iterator<Pair> itExtends2 = extendsSetAllOfOr.iterator(); for(int i=0; i<orCons.size(); i++) {
Constraint<Pair> extendsSet = new Constraint<Pair>();
Constraint<Pair> equalSet = new Constraint<Pair>();
//für jede einzelne OrConstraint-Menge gehe durch
for (Constraint con : orCons.get(i)) {
Iterator<Pair> it = con.iterator();
while (it.hasNext()) {
Pair p = it.next();
if (p.OperatorSmallerDot()) {
extendsSet.add(p);
} else if (p.OperatorEqual()) {
equalSet.add(p);
}
}
Iterator<Pair> itExtends2 = extendsSet.iterator();
while(itExtends2.hasNext()) { while(itExtends2.hasNext()) {
Pair pairExtends2 = itExtends2.next(); Pair pairExtends2 = itExtends2.next();
Iterator<Pair> itEqual2 = equalSetAllOfOr.iterator(); Iterator<Pair> itEqual2 = equalSet.iterator();
while (itEqual2.hasNext()) { while (itEqual2.hasNext()) {
Pair pairEqual2 = itEqual2.next(); Pair pairEqual2 = itEqual2.next();
Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT); Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT);
boolean rEqRtilde = (tphR == pairEqual2.TA1 && checkForDuplicatesForSets(new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA2)).resolvedType, PairOperator.EQUALSDOT), equalSetAllOfOr)); TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
boolean rExRtilde = (tphR == pairExtends2.TA1 && checkForDuplicatesForSets(new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT), extendsSetAllOfOr)); Iterator<Pair> itUndCons = undCons.iterator();
while (itUndCons.hasNext()) {
Pair pairUndCons2 = itUndCons.next();
boolean rEqRtilde = (tphR == pairUndCons2.TA1);
boolean rExRtilde = (tphR == pairUndCons2.TA1);
Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT);
boolean isPairInTExTapostrophe = checkForDuplicatesForSets(rExRtildePair, extendsSetAllOfOr); boolean isPairInTExTapostrophe = checkForDuplicatesForSets(rExRtildePair, extendsSet);
if (rEqRtilde || rExRtilde || !isPairInTExTapostrophe) {
if (rEqRtilde || rExRtilde || isPairInTExTapostrophe) {
if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA
if (!checkForDuplicatesForSets(newPair2, tempSet2)) { if (!checkForDuplicatesForSets(newPair2, tempSet2)) {
tempSet2.add(pairExtends2);
tempSet2.add(newPair2); tempSet2.add(newPair2);
} }
} }
} }
} }
} }
}
}
}
// aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil
Iterator<Pair> itTemp = tempSet.iterator(); Iterator<Pair> itTemp = tempSet.iterator();

View File

@ -65,6 +65,7 @@ public class TestTwoCalls {
lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS)); lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS));
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc); methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg; FamilyOfGeneratedGenerics fogg = compiler.fogg;