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);
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
MethodAndTPH methAndTphs = methodAndTPH;
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
//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
TypePlaceholder tphR = null;
Constraint<Pair> extendsSetAllOfOr = new Constraint<Pair>();
Constraint<Pair> equalSetAllOfOr = new Constraint<Pair>();
// TypePlaceholder tphR = null;
// Constraint<Pair> extendsSetAllOfOr = new Constraint<Pair>();
// Constraint<Pair> equalSetAllOfOr = new Constraint<Pair>();
// Berechnung des ersten Teils der Regel
for(int i=0; i<orCons.size(); i++) {
@ -583,10 +584,10 @@ public class FamilyOfGeneratedGenerics {
Pair p = it.next();
if (p.OperatorSmallerDot()) {
extendsSet.add(p);
extendsSetAllOfOr.add(p);
// extendsSetAllOfOr.add(p);
} else if (p.OperatorEqual()) {
equalSet.add(p);
equalSetAllOfOr.add(p);
// equalSetAllOfOr.add(p);
}
}
Iterator<Pair> itExtends = extendsSet.iterator();
@ -595,7 +596,7 @@ public class FamilyOfGeneratedGenerics {
Iterator<Pair> itEqual = equalSet.iterator();
while(itEqual.hasNext()) {
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);
Iterator<Pair> itTC = tcOfoldConsSet.iterator();
while(itTC.hasNext()) {
@ -634,28 +635,55 @@ public class FamilyOfGeneratedGenerics {
}*/
}
// Berechnung des zweiten Teils der Regel
Iterator<Pair> itExtends2 = extendsSetAllOfOr.iterator();
while(itExtends2.hasNext()) {
Pair pairExtends2 = itExtends2.next();
Iterator<Pair> itEqual2 = equalSetAllOfOr.iterator();
while (itEqual2.hasNext()) {
Pair pairEqual2 = itEqual2.next();
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));
boolean rExRtilde = (tphR == pairExtends2.TA1 && checkForDuplicatesForSets(new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT), extendsSetAllOfOr));
Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT);
boolean isPairInTExTapostrophe = checkForDuplicatesForSets(rExRtildePair, extendsSetAllOfOr);
if (rEqRtilde || rExRtilde || !isPairInTExTapostrophe) {
if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA
if (!checkForDuplicatesForSets(newPair2, tempSet2)) {
tempSet2.add(newPair2);
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()) {
Pair pairExtends2 = itExtends2.next();
Iterator<Pair> itEqual2 = equalSet.iterator();
while (itEqual2.hasNext()) {
Pair pairEqual2 = itEqual2.next();
Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT);
TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
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);
boolean isPairInTExTapostrophe = checkForDuplicatesForSets(rExRtildePair, extendsSet);
if (rEqRtilde || rExRtilde || isPairInTExTapostrophe) {
if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA
if (!checkForDuplicatesForSets(newPair2, tempSet2)) {
tempSet2.add(pairExtends2);
tempSet2.add(newPair2);
}
}
}
}
}
}
}
}
// aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil
Iterator<Pair> itTemp = tempSet.iterator();
while(itTemp.hasNext()) {

View File

@ -65,6 +65,7 @@ public class TestTwoCalls {
lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS));
lmc.add(new MethodConstraint("O", "R", 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);
FamilyOfGeneratedGenerics fogg = compiler.fogg;