From 13144d0ac9e7e5750f06a33e9983aefd2d4534ac Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 19 Mar 2021 14:23:07 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 5aafb37a..39f1b3cc 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -60,7 +60,7 @@ public class FamilyOfGeneratedGenerics { } } while (addedToConstraintsListForCC2); - List classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs); + List classConstraints3 = hasNoSupertypeForClassTypes(cs_cl, posOfTphs); for (ClassConstraint cons: classConstraints3) { if (!checkForDuplicates(cons, cs_cl)) { cs_cl.add(cons); @@ -224,28 +224,34 @@ public class FamilyOfGeneratedGenerics { * {T <. Object | ((T is a type variable in a type of a node of a field * or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)} */ - public static List hasNoSupertypeForClassTypes(List allConstraints, List cs_cl, HashMap>> posOfTphs) { + public static List hasNoSupertypeForClassTypes(List cs_cl, HashMap>> posOfTphs) { List tempCC= new ArrayList<>(); - for(TPHConstraint allCons: allConstraints) { - for(ClassConstraint cCons: cs_cl) { - for(String tph: posOfTphs.keySet()) { - for(PairTphMethod pair: posOfTphs.get(tph)) { - boolean tvInField = pair.fst == PositionFinder.Position.FIELD; - boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null); - if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) && - !checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) { - ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS); - if (!checkForDuplicates(consToAdd, tempCC)){ - tempCC.add(consToAdd); - } + List clCons = new ArrayList<>(cs_cl); + for(String tph: posOfTphs.keySet()) { + for(PairTphMethod pair: posOfTphs.get(tph)) { + boolean tvInField = pair.fst == PositionFinder.Position.FIELD; + boolean hasSmallerTVInClCons = hasSmallerTVInClCons(tph, cs_cl); + if ((tvInField || hasSmallerTVInClCons) && + !checkUpperBound(clCons, tph)) { + ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempCC)) { + tempCC.add(consToAdd); } } } } - } return tempCC; } + public static boolean hasSmallerTVInClCons(String tph, List cs_cl) { + for(ClassConstraint cC: cs_cl) { + if(tph == cC.getRight() && cC.getRel() == Relation.EXTENDS) { + return true; + } + } + return false; + } + /** * Def. FGG: erste Zeile von cs_m * {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs} @@ -496,7 +502,7 @@ public class FamilyOfGeneratedGenerics { r = Relation.EQUAL; } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); - if(mc.getRel() != Relation.EQUAL) { + if(mc.getRel() == Relation.EXTENDS) { if(!checkForDuplicates(mc, tempMC)) { tempMC.add(mc); } @@ -678,20 +684,16 @@ public class FamilyOfGeneratedGenerics { return false; } - public static List hasNoSupertypeForMethodTypesNew(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH) { + public static List hasNoSupertypeForMethodTypesNew(HashMap>> posOfTphs, MethodAndTPH methodAndTPH, List cs_m) { List tempMC = new ArrayList<>(); - List allCons = allConstraints; + List methCons = new ArrayList<>(cs_m); MethodAndTPH methAndTphs = methodAndTPH; for(String tph: posOfTphs.keySet()) { for(int i=0; i