From dce7ac82623a2cc55374951c9ddc37eb0b4b1cc0 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 8 Jan 2021 21:43:06 +0100 Subject: [PATCH 001/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java new file: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java --- .../FamilyOfGeneratedGenerics.java | 23 ++++++++- .../PairMethodAndConstraint.java | 47 +++++++++++++++++++ .../FamilyOfGeneratedGenericsTest.java | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index d8df6cc1..d59ece82 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -16,13 +16,34 @@ public class FamilyOfGeneratedGenerics { public HashMap> posOfTPHs = new HashMap<>(); public List classConstraints = new ArrayList<>(); public List methodConstraints = new ArrayList<>(); + public HashMap> methodConstraintsWithPosition = new HashMap<>(); public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); -// this.methodConstraints = + this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); + for(MethodAndTPH method: tphExtractor.ListOfMethodsAndTph){ + List methodsAddedToHashMap = new ArrayList<>(); + String currentMethod = method.getId(); + boolean containsCurrentMethod = false; + if(!containsCurrentMethod) { + methodsAddedToHashMap.add(currentMethod); + containsCurrentMethod = true; + List listOfThisMethod = new ArrayList<>(); + HashMap> posOfTPHsForThisMethod = new HashMap<>(); + for(String s: posOfTPHs.keySet()) { + if(posOfTPHs.get(s).snd == currentMethod && posOfTPHs.get(s).snd != null) { + posOfTPHsForThisMethod.put(s,posOfTPHs.get(s)); + System.out.println(posOfTPHsForThisMethod); + } + } + listOfThisMethod = getMethodConstraints(allConstraints,classConstraints,posOfTPHsForThisMethod); + methodConstraintsWithPosition.put(currentMethod, listOfThisMethod); + System.out.println(methodConstraintsWithPosition); + } + } } public static List getClassConstraints(List cs, HashMap> posOfTphs) { //Inputparameter List constraintsSet weg diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java new file mode 100644 index 00000000..c8f44ea6 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java @@ -0,0 +1,47 @@ +package de.dhbwstuttgart.bytecode.insertGenerics; + +import java.util.Objects; + +/** A generic class for pairs. + * + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ + + +public class PairMethodAndConstraint { + public final A fst; + public final B snd; + + public PairMethodAndConstraint(A fst, B snd) { + this.fst = fst; + this.snd = snd; + } + + public String toString() { + return "PairTphMethod[" + fst + "," + snd + "]"; + } + + public boolean equals(Object other) { + return + other instanceof PairMethodAndConstraint && + Objects.equals(fst, ((PairMethodAndConstraint)other).fst) && + Objects.equals(snd, ((PairMethodAndConstraint)other).snd); + } + + public int hashCode() { + if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1; + else if (snd == null) return fst.hashCode() + 2; + else return fst.hashCode() * 17 + snd.hashCode(); + } + + public static PairMethodAndConstraint of(A a, B b) { + return new PairMethodAndConstraint<>(a,b); + } + + public PairMethodAndConstraint add(A fst, B snd){ + return new PairMethodAndConstraint<>(fst,snd); + } +} diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java index 77a7d997..9d7689a0 100644 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -114,7 +114,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 6); assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size() == 5); + assertTrue(methodConstraints.size() == 2); } From 3f5f51df5b95d6e963a06ed4a92098bbb182bbaa Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 8 Jan 2021 22:05:09 +0100 Subject: [PATCH 002/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index d59ece82..03ea3f41 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -24,26 +24,7 @@ public class FamilyOfGeneratedGenerics { this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); - for(MethodAndTPH method: tphExtractor.ListOfMethodsAndTph){ - List methodsAddedToHashMap = new ArrayList<>(); - String currentMethod = method.getId(); - boolean containsCurrentMethod = false; - if(!containsCurrentMethod) { - methodsAddedToHashMap.add(currentMethod); - containsCurrentMethod = true; - List listOfThisMethod = new ArrayList<>(); - HashMap> posOfTPHsForThisMethod = new HashMap<>(); - for(String s: posOfTPHs.keySet()) { - if(posOfTPHs.get(s).snd == currentMethod && posOfTPHs.get(s).snd != null) { - posOfTPHsForThisMethod.put(s,posOfTPHs.get(s)); - System.out.println(posOfTPHsForThisMethod); - } - } - listOfThisMethod = getMethodConstraints(allConstraints,classConstraints,posOfTPHsForThisMethod); - methodConstraintsWithPosition.put(currentMethod, listOfThisMethod); - System.out.println(methodConstraintsWithPosition); - } - } + this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); } public static List getClassConstraints(List cs, HashMap> posOfTphs) { //Inputparameter List constraintsSet weg @@ -101,6 +82,31 @@ public class FamilyOfGeneratedGenerics { return cs_m; } + public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap> posOfTphs, List listOfMethodsAndTph) { + HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); + for(MethodAndTPH method: listOfMethodsAndTph){ + List methodsAddedToHashMap = new ArrayList<>(); + String currentMethod = method.getId(); + boolean containsCurrentMethod = false; + if(!containsCurrentMethod) { + methodsAddedToHashMap.add(currentMethod); + containsCurrentMethod = true; + List listOfThisMethod = new ArrayList<>(); + HashMap> posOfTPHsForThisMethod = new HashMap<>(); + for(String s: posOfTphs.keySet()) { + if(posOfTphs.get(s).snd == currentMethod && posOfTphs.get(s).snd != null) { + posOfTPHsForThisMethod.put(s,posOfTphs.get(s)); + System.out.println(posOfTPHsForThisMethod); + } + } + listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod); + tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); + System.out.println(tempMethodConstraintsWithPosition); + } + } + return tempMethodConstraintsWithPosition; + } + /** * Def. FGG: erste Zeile von cs_cl * {T < .T' | T is a type variable in a type of a node of a field} From fec83c3a6261bf1ef2e09f91dce4b6046d04e9dc Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 12 Jan 2021 21:27:44 +0100 Subject: [PATCH 003/101] modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Fuer den Receiver wieder = eingefuegt. modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Kommentierung begonnen --- .../typeinference/typeAlgo/TYPEStmt.java | 10 ++-- .../typeinference/unify/TypeUnifyTask.java | 48 ++++++++++++------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index c3c23079..b557e211 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -587,9 +587,13 @@ public class TYPEStmt implements StatementVisitor{ */ RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver); - methodConstraint.add(forMethod.name.equals("apply") ? //PL 2019-11-29: Tenaerer Operator eingefügt, weil bei Lambda-Ausdrücken keine Suntype FunN$$ existiert - new Pair(forMethod.receiver.getType(), retType, PairOperator.EQUALSDOT) - : new Pair(forMethod.receiver.getType(), retType, PairOperator.SMALLERDOT)); + methodConstraint.add(new Pair(forMethod.receiver.getType(), retType, + PairOperator.EQUALSDOT));//PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind. + + //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG + //methodConstraint.add(new Pair(forMethod.receiverType, retType, + // PairOperator.EQUALSDOT)); + //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 6de6b9de..66ceb6d0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -457,7 +457,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); + return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); } @@ -587,10 +587,21 @@ public class TypeUnifyTask extends RecursiveTask>> { } - - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + /** + * Computes the cartesian product of topLevelSets step by step. + * @param topLevelSets List of Sets of Sets, where a cartesian product have to be built + * Ex.: [{{a =. Integer}, {a = Object}}, {{a = Vector, b =. Integer}, {a = Vector, b =. Object}}] + * @param eq Original set of equations which should be unified + * @param oderConstraints Remaining or-constraints + * @param fc The finite closure + * @param parallel If the algorithm should be parallelized run + * @param rekTiefe Deep of recursive calls + * @param finalresult Gives if unify is not called from checkA + * @return The set of all principal type unifiers + */ + Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); - + Set> fstElems = new HashSet<>(); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) .map(y -> y.stream().findFirst().get()) @@ -617,6 +628,12 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); int variance = 0; + /* Varianzbestimmung Anfang + * Oderconstraint, wenn entweder kein Basepair oder unterschiedliche Basepairs => oderConstraint = true; + * Varianz = 1 => Argumentvariable + * Varianz = -1 => Rückgabevariable + * Varianz = 0 => unklar + * Varianz = 2 => Operatoren oderConstraints */ ArrayList zeroNextElem = new ArrayList<>(nextSetasList.get(0)); UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair(); Boolean oderConstraint = false; @@ -639,16 +656,15 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { - //variance = 2; oderConstraint = true; } } else { - //variance = 2; oderConstraint = true; } - if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints + //Varianz-Bestimmung Oder-Constraints + if (oderConstraint) { if (printtag) System.out.println("nextSetasList " + nextSetasList); Optional optVariance = nextSetasList.iterator() @@ -661,20 +677,18 @@ public class TypeUnifyTask extends RecursiveTask>> { ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance()) .findAny(); //Fuer Operatorenaufrufe wird variance auf 2 gesetzt. - //da kein Receiver existiert also keon x.getGroundBasePair().getLhsType() instanceof PlaceholderType - //Es werden alle Elemente des Kartesischen Produkts abgearbeitet + //da kein Receiver existiert also kein x.getGroundBasePair().getLhsType() instanceof PlaceholderType + //Bei Varianz = 2 werden alle Elemente des Kartesischen Produkts abgearbeitet variance = optVariance.isPresent() ? optVariance.get() : 2; } + /* Varianzbestimmung Ende */ - if (!nextSetasList.iterator().hasNext()) - System.out.print(""); - if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) - System.out.print(""); //writeLog("nextSetasList: " + nextSetasList.toString()); Set nextSetElem = nextSetasList.get(0); //writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); - /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ + /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet + * alle Paare a < ty1 oder ty2 < a aus fstElems */ Set sameEqSet = new HashSet<>(); Optional optOrigPair = null; //if (variance != 2) { @@ -710,14 +724,14 @@ public class TypeUnifyTask extends RecursiveTask>> { /* sameEqSet-Bestimmung Ende */ Set a = null; - while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { + while (nextSetasList.size() > 0) { Set a_last = a; - //Liste der Faelle für die parallele Verarbeitung + //Liste der Faelle für die parallele Verarbeitung List> nextSetasListRest = new ArrayList<>(); //Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt - //In der Regel ein Element + //In der Regel is dies ein Element List> nextSetasListOderConstraints = new ArrayList<>(); writeLog("nextSet: " + nextSet.toString()); From e00d76ce3b1cdfdf12997e05b726a35c1fcd4400 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 13 Jan 2021 19:39:01 +0100 Subject: [PATCH 004/101] Occurs-Check mit Abbruch eingebaut finalResult zum Attribut der Klasse gemacht --- .../typeinference/unify/RuleSet.java | 2 +- .../typeinference/unify/TypeUnify2Task.java | 2 +- .../typeinference/unify/TypeUnifyTask.java | 59 ++++++++++++++----- src/test/java/AllgemeinTest.java | 3 +- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 93f33d08..50ea9a2e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -655,7 +655,6 @@ public class RuleSet implements IRuleSet{ else t1.getTypeParams().forEach(x -> occuringTypes.push(x)); } - Queue result1 = new LinkedList(pairs); ArrayList result = new ArrayList(); boolean applied = false; @@ -669,6 +668,7 @@ public class RuleSet implements IRuleSet{ && pair.getLhsType() instanceof PlaceholderType) lhsType = (PlaceholderType) pair.getLhsType(); rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType) + if(lhsType != null //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden. && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 798c6f05..317f3660 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -34,7 +34,7 @@ public class TypeUnify2Task extends TypeUnifyTask { System.out.println("two"); } one = true; - Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true); + Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField); /*if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 66ceb6d0..580fee5c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -110,6 +110,9 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean parallel; + //Gives if unify is not called from checkA + private boolean finalresult = true; + int rekTiefeField; Integer nOfUnify = 0; @@ -257,7 +260,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); noOfThread--; try { logFile.close(); @@ -299,7 +302,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); @@ -308,9 +311,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //} //.collect(Collectors.toCollection(HashSet::new))); - /* - * Step 1: Repeated application of reduce, adapt, erase, swap - */ + synchronized (usedTasks) { if (this.myIsCancelled()) { return new HashSet<>(); @@ -339,6 +340,29 @@ public class TypeUnifyTask extends RecursiveTask>> { return ret; } + /* + * Occurs-Check durchfuehren + */ + + Set ocurrPairs = eq.stream().filter(x -> { + UnifyType lhs, rhs; + return (lhs = x.getLhsType()) instanceof PlaceholderType + && !((rhs = x.getRhsType()) instanceof PlaceholderType) + && rhs.getTypeParams().occurs((PlaceholderType)lhs);}) + .map(x -> { x.setUndefinedPair(); return x;}) + .collect(Collectors.toCollection(HashSet::new)); + writeLog("ocurrPairs: " + ocurrPairs); + if (ocurrPairs.size() > 0) { + Set> ret = new HashSet<>(); + ret.add(ocurrPairs); + return ret; + } + + + + /* + * Step 1: Repeated application of reduce, adapt, erase, swap + */ Set eq0; Set eq0Prime; Optional> eqSubst = Optional.of(eq); @@ -457,12 +481,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); + return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); } - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -551,12 +575,12 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, finalresult); + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); @@ -596,10 +620,9 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @param parallel If the algorithm should be parallelized run * @param rekTiefe Deep of recursive calls - * @param finalresult Gives if unify is not called from checkA * @return The set of all principal type unifiers */ - Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); Set> fstElems = new HashSet<>(); fstElems.addAll(topLevelSets.stream() @@ -610,7 +633,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); return result; } Set> nextSet = remainingSets.remove(0); @@ -1173,7 +1196,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 - res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); }}} if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen @@ -1523,7 +1546,9 @@ public class TypeUnifyTask extends RecursiveTask>> { unitedSubst.addAll(sameEq.getAllSubstitutions()); unitedSubst.addAll(sameEq.getAllBases()); localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + finalresult = false; + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); + finalresult = true; if (isUndefinedPairSetSet(localRes)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); @@ -1539,7 +1564,9 @@ public class TypeUnifyTask extends RecursiveTask>> { unitedSubst.addAll(sameEq.getAllSubstitutions()); unitedSubst.addAll(sameEq.getAllBases()); localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + finalresult = false; + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); + finalresult = true; if (isUndefinedPairSetSet(localRes)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); @@ -2519,7 +2546,7 @@ public class TypeUnifyTask extends RecursiveTask>> { void writeLog(String str) { synchronized ( this ) { - if (log) { + if (log && finalresult) { try { logFile.write("Thread no.:" + thNo + "\n"); logFile.write("noOfThread:" + noOfThread + "\n"); diff --git a/src/test/java/AllgemeinTest.java b/src/test/java/AllgemeinTest.java index c937035e..50a67b38 100644 --- a/src/test/java/AllgemeinTest.java +++ b/src/test/java/AllgemeinTest.java @@ -40,7 +40,8 @@ public class AllgemeinTest { //String className = "FCTest3"; //String className = "Var"; //String className = "Put"; - String className = "Twice"; + //String className = "Twice"; + String className = "TestSubTypless"; //PL 2019-10-24: genutzt fuer unterschiedliche Tests path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav"; //path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav"; From d8ac25234fa58ca0fb1d7de5da6a5f49f2d5787c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 14 Jan 2021 10:38:32 +0100 Subject: [PATCH 005/101] modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java vor entfernung von Remaining --- .../typeinference/unify/TypeUnifyTask.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 580fee5c..a2667a85 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -623,15 +623,20 @@ public class TypeUnifyTask extends RecursiveTask>> { * @return The set of all principal type unifiers */ Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { - //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + + //fstElems: Alle 1-elementigen Mengen, die nur ein Paar + //a <. theta, theta <. a oder a =. theta enthalten Set> fstElems = new HashSet<>(); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) .map(y -> y.stream().findFirst().get()) .collect(Collectors.toCollection(HashSet::new))); + + //remainingSets: Alle mehrelementigen Mengen ArrayList>> remainingSets = topLevelSets.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); + writeLog("Anzahl der Elemente von Remaining: " + remainingSets.size()); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); return result; @@ -713,8 +718,9 @@ public class TypeUnifyTask extends RecursiveTask>> { /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet * alle Paare a < ty1 oder ty2 < a aus fstElems */ Set sameEqSet = new HashSet<>(); + + //optOrigPair enthaelt ggf. das Paar a = ty \in nextSet Optional optOrigPair = null; - //if (variance != 2) { if (!oderConstraint) { optOrigPair = nextSetElem.stream().filter(x -> ( //x.getBasePair() != null && ist gegeben wenn variance != 2 @@ -750,11 +756,18 @@ public class TypeUnifyTask extends RecursiveTask>> { while (nextSetasList.size() > 0) { Set a_last = a; - //Liste der Faelle für die parallele Verarbeitung + /* Liste der Faelle für die parallele Verarbeitung + * Enthaelt Elemente, die nicht in Relation zu aktuellem Fall in der + * Variablen a stehen. Diese muesse auf alle Faelle bearbeitet werden, + * Deshalb wird ihre Berechnung parallel angestossen. + */ List> nextSetasListRest = new ArrayList<>(); - //Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt - //In der Regel is dies ein Element + /* Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt + * In der Regel ist dies genau ein Element + * Dieses Element wird später aus nextSetasList geloescht, wenn das jeweils andere Element zum Erfolg + * gefuehrt hat. + */ List> nextSetasListOderConstraints = new ArrayList<>(); writeLog("nextSet: " + nextSet.toString()); @@ -777,6 +790,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } //Alle maximale Elemente in nextSetasListRest bestimmen + //nur für diese wird parallele Berechnung angestossen. nextSetasListRest = oup.maxElements(nextSetasListRest); } else if (variance == -1) { @@ -797,10 +811,13 @@ public class TypeUnifyTask extends RecursiveTask>> { } } //Alle minimalen Elemente in nextSetasListRest bestimmen + //nur für diese wird parallele Berechnung angestossen. nextSetasListRest = oup.minElements(nextSetasListRest); } else if (variance == 2) { a = nextSetasList.remove(0); + + //Fuer alle Elemente wird parallele Berechnung angestossen. nextSetasListRest = new ArrayList<>(nextSetasList); } else if (variance == 0) { @@ -826,20 +843,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } - //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); - //nextSetasList.remove(a); - //PL 2018-03-01 - //TODO: 1. Maximum und Minimum unterscheiden - //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern - //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); - //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall - //im else-Zweig - //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt - //writeLog("Vor unify2 Aufruf: " + elems.toString()); Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); Set> aParDef = new HashSet<>(); @@ -1553,7 +1560,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); } - //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); + writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); return false; } } @@ -1571,12 +1578,12 @@ public class TypeUnifyTask extends RecursiveTask>> { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); } - //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); + writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); return false; } } } - //writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); + writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); return true; } From 1cf22d2602206e8421d1e45e4c4bcc7deabdc717 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 14 Jan 2021 11:27:19 +0100 Subject: [PATCH 006/101] modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java remaingSet entfernt fstElems in oneElems umbenannt --- .../typeinference/unify/TypeUnifyTask.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index a2667a85..aa2e25a0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -626,22 +626,21 @@ public class TypeUnifyTask extends RecursiveTask>> { //fstElems: Alle 1-elementigen Mengen, die nur ein Paar //a <. theta, theta <. a oder a =. theta enthalten - Set> fstElems = new HashSet<>(); - fstElems.addAll(topLevelSets.stream() + Set> oneElems = new HashSet<>(); + oneElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) .map(y -> y.stream().findFirst().get()) .collect(Collectors.toCollection(HashSet::new))); - //remainingSets: Alle mehrelementigen Mengen - ArrayList>> remainingSets = topLevelSets.stream() - .filter(x -> x.size()>1) - .collect(Collectors.toCollection(ArrayList::new)); - writeLog("Anzahl der Elemente von Remaining: " + remainingSets.size()); - if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); + //optNextSet: Eine mehrelementige Menge, wenn vorhanden + Optional>> optNextSet = topLevelSets.stream().filter(x -> x.size()>1).findAny(); + + if (!optNextSet.isPresent()) {//Alle Elemente sind 1-elementig + Set> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe); return result; } - Set> nextSet = remainingSets.remove(0); + + Set> nextSet = optNextSet.get(); //writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); /* @@ -716,7 +715,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet - * alle Paare a < ty1 oder ty2 < a aus fstElems */ + * alle Paare a < ty1 oder ty2 < a aus oneElems */ Set sameEqSet = new HashSet<>(); //optOrigPair enthaelt ggf. das Paar a = ty \in nextSet @@ -744,7 +743,7 @@ public class TypeUnifyTask extends RecursiveTask>> { tyVar = origPair.getRhsType(); } UnifyType tyVarEF = tyVar; - sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) + sameEqSet = oneElems.stream().map(xx -> xx.iterator().next()) .filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType)) || (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType))))) .collect(Collectors.toCollection(HashSet::new)); @@ -845,7 +844,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } i++; - Set> elems = new HashSet>(fstElems); + Set> elems = new HashSet>(oneElems); writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); @@ -853,6 +852,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ if (!oderConstraint && !sameEqSet.isEmpty()) { + //optAPair enthaelt ggf. das Paar a = ty' \in a + //unterscheidet sich von optOrigPair, da dort a = ty Optional optAPair = a.stream().filter(x -> ( //x.getBasePair() != null && ist gegeben wenn variance != 2 //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && @@ -871,7 +872,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + writeLog("variance: " + variance + "sameEqSet:" + sameEqSet); if (!checkA(aPair, sameEqSet, elems, result)) { a = null; noShortendElements++; @@ -1291,7 +1292,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES Fst: reuslt: " + result.toString() + " res: " + res.toString()); + writeLog("RES Fst: result: " + result.toString() + " res: " + res.toString()); result.addAll(res); } } @@ -1303,10 +1304,6 @@ public class TypeUnifyTask extends RecursiveTask>> { //} } - //} - //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); - //} if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { From 163f0f304763a26533abd0a57d89a48442cd8106 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 14 Jan 2021 14:59:20 +0100 Subject: [PATCH 007/101] modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java vor Loeschung von checkA --- .../typeinference/unify/TypeUnifyTask.java | 90 +++++++++++++++++-- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index aa2e25a0..8377edd6 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -624,7 +624,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { - //fstElems: Alle 1-elementigen Mengen, die nur ein Paar + //oneElems: Alle 1-elementigen Mengen, die nur ein Paar //a <. theta, theta <. a oder a =. theta enthalten Set> oneElems = new HashSet<>(); oneElems.addAll(topLevelSets.stream() @@ -846,11 +846,19 @@ public class TypeUnifyTask extends RecursiveTask>> { i++; Set> elems = new HashSet>(oneElems); writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); + + //Ergebnisvariable für den aktuelle Thread Set> res = new HashSet<>(); + + //Menge der Ergebnisse der geforkten Threads Set>> add_res = new HashSet<>(); + + Set> aParDef = new HashSet<>(); - /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + /* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird + * a verworfen und zu nächstem Element von nextSetasList gegangen + */ if (!oderConstraint && !sameEqSet.isEmpty()) { //optAPair enthaelt ggf. das Paar a = ty' \in a //unterscheidet sich von optOrigPair, da dort a = ty @@ -873,15 +881,20 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); writeLog("variance: " + variance + "sameEqSet:" + sameEqSet); + boolean newCheckA = newCheckA(a, sameEqSet, result); if (!checkA(aPair, sameEqSet, elems, result)) { + writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); a = null; noShortendElements++; continue; } + else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); } } - /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + /* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread + * gestartet, der parallel weiterarbeitet. + */ if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); @@ -931,11 +944,14 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + boolean newCheckA = newCheckA(nSaL, sameEqSet, result); if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); nSaL = null; noShortendElements++; continue; } + else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); } } /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ @@ -1051,11 +1067,14 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + boolean newCheckA = newCheckA(nSaL, sameEqSet, result); if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); nSaL = null; noShortendElements++; continue; } + else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); } } /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ @@ -1201,11 +1220,12 @@ public class TypeUnifyTask extends RecursiveTask>> { }; } //noOfThread++; - } else { - //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten + } else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); }}} + + //Ab hier alle parallele Berechnungen wieder zusammengeführt. if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -1540,6 +1560,66 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } + protected Boolean newCheckA(Set a, Set sameEqSet, Set> result) { + + //optAPair enthaelt ggf. das Paar a = ty' \in a + //unterscheidet sich von optOrigPair, da dort a = ty + Optional optAPair = + a.stream().filter(x -> (x.getPairOp().equals(PairOperator.EQUALSDOT))) + .filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType())) + .findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + + writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); + for (UnifyPair sameEq : sameEqSet) { + if (sameEq.getLhsType() instanceof PlaceholderType) { + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); + unitedSubst.addAll(aPair.getAllBases()); + unitedSubst.addAll(sameEq.getAllSubstitutions()); + unitedSubst.addAll(sameEq.getAllBases()); + localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + finalresult = false; + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); + finalresult = true; + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); + return false; + } + } + else { + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); + unitedSubst.addAll(aPair.getAllBases()); + unitedSubst.addAll(sameEq.getAllSubstitutions()); + unitedSubst.addAll(sameEq.getAllBases()); + localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + finalresult = false; + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); + finalresult = true; + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); + return false; + } + } + } + writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); + return true; + } + return true; + } + protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); for (UnifyPair sameEq : sameEqSet) { From 95f48ffcb73ec7e1f938da7f9ac74e81c1ca3da1 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 14 Jan 2021 15:29:06 +0100 Subject: [PATCH 008/101] modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java ckeckA druch checkNoContradiction ersetzt --- .../typeinference/unify/TypeUnifyTask.java | 160 +++--------------- 1 file changed, 25 insertions(+), 135 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8377edd6..5abacf70 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -859,37 +859,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird * a verworfen und zu nächstem Element von nextSetasList gegangen */ - if (!oderConstraint && !sameEqSet.isEmpty()) { - //optAPair enthaelt ggf. das Paar a = ty' \in a - //unterscheidet sich von optOrigPair, da dort a = ty - Optional optAPair = a.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + variance + "sameEqSet:" + sameEqSet); - boolean newCheckA = newCheckA(a, sameEqSet, result); - if (!checkA(aPair, sameEqSet, elems, result)) { - writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); - a = null; - noShortendElements++; - continue; - } - else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); - } + if (!oderConstraint && !sameEqSet.isEmpty() && !checkNoContradiction(a, sameEqSet, result)) { + a = null; + noShortendElements++; + continue; } /* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread @@ -923,38 +896,14 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("1 RM" + nSaL.toString()); } - /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - if (!oderConstraint) {//weiss nicht ob das wirklich stimmt - Optional optAPair = nSaL.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - boolean newCheckA = newCheckA(nSaL, sameEqSet, result); - if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); - nSaL = null; - noShortendElements++; - continue; - } - else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); + if (!oderConstraint) { + //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht + if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) { + nSaL = null; + noShortendElements++; + continue; } } - /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ else { nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); } @@ -1046,38 +995,14 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("-1 RM" + nSaL.toString()); } - if (!oderConstraint) {//weiss nicht ob das wirklich stimmt - /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = nSaL.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - boolean newCheckA = newCheckA(nSaL, sameEqSet, result); - if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); - nSaL = null; - noShortendElements++; - continue; - } - else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); + if (!oderConstraint) { + //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht + if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) { + nSaL = null; + noShortendElements++; + continue; } } - /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ else { nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); } @@ -1560,7 +1485,15 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } - protected Boolean newCheckA(Set a, Set sameEqSet, Set> result) { + /** + * checks if there is for (a = ty) \in a in sameEqSet a constradiction + * @param a Set of actual element of constraints with a =. ty \in a + * @param sameEqSet Set of constraints where a <. ty' and ty' <. a + * @param result set of results which contains correct solution s and the + * the error constraints. Error constraints are added + * @result contradiction of (a = ty) in sameEqSet + */ + protected Boolean checkNoContradiction(Set a, Set sameEqSet, Set> result) { //optAPair enthaelt ggf. das Paar a = ty' \in a //unterscheidet sich von optOrigPair, da dort a = ty @@ -1620,49 +1553,6 @@ public class TypeUnifyTask extends RecursiveTask>> { return true; } - protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { - writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); - for (UnifyPair sameEq : sameEqSet) { - if (sameEq.getLhsType() instanceof PlaceholderType) { - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); - unitedSubst.addAll(aPair.getAllBases()); - unitedSubst.addAll(sameEq.getAllSubstitutions()); - unitedSubst.addAll(sameEq.getAllBases()); - localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - finalresult = false; - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); - finalresult = true; - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); - return false; - } - } - else { - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); - unitedSubst.addAll(aPair.getAllBases()); - unitedSubst.addAll(sameEq.getAllSubstitutions()); - unitedSubst.addAll(sameEq.getAllBases()); - localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - finalresult = false; - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); - finalresult = true; - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); - return false; - } - } - } - writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); - return true; - } protected boolean couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { return reducedUndefResSubstGroundedBasePair.stream() From ab850edae80633d9a2fa149638b29f28c09a661b Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 15 Jan 2021 01:12:13 +0100 Subject: [PATCH 009/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 871dd300..35e83cc6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,7 +136,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); - + System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); tphsClass = tphExtractor.tphsClass; simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass); if(!isVisited) { From eb97dd810fcc837cf6adce929c02bd90b96dabfc Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 15 Jan 2021 13:18:09 +0100 Subject: [PATCH 010/101] modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java new file: src/test/java/insertGenerics/TestClassField.java new file: src/test/java/insertGenerics/TestReturnVar.java new file: src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java new file: src/test/java/insertGenerics/TestTPHsAndGenerics.java new file: src/test/java/insertGenerics/TestVoidMeth.java new file: src/test/resources/insertGenericsJav/TestClassField.jav new file: src/test/resources/insertGenericsJav/TestReturnVar.jav new file: src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav new file: src/test/resources/insertGenericsJav/TestTPHsAndGenerics.jav new file: src/test/resources/insertGenericsJav/TestVoidMeth.jav --- .../FamilyOfGeneratedGenericsTest.java | 1 + .../java/insertGenerics/TestClassField.java | 72 +++++++++++++++++++ .../java/insertGenerics/TestReturnVar.java | 72 +++++++++++++++++++ .../TestSecondLineOfClassConstraints.java | 72 +++++++++++++++++++ .../insertGenerics/TestTPHsAndGenerics.java | 72 +++++++++++++++++++ .../java/insertGenerics/TestVoidMeth.java | 72 +++++++++++++++++++ .../insertGenericsJav/TestClassField.jav | 6 ++ .../insertGenericsJav/TestReturnVar.jav | 5 ++ .../TestSecondLineOfClassConstraints.jav | 13 ++++ .../insertGenericsJav/TestTPHsAndGenerics.jav | 13 ++++ .../insertGenericsJav/TestVoidMeth.jav | 4 ++ 11 files changed, 402 insertions(+) create mode 100644 src/test/java/insertGenerics/TestClassField.java create mode 100644 src/test/java/insertGenerics/TestReturnVar.java create mode 100644 src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java create mode 100644 src/test/java/insertGenerics/TestTPHsAndGenerics.java create mode 100644 src/test/java/insertGenerics/TestVoidMeth.java create mode 100644 src/test/resources/insertGenericsJav/TestClassField.jav create mode 100644 src/test/resources/insertGenericsJav/TestReturnVar.jav create mode 100644 src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav create mode 100644 src/test/resources/insertGenericsJav/TestTPHsAndGenerics.jav create mode 100644 src/test/resources/insertGenericsJav/TestVoidMeth.jav diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java index 9d7689a0..e3ee708b 100644 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -66,6 +66,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { assertTrue(classConstraints.size() == 2); //assertTrue(classConstraints.get(0).getLeft().equals("A")); //assertTrue(classConstraints.get(0).getRight().equals("B")); +// HashMap> methodConstraintsWithPosition = FamilyOfGeneratedGenerics.getMethodConstraintsWithPosition(inputConstraints,classConstraints,tphPositions,) } public void testSecondLineOfClassConstraints() { diff --git a/src/test/java/insertGenerics/TestClassField.java b/src/test/java/insertGenerics/TestClassField.java new file mode 100644 index 00000000..81480123 --- /dev/null +++ b/src/test/java/insertGenerics/TestClassField.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestClassField { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestClassField.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestReturnVar.java b/src/test/java/insertGenerics/TestReturnVar.java new file mode 100644 index 00000000..026c03cd --- /dev/null +++ b/src/test/java/insertGenerics/TestReturnVar.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestReturnVar { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestReturnVar.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java b/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java new file mode 100644 index 00000000..0d8093fd --- /dev/null +++ b/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestSecondLineOfClassConstraints { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java new file mode 100644 index 00000000..ed5016c7 --- /dev/null +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTPHsAndGenerics { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestTPHSAndGenerics.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestVoidMeth.java b/src/test/java/insertGenerics/TestVoidMeth.java new file mode 100644 index 00000000..3f325a6e --- /dev/null +++ b/src/test/java/insertGenerics/TestVoidMeth.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestVoidMeth { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestVoidMeth.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/resources/insertGenericsJav/TestClassField.jav b/src/test/resources/insertGenericsJav/TestClassField.jav new file mode 100644 index 00000000..f3d24e51 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestClassField.jav @@ -0,0 +1,6 @@ +class Example{ + f; + fReturn(){ + return f; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestReturnVar.jav b/src/test/resources/insertGenericsJav/TestReturnVar.jav new file mode 100644 index 00000000..8906df24 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestReturnVar.jav @@ -0,0 +1,5 @@ +class VarReturn { + anyMethod() { + return f; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav b/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav new file mode 100644 index 00000000..6ef08afe --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav @@ -0,0 +1,13 @@ +class Example() { + a; + b = a; + anyMethod() { + f; + return f; + } + otherMethod(e) { + this.b = e; + e = this.a; + return e; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestTPHsAndGenerics.jav b/src/test/resources/insertGenericsJav/TestTPHsAndGenerics.jav new file mode 100644 index 00000000..33a79e51 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTPHsAndGenerics.jav @@ -0,0 +1,13 @@ +class TPHsAndGenerics { + id = x -> x; + id2 (x) { + return id.apply(x); + } + m(a, b){ + var c = m2(a,b); + return a; + } + m2(a, b){ + return b; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestVoidMeth.jav b/src/test/resources/insertGenericsJav/TestVoidMeth.jav new file mode 100644 index 00000000..50ee7206 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestVoidMeth.jav @@ -0,0 +1,4 @@ +class VoidMeth { + anyMethod() { + } +} \ No newline at end of file From fc8f11ebb1d4d900b2611616b89a1f24f054e9b4 Mon Sep 17 00:00:00 2001 From: AluAli Date: Sat, 16 Jan 2021 00:35:12 +0100 Subject: [PATCH 011/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java new file: src/test/java/insertGenerics/TestAny.java new file: src/test/java/insertGenerics/TestTPHsAndGenerics2.java new file: src/test/resources/insertGenericsJav/TestAny.jav modified: src/test/resources/insertGenericsJav/TestReturnVar.jav modified: src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav new file: src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav --- .../GeneratedGenericsFinder.java | 6 +- src/test/java/insertGenerics/TestAny.java | 72 +++++++++++++++++++ .../insertGenerics/TestTPHsAndGenerics2.java | 72 +++++++++++++++++++ .../resources/insertGenericsJav/TestAny.jav | 13 ++++ .../insertGenericsJav/TestReturnVar.jav | 1 + .../TestSecondLineOfClassConstraints.jav | 7 +- .../TestTPHsAndGenerics2.jav | 13 ++++ 7 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 src/test/java/insertGenerics/TestAny.java create mode 100644 src/test/java/insertGenerics/TestTPHsAndGenerics2.java create mode 100644 src/test/resources/insertGenericsJav/TestAny.jav create mode 100644 src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 35e83cc6..dfdba215 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,7 +136,11 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); - System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); + System.out.println("fogg.allConstraints: "+ fogg.allConstraints); + System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); + System.out.println("fogg.classConstraints: "+ fogg.classConstraints); + System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); + tphsClass = tphExtractor.tphsClass; simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass); if(!isVisited) { diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java new file mode 100644 index 00000000..6c6d2a95 --- /dev/null +++ b/src/test/java/insertGenerics/TestAny.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestAny { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestAny.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics2.java b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java new file mode 100644 index 00000000..fc5a90e6 --- /dev/null +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTPHsAndGenerics2 { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/resources/insertGenericsJav/TestAny.jav b/src/test/resources/insertGenericsJav/TestAny.jav new file mode 100644 index 00000000..9ba18b63 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestAny.jav @@ -0,0 +1,13 @@ +class Example { + a; + b = a; + anyMethod() { + var f; + return f; + } + otherMethod(e) { + b = e; + e = a; + return e; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestReturnVar.jav b/src/test/resources/insertGenericsJav/TestReturnVar.jav index 8906df24..0688e5b8 100644 --- a/src/test/resources/insertGenericsJav/TestReturnVar.jav +++ b/src/test/resources/insertGenericsJav/TestReturnVar.jav @@ -1,5 +1,6 @@ class VarReturn { anyMethod() { + var f; return f; } } \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav b/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav index 6ef08afe..16275a50 100644 --- a/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav +++ b/src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav @@ -1,13 +1,12 @@ -class Example() { +class Example { a; b = a; anyMethod() { - f; + var f; return f; } otherMethod(e) { - this.b = e; - e = this.a; + e = a; return e; } } \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav b/src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav new file mode 100644 index 00000000..9cdc21f7 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav @@ -0,0 +1,13 @@ +class TPHsAndGenerics2 { + id = x -> x; + id2 (x) { + return id.apply(x); + } + m(a, b){ + var c = m2(a,b); + return a; + } + m2(a, b){ + return b; + } +} \ No newline at end of file From 842b85cfd74c1c2cc3e7ebe14fce34cadbb81a7c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 16 Jan 2021 09:12:34 +0100 Subject: [PATCH 012/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 35e83cc6..472d9686 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -137,7 +137,11 @@ public class GeneratedGenericsFinder implements ASTVisitor { //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); + + /* tphsClass = tphExtractor.tphsClass; + //PL 2020-01-15 + //Es muss ggResult aus fogg gebildet werden simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass); if(!isVisited) { ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints); @@ -148,6 +152,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } + */ if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); From 3d8275c676088352bd8d9fb9932422d641171cc9 Mon Sep 17 00:00:00 2001 From: AluAli Date: Sat, 16 Jan 2021 16:34:31 +0100 Subject: [PATCH 013/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../genericsGenerator/GeneratedGenericsFinder.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 2b03b38a..4b4fa686 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,17 +136,12 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); -<<<<<<< HEAD - System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); - - /* -======= System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); ->>>>>>> fc8f11ebb1d4d900b2611616b89a1f24f054e9b4 + /* tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -158,10 +153,10 @@ public class GeneratedGenericsFinder implements ASTVisitor { for(Method m : classOrInterface.getMethods()) { addMethodConstraints(simplifiedConstraints, ggResult, m); - + } */ - + if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); System.out.println("ddd"); From bd6d74c74d48177f66ce38eab6edb6072b46deb6 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 18 Jan 2021 13:40:20 +0100 Subject: [PATCH 014/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 2b03b38a..15b495db 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,17 +136,15 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); -<<<<<<< HEAD + System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); /* -======= System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); ->>>>>>> fc8f11ebb1d4d900b2611616b89a1f24f054e9b4 tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden From 1242252cde6fae971b8b0832597a6ccb8b8fdb1a Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 18 Jan 2021 13:46:06 +0100 Subject: [PATCH 015/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index c53cb7c5..d8d36baf 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -139,15 +139,12 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); - - /* - - System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); + /* tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden From a8f04a25cd4c9c7c785fe90fdc34298a00fbe37f Mon Sep 17 00:00:00 2001 From: AluAli Date: Mon, 18 Jan 2021 19:10:04 +0100 Subject: [PATCH 016/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 4b4fa686..d78d3bc9 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -141,7 +141,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); - /* + /**/ tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -155,7 +155,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - */ + /**/ if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); From c15953bbacd8ca0abd511b1a449ec59156509f49 Mon Sep 17 00:00:00 2001 From: AluAli Date: Mon, 18 Jan 2021 19:15:36 +0100 Subject: [PATCH 017/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 6659490c..4a717879 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,9 +136,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); - - - System.out.println("fogg: "+ fogg.methodConstraintsWithPosition); + System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); From 1a135ebe5c2d40ee9780c213a4a0220ec85d047d Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 22 Jan 2021 15:07:03 +0100 Subject: [PATCH 018/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../GeneratedGenericsFinder.java | 2 +- .../FamilyOfGeneratedGenerics.java | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 4a717879..5be20f2d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -136,7 +136,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF fogg = new FamilyOfGeneratedGenerics(tphExtractor); - + System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 03ea3f41..f5c06a0c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -35,12 +35,26 @@ public class FamilyOfGeneratedGenerics { cs_cl.add(cons); } } - List classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher - for (ClassConstraint cons: classConstraints2) { - if (!checkForDuplicates(cons, cs_cl)) { - cs_cl.add(cons); + boolean equalsConstraintsList = false; + List tempList = new ArrayList<>(); + do { + List classConstraints2 = new ArrayList<>(); + classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher + if (classConstraints2 == tempList) { + equalsConstraintsList = true; } - } + for (ClassConstraint cons: classConstraints2) { + if (!checkForDuplicates(cons, cs_cl)) { + cs_cl.add(cons); + } + } + tempList = new ArrayList<>(classConstraints2); + for (ClassConstraint cc : tempList) { + classConstraints2.remove(cc); + System.out.println(classConstraints2); + } + }while(!equalsConstraintsList); + List classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs); for (ClassConstraint cons: classConstraints3) { if (!checkForDuplicates(cons, cs_cl)) { @@ -113,7 +127,7 @@ public class FamilyOfGeneratedGenerics { */ public static List typeOfANodeOfAField(List allConstraints, HashMap> posOfTphs) { //RuntimeException re = new RuntimeException("enthält EQUALS-Relation"); - List tempCC= new ArrayList<>(); + List tempCC = new ArrayList<>(); for(TPHConstraint allCons: allConstraints){ if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { for(String tph: posOfTphs.keySet()) { @@ -137,15 +151,19 @@ public class FamilyOfGeneratedGenerics { * {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs } */ public static List transitiveSubtypeForClassTypes(List allConstraints, List cs_cl) { - List tempCC= new ArrayList<>(); + List tempCC = new ArrayList<>(); + ClassConstraint consToAdd; for(ClassConstraint cCons: cs_cl) { if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) { for(TPHConstraint allCons: allConstraints) { if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){ - ClassConstraint consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); + consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); } +// if (tempCC != null) { +// transitiveSubtypeForClassTypes(allConstraints, tempCC); +// } } } } @@ -279,12 +297,15 @@ public class FamilyOfGeneratedGenerics { * nimm die Menge cs_cl aus cs_m raus */ public static List methodTypesWithoutClassTypes(List cs_cl, List cs_m) { - //TODO: + // erstelle Kopie der Liste cs_cl List tempCC = new ArrayList<>(); for(ClassConstraint cc: cs_cl) { TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel()); tempCC.add(tphC); } + // Transitive Hülle von cs_cl + List tcOfCsCl = buildTransitiveClosure(tempCC); + List tempMC = new ArrayList<>(); for(MethodConstraint mc: cs_m) { TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel()); @@ -294,7 +315,7 @@ public class FamilyOfGeneratedGenerics { tempMC2.addAll(tempMC); List tempMCToReturn = new ArrayList<>(); - for(TPHConstraint cc: tempCC) { + for(TPHConstraint cc: tcOfCsCl) { for(TPHConstraint mc: tempMC) { if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) { tempMC2.remove(mc); From cfacc6235ce6c8e98da77aa487594ddc1c4e2d90 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 22 Jan 2021 15:13:03 +0100 Subject: [PATCH 019/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index f5c06a0c..3f11424b 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -35,25 +35,19 @@ public class FamilyOfGeneratedGenerics { cs_cl.add(cons); } } - boolean equalsConstraintsList = false; - List tempList = new ArrayList<>(); + boolean addedToConstraintsList = false; do { + addedToConstraintsList = false; List classConstraints2 = new ArrayList<>(); classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher - if (classConstraints2 == tempList) { - equalsConstraintsList = true; - } + for (ClassConstraint cons: classConstraints2) { if (!checkForDuplicates(cons, cs_cl)) { cs_cl.add(cons); + addedToConstraintsList = true; } } - tempList = new ArrayList<>(classConstraints2); - for (ClassConstraint cc : tempList) { - classConstraints2.remove(cc); - System.out.println(classConstraints2); - } - }while(!equalsConstraintsList); + }while(addedToConstraintsList); List classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs); for (ClassConstraint cons: classConstraints3) { From bb900af6bff416bdca7686a380e075ac8f98d74a Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 22 Jan 2021 15:52:14 +0100 Subject: [PATCH 020/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 3f11424b..30323d6e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -35,19 +35,19 @@ public class FamilyOfGeneratedGenerics { cs_cl.add(cons); } } - boolean addedToConstraintsList = false; - do { - addedToConstraintsList = false; - List classConstraints2 = new ArrayList<>(); - classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher + // if sth new is added to cs_cl, then do same step again + boolean addedToConstraintsListForCC2 = false; + do { + addedToConstraintsListForCC2 = false; + List classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher for (ClassConstraint cons: classConstraints2) { if (!checkForDuplicates(cons, cs_cl)) { cs_cl.add(cons); - addedToConstraintsList = true; + addedToConstraintsListForCC2 = true; } } - }while(addedToConstraintsList); + } while (addedToConstraintsListForCC2); List classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs); for (ClassConstraint cons: classConstraints3) { @@ -59,7 +59,6 @@ public class FamilyOfGeneratedGenerics { } public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs) { - //TODO: Regeln List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { @@ -67,18 +66,32 @@ public class FamilyOfGeneratedGenerics { cs_m.add(cons); } } - List methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m); - for (MethodConstraint cons: methodConstraints2) { - if (!checkForDuplicates(cons, cs_m)) { - cs_m.add(cons); + + // if sth new is added to cs_cl, then do same step again + boolean addedToConstraintsListForMC2 = false; + do { + addedToConstraintsListForMC2 = false; + List methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m); + for (MethodConstraint cons : methodConstraints2) { + if (!checkForDuplicates(cons, cs_m)) { + cs_m.add(cons); + addedToConstraintsListForMC2 = true; + } } - } - List methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m); - for (MethodConstraint cons: methodConstraints3) { - if (!checkForDuplicates(cons, cs_m)) { - cs_m.add(cons); + } while (addedToConstraintsListForMC2); + + // if sth new is added to cs_cl, then do same step again + boolean addedToConstraintsListForMC3 = false; + do { + addedToConstraintsListForMC3 = false; + List methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m); + for (MethodConstraint cons : methodConstraints3) { + if (!checkForDuplicates(cons, cs_m)) { + cs_m.add(cons); + addedToConstraintsListForMC3 = true; + } } - } + } while (addedToConstraintsListForMC3); List methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs); for (MethodConstraint cons: methodConstraints4) { if (!checkForDuplicates(cons, cs_m)) { From 3f4aa7bbd5790d6a813010278f7ad00eaa7fd81e Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 22 Jan 2021 23:49:25 +0100 Subject: [PATCH 021/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java modified: src/test/java/insertGenerics/TestExample42.java modified: src/test/java/insertGenerics/TestExample42_allInOneMethod.java --- .../FamilyOfGeneratedGenerics.java | 60 +++++++++++++++---- .../FamilyOfGeneratedGenericsTest.java | 24 ++++---- .../java/insertGenerics/TestExample42.java | 4 +- .../TestExample42_allInOneMethod.java | 4 +- 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 30323d6e..5c2442b9 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -1,6 +1,5 @@ package de.dhbwstuttgart.bytecode.insertGenerics; -import com.ibm.icu.text.CurrencyMetaInfo; import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; @@ -23,7 +22,7 @@ public class FamilyOfGeneratedGenerics { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); - this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); +// this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); } @@ -58,7 +57,7 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs) { + public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { @@ -92,7 +91,7 @@ public class FamilyOfGeneratedGenerics { } } } while (addedToConstraintsListForMC3); - List methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs); + List methodConstraints4 = hasNoSupertypeForMethodTypes(cs, cs_m, posOfTphs, listOfMethodsAndTph); for (MethodConstraint cons: methodConstraints4) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); @@ -120,14 +119,35 @@ public class FamilyOfGeneratedGenerics { System.out.println(posOfTPHsForThisMethod); } } - listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod); + listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); System.out.println(tempMethodConstraintsWithPosition); } } + + for(String curMeth: tempMethodConstraintsWithPosition.keySet()){ + for(int i=0; i tempList = new ArrayList<>(list); + for(TPHConstraint tphC: tempList) { + if(tph == tphC.getLeft()) { + return true; + } + } + return false; + } + /** * Def. FGG: erste Zeile von cs_cl * {T < .T' | T is a type variable in a type of a node of a field} @@ -168,9 +188,6 @@ public class FamilyOfGeneratedGenerics { if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); } -// if (tempCC != null) { -// transitiveSubtypeForClassTypes(allConstraints, tempCC); -// } } } } @@ -191,7 +208,7 @@ public class FamilyOfGeneratedGenerics { boolean tvInField = posOfTphs.get(tph).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) { + !checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) { ClassConstraint consToAdd = new ClassConstraint(tph, "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempCC)){ tempCC.add(consToAdd); @@ -283,12 +300,12 @@ public class FamilyOfGeneratedGenerics { * {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 List hasNoSupertypeForMethodTypes(List allConstraints, HashMap> posOfTphs) { + public static List hasNoSupertypeForMethodTypes(List allConstraints, List cs_m, HashMap> posOfTphs, List listOfMethodsAndTph) { //TODO: List tempMC= new ArrayList<>(); 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)) { + 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 (!checkForDuplicates(consToAdd, tempMC)) { tempMC.add(consToAdd); @@ -296,6 +313,22 @@ public class FamilyOfGeneratedGenerics { } } } + List tempMCObject1 = new ArrayList<>(cs_m); + String currentMethod = ""; + for(MethodAndTPH mat: listOfMethodsAndTph) { + if(mat.getId().equals(posOfTphs.get(tph).snd)) { + currentMethod = mat.getId(); + } + for(TPHConstraint mc1: tempMCObject1) { + if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) { + MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempMC)) { + tempMC.add(consToAdd); + System.out.println(consToAdd); + } + } + } + } } return tempMC; } @@ -374,10 +407,11 @@ public class FamilyOfGeneratedGenerics { public static boolean checkUpperBound(List cs, String tph) { for(int i=0; i methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); - assertTrue(methodConstraints.size() == 2); - assertTrue(methodConstraints.get(0).getLeft().equals("B")); - assertTrue(methodConstraints.get(0).getRight().equals("A")); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); +// assertTrue(methodConstraints.size() == 2); +// assertTrue(methodConstraints.get(0).getLeft().equals("B")); +// assertTrue(methodConstraints.get(0).getRight().equals("A")); } public void testClassField(){ @@ -110,12 +110,12 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); System.out.println(classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); - System.out.println(methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); +// System.out.println(methodConstraints); assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 6); - assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size() == 2); +// assertFalse(methodConstraints.isEmpty()); +// assertTrue(methodConstraints.size() == 2); } @@ -170,13 +170,13 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); System.out.println(classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); - System.out.println(methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); +// System.out.println(methodConstraints); assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 3); - assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size()==9); +// assertFalse(methodConstraints.isEmpty()); +// assertTrue(methodConstraints.size()==9); } diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java index 8d291a2d..127ddd59 100644 --- a/src/test/java/insertGenerics/TestExample42.java +++ b/src/test/java/insertGenerics/TestExample42.java @@ -54,8 +54,8 @@ public class TestExample42 { public void genericTest() { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); System.out.println("ClassConstraints: " + classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); - System.out.println("MethodConstraints: " + methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); +// System.out.println("MethodConstraints: " + methodConstraints); List testCons; } diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java index f6fa8d7f..1d355288 100644 --- a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java +++ b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java @@ -53,8 +53,8 @@ public class TestExample42_allInOneMethod { public void genericTest() { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); System.out.println("ClassConstraints: " + classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); - System.out.println("MethodConstraints: " + methodConstraints); +// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),); +// System.out.println("MethodConstraints: " + methodConstraints); List testCons; } From 1348a7a4b61ea97a24f0a40f185050652991a730 Mon Sep 17 00:00:00 2001 From: AluAli Date: Sat, 23 Jan 2021 00:07:05 +0100 Subject: [PATCH 022/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../bytecode/insertGenerics/FamilyOfGeneratedGenerics.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 5c2442b9..a475ce7c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -116,12 +116,10 @@ public class FamilyOfGeneratedGenerics { for(String s: posOfTphs.keySet()) { if(posOfTphs.get(s).snd == currentMethod && posOfTphs.get(s).snd != null) { posOfTPHsForThisMethod.put(s,posOfTphs.get(s)); - System.out.println(posOfTPHsForThisMethod); } } listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); - System.out.println(tempMethodConstraintsWithPosition); } } @@ -285,7 +283,6 @@ public class FamilyOfGeneratedGenerics { MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel()); if (!checkForDuplicates(consToAdd, tempMC)) { tempMC.add(consToAdd); - System.out.println(consToAdd); } } @@ -309,7 +306,6 @@ public class FamilyOfGeneratedGenerics { MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempMC)) { tempMC.add(consToAdd); - System.out.println(consToAdd); } } } @@ -324,7 +320,6 @@ public class FamilyOfGeneratedGenerics { MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempMC)) { tempMC.add(consToAdd); - System.out.println(consToAdd); } } } From 1236ca2953edd6392ba21db9427d9a810fbe772a Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 28 Jan 2021 16:12:17 +0100 Subject: [PATCH 023/101] modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java modified: src/test/resources/insertGenericsJav/TestGGFinder.jav --- .../java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java | 1 + src/test/resources/insertGenericsJav/TestGGFinder.jav | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 6fd83f3b..b7b04084 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -126,6 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(Assign assign) { assign.lefSide.accept(this); assign.rightSide.accept(this); + assign.rightSide.getType().accept(this); } @Override diff --git a/src/test/resources/insertGenericsJav/TestGGFinder.jav b/src/test/resources/insertGenericsJav/TestGGFinder.jav index d9309646..9ce2691f 100644 --- a/src/test/resources/insertGenericsJav/TestGGFinder.jav +++ b/src/test/resources/insertGenericsJav/TestGGFinder.jav @@ -1,4 +1,4 @@ -class Generics{ +class TestGGFinder { a; id(b) { From 918d0db79977eab20184d9edc7a37693eb264f58 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 29 Jan 2021 09:25:10 +0100 Subject: [PATCH 024/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java --- src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index f6292f3b..de5e29c1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -78,7 +78,7 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(TypePlaceholder tph) { if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) { TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType; - if (inMethod) { + if (inMethod && !tphsClass.contains(resolvedTPH.getName())) { methodAndTph.getTphs().add(resolvedTPH.getName()); if (inLocalOrParamOrReturn) methodAndTph.getLocalTphs().add(resolvedTPH.getName()); From 8706882388bbd6140c54c28cf1fe4168c58a88d3 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 29 Jan 2021 10:55:04 +0100 Subject: [PATCH 025/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java new file: src/test/java/insertGenerics/TestGGFinder.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 26 ++++--- .../java/insertGenerics/TestGGFinder.java | 72 +++++++++++++++++++ 2 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 src/test/java/insertGenerics/TestGGFinder.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index de5e29c1..9b895199 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -78,15 +78,25 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(TypePlaceholder tph) { if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) { TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType; - if (inMethod && !tphsClass.contains(resolvedTPH.getName())) { - methodAndTph.getTphs().add(resolvedTPH.getName()); - if (inLocalOrParamOrReturn) - methodAndTph.getLocalTphs().add(resolvedTPH.getName()); - }else { - tphsClass.add(resolvedTPH.getName()); + String tphName = resolvedTPH.getName(); + if (inMethod && !tphsClass.contains(tphName)) { + ArrayList tphs = null; + if (!(tphs = methodAndTph.getTphs()).contains(tphName)) { + tphs.add(tphName); + } + if (inLocalOrParamOrReturn) { + if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) { + tphs.add(tphName); + } + } + } else { + if (!tphsClass.contains(tphName)) { + tphsClass.add(tphName); + } + } + if (!allTPHS.containsKey(tphName)) { + allTPHS.put(tphName, inMethod); } - - allTPHS.put(resolvedTPH.getName(), inMethod); // final List cons = new ArrayList<>(); // resultSet.resolveType(tph).additionalGenerics.forEach(ag -> { // TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java new file mode 100644 index 00000000..c517136c --- /dev/null +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestGGFinder { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestGGFinder.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} From 8fb7a2327938f6211723f799b08644e2a6566659 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 29 Jan 2021 12:24:16 +0100 Subject: [PATCH 026/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java modified: src/test/java/insertGenerics/TestExample42.java modified: src/test/java/insertGenerics/TestExample42_allInOneMethod.java --- .../FamilyOfGeneratedGenerics.java | 106 ++++++++++-------- .../FamilyOfGeneratedGenericsTest.java | 41 ++++--- .../java/insertGenerics/TestExample42.java | 4 +- .../TestExample42_allInOneMethod.java | 4 +- 4 files changed, 90 insertions(+), 65 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index a475ce7c..b1d2510b 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -12,7 +12,7 @@ import java.util.List; public class FamilyOfGeneratedGenerics { public List allConstraints = new ArrayList<>(); // HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode - public HashMap> posOfTPHs = new HashMap<>(); + public HashMap>> posOfTPHs = new HashMap<>(); public List classConstraints = new ArrayList<>(); public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); @@ -22,11 +22,11 @@ public class FamilyOfGeneratedGenerics { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); -// this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); + this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); } - public static List getClassConstraints(List cs, HashMap> posOfTphs) { //Inputparameter List constraintsSet weg + public static List getClassConstraints(List cs, HashMap>> posOfTphs) { //Inputparameter List constraintsSet weg List cs_cl = new ArrayList<>(); List classConstraints1 = typeOfANodeOfAField(cs, posOfTphs); for (ClassConstraint cons: classConstraints1) { @@ -57,7 +57,7 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs, List listOfMethodsAndTph) { + public static List getMethodConstraints(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { @@ -102,7 +102,7 @@ public class FamilyOfGeneratedGenerics { return cs_m; } - public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap> posOfTphs, List listOfMethodsAndTph) { + public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); for(MethodAndTPH method: listOfMethodsAndTph){ List methodsAddedToHashMap = new ArrayList<>(); @@ -112,10 +112,12 @@ public class FamilyOfGeneratedGenerics { methodsAddedToHashMap.add(currentMethod); containsCurrentMethod = true; List listOfThisMethod = new ArrayList<>(); - HashMap> posOfTPHsForThisMethod = new HashMap<>(); + HashMap>> posOfTPHsForThisMethod = new HashMap<>(); for(String s: posOfTphs.keySet()) { - if(posOfTphs.get(s).snd == currentMethod && posOfTphs.get(s).snd != null) { - posOfTPHsForThisMethod.put(s,posOfTphs.get(s)); + for(PairTphMethod pair: posOfTphs.get(s)) { + if(pair.snd == currentMethod && pair.snd != null) { + posOfTPHsForThisMethod.put(s,posOfTphs.get(s)); + } } } listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); @@ -150,16 +152,18 @@ public class FamilyOfGeneratedGenerics { * Def. FGG: erste Zeile von cs_cl * {T < .T' | T is a type variable in a type of a node of a field} */ - public static List typeOfANodeOfAField(List allConstraints, HashMap> posOfTphs) { + public static List typeOfANodeOfAField(List allConstraints, HashMap>> posOfTphs) { //RuntimeException re = new RuntimeException("enthält EQUALS-Relation"); List tempCC = new ArrayList<>(); for(TPHConstraint allCons: allConstraints){ if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { for(String tph: posOfTphs.keySet()) { - if(tph == allCons.getLeft() && posOfTphs.get(tph).fst == PositionFinder.Position.FIELD) { - ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel()); - if (!checkForDuplicates(consToAdd, tempCC)) { - tempCC.add(consToAdd); + for(PairTphMethod pair: posOfTphs.get(tph)) { + if(tph == allCons.getLeft() && pair.fst == PositionFinder.Position.FIELD) { + ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel()); + if (!checkForDuplicates(consToAdd, tempCC)) { + tempCC.add(consToAdd); + } } } } @@ -198,18 +202,20 @@ 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 allConstraints, List cs_cl, HashMap>> posOfTphs) { List tempCC= new ArrayList<>(); for(TPHConstraint allCons: allConstraints) { for(ClassConstraint cCons: cs_cl) { for(String tph: posOfTphs.keySet()) { - boolean tvInField = posOfTphs.get(tph).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, "Object", Relation.EXTENDS); - if (!checkForDuplicates(consToAdd, tempCC)){ - tempCC.add(consToAdd); + 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, "Object", Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempCC)){ + tempCC.add(consToAdd); + } } } } @@ -222,16 +228,18 @@ public class FamilyOfGeneratedGenerics { * 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} */ - public static List typeOfTheMethodInClSigma(List allConstraints, HashMap> posOfTphs) { // cl_\sigma?? + public static List typeOfTheMethodInClSigma(List allConstraints, HashMap>> posOfTphs) { // cl_\sigma?? //TODO: List tempMC= new ArrayList<>(); for(TPHConstraint allCons: allConstraints){ if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { for(String tph: posOfTphs.keySet()) { - if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) { - MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); - if (!checkForDuplicates(consToAdd, tempMC)) { - tempMC.add(consToAdd); + for(PairTphMethod pair: posOfTphs.get(tph)) { + if(tph == allCons.getLeft() && (pair.fst == PositionFinder.Position.METHOD || pair.fst == PositionFinder.Position.CONSTRUCTOR)) { + MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); + if (!checkForDuplicates(consToAdd, tempMC)) { + tempMC.add(consToAdd); + } } } } @@ -297,32 +305,34 @@ public class FamilyOfGeneratedGenerics { * {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 List hasNoSupertypeForMethodTypes(List allConstraints, List cs_m, HashMap> posOfTphs, List listOfMethodsAndTph) { + public static List hasNoSupertypeForMethodTypes(List allConstraints, List cs_m, HashMap>> posOfTphs, List listOfMethodsAndTph) { //TODO: List tempMC= new ArrayList<>(); 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 (!checkForDuplicates(consToAdd, tempMC)) { - tempMC.add(consToAdd); - } - } - } - List tempMCObject1 = new ArrayList<>(cs_m); - String currentMethod = ""; - for(MethodAndTPH mat: listOfMethodsAndTph) { - if(mat.getId().equals(posOfTphs.get(tph).snd)) { - currentMethod = mat.getId(); - } - for(TPHConstraint mc1: tempMCObject1) { - if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) { + for(PairTphMethod pair: posOfTphs.get(tph)) { + for(TPHConstraint allCons: allConstraints) { + if((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) { MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempMC)) { tempMC.add(consToAdd); } } } + List tempMCObject1 = new ArrayList<>(cs_m); + String currentMethod = ""; + for(MethodAndTPH mat: listOfMethodsAndTph) { + if(mat.getId().equals(pair.snd)) { + currentMethod = mat.getId(); + } + for(TPHConstraint mc1: tempMCObject1) { + if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) { + MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempMC)) { + tempMC.add(consToAdd); + } + } + } + } } } return tempMC; @@ -410,18 +420,20 @@ public class FamilyOfGeneratedGenerics { } - public static HashMap> positionConverter(HashMap allTphs, List listOfMethodsAndTphs) { - HashMap> convertedPositions = new HashMap<>(); + public static HashMap>> positionConverter(HashMap allTphs, List listOfMethodsAndTphs) { + HashMap>> convertedPositions = new HashMap<>(); for(String tph: allTphs.keySet()) { + List> currMeth = new ArrayList<>(); if(allTphs.get(tph)) { //if true, then tph is a method-TPH for(MethodAndTPH methTph: listOfMethodsAndTphs) { if (methTph.getTphs().contains(tph)) { - convertedPositions.put(tph, new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId())); + currMeth.add(new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId())); } } } else { // else it is in the class-TPH - convertedPositions.put(tph, new PairTphMethod<>(PositionFinder.Position.FIELD, null)); + currMeth.add(new PairTphMethod<>(PositionFinder.Position.FIELD, null)); } + convertedPositions.put(tph, currMeth); } return convertedPositions; } diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java index be17ea3a..53122862 100644 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -1,3 +1,4 @@ +/* package insertGenerics; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; @@ -12,11 +13,13 @@ import java.util.List; public class FamilyOfGeneratedGenericsTest extends TestCase { public void testIdentityMethod(){ - /* + */ +/* Example method: A id(B i) return i; gives constraint: B <. A and A <. Object, which are method constraints - */ + *//* + List inputConstraints = new ArrayList<>(); inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS)); @@ -29,9 +32,11 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); assertTrue(classConstraints.isEmpty()); - /* + */ +/* MethodConstraints should be the same as the input constraint - */ + *//* + // List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); // assertTrue(methodConstraints.size() == 2); // assertTrue(methodConstraints.get(0).getLeft().equals("B")); @@ -39,7 +44,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { } public void testClassField(){ - /* + */ +/* class Example{ A f; B fReturn(){ @@ -47,7 +53,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { } } gives constraint: A <. B and B <. Object which are class constraints - */ + *//* + List inputConstraints = new ArrayList<>(); inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); @@ -58,9 +65,11 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { PairTphMethod posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn"); tphPositions.put("B", posOfB); - /* + */ +/* ClassConstraints should not be the same as the input constraint - */ + *//* + List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); System.out.println(classConstraints); assertTrue(classConstraints.size() == 2); @@ -70,7 +79,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { } public void testSecondLineOfClassConstraints() { - /* + */ +/* class Example() { A a; B b = a; @@ -84,7 +94,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { return e; } } - */ + *//* + List inputConstraints = new ArrayList<>(); inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); @@ -120,7 +131,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { } public void testTPHsAndGenerics() { - /* + */ +/* class TPHsAndGenerics { Fun1 id = x -> x; C id2 (D x) { @@ -134,7 +146,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { return b; } } - */ + *//* + List inputConstraints = new ArrayList<>(); inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS)); @@ -196,7 +209,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { - HashMap> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs); + HashMap>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs); System.out.println(allTphsNew); //was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten? //ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt? @@ -212,4 +225,4 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { } -} \ No newline at end of file +}*/ diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java index 127ddd59..a052bacf 100644 --- a/src/test/java/insertGenerics/TestExample42.java +++ b/src/test/java/insertGenerics/TestExample42.java @@ -52,8 +52,8 @@ public class TestExample42 { @Test public void genericTest() { - List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); - System.out.println("ClassConstraints: " + classConstraints); +// List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); +// System.out.println("ClassConstraints: " + classConstraints); // List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); // System.out.println("MethodConstraints: " + methodConstraints); diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java index 1d355288..f3fe7213 100644 --- a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java +++ b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java @@ -51,8 +51,8 @@ public class TestExample42_allInOneMethod { @Test public void genericTest() { - List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); - System.out.println("ClassConstraints: " + classConstraints); +// List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); +// System.out.println("ClassConstraints: " + classConstraints); // List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),); // System.out.println("MethodConstraints: " + methodConstraints); From e07e5e9b4225909f3013ab25afe89d6b3e9ca37b Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 29 Jan 2021 12:29:08 +0100 Subject: [PATCH 027/101] modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java --- .../java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index b7b04084..02331429 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -187,6 +187,9 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(MethodCall methodCall) { methodCall.receiver.accept(this); methodCall.getArgumentList().accept(this); + methodCall.getArgumentList() + .getArguments() + .forEach(x -> x.getType().accept(this)); } @Override From 0bc0e4c7221e663be0a32b43e162cfabf4b642c3 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 29 Jan 2021 18:03:43 +0100 Subject: [PATCH 028/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java deleted: src/test/java/insertGenerics/MethodsTest.java deleted: src/test/java/insertGenerics/TryTest.java --- .../GeneratedGenericsFinder.java | 41 +++++++-- src/test/java/insertGenerics/MethodsTest.java | 30 ------ src/test/java/insertGenerics/TryTest.java | 92 ------------------- 3 files changed, 31 insertions(+), 132 deletions(-) delete mode 100644 src/test/java/insertGenerics/MethodsTest.java delete mode 100644 src/test/java/insertGenerics/TryTest.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 5be20f2d..8e4d2a5d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -3,16 +3,13 @@ */ package de.dhbwstuttgart.bytecode.genericsGenerator; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import java.util.*; import de.dhbwstuttgart.bytecode.TPHExtractor; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import de.dhbwstuttgart.bytecode.utilities.MethodUtility; import de.dhbwstuttgart.bytecode.utilities.Resolver; @@ -142,7 +139,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); - /**/ + /* tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -156,11 +153,35 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - /**/ + if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); - System.out.println("ddd"); + */ + + List listOfClassCons = new ArrayList<>(); + for(TPHConstraint clCons: fogg.classConstraints) { + GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>()); + listOfClassCons.add(ggR); + } + + GenericGeneratorResultsForAllMethods ggRfaM = null; + for(String methID: fogg.methodConstraintsWithPosition.keySet()) { + List listOfMethAndCons = new ArrayList<>(); + List listOfGGR = new ArrayList<>(); + for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) { + GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>()); + listOfGGR.add(ggR); + } + MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR); + listOfMethAndCons.add(mac); + ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); + } + ggResult = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); + + if(ggResult != null) { + generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + } } diff --git a/src/test/java/insertGenerics/MethodsTest.java b/src/test/java/insertGenerics/MethodsTest.java deleted file mode 100644 index 91e67a1d..00000000 --- a/src/test/java/insertGenerics/MethodsTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import junit.framework.TestResult; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -public class MethodsTest { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - public static final String fileDirectory = rootDirectory + "TestGGFinder.jav"; - - @Test - public void testVisit(ClassOrInterface coi) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(new File(fileDirectory)); - SourceFile sf = compiler.sourceFiles.get(compiler.sourceFiles.keySet()); - List results = compiler.typeInference(); - - GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results); - ClassOrInterface coiHere = coi; - ggf.visit(coiHere); - //assert results.size()>0; - } -} diff --git a/src/test/java/insertGenerics/TryTest.java b/src/test/java/insertGenerics/TryTest.java deleted file mode 100644 index d0b1ae2f..00000000 --- a/src/test/java/insertGenerics/TryTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TryTest { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestGGFinder.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - //filesToTest.add(new File(rootDirectory+"fc.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); - //filesToTest.add(new File(rootDirectory+"Vector.jav")); - //filesToTest.add(new File(rootDirectory+"Generics.jav")); - //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); - //filesToTest.add(new File(rootDirectory+"Matrix.jav")); - //filesToTest.add(new File(rootDirectory+"Import.jav")); - // //filesToTest.add(new File(rootDirectory+"Faculty.jav")); - // //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); - // //filesToTest.add(new File(rootDirectory+"test.jav")); - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); -// System.out.println(ASTTypePrinter.print(sf)); -// System.out.println("---------------------------1"); -// System.out.println(ASTPrinter.print(sf)); -// System.out.println("---------------------------2"); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); -// System.out.println("---------------------------3"); - System.out.println(ASTPrinter.print(sf)); -// System.out.println("---------------------------4"); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println("---------------------------51"); - System.out.println(s); - System.out.println("---------------------------52"); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} From 604300a07edcad98ead1cc5826e120123af3d0fc Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 29 Jan 2021 18:12:44 +0100 Subject: [PATCH 029/101] modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java new file: src/test/java/insertGenerics/TestTwoArgs.java new file: src/test/java/insertGenerics/TestTwoArgs2.java new file: src/test/resources/insertGenericsJav/TestTwoArgs.jav new file: src/test/resources/insertGenericsJav/TestTwoArgs2.jav --- .../syntaxtree/AbstractASTWalker.java | 1 + src/test/java/insertGenerics/TestTwoArgs.java | 72 +++++++++++++++++++ .../java/insertGenerics/TestTwoArgs2.java | 72 +++++++++++++++++++ .../insertGenericsJav/TestTwoArgs.jav | 21 ++++++ .../insertGenericsJav/TestTwoArgs2.jav | 22 ++++++ 5 files changed, 188 insertions(+) create mode 100644 src/test/java/insertGenerics/TestTwoArgs.java create mode 100644 src/test/java/insertGenerics/TestTwoArgs2.java create mode 100644 src/test/resources/insertGenericsJav/TestTwoArgs.jav create mode 100644 src/test/resources/insertGenericsJav/TestTwoArgs2.jav diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 02331429..4f319856 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -215,6 +215,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); + aReturn.retexpr.getType().accept(this); } @Override diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java new file mode 100644 index 00000000..7513b65f --- /dev/null +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTwoArgs { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestTwoArgs.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java new file mode 100644 index 00000000..084eeb1c --- /dev/null +++ b/src/test/java/insertGenerics/TestTwoArgs2.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTwoArgs2 { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestTwoArgs2.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/resources/insertGenericsJav/TestTwoArgs.jav b/src/test/resources/insertGenericsJav/TestTwoArgs.jav new file mode 100644 index 00000000..78b274e4 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTwoArgs.jav @@ -0,0 +1,21 @@ +class TestTwoArgs { + a; + + id(b) { + var c = b; + return c; + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + } + + main(x,y) { + return m(id(x),setA(y)); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestTwoArgs2.jav b/src/test/resources/insertGenericsJav/TestTwoArgs2.jav new file mode 100644 index 00000000..a1913bfc --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTwoArgs2.jav @@ -0,0 +1,22 @@ +class TestTwoArgs { + a; + + id(b) { + var c = b; + return c; + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + return m(id(x),setA(y)); + } +} \ No newline at end of file From cd135c3962ec6497532fb8ab7be0f2852ea2e4af Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 29 Jan 2021 18:22:04 +0100 Subject: [PATCH 030/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../GeneratedGenericsFinder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 8e4d2a5d..32ea27bc 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -124,6 +124,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ConstraintsSimplierResult simplifiedConstraints = null; GenericsGeneratorResultForClass ggResult = null; + GenericsGeneratorResultForClass ggResultAlternative = null; for (int i = 0; i < listOfResultSetsList.size(); i++) { resultSet = listOfResultSetsList.get(i); @@ -139,7 +140,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); - /* + /**/ tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -153,11 +154,11 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - + /**/ if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); - */ + List listOfClassCons = new ArrayList<>(); for(TPHConstraint clCons: fogg.classConstraints) { @@ -177,11 +178,13 @@ public class GeneratedGenericsFinder implements ASTVisitor { listOfMethAndCons.add(mac); ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); } - ggResult = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); + ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); - if(ggResult != null) { - generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + if(ggResultAlternative != null) { + generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); + System.out.println(generatedGenericsForSF); } + System.out.println(ggResultAlternative); } From dc62b72f7f4ba4723747695a355370527e51a272 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 29 Jan 2021 19:36:17 +0100 Subject: [PATCH 031/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../genericsGenerator/GeneratedGenericsFinder.java | 4 ++-- .../insertGenerics/FamilyOfGeneratedGenerics.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 32ea27bc..4a2c1dee 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -167,8 +167,8 @@ public class GeneratedGenericsFinder implements ASTVisitor { } GenericGeneratorResultsForAllMethods ggRfaM = null; + List listOfMethAndCons = new ArrayList<>(); for(String methID: fogg.methodConstraintsWithPosition.keySet()) { - List listOfMethAndCons = new ArrayList<>(); List listOfGGR = new ArrayList<>(); for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) { GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>()); @@ -176,8 +176,8 @@ public class GeneratedGenericsFinder implements ASTVisitor { } MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR); listOfMethAndCons.add(mac); - ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); } + ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); if(ggResultAlternative != null) { diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index b1d2510b..92f13760 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -128,8 +128,8 @@ public class FamilyOfGeneratedGenerics { for(String curMeth: tempMethodConstraintsWithPosition.keySet()){ for(int i=0; i Date: Fri, 29 Jan 2021 20:41:43 +0100 Subject: [PATCH 032/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 4a2c1dee..7e89e755 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -6,6 +6,7 @@ package de.dhbwstuttgart.bytecode.genericsGenerator; import java.util.*; import de.dhbwstuttgart.bytecode.TPHExtractor; +import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*; import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; @@ -162,6 +163,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { List listOfClassCons = new ArrayList<>(); for(TPHConstraint clCons: fogg.classConstraints) { +// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight()); GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>()); listOfClassCons.add(ggR); } @@ -171,6 +173,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { for(String methID: fogg.methodConstraintsWithPosition.keySet()) { List listOfGGR = new ArrayList<>(); for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) { +// ExtendsConstraint ec = new ExtendsConstraint(methCons.getLeft(),methCons.getRight()); GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>()); listOfGGR.add(ggR); } From 2dc4331afb5bd9537615199d543604ed6f36e2f1 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 29 Jan 2021 20:45:54 +0100 Subject: [PATCH 033/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java --- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 7e89e755..58bc4638 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -141,7 +141,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); - /**/ + /* tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -155,11 +155,11 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - /**/ + if(ggResult != null) generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); - + */ List listOfClassCons = new ArrayList<>(); for(TPHConstraint clCons: fogg.classConstraints) { From f33002e9983f9d61aa58e7ceb475afd92eb88a2a Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 29 Jan 2021 22:48:20 +0100 Subject: [PATCH 034/101] new file: src/test/java/insertGenerics/TestTwoArgs.java new file: src/test/resources/insertGenericsJav/TestTwoArgs.jav --- src/test/java/insertGenerics/TestTwoArgs.java | 72 +++++++++++++++++++ .../insertGenericsJav/TestTwoArgs.jav | 21 ++++++ 2 files changed, 93 insertions(+) create mode 100644 src/test/java/insertGenerics/TestTwoArgs.java create mode 100644 src/test/resources/insertGenericsJav/TestTwoArgs.jav diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java new file mode 100644 index 00000000..7513b65f --- /dev/null +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -0,0 +1,72 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTwoArgs { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestTwoArgs.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/resources/insertGenericsJav/TestTwoArgs.jav b/src/test/resources/insertGenericsJav/TestTwoArgs.jav new file mode 100644 index 00000000..78b274e4 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTwoArgs.jav @@ -0,0 +1,21 @@ +class TestTwoArgs { + a; + + id(b) { + var c = b; + return c; + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + } + + main(x,y) { + return m(id(x),setA(y)); + } +} \ No newline at end of file From c6d896fa3bdf8f6ecae01776cc30dbf500e1850c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 30 Jan 2021 22:06:27 +0100 Subject: [PATCH 035/101] modified: ../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: ../../java/insertGenerics/TestGGFinder.java modified: TestGGFinder.jav --- .../GeneratedGenericsFinder.java | 8 +-- .../java/insertGenerics/TestGGFinder.java | 52 ++++++------------- .../insertGenericsJav/TestGGFinder.jav | 2 +- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 7e89e755..7a7f876e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -157,9 +157,9 @@ public class GeneratedGenericsFinder implements ASTVisitor { } /**/ - if(ggResult != null) - generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); - + if(ggResult != null) { //Hinzufuegen von Fayez ggResult + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + } List listOfClassCons = new ArrayList<>(); for(TPHConstraint clCons: fogg.classConstraints) { @@ -183,7 +183,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); - if(ggResultAlternative != null) { + if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index c517136c..3b9e378e 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -12,6 +12,9 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -22,51 +25,30 @@ import java.util.Set; public class TestGGFinder { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestGGFinder"; + @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestGGFinder.jav")); + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); } private static class TestResultSet{ } - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); return new TestResultSet(); } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } } diff --git a/src/test/resources/insertGenericsJav/TestGGFinder.jav b/src/test/resources/insertGenericsJav/TestGGFinder.jav index 9ce2691f..cc94cad5 100644 --- a/src/test/resources/insertGenericsJav/TestGGFinder.jav +++ b/src/test/resources/insertGenericsJav/TestGGFinder.jav @@ -1,4 +1,4 @@ -class TestGGFinder { +public class TestGGFinder { a; id(b) { From 9f061181384e88d21e9a701614233f6c137b3f40 Mon Sep 17 00:00:00 2001 From: AluAli Date: Sun, 31 Jan 2021 20:54:03 +0100 Subject: [PATCH 036/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../genericsGenerator/GeneratedGenericsFinder.java | 1 - .../insertGenerics/FamilyOfGeneratedGenerics.java | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index cba02170..493bf1ed 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -155,7 +155,6 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - */ if(ggResult != null) { //Hinzufuegen von Fayez ggResult diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 92f13760..3628ed1d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.objectweb.asm.Type; public class FamilyOfGeneratedGenerics { public List allConstraints = new ArrayList<>(); @@ -17,6 +18,7 @@ public class FamilyOfGeneratedGenerics { public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); + private static final String objectType = Type.getInternalName(Object.class); public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) { this.allConstraints = tphExtractor.allCons; @@ -128,8 +130,8 @@ public class FamilyOfGeneratedGenerics { for(String curMeth: tempMethodConstraintsWithPosition.keySet()){ for(int i=0; i Date: Mon, 1 Feb 2021 16:56:33 +0100 Subject: [PATCH 037/101] modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java Zusaetzliche Typvariablen weider entfernt --- .../de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 4f319856..b8c7cc5f 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -126,7 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(Assign assign) { assign.lefSide.accept(this); assign.rightSide.accept(this); - assign.rightSide.getType().accept(this); + //assign.rightSide.getType().accept(this); } @Override @@ -187,9 +187,9 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(MethodCall methodCall) { methodCall.receiver.accept(this); methodCall.getArgumentList().accept(this); - methodCall.getArgumentList() - .getArguments() - .forEach(x -> x.getType().accept(this)); + //methodCall.getArgumentList() + // .getArguments() + // .forEach(x -> x.getType().accept(this)); } @Override @@ -215,7 +215,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); - aReturn.retexpr.getType().accept(this); +// aReturn.retexpr.getType().accept(this); } @Override From 92bc3d626cade2a64fb45f70ecb2f69ec9530ff0 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 3 Feb 2021 16:55:12 +0100 Subject: [PATCH 038/101] modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java SourceFile und nameToMeth ergaenzt modified: ../../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java List getAllMethods() ergaenzty modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java variance wird uebernommen modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java setVariance gefuegt. modified: ../../../java/insertGenerics/TestTwoArgs.java modified: ../../../java/insertGenerics/TestTwoArgs2.java modified: ../../insertGenericsJav/TestTwoArgs.jav modified: ../../insertGenericsJav/TestTwoArgs2.jav --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 30 ++++++++++- .../GeneratedGenericsFinder.java | 3 +- .../dhbwstuttgart/syntaxtree/SourceFile.java | 6 +++ .../syntaxtree/factory/UnifyTypeFactory.java | 1 + .../syntaxtree/type/TypePlaceholder.java | 7 +-- src/test/java/insertGenerics/TestTwoArgs.java | 54 +++++++------------ .../java/insertGenerics/TestTwoArgs2.java | 54 +++++++------------ .../insertGenericsJav/TestTwoArgs.jav | 3 +- .../insertGenericsJav/TestTwoArgs2.jav | 9 +--- 9 files changed, 79 insertions(+), 88 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 9b895199..e3029932 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -24,8 +24,10 @@ import de.dhbwstuttgart.syntaxtree.Field; import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; +import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.statement.LocalVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl; +import de.dhbwstuttgart.syntaxtree.statement.MethodCall; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -41,6 +43,8 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; public class TPHExtractor extends AbstractASTWalker { // Alle TPHs der Felder werden iKopf der Klasse definiert // alle TPHs der Klasse: (TPH, is in Method?) + public final SourceFile sf; + public final HashMap nameToMeth; public final HashMap allTPHS = new HashMap<>(); public final List tphsClass = new ArrayList<>(); MethodAndTPH methodAndTph; @@ -54,8 +58,12 @@ public class TPHExtractor extends AbstractASTWalker { private ResultSet resultSet; private Resolver resolver; - public TPHExtractor() { - + public TPHExtractor(SourceFile sf) { + this.sf = sf; + this.nameToMeth = new HashMap<>(); + for(Method m : sf.getAllMethods()) { + this.nameToMeth.put(m.getName(), m); + } } public void setResultSet(ResultSet resultSet) { @@ -216,6 +224,24 @@ public class TPHExtractor extends AbstractASTWalker { // inLocalOrParamOrReturn = false; } + + @Override + public void visit(MethodCall methodCall) { + super.visit(methodCall); + Iterator paraIt = nameToMeth.get(methodCall.name).getParameterList().iterator(); + methodCall.getArgumentList() + .getArguments() + .forEach(x -> { + RefTypeOrTPHOrWildcardOrGeneric left = null; + RefTypeOrTPHOrWildcardOrGeneric right = null; + if ((left = x.getType()) instanceof TypePlaceholder) { + if ((right = paraIt.next().getType()) instanceof TypePlaceholder) { + methodAndTph.addPair(((TypePlaceholder)left).getName(), + ((TypePlaceholder)left).getName()); + } + } + }); + } @Override public void visit(LocalVar localVar) { // inLocalOrParamOrReturn = inMethod; diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 493bf1ed..71c44f83 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -66,7 +66,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; * */ public class GeneratedGenericsFinder implements ASTVisitor { - private final TPHExtractor tphExtractor = new TPHExtractor(); + private final TPHExtractor tphExtractor; private Collection listOfResultSets; private SourceFile sf; private List tphsClass; @@ -86,6 +86,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { public GeneratedGenericsFinder(SourceFile sf, Collection listOfResultSets) { this.sf = sf; this.listOfResultSets = listOfResultSets; + this.tphExtractor = new TPHExtractor(sf); } public GenericGenratorResultForSourceFile findGeneratedGenerics() { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java index 4a22147b..f9ec340b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -45,6 +45,12 @@ public class SourceFile extends SyntaxTreeNode{ public List getClasses() { return KlassenVektor; } + + public List getAllMethods() { + List ret = new ArrayList<>(); + getClasses().forEach(cl -> ret.addAll(cl.getMethods())); + return ret; + } @Override public void accept(ASTVisitor visitor) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index b60270b3..a698ce3b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -258,6 +258,7 @@ public class UnifyTypeFactory { ret = TypePlaceholder.fresh(new NullToken()); tphs.put(t.getName(), ret); } + ret.setVariance(t.getVariance()); return ret; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 66435b68..38932247 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -20,10 +20,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric private final String name; /** - * wird bisher nicht genutzt - * setVariance muss ggf. auskommentiert werden. + * wird im Generate Generics Teil nach der Rueckumwandlung nach dem Unify genutzt */ - int variance = 0; + private int variance = 0; /** @@ -78,11 +77,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric return name; } - /* wird bisher nicht genutzt public void setVariance(int variance) { this.variance= variance; } - */ public int getVariance() { return this.variance; diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index 7513b65f..0b2b87e3 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -12,6 +12,9 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -22,51 +25,30 @@ import java.util.Set; public class TestTwoArgs { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestTwoArgs.jav")); + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestTwoArgs"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); } private static class TestResultSet{ } - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); return new TestResultSet(); } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } } diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java index 084eeb1c..6522187a 100644 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ b/src/test/java/insertGenerics/TestTwoArgs2.java @@ -12,6 +12,9 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -22,51 +25,30 @@ import java.util.Set; public class TestTwoArgs2 { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestTwoArgs2.jav")); + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestTwoArgs2"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); } private static class TestResultSet{ } - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); return new TestResultSet(); } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } } diff --git a/src/test/resources/insertGenericsJav/TestTwoArgs.jav b/src/test/resources/insertGenericsJav/TestTwoArgs.jav index 78b274e4..84631151 100644 --- a/src/test/resources/insertGenericsJav/TestTwoArgs.jav +++ b/src/test/resources/insertGenericsJav/TestTwoArgs.jav @@ -1,4 +1,4 @@ -class TestTwoArgs { +public class TestTwoArgs { a; id(b) { @@ -13,6 +13,7 @@ class TestTwoArgs { m(x,y) { x = id(y); + return x; } main(x,y) { diff --git a/src/test/resources/insertGenericsJav/TestTwoArgs2.jav b/src/test/resources/insertGenericsJav/TestTwoArgs2.jav index a1913bfc..f8c270a7 100644 --- a/src/test/resources/insertGenericsJav/TestTwoArgs2.jav +++ b/src/test/resources/insertGenericsJav/TestTwoArgs2.jav @@ -1,4 +1,4 @@ -class TestTwoArgs { +public class TestTwoArgs2 { a; id(b) { @@ -6,17 +6,12 @@ class TestTwoArgs { return c; } - setA(x) { - a = x; - return a; - } - m(x,y) { x = id(y); return x; } main(x,y) { - return m(id(x),setA(y)); + return m(id(x),m(x,y)); } } \ No newline at end of file From f270686b3c19e5973061b9cf4e3ef286ca96af0c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 4 Feb 2021 23:58:49 +0100 Subject: [PATCH 039/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java modified: src/test/java/constraintSimplify/FamilyOfGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 66 +++++++++++++++++-- .../FamilyOfGeneratedGenerics.java | 3 +- .../bytecode/utilities/MethodAndTPH.java | 17 ++++- .../syntaxtree/AbstractASTWalker.java | 6 +- .../constraintSimplify/FamilyOfGenerics.java | 2 +- 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index e3029932..a9e2162e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -25,9 +25,11 @@ import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.statement.Assign; import de.dhbwstuttgart.syntaxtree.statement.LocalVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl; import de.dhbwstuttgart.syntaxtree.statement.MethodCall; +import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -44,7 +46,12 @@ public class TPHExtractor extends AbstractASTWalker { // Alle TPHs der Felder werden iKopf der Klasse definiert // alle TPHs der Klasse: (TPH, is in Method?) public final SourceFile sf; + + /* + * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen in der abstrakte Syntax zu + */ public final HashMap nameToMeth; + public final HashMap allTPHS = new HashMap<>(); public final List tphsClass = new ArrayList<>(); MethodAndTPH methodAndTph; @@ -193,7 +200,7 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(Method method) { inMethod = true; String id = MethodUtility.createID(resolver,method); - methodAndTph = new MethodAndTPH(id); + methodAndTph = new MethodAndTPH(id, (TypePlaceholder)method.getReturnType()); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); @@ -217,6 +224,24 @@ public class TPHExtractor extends AbstractASTWalker { inMethod = true; } + @Override + public void visit(Assign assign) { + super.visit(assign); + RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType; + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (right instanceof TypePlaceholder) { + methodAndTph.addPair(allPairs.stream().filter( + p -> (p.getLeft() instanceof TypePlaceholder && + p.getRight() instanceof TypePlaceholder) && + ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && + ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) + ).findFirst() + .get()); + } + } + } + @Override public void visit(LocalVarDecl localVarDecl) { // inLocalOrParamOrReturn = inMethod; @@ -228,20 +253,47 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(MethodCall methodCall) { super.visit(methodCall); + if (nameToMeth.keySet().contains(methodCall.name)) {//Method-call of a method in the actuial Sourcefile Iterator paraIt = nameToMeth.get(methodCall.name).getParameterList().iterator(); methodCall.getArgumentList() .getArguments() .forEach(x -> { - RefTypeOrTPHOrWildcardOrGeneric left = null; - RefTypeOrTPHOrWildcardOrGeneric right = null; - if ((left = x.getType()) instanceof TypePlaceholder) { - if ((right = paraIt.next().getType()) instanceof TypePlaceholder) { - methodAndTph.addPair(((TypePlaceholder)left).getName(), - ((TypePlaceholder)left).getName()); + RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next().getType()).resolvedType; + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (right instanceof TypePlaceholder) { + methodAndTph.addPair(allPairs.stream().filter( + p -> (p.getLeft() instanceof TypePlaceholder && + p.getRight() instanceof TypePlaceholder) && + ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && + ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) + ).findFirst() + .get()); } } }); + } } + + @Override + public void visit(Return aReturn) { + super.visit(aReturn); + RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (right instanceof TypePlaceholder) { + methodAndTph.addPair(allPairs.stream().filter( + p -> (p.getLeft() instanceof TypePlaceholder && + p.getRight() instanceof TypePlaceholder) && + ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && + ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) + ).findFirst() + .get()); + } + } + } + + @Override public void visit(LocalVar localVar) { // inLocalOrParamOrReturn = inMethod; diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 3628ed1d..4859ab63 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -62,6 +62,7 @@ public class FamilyOfGeneratedGenerics { public static List getMethodConstraints(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); + //List methodConstraints1 = listOfMethodsAndTph. for (MethodConstraint cons: methodConstraints1) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); @@ -249,7 +250,7 @@ public class FamilyOfGeneratedGenerics { } return tempMC; } - + /** * Def. FGG: zweite Zeile von cs_m diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index d8eed39c..de434ebb 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -15,9 +15,16 @@ public class MethodAndTPH { private final ArrayList> pairs = new ArrayList<>(); // tphs of local variables and parameters private final ArrayList localTphs = new ArrayList<>(); + private final ArrayList> basePairs = new ArrayList<>(); + + /* + * Returntyp der zugehoerigen Methode in er abstrakten Syntax + */ + TypePlaceholder returnType; - public MethodAndTPH(String name) { + public MethodAndTPH(String name, TypePlaceholder returnType) { this.id = name; + this.returnType = returnType; } public ArrayList getTphs() { @@ -39,4 +46,12 @@ public class MethodAndTPH { return localTphs; } + public void addPair(ResultPair p) { + basePairs.add(p); + } + + public TypePlaceholder getReturnType() { + return returnType; + } + } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index b8c7cc5f..9d0d29b0 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -126,7 +126,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(Assign assign) { assign.lefSide.accept(this); assign.rightSide.accept(this); - //assign.rightSide.getType().accept(this); } @Override @@ -187,11 +186,9 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(MethodCall methodCall) { methodCall.receiver.accept(this); methodCall.getArgumentList().accept(this); - //methodCall.getArgumentList() - // .getArguments() - // .forEach(x -> x.getType().accept(this)); } + @Override public void visit(NewClass methodCall) { visit((MethodCall) methodCall); @@ -215,7 +212,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); -// aReturn.retexpr.getType().accept(this); } @Override diff --git a/src/test/java/constraintSimplify/FamilyOfGenerics.java b/src/test/java/constraintSimplify/FamilyOfGenerics.java index e5c9ad13..01b204b6 100644 --- a/src/test/java/constraintSimplify/FamilyOfGenerics.java +++ b/src/test/java/constraintSimplify/FamilyOfGenerics.java @@ -24,7 +24,7 @@ public class FamilyOfGenerics { public void generateBC() throws Exception { SourceFile sf = generateAST(); PositionFinder.getPositionOfTPH(sf, null); - TPHExtractor tphExtractor = new TPHExtractor(); + TPHExtractor tphExtractor = new TPHExtractor(sf); List results = new ArrayList(); GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results); } From 5980f1c7b8731cc7f74d28aa31e9e361124bc4aa Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 5 Feb 2021 22:37:39 +0100 Subject: [PATCH 040/101] modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: ../../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: ../../../../main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: ../../../../main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java modified: ../../../java/constraintSimplify/FamilyOfGenerics.java modified: ../../../java/insertGenerics/TestTPHsAndGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 84 +++++++++---- .../GeneratedGenericsFinder.java | 2 +- .../FamilyOfGeneratedGenerics.java | 23 +++- .../bytecode/utilities/MethodAndTPH.java | 4 + .../constraintSimplify/FamilyOfGenerics.java | 2 +- .../insertGenerics/TestTPHsAndGenerics.java | 112 ++++++++---------- 6 files changed, 135 insertions(+), 92 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index a9e2162e..4a5e9ed8 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; @@ -26,10 +27,16 @@ import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.statement.Assign; +import de.dhbwstuttgart.syntaxtree.statement.AssignToField; +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; +import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver; +import de.dhbwstuttgart.syntaxtree.statement.FieldVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl; import de.dhbwstuttgart.syntaxtree.statement.MethodCall; import de.dhbwstuttgart.syntaxtree.statement.Return; +import de.dhbwstuttgart.syntaxtree.statement.Statement; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -45,13 +52,17 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; public class TPHExtractor extends AbstractASTWalker { // Alle TPHs der Felder werden iKopf der Klasse definiert // alle TPHs der Klasse: (TPH, is in Method?) - public final SourceFile sf; /* - * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen in der abstrakte Syntax zu + * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu */ - public final HashMap nameToMeth; + public HashMap nameToMeth; + + /* + * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu + */ + public HashMap nameToField; public final HashMap allTPHS = new HashMap<>(); public final List tphsClass = new ArrayList<>(); MethodAndTPH methodAndTph; @@ -65,12 +76,8 @@ public class TPHExtractor extends AbstractASTWalker { private ResultSet resultSet; private Resolver resolver; - public TPHExtractor(SourceFile sf) { - this.sf = sf; - this.nameToMeth = new HashMap<>(); - for(Method m : sf.getAllMethods()) { - this.nameToMeth.put(m.getName(), m); - } + public TPHExtractor() { + } public void setResultSet(ResultSet resultSet) { @@ -214,6 +221,28 @@ public class TPHExtractor extends AbstractASTWalker { ListOfMethodsAndTph.add(methodAndTph); } + @Override + public void visit(ClassOrInterface classOrInterface) { + Optional optInitialConstructor = classOrInterface.getfieldInitializations(); + this.nameToField = new HashMap<>(); + if (optInitialConstructor.isPresent()) { + classOrInterface.getfieldInitializations() + .get() + .block + .statements + .stream() + .filter(s -> s instanceof Assign) + .forEach(as -> + this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName, ((Assign)as).rightSide)); + } + + this.nameToMeth = new HashMap<>(); + for(Method m : classOrInterface.getMethods()) { + this.nameToMeth.put(m.getName(), m); + } + super.visit(classOrInterface); + } + @Override public void visit(Constructor cons) { inMethod = false; @@ -252,26 +281,37 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(MethodCall methodCall) { + String fieldOrMethName; super.visit(methodCall); - if (nameToMeth.keySet().contains(methodCall.name)) {//Method-call of a method in the actuial Sourcefile - Iterator paraIt = nameToMeth.get(methodCall.name).getParameterList().iterator(); - methodCall.getArgumentList() - .getArguments() - .forEach(x -> { - RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next().getType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { - if (right instanceof TypePlaceholder) { - methodAndTph.addPair(allPairs.stream().filter( + if (nameToMeth.keySet().contains(fieldOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile + || (methodCall.name.equals("apply") && + (methodCall.receiver instanceof ExpressionReceiver) && + (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) && + nameToField.keySet().contains(fieldOrMethName=((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) + ) + ) + { + Iterator paraIt = + methodCall.name.equals("apply") + ? ((LambdaExpression)nameToField.get(fieldOrMethName)).params.iterator() + : nameToMeth.get(methodCall.name).getParameterList().iterator(); + methodCall.getArgumentList() + .getArguments() + .forEach(x -> { + RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next().getType()).resolvedType; + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (right instanceof TypePlaceholder) { + methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && p.getRight() instanceof TypePlaceholder) && ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) ).findFirst() .get()); - } - } - }); + } + } + }); } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 71c44f83..6a89bde3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -86,7 +86,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { public GeneratedGenericsFinder(SourceFile sf, Collection listOfResultSets) { this.sf = sf; this.listOfResultSets = listOfResultSets; - this.tphExtractor = new TPHExtractor(sf); + this.tphExtractor = new TPHExtractor(); } public GenericGenratorResultForSourceFile findGeneratedGenerics() { diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 4859ab63..77d17f00 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -4,10 +4,14 @@ import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.result.ResultPair; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; + import org.objectweb.asm.Type; public class FamilyOfGeneratedGenerics { @@ -15,7 +19,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>> posOfTPHs = new HashMap<>(); public List classConstraints = new ArrayList<>(); - public List methodConstraints = new ArrayList<>(); + //public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); private static final String objectType = Type.getInternalName(Object.class); @@ -24,7 +28,7 @@ public class FamilyOfGeneratedGenerics { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); - this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); + //this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, null, tphExtractor.ListOfMethodsAndTph); this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); } @@ -59,10 +63,19 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraints(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { + public static List getMethodConstraints(List cs, + List cs_cl, + HashMap>> posOfTphs, + ArrayList> methodConstraints1Pairs, + List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); - //List methodConstraints1 = listOfMethodsAndTph. + + List methodConstraints1prime = + methodConstraints1Pairs.stream() + .map(p -> new MethodConstraint(p.getLeft().getName(), p.getRight().getName(), Relation.EXTENDS)) + .collect(Collectors.toList()); + for (MethodConstraint cons: methodConstraints1) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); @@ -123,7 +136,7 @@ public class FamilyOfGeneratedGenerics { } } } - listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); + listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod, method.getBasePairs(),listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index de434ebb..e26eca10 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -53,5 +53,9 @@ public class MethodAndTPH { public TypePlaceholder getReturnType() { return returnType; } + + public ArrayList> getBasePairs() { + return basePairs; + } } diff --git a/src/test/java/constraintSimplify/FamilyOfGenerics.java b/src/test/java/constraintSimplify/FamilyOfGenerics.java index 01b204b6..e5c9ad13 100644 --- a/src/test/java/constraintSimplify/FamilyOfGenerics.java +++ b/src/test/java/constraintSimplify/FamilyOfGenerics.java @@ -24,7 +24,7 @@ public class FamilyOfGenerics { public void generateBC() throws Exception { SourceFile sf = generateAST(); PositionFinder.getPositionOfTPH(sf, null); - TPHExtractor tphExtractor = new TPHExtractor(sf); + TPHExtractor tphExtractor = new TPHExtractor(); List results = new ArrayList(); GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results); } diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index ed5016c7..e49ed344 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -1,72 +1,58 @@ package insertGenerics; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import org.junit.Test; + import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; + import de.dhbwstuttgart.core.JavaTXCompiler; + import de.dhbwstuttgart.syntaxtree.SourceFile; + import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; + import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; + import de.dhbwstuttgart.typedeployment.TypeInsert; + import de.dhbwstuttgart.typedeployment.TypeInsertFactory; + import de.dhbwstuttgart.typeinference.result.ResultSet; + import org.junit.Test; + + import java.io.File; + import java.io.IOException; + import java.lang.reflect.InvocationTargetException; + import java.net.URL; + import java.net.URLClassLoader; + import java.nio.charset.Charset; + import java.nio.charset.StandardCharsets; + import java.nio.file.Files; + import java.nio.file.Paths; + import java.util.HashSet; + import java.util.List; + import java.util.Set; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; public class TestTPHsAndGenerics { - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestTPHsAndGenerics"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); + } - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestTPHSAndGenerics.jav")); - } + private static class TestResultSet{ - private static class TestResultSet{ + } - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + /* + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + */ + return new TestResultSet(); + + } + } From 5b7fec660dca603c98de4ec4372fdbb25766f9d9 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 6 Feb 2021 09:51:42 +0100 Subject: [PATCH 041/101] modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 4a5e9ed8..6bc8b6d2 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -62,7 +62,7 @@ public class TPHExtractor extends AbstractASTWalker { /* * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu */ - public HashMap nameToField; + public HashMap nameToField; public final HashMap allTPHS = new HashMap<>(); public final List tphsClass = new ArrayList<>(); MethodAndTPH methodAndTph; @@ -233,7 +233,8 @@ public class TPHExtractor extends AbstractASTWalker { .stream() .filter(s -> s instanceof Assign) .forEach(as -> - this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName, ((Assign)as).rightSide)); + this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName, + ((AssignToField)(((Assign)as).lefSide)).getType())) ; } this.nameToMeth = new HashMap<>(); @@ -287,14 +288,19 @@ public class TPHExtractor extends AbstractASTWalker { || (methodCall.name.equals("apply") && (methodCall.receiver instanceof ExpressionReceiver) && (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) && - nameToField.keySet().contains(fieldOrMethName=((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) + nameToField.keySet().contains(fieldOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) ) ) { - Iterator paraIt = + Iterator paraIt = methodCall.name.equals("apply") - ? ((LambdaExpression)nameToField.get(fieldOrMethName)).params.iterator() - : nameToMeth.get(methodCall.name).getParameterList().iterator(); + ? (FuNTYPE)(resultSet.resolveType((nameToField.get(fieldOrMethName))).resolvedType).GETARGTYPES + : nameToMeth.get(methodCall.name) + .getParameterList() + .getFormalparalist() + .stream() + .map(p -> p.getType()) + .iterator(); methodCall.getArgumentList() .getArguments() .forEach(x -> { From 5fb2d57d3bef0b53472ec3fcaaf96077f2abe4dc Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sun, 7 Feb 2021 09:47:25 +0100 Subject: [PATCH 042/101] modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java --- .../de/dhbwstuttgart/bytecode/TPHExtractor.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 6bc8b6d2..7729eb88 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -287,14 +287,17 @@ public class TPHExtractor extends AbstractASTWalker { if (nameToMeth.keySet().contains(fieldOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile || (methodCall.name.equals("apply") && (methodCall.receiver instanceof ExpressionReceiver) && - (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) && - nameToField.keySet().contains(fieldOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) + ((((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) && + nameToField.keySet().contains(fieldOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) + || (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) && + nameToField.keySet().contains(fieldOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name) ) - ) + ) + ) { Iterator paraIt = methodCall.name.equals("apply") - ? (FuNTYPE)(resultSet.resolveType((nameToField.get(fieldOrMethName))).resolvedType).GETARGTYPES + ? ((RefType)(resultSet.resolveType((nameToField.get(fieldOrMethName))).resolvedType)).getParaList().iterator() : nameToMeth.get(methodCall.name) .getParameterList() .getFormalparalist() @@ -305,7 +308,7 @@ public class TPHExtractor extends AbstractASTWalker { .getArguments() .forEach(x -> { RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next().getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType; if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( From 905dfd8a27e2e2c4b3aa79d15325460aaa75ce80 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 8 Feb 2021 00:15:25 +0100 Subject: [PATCH 043/101] modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: ../../../../main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 29 +++++++++++++------ .../FamilyOfGeneratedGenerics.java | 4 +-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 7729eb88..d13ef5f4 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -69,6 +69,7 @@ public class TPHExtractor extends AbstractASTWalker { Boolean inMethod = false; boolean inLocalOrParamOrReturn = false; + Boolean inLambdaExpression = false; public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); final ArrayList> allPairs = new ArrayList<>(); @@ -254,12 +255,19 @@ public class TPHExtractor extends AbstractASTWalker { inMethod = true; } + @Override + public void visit(LambdaExpression lambdaExpression) { + inLambdaExpression = true; + super.visit(lambdaExpression); + inLambdaExpression = false; + } + @Override public void visit(Assign assign) { super.visit(assign); RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && @@ -292,6 +300,7 @@ public class TPHExtractor extends AbstractASTWalker { || (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) && nameToField.keySet().contains(fieldOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name) ) + //LOKALE VARIABLEN MUESSE NOCH IN nameToField EINGETRAGEN WERDEN ) ) { @@ -309,7 +318,7 @@ public class TPHExtractor extends AbstractASTWalker { .forEach(x -> { RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && @@ -327,19 +336,21 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(Return aReturn) { super.visit(aReturn); - RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { - if (right instanceof TypePlaceholder) { - methodAndTph.addPair(allPairs.stream().filter( + if (!inLambdaExpression) { + RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; + if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { + if (right instanceof TypePlaceholder) { + methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && p.getRight() instanceof TypePlaceholder) && ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) ).findFirst() .get()); - } - } + } + } + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 77d17f00..9de58c59 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -69,9 +69,9 @@ public class FamilyOfGeneratedGenerics { ArrayList> methodConstraints1Pairs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); - List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); + //List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); - List methodConstraints1prime = + List methodConstraints1 = methodConstraints1Pairs.stream() .map(p -> new MethodConstraint(p.getLeft().getName(), p.getRight().getName(), Relation.EXTENDS)) .collect(Collectors.toList()); From f2d6dae4c77dde63aec955459131ddf54d5c6916 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 16 Feb 2021 15:29:24 +0100 Subject: [PATCH 044/101] Letzer Stand mit Pair Bildug waehrend des Typvars sammeln --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 47 ++++++++++++++----- .../GeneratedGenericsFinder.java | 16 ++++--- .../FamilyOfGeneratedGenerics.java | 3 +- .../bytecode/utilities/MethodAndTPH.java | 7 +-- .../syntaxtree/AbstractASTWalker.java | 3 ++ .../de/dhbwstuttgart/syntaxtree/Method.java | 10 +++- .../typeinference/typeAlgo/TYPE.java | 4 +- 7 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index d13ef5f4..77d51b64 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -60,9 +60,17 @@ public class TPHExtractor extends AbstractASTWalker { /* - * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu + * ordnet den Fieldnamen ihre jeweiligen Lambda-respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu */ public HashMap nameToField; + + /* + * ordnet den Variablennamen ihre jeweiligen Lambda-Respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu + * wird in jeder Methode neu initialisiert + * Einträge werden nicht geloescht, da das Java-Programm korrekt ist und in umgebenden Bloecken nicht die gleichen Variablen vorkommen können + */ + public HashMap nameToLocalVar; + public final HashMap allTPHS = new HashMap<>(); public final List tphsClass = new ArrayList<>(); MethodAndTPH methodAndTph; @@ -207,8 +215,9 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(Method method) { inMethod = true; + this.nameToLocalVar = new HashMap<>(); String id = MethodUtility.createID(resolver,method); - methodAndTph = new MethodAndTPH(id, (TypePlaceholder)method.getReturnType()); + methodAndTph = new MethodAndTPH(id, method.getReturnType()); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); @@ -232,7 +241,7 @@ public class TPHExtractor extends AbstractASTWalker { .block .statements .stream() - .filter(s -> s instanceof Assign) + .filter(s -> s instanceof Assign && ((Assign)s).rightSide instanceof LambdaExpression) .forEach(as -> this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName, ((AssignToField)(((Assign)as).lefSide)).getType())) ; @@ -247,8 +256,10 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(Constructor cons) { + this.nameToLocalVar = new HashMap<>(); inMethod = false; //super.visit(cons); + cons.getParameterList().accept(this); if(cons.block != null) cons.block.accept(this); @@ -258,6 +269,12 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(LambdaExpression lambdaExpression) { inLambdaExpression = true; + lambdaExpression.params.getFormalparalist().forEach(param -> { + RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(param.getType()).resolvedType; + if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) { + this.nameToLocalVar.put(param.getName(), param.getType()); + } + }); super.visit(lambdaExpression); inLambdaExpression = false; } @@ -267,7 +284,7 @@ public class TPHExtractor extends AbstractASTWalker { super.visit(assign); RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && @@ -284,21 +301,25 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(LocalVarDecl localVarDecl) { // inLocalOrParamOrReturn = inMethod; super.visit(localVarDecl); + RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(localVarDecl.getType()).resolvedType; + if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) { + this.nameToLocalVar.put(localVarDecl.getName(), localVarDecl.getType()); + } // inLocalOrParamOrReturn = false; } @Override public void visit(MethodCall methodCall) { - String fieldOrMethName; + String fieldLocalvarOrMethName; super.visit(methodCall); - if (nameToMeth.keySet().contains(fieldOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile + if (nameToMeth.keySet().contains(fieldLocalvarOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile || (methodCall.name.equals("apply") && (methodCall.receiver instanceof ExpressionReceiver) && ((((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) && - nameToField.keySet().contains(fieldOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) + nameToField.keySet().contains(fieldLocalvarOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) || (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) && - nameToField.keySet().contains(fieldOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name) + nameToLocalVar.keySet().contains(fieldLocalvarOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name) ) //LOKALE VARIABLEN MUESSE NOCH IN nameToField EINGETRAGEN WERDEN ) @@ -306,8 +327,10 @@ public class TPHExtractor extends AbstractASTWalker { { Iterator paraIt = methodCall.name.equals("apply") - ? ((RefType)(resultSet.resolveType((nameToField.get(fieldOrMethName))).resolvedType)).getParaList().iterator() - : nameToMeth.get(methodCall.name) + ? (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) + ? ((RefType)(resultSet.resolveType((nameToField.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator() + : ((RefType)(resultSet.resolveType((nameToLocalVar.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator() + : nameToMeth.get(fieldLocalvarOrMethName) .getParameterList() .getFormalparalist() .stream() @@ -318,7 +341,7 @@ public class TPHExtractor extends AbstractASTWalker { .forEach(x -> { RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && @@ -339,7 +362,7 @@ public class TPHExtractor extends AbstractASTWalker { if (!inLambdaExpression) { RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 6a89bde3..8366368f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -142,7 +142,8 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); - /* + ///* + //Fayez Ansatz Anfang tphsClass = tphExtractor.tphsClass; //PL 2020-01-15 //Es muss ggResult aus fogg gebildet werden @@ -156,13 +157,15 @@ public class GeneratedGenericsFinder implements ASTVisitor { addMethodConstraints(simplifiedConstraints, ggResult, m); } - */ + if(ggResult != null) { //Hinzufuegen von Fayez ggResult - //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); } - - + // Fayez Ansatz Ende + //*/ + + //Ali Ansatz Anfang List listOfClassCons = new ArrayList<>(); for(TPHConstraint clCons: fogg.classConstraints) { // ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight()); @@ -186,10 +189,11 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult - generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } System.out.println(ggResultAlternative); + //Ali Ansatz Ende } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 9de58c59..100dd1a2 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -69,7 +69,8 @@ public class FamilyOfGeneratedGenerics { ArrayList> methodConstraints1Pairs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); - //List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); + //List methodConstraints1 = + typeOfTheMethodInClSigma(cs, posOfTphs); List methodConstraints1 = methodConstraints1Pairs.stream() diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index e26eca10..570ef720 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.ResultPair; @@ -20,9 +21,9 @@ public class MethodAndTPH { /* * Returntyp der zugehoerigen Methode in er abstrakten Syntax */ - TypePlaceholder returnType; + RefTypeOrTPHOrWildcardOrGeneric returnType; - public MethodAndTPH(String name, TypePlaceholder returnType) { + public MethodAndTPH(String name, RefTypeOrTPHOrWildcardOrGeneric returnType) { this.id = name; this.returnType = returnType; } @@ -50,7 +51,7 @@ public class MethodAndTPH { basePairs.add(p); } - public TypePlaceholder getReturnType() { + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { return returnType; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 9d0d29b0..0cbad897 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -126,6 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(Assign assign) { assign.lefSide.accept(this); assign.rightSide.accept(this); + assign.rightSide.getType().accept((ASTVisitor) this); } @Override @@ -186,6 +187,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ public void visit(MethodCall methodCall) { methodCall.receiver.accept(this); methodCall.getArgumentList().accept(this); + methodCall.getArgumentList().getArguments().forEach(a -> a.getType().accept((ASTVisitor) this)); } @@ -212,6 +214,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); + aReturn.getType().accept((ASTVisitor) this); } @Override diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java index 13e36b7b..412fbd97 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java @@ -31,8 +31,14 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope private ExceptionList exceptionlist; private GenericDeclarationList generics; private final RefTypeOrTPHOrWildcardOrGeneric returnType; - public final Boolean isInherited; - + public final Boolean isInherited; + + /* + * its Constraints + * eingefuegt PL 2021-02-15 + */ + public final ConstraintSet constraints = new ConstraintSet(); + public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) { super(offset); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index c84fa143..685ac9f6 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -32,8 +32,10 @@ public class TYPE { private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) { ConstraintSet ret = new ConstraintSet(); + ConstraintSet methConstrains; for(Method m : cl.getMethods()){ - ret.addAll(getConstraintsMethod(m,info, cl)); + ret.addAll(methConstrains = getConstraintsMethod(m,info, cl)); + m.constraints.addAll(methConstrains); } for(Constructor m : cl.getConstructors()){ ret.addAll(getConstraintsConstructor(m,info, cl)); From bbdf220324a5b65ccabc1ea2c3e961a1e77045f7 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 16 Feb 2021 16:27:17 +0100 Subject: [PATCH 045/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/Method.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java Pairs sammeln rueckgaengig gemacht --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 165 +----------------- .../GeneratedGenericsFinder.java | 3 +- .../FamilyOfGeneratedGenerics.java | 27 +-- .../bytecode/utilities/MethodAndTPH.java | 22 +-- .../de/dhbwstuttgart/syntaxtree/Method.java | 10 +- .../dhbwstuttgart/syntaxtree/SourceFile.java | 6 - .../typeinference/typeAlgo/TYPE.java | 4 +- 7 files changed, 13 insertions(+), 224 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 77d51b64..9b895199 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -9,7 +9,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; @@ -25,18 +24,8 @@ import de.dhbwstuttgart.syntaxtree.Field; import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.statement.Assign; -import de.dhbwstuttgart.syntaxtree.statement.AssignToField; -import de.dhbwstuttgart.syntaxtree.statement.Expression; -import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; -import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver; -import de.dhbwstuttgart.syntaxtree.statement.FieldVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl; -import de.dhbwstuttgart.syntaxtree.statement.MethodCall; -import de.dhbwstuttgart.syntaxtree.statement.Return; -import de.dhbwstuttgart.syntaxtree.statement.Statement; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -52,32 +41,12 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; public class TPHExtractor extends AbstractASTWalker { // Alle TPHs der Felder werden iKopf der Klasse definiert // alle TPHs der Klasse: (TPH, is in Method?) - - /* - * ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu - */ - public HashMap nameToMeth; - - - /* - * ordnet den Fieldnamen ihre jeweiligen Lambda-respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu - */ - public HashMap nameToField; - - /* - * ordnet den Variablennamen ihre jeweiligen Lambda-Respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu - * wird in jeder Methode neu initialisiert - * Einträge werden nicht geloescht, da das Java-Programm korrekt ist und in umgebenden Bloecken nicht die gleichen Variablen vorkommen können - */ - public HashMap nameToLocalVar; - public final HashMap allTPHS = new HashMap<>(); public final List tphsClass = new ArrayList<>(); MethodAndTPH methodAndTph; Boolean inMethod = false; boolean inLocalOrParamOrReturn = false; - Boolean inLambdaExpression = false; public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); final ArrayList> allPairs = new ArrayList<>(); @@ -86,7 +55,7 @@ public class TPHExtractor extends AbstractASTWalker { private Resolver resolver; public TPHExtractor() { - + } public void setResultSet(ResultSet resultSet) { @@ -215,9 +184,8 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(Method method) { inMethod = true; - this.nameToLocalVar = new HashMap<>(); String id = MethodUtility.createID(resolver,method); - methodAndTph = new MethodAndTPH(id, method.getReturnType()); + methodAndTph = new MethodAndTPH(id); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); @@ -231,152 +199,23 @@ public class TPHExtractor extends AbstractASTWalker { ListOfMethodsAndTph.add(methodAndTph); } - @Override - public void visit(ClassOrInterface classOrInterface) { - Optional optInitialConstructor = classOrInterface.getfieldInitializations(); - this.nameToField = new HashMap<>(); - if (optInitialConstructor.isPresent()) { - classOrInterface.getfieldInitializations() - .get() - .block - .statements - .stream() - .filter(s -> s instanceof Assign && ((Assign)s).rightSide instanceof LambdaExpression) - .forEach(as -> - this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName, - ((AssignToField)(((Assign)as).lefSide)).getType())) ; - } - - this.nameToMeth = new HashMap<>(); - for(Method m : classOrInterface.getMethods()) { - this.nameToMeth.put(m.getName(), m); - } - super.visit(classOrInterface); - } - @Override public void visit(Constructor cons) { - this.nameToLocalVar = new HashMap<>(); inMethod = false; //super.visit(cons); - cons.getParameterList().accept(this); if(cons.block != null) cons.block.accept(this); inMethod = true; } - @Override - public void visit(LambdaExpression lambdaExpression) { - inLambdaExpression = true; - lambdaExpression.params.getFormalparalist().forEach(param -> { - RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(param.getType()).resolvedType; - if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) { - this.nameToLocalVar.put(param.getName(), param.getType()); - } - }); - super.visit(lambdaExpression); - inLambdaExpression = false; - } - - @Override - public void visit(Assign assign) { - super.visit(assign); - RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { - if (right instanceof TypePlaceholder) { - methodAndTph.addPair(allPairs.stream().filter( - p -> (p.getLeft() instanceof TypePlaceholder && - p.getRight() instanceof TypePlaceholder) && - ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && - ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) - ).findFirst() - .get()); - } - } - } - @Override public void visit(LocalVarDecl localVarDecl) { // inLocalOrParamOrReturn = inMethod; super.visit(localVarDecl); - RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(localVarDecl.getType()).resolvedType; - if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) { - this.nameToLocalVar.put(localVarDecl.getName(), localVarDecl.getType()); - } // inLocalOrParamOrReturn = false; } - - @Override - public void visit(MethodCall methodCall) { - String fieldLocalvarOrMethName; - super.visit(methodCall); - if (nameToMeth.keySet().contains(fieldLocalvarOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile - || (methodCall.name.equals("apply") && - (methodCall.receiver instanceof ExpressionReceiver) && - ((((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) && - nameToField.keySet().contains(fieldLocalvarOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName) - || (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) && - nameToLocalVar.keySet().contains(fieldLocalvarOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name) - ) - //LOKALE VARIABLEN MUESSE NOCH IN nameToField EINGETRAGEN WERDEN - ) - ) - { - Iterator paraIt = - methodCall.name.equals("apply") - ? (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) - ? ((RefType)(resultSet.resolveType((nameToField.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator() - : ((RefType)(resultSet.resolveType((nameToLocalVar.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator() - : nameToMeth.get(fieldLocalvarOrMethName) - .getParameterList() - .getFormalparalist() - .stream() - .map(p -> p.getType()) - .iterator(); - methodCall.getArgumentList() - .getArguments() - .forEach(x -> { - RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { - if (right instanceof TypePlaceholder) { - methodAndTph.addPair(allPairs.stream().filter( - p -> (p.getLeft() instanceof TypePlaceholder && - p.getRight() instanceof TypePlaceholder) && - ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && - ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) - ).findFirst() - .get()); - } - } - }); - } - } - - @Override - public void visit(Return aReturn) { - super.visit(aReturn); - if (!inLambdaExpression) { - RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { - if (right instanceof TypePlaceholder) { - methodAndTph.addPair(allPairs.stream().filter( - p -> (p.getLeft() instanceof TypePlaceholder && - p.getRight() instanceof TypePlaceholder) && - ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && - ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) - ).findFirst() - .get()); - } - } - } - } - - @Override public void visit(LocalVar localVar) { // inLocalOrParamOrReturn = inMethod; diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 8366368f..a73d2b3c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -66,7 +66,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; * */ public class GeneratedGenericsFinder implements ASTVisitor { - private final TPHExtractor tphExtractor; + private final TPHExtractor tphExtractor = new TPHExtractor(); private Collection listOfResultSets; private SourceFile sf; private List tphsClass; @@ -86,7 +86,6 @@ public class GeneratedGenericsFinder implements ASTVisitor { public GeneratedGenericsFinder(SourceFile sf, Collection listOfResultSets) { this.sf = sf; this.listOfResultSets = listOfResultSets; - this.tphExtractor = new TPHExtractor(); } public GenericGenratorResultForSourceFile findGeneratedGenerics() { diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 100dd1a2..3628ed1d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -4,14 +4,10 @@ import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.result.ResultPair; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; - import org.objectweb.asm.Type; public class FamilyOfGeneratedGenerics { @@ -19,7 +15,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>> posOfTPHs = new HashMap<>(); public List classConstraints = new ArrayList<>(); - //public List methodConstraints = new ArrayList<>(); + public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); private static final String objectType = Type.getInternalName(Object.class); @@ -28,7 +24,7 @@ public class FamilyOfGeneratedGenerics { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); - //this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, null, tphExtractor.ListOfMethodsAndTph); + this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); } @@ -63,20 +59,9 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraints(List cs, - List cs_cl, - HashMap>> posOfTphs, - ArrayList> methodConstraints1Pairs, - List listOfMethodsAndTph) { + public static List getMethodConstraints(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); - //List methodConstraints1 = - typeOfTheMethodInClSigma(cs, posOfTphs); - - List methodConstraints1 = - methodConstraints1Pairs.stream() - .map(p -> new MethodConstraint(p.getLeft().getName(), p.getRight().getName(), Relation.EXTENDS)) - .collect(Collectors.toList()); - + List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); @@ -137,7 +122,7 @@ public class FamilyOfGeneratedGenerics { } } } - listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod, method.getBasePairs(),listOfMethodsAndTph); + listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); } } @@ -264,7 +249,7 @@ public class FamilyOfGeneratedGenerics { } return tempMC; } - + /** * Def. FGG: zweite Zeile von cs_m diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index 570ef720..d8eed39c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.ResultPair; @@ -16,16 +15,9 @@ public class MethodAndTPH { private final ArrayList> pairs = new ArrayList<>(); // tphs of local variables and parameters private final ArrayList localTphs = new ArrayList<>(); - private final ArrayList> basePairs = new ArrayList<>(); - - /* - * Returntyp der zugehoerigen Methode in er abstrakten Syntax - */ - RefTypeOrTPHOrWildcardOrGeneric returnType; - public MethodAndTPH(String name, RefTypeOrTPHOrWildcardOrGeneric returnType) { + public MethodAndTPH(String name) { this.id = name; - this.returnType = returnType; } public ArrayList getTphs() { @@ -47,16 +39,4 @@ public class MethodAndTPH { return localTphs; } - public void addPair(ResultPair p) { - basePairs.add(p); - } - - public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { - return returnType; - } - - public ArrayList> getBasePairs() { - return basePairs; - } - } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java index 412fbd97..13e36b7b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java @@ -31,14 +31,8 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope private ExceptionList exceptionlist; private GenericDeclarationList generics; private final RefTypeOrTPHOrWildcardOrGeneric returnType; - public final Boolean isInherited; - - /* - * its Constraints - * eingefuegt PL 2021-02-15 - */ - public final ConstraintSet constraints = new ConstraintSet(); - + public final Boolean isInherited; + public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) { super(offset); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java index f9ec340b..4a22147b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -45,12 +45,6 @@ public class SourceFile extends SyntaxTreeNode{ public List getClasses() { return KlassenVektor; } - - public List getAllMethods() { - List ret = new ArrayList<>(); - getClasses().forEach(cl -> ret.addAll(cl.getMethods())); - return ret; - } @Override public void accept(ASTVisitor visitor) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 685ac9f6..c84fa143 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -32,10 +32,8 @@ public class TYPE { private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) { ConstraintSet ret = new ConstraintSet(); - ConstraintSet methConstrains; for(Method m : cl.getMethods()){ - ret.addAll(methConstrains = getConstraintsMethod(m,info, cl)); - m.constraints.addAll(methConstrains); + ret.addAll(getConstraintsMethod(m,info, cl)); } for(Constructor m : cl.getConstructors()){ ret.addAll(getConstraintsConstructor(m,info, cl)); From ab99889c3c25861499ce4871e9310088228ff566 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 16 Feb 2021 16:52:53 +0100 Subject: [PATCH 046/101] modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Bei Return SMALLERDOT durch EQUALSDOT ersetzt --- .../java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index b557e211..b3ba00de 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -490,7 +490,7 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(Return returnExpr) { returnExpr.retexpr.accept(this); - constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT)); + constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT)); } @Override From 7e35e09c4795200750b82e5ea59d3473cf387e27 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 19 Feb 2021 13:58:48 +0100 Subject: [PATCH 047/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/Method.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java AndConstraints einer Methode in Methode.java und iin MethodAndTPH.java eingefuegt modified: src/test/resources/insertGenericsJav/TestAny.jav --- .../de/dhbwstuttgart/bytecode/TPHExtractor.java | 2 +- .../bytecode/utilities/MethodAndTPH.java | 9 ++++++++- .../java/de/dhbwstuttgart/syntaxtree/Method.java | 14 ++++++++++++-- .../de/dhbwstuttgart/syntaxtree/SourceFile.java | 6 ++++++ .../dhbwstuttgart/typeinference/typeAlgo/TYPE.java | 4 +++- src/test/resources/insertGenericsJav/TestAny.jav | 2 +- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 9b895199..b26c4da3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -185,7 +185,7 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(Method method) { inMethod = true; String id = MethodUtility.createID(resolver,method); - methodAndTph = new MethodAndTPH(id); + methodAndTph = new MethodAndTPH(id, method.getConstraints()); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index d8eed39c..884124c9 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.ResultPair; @@ -15,9 +16,15 @@ public class MethodAndTPH { private final ArrayList> pairs = new ArrayList<>(); // tphs of local variables and parameters private final ArrayList localTphs = new ArrayList<>(); + /* + * its Constraints + * eingefuegt PL 2021-02-15 + */ + public final ConstraintSet constraints; - public MethodAndTPH(String name) { + public MethodAndTPH(String name, ConstraintSet constraints) { this.id = name; + this.constraints = constraints; } public ArrayList getTphs() { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java index 13e36b7b..9eda85e4 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java @@ -31,8 +31,14 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope private ExceptionList exceptionlist; private GenericDeclarationList generics; private final RefTypeOrTPHOrWildcardOrGeneric returnType; - public final Boolean isInherited; - + public final Boolean isInherited; + + /* + * its Constraints + * eingefuegt PL 2021-02-15 + */ + public final ConstraintSet constraints = new ConstraintSet(); + public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) { super(offset); @@ -70,6 +76,10 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope return this.returnType; } + public ConstraintSet getConstraints() { + return this.constraints; + } + @Override public void accept(ASTVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java index 4a22147b..f9ec340b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -45,6 +45,12 @@ public class SourceFile extends SyntaxTreeNode{ public List getClasses() { return KlassenVektor; } + + public List getAllMethods() { + List ret = new ArrayList<>(); + getClasses().forEach(cl -> ret.addAll(cl.getMethods())); + return ret; + } @Override public void accept(ASTVisitor visitor) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index c84fa143..685ac9f6 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -32,8 +32,10 @@ public class TYPE { private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) { ConstraintSet ret = new ConstraintSet(); + ConstraintSet methConstrains; for(Method m : cl.getMethods()){ - ret.addAll(getConstraintsMethod(m,info, cl)); + ret.addAll(methConstrains = getConstraintsMethod(m,info, cl)); + m.constraints.addAll(methConstrains); } for(Constructor m : cl.getConstructors()){ ret.addAll(getConstraintsConstructor(m,info, cl)); diff --git a/src/test/resources/insertGenericsJav/TestAny.jav b/src/test/resources/insertGenericsJav/TestAny.jav index 9ba18b63..86c0ceb1 100644 --- a/src/test/resources/insertGenericsJav/TestAny.jav +++ b/src/test/resources/insertGenericsJav/TestAny.jav @@ -1,4 +1,4 @@ -class Example { +class TestAny { a; b = a; anyMethod() { From 60f2e3def4e6c7e15eb7042b0961e1a2f79fbe27 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Feb 2021 00:13:29 +0100 Subject: [PATCH 048/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 32 +++++++++++++++++-- .../constraints/ConstraintSet.java | 12 +++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index b26c4da3..b908afa6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -10,6 +10,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; @@ -30,6 +33,9 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; @@ -185,7 +191,29 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(Method method) { inMethod = true; String id = MethodUtility.createID(resolver,method); - methodAndTph = new MethodAndTPH(id, method.getConstraints()); + Predicate filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) && + (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) && + (resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder)); + + Function, ConstraintSet> filterConstrRemainingTVar = + csS -> { + ConstraintSet ret = new ConstraintSet<>(); + ret.addAllUndConstraint( + csS.getUndConstraints() + .stream().filter(filterUndConstraints) + .collect(Collectors.toCollection(Constraint::new))); + + csS.getOderConstraints() + .forEach(oConSSet -> { Set> setCons = new HashSet<>(); + oConSSet.forEach(OConS -> { setCons.add( + OConS.stream() + .filter(filterUndConstraints) + .collect(Collectors.toCollection(Constraint::new)) ); + } ); + ret.addOderConstraint(setCons);} ); + return ret; + }; + methodAndTph = new MethodAndTPH(id, filterConstrRemainingTVar.apply(method.getConstraints())); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); @@ -194,7 +222,7 @@ public class TPHExtractor extends AbstractASTWalker { if(method.block != null) method.block.accept(this); - + inMethod = false; ListOfMethodsAndTph.add(methodAndTph); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 31a466dd..1c7b7439 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -23,9 +23,17 @@ public class ConstraintSet { oderConstraints.add(methodConstraints); } + public void addAllUndConstraint(Constraint allUndConstraints){ + undConstraints.addAll(allUndConstraints); + } + + public void addAllOderConstraint(List>> allOderConstraints){ + this.oderConstraints.addAll(allOderConstraints); + } + public void addAll(ConstraintSet constraints) { - this.undConstraints.addAll(constraints.undConstraints); - this.oderConstraints.addAll(constraints.oderConstraints); + this.addAllUndConstraint(constraints.undConstraints); + this.addAllOderConstraint(constraints.oderConstraints); } @Override From ebb0803a38e3b84ccfa121bd8c1949f43ea02007 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Feb 2021 15:59:24 +0100 Subject: [PATCH 049/101] new file: ../../../java/insertGenerics/TestTwoCalls.java new file: ../../../java/insertGenerics/TestVector.java new file: ../../insertGenericsJav/TestLocalVarLambda.jav new file: ../../insertGenericsJav/TestMutualRecursion.jav new file: ../../insertGenericsJav/TestMutualRecursionWithField.jav new file: ../../insertGenericsJav/TestThreeArgs.jav new file: ../../insertGenericsJav/TestTwoCalls.jav new file: ../../insertGenericsJav/TestVector.jav --- .../java/insertGenerics/TestTwoCalls.java | 54 +++++++++++++++++++ src/test/java/insertGenerics/TestVector.java | 54 +++++++++++++++++++ .../insertGenericsJav/TestLocalVarLambda.jav | 7 +++ .../insertGenericsJav/TestMutualRecursion.jav | 17 ++++++ .../TestMutualRecursionWithField.jav | 22 ++++++++ .../insertGenericsJav/TestThreeArgs.jav | 15 ++++++ .../insertGenericsJav/TestTwoCalls.jav | 12 +++++ .../insertGenericsJav/TestVector.jav | 12 +++++ 8 files changed, 193 insertions(+) create mode 100644 src/test/java/insertGenerics/TestTwoCalls.java create mode 100644 src/test/java/insertGenerics/TestVector.java create mode 100644 src/test/resources/insertGenericsJav/TestLocalVarLambda.jav create mode 100644 src/test/resources/insertGenericsJav/TestMutualRecursion.jav create mode 100644 src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav create mode 100644 src/test/resources/insertGenericsJav/TestThreeArgs.jav create mode 100644 src/test/resources/insertGenericsJav/TestTwoCalls.jav create mode 100644 src/test/resources/insertGenericsJav/TestVector.jav diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java new file mode 100644 index 00000000..6d107b16 --- /dev/null +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -0,0 +1,54 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestTwoCalls { + + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestTwoCalls"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + return new TestResultSet(); + } +} diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java new file mode 100644 index 00000000..a585abe5 --- /dev/null +++ b/src/test/java/insertGenerics/TestVector.java @@ -0,0 +1,54 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestVector { + + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestVector"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + return new TestResultSet(); + } +} diff --git a/src/test/resources/insertGenericsJav/TestLocalVarLambda.jav b/src/test/resources/insertGenericsJav/TestLocalVarLambda.jav new file mode 100644 index 00000000..ab4455c7 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestLocalVarLambda.jav @@ -0,0 +1,7 @@ +public class TestLocalVarLambda { + +m(x) { + var id = z -> z; + return id.apply(x); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestMutualRecursion.jav b/src/test/resources/insertGenericsJav/TestMutualRecursion.jav new file mode 100644 index 00000000..60ce72ca --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestMutualRecursion.jav @@ -0,0 +1,17 @@ +public class TestMutualRecursion { + a; + + id(b) { + var c = b; + return main(b,c); + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + return m(id(x),y); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav new file mode 100644 index 00000000..82dc42d2 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField.jav @@ -0,0 +1,22 @@ +public class TestMutualRecursionWithField { + a; + + id(b) { + var c = b; + return main(b,c); + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + return m(id(x),setA(y)); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestThreeArgs.jav b/src/test/resources/insertGenericsJav/TestThreeArgs.jav new file mode 100644 index 00000000..fe22dd3c --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestThreeArgs.jav @@ -0,0 +1,15 @@ +public class TestThreeArgs { + a; + + id(b) { + var a /* = null */; + var c = b; + m(a,a,b); + return c; + } + + m(x,y, z) { + x = id(y); + return x; + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestTwoCalls.jav b/src/test/resources/insertGenericsJav/TestTwoCalls.jav new file mode 100644 index 00000000..be3137f0 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestTwoCalls.jav @@ -0,0 +1,12 @@ +public class TestTwoCalls { + + id(b) { + var c = b; + return c; + } + + main(x,y) { + id(x); + return id(y); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestVector.jav b/src/test/resources/insertGenericsJav/TestVector.jav new file mode 100644 index 00000000..1519afb7 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestVector.jav @@ -0,0 +1,12 @@ +import java.util.Vector; + +public class TestVector { + + m(v, w) { + w.addElement(id(v.elementAt(0))); + } + + id(x) { + return x; + } +} \ No newline at end of file From d14f1d92c97303cb8280029edd4884c07dec4fe8 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Feb 2021 11:42:31 +0100 Subject: [PATCH 050/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../bytecode/insertGenerics/FamilyOfGeneratedGenerics.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 3628ed1d..853f4bf4 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -166,6 +166,11 @@ public class FamilyOfGeneratedGenerics { if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); } + }else if(pair.fst == PositionFinder.Position.FIELD){ + ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempCC)) { + tempCC.add(consToAdd); + } } } } From b711dc72e01e734a11f591d5271644fff78ce959 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 4 Mar 2021 18:58:33 +0100 Subject: [PATCH 051/101] new file: src/test/java/insertGenerics/AllTests.java --- src/test/java/insertGenerics/AllTests.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/test/java/insertGenerics/AllTests.java diff --git a/src/test/java/insertGenerics/AllTests.java b/src/test/java/insertGenerics/AllTests.java new file mode 100644 index 00000000..42fa736f --- /dev/null +++ b/src/test/java/insertGenerics/AllTests.java @@ -0,0 +1,79 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class AllTests { + + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className; + + @Test + public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + className = "TestMutualRecursion"; + execute(new File(rootDirectory+className+".jav")); + } + + @Test + public void TestMutualRecursionWithField() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + className = "TestMutualRecursionWithField"; + execute(new File(rootDirectory+className+".jav")); + } + + @Test + public void TestMutualRecursionWithField2() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + className = "TestMutualRecursionWithField2"; + execute(new File(rootDirectory+className+".jav")); + } + + @Test + public void TestMutualRecursionWithField3() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + className = "TestMutualRecursionWithField3"; + execute(new File(rootDirectory+className+".jav")); + } + + @Test + public void TestContraVariant() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + className = "TestContraVariant"; + execute(new File(rootDirectory+className+".jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + return new TestResultSet(); + } +} From 31d7856afac31bfc6e0c316dcddc6c8d87bb02ff Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 5 Mar 2021 00:31:36 +0100 Subject: [PATCH 052/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../GeneratedGenericsFinder.java | 2 +- .../FamilyOfGeneratedGenerics.java | 59 +++++++++++++++++-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index a73d2b3c..595f874e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -134,7 +134,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { classOrInterface.accept(tphExtractor); //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //Rueckgabe an generatedGenericsForSF - fogg = new FamilyOfGeneratedGenerics(tphExtractor); + fogg = new FamilyOfGeneratedGenerics(tphExtractor, resultSet); System.out.println("fogg.allConstraints: "+ fogg.allConstraints); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 853f4bf4..544d43be 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -5,11 +5,18 @@ import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; +import java.util.function.Predicate; + +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.result.ResultPair; +import de.dhbwstuttgart.typeinference.result.ResultSet; import org.objectweb.asm.Type; +import javax.naming.ldap.PagedResultsResponseControl; + public class FamilyOfGeneratedGenerics { public List allConstraints = new ArrayList<>(); // HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode @@ -17,15 +24,19 @@ public class FamilyOfGeneratedGenerics { public List classConstraints = new ArrayList<>(); public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); +// public List methodAndTPHList = new ArrayList<>(); //not necessary? + public ResultSet resSet; private static final String objectType = Type.getInternalName(Object.class); - public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) { + public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor, ResultSet resultSet) { + this.resSet = resultSet; this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); - this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); + this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet); +// this.methodAndTPHList = tphExtractor.ListOfMethodsAndTph; //not necessary? } public static List getClassConstraints(List cs, HashMap>> posOfTphs) { //Inputparameter List constraintsSet weg @@ -104,7 +115,7 @@ public class FamilyOfGeneratedGenerics { return cs_m; } - public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { + public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); for(MethodAndTPH method: listOfMethodsAndTph){ List methodsAddedToHashMap = new ArrayList<>(); @@ -124,6 +135,8 @@ public class FamilyOfGeneratedGenerics { } listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); + + List newMCList = firstLineMethodDefinition(cs, posOfTphs, resSet); } } @@ -464,4 +477,38 @@ public class FamilyOfGeneratedGenerics { } */ + public static List firstLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, ResultSet resSet) { + List tempMC= new ArrayList<>(); +// MethodAndTPH methAndTphs = methodAndTPH; +// Set undCons = methAndTphs.constraints.getUndConstraints(); +// Iterator it = undCons.iterator(); +// while(it.hasNext()) { +// System.out.println(it.next()); +// } + Set res = resSet.results; + Iterator it = res.iterator(); + System.out.println("res: " + res.size() + res); + System.out.println("booooooooo"); + while(it.hasNext()) { + System.out.println(it.next()); + } + System.out.println("booooooooo2"); + +// for(TPHConstraint tphC: allConstraints) { +// } + Predicate filterUndConstraints = ab -> resSet.resolveType((TypePlaceholder)(ab.TA1)).resolvedType instanceof TypePlaceholder; + System.out.println(filterUndConstraints); + Predicate the = x -> resSet.resolveType((TypePlaceholder)(x.TA1)).resolvedType instanceof TypePlaceholder; + ResultPair rp = y -> resSet.resolveType((TypePlaceholder)(y.TA1)).getResultPair(); + +// (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) + + + return null; + } + + + + + } From b99c022b5048a84283cae50620b70dd775ba714e Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 5 Mar 2021 09:12:19 +0100 Subject: [PATCH 053/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 1 + .../FamilyOfGeneratedGenerics.java | 41 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index b908afa6..2923da74 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -55,6 +55,7 @@ public class TPHExtractor extends AbstractASTWalker { boolean inLocalOrParamOrReturn = false; public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); + public Set oldConstraints = new HashSet<>(); // Alle Constraints in einer Menge (und- & Oder-Constraints) final ArrayList> allPairs = new ArrayList<>(); public final ArrayList allCons = new ArrayList<>(); private ResultSet resultSet; diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 544d43be..6b3cd99b 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -136,7 +136,7 @@ public class FamilyOfGeneratedGenerics { listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph); tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); - List newMCList = firstLineMethodDefinition(cs, posOfTphs, resSet); + List newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet); } } @@ -477,29 +477,36 @@ public class FamilyOfGeneratedGenerics { } */ - public static List firstLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, ResultSet resSet) { + public static List firstLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet) { List tempMC= new ArrayList<>(); -// MethodAndTPH methAndTphs = methodAndTPH; -// Set undCons = methAndTphs.constraints.getUndConstraints(); -// Iterator it = undCons.iterator(); + MethodAndTPH methAndTphs = methodAndTPH; + Set undCons = methAndTphs.constraints.getUndConstraints(); + List> orCons = methAndTphs.constraints.getOderConstraints(); + Iterator it = undCons.iterator(); + while(it.hasNext()) { + Pair p = it.next(); + String ta1 = ((TypePlaceholder) p.TA1).getName(); + String ta2 = ((TypePlaceholder) p.TA2).getName(); + + System.out.println(p); + + } + +// Set res = resSet.results; +// Iterator it = res.iterator(); +// System.out.println("res: " + res.size() + res); +// System.out.println("booooooooo"); // while(it.hasNext()) { // System.out.println(it.next()); // } - Set res = resSet.results; - Iterator it = res.iterator(); - System.out.println("res: " + res.size() + res); - System.out.println("booooooooo"); - while(it.hasNext()) { - System.out.println(it.next()); - } - System.out.println("booooooooo2"); +// System.out.println("booooooooo2"); // for(TPHConstraint tphC: allConstraints) { // } - Predicate filterUndConstraints = ab -> resSet.resolveType((TypePlaceholder)(ab.TA1)).resolvedType instanceof TypePlaceholder; - System.out.println(filterUndConstraints); - Predicate the = x -> resSet.resolveType((TypePlaceholder)(x.TA1)).resolvedType instanceof TypePlaceholder; - ResultPair rp = y -> resSet.resolveType((TypePlaceholder)(y.TA1)).getResultPair(); +// Predicate filterUndConstraints = ab -> resSet.resolveType((TypePlaceholder)(ab.TA1)).resolvedType instanceof TypePlaceholder; +// System.out.println(filterUndConstraints); +// Predicate the = x -> resSet.resolveType((TypePlaceholder)(x.TA1)).resolvedType instanceof TypePlaceholder; +// ResultPair rp = y -> resSet.resolveType((TypePlaceholder)(y.TA1)).getResultPair(); // (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) From 2ca4aad07df2a8b47e9ea55b1bf46f6fdb23b64e Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 5 Mar 2021 10:57:42 +0100 Subject: [PATCH 054/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java --- .../java/de/dhbwstuttgart/bytecode/TPHExtractor.java | 9 +++++++-- .../dhbwstuttgart/bytecode/utilities/MethodAndTPH.java | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 2923da74..d74ecad8 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -55,7 +55,10 @@ public class TPHExtractor extends AbstractASTWalker { boolean inLocalOrParamOrReturn = false; public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); - public Set oldConstraints = new HashSet<>(); // Alle Constraints in einer Menge (und- & Oder-Constraints) + + // Alle Constraints in einer Menge (und- & Oder-Constraints) + public Set oldConstraints = new HashSet<>(); + final ArrayList> allPairs = new ArrayList<>(); public final ArrayList allCons = new ArrayList<>(); private ResultSet resultSet; @@ -214,7 +217,9 @@ public class TPHExtractor extends AbstractASTWalker { ret.addOderConstraint(setCons);} ); return ret; }; - methodAndTph = new MethodAndTPH(id, filterConstrRemainingTVar.apply(method.getConstraints())); + ConstraintSet filteredConstraints = filterConstrRemainingTVar.apply(method.getConstraints()); + methodAndTph = new MethodAndTPH(id, filteredConstraints); + oldConstraints.addAll(filteredConstraints.getAll()); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index 884124c9..892b0894 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.ResultPair; @@ -22,7 +23,7 @@ public class MethodAndTPH { */ public final ConstraintSet constraints; - public MethodAndTPH(String name, ConstraintSet constraints) { + public MethodAndTPH(String name, ConstraintSet constraints) { this.id = name; this.constraints = constraints; } From f208432c545dec59cad20fb4db189073a0c1e660 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 5 Mar 2021 20:18:48 +0100 Subject: [PATCH 055/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 2 +- .../FamilyOfGeneratedGenerics.java | 95 ++++++++++++------- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index d74ecad8..3154c931 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -56,7 +56,7 @@ public class TPHExtractor extends AbstractASTWalker { public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); - // Alle Constraints in einer Menge (und- & Oder-Constraints) + // Alle Constraints in einer Menge (Und- & Oder-Constraints) public Set oldConstraints = new HashSet<>(); final ArrayList> allPairs = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 6b3cd99b..8ea4638a 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -13,10 +13,9 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import org.objectweb.asm.Type; -import javax.naming.ldap.PagedResultsResponseControl; - public class FamilyOfGeneratedGenerics { public List allConstraints = new ArrayList<>(); // HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode @@ -24,19 +23,19 @@ public class FamilyOfGeneratedGenerics { public List classConstraints = new ArrayList<>(); public List methodConstraints = new ArrayList<>(); public HashMap> methodConstraintsWithPosition = new HashMap<>(); -// public List methodAndTPHList = new ArrayList<>(); //not necessary? public ResultSet resSet; + public Set oldCons = new HashSet<>(); private static final String objectType = Type.getInternalName(Object.class); public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor, ResultSet resultSet) { this.resSet = resultSet; + this.oldCons = tphExtractor.oldConstraints; this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); - this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet); -// this.methodAndTPHList = tphExtractor.ListOfMethodsAndTph; //not necessary? + this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons); } public static List getClassConstraints(List cs, HashMap>> posOfTphs) { //Inputparameter List constraintsSet weg @@ -115,7 +114,7 @@ public class FamilyOfGeneratedGenerics { return cs_m; } - public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet) { + public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); for(MethodAndTPH method: listOfMethodsAndTph){ List methodsAddedToHashMap = new ArrayList<>(); @@ -137,6 +136,7 @@ public class FamilyOfGeneratedGenerics { tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod); List newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet); + List newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons); } } @@ -481,41 +481,72 @@ public class FamilyOfGeneratedGenerics { List tempMC= new ArrayList<>(); MethodAndTPH methAndTphs = methodAndTPH; Set undCons = methAndTphs.constraints.getUndConstraints(); - List> orCons = methAndTphs.constraints.getOderConstraints(); + List>> orCons = methAndTphs.constraints.getOderConstraints(); Iterator it = undCons.iterator(); while(it.hasNext()) { Pair p = it.next(); - String ta1 = ((TypePlaceholder) p.TA1).getName(); - String ta2 = ((TypePlaceholder) p.TA2).getName(); - - System.out.println(p); + String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(); + String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(); + Relation r = null; + if(p.GetOperator() == PairOperator.SMALLERDOT) { + r = Relation.EXTENDS; + } else if(p.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + } + MethodConstraint mc = new MethodConstraint(ta1, ta2, r); + System.out.println(mc); + tempMC.add(mc); + } + return tempMC; + } + public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { + List tempMC= new ArrayList<>(); + MethodAndTPH methAndTphs = methodAndTPH; + List>> orCons = methAndTphs.constraints.getOderConstraints(); + List>> orConsList = new ArrayList<>(); + List>> orConsListConverted = new ArrayList<>(); + for(int i=0; i> orConsInternal = new ArrayList<>(); + List orConsWithEQUAL = new ArrayList(); + List orConsWithEXTENDS = new ArrayList(); + for(Constraint con: orCons.get(i)) { + Iterator it = con.iterator(); + while(it.hasNext()) { + Pair p = it.next(); + Relation r = null; + if(p.GetOperator() == PairOperator.SMALLERDOT) { + r = Relation.EXTENDS; + orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); + } else if(p.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); + } + } + } + orConsInternal.add(orConsWithEXTENDS); + orConsInternal.add(orConsWithEQUAL); + orConsListConverted.add(orConsInternal); } -// Set res = resSet.results; -// Iterator it = res.iterator(); -// System.out.println("res: " + res.size() + res); -// System.out.println("booooooooo"); -// while(it.hasNext()) { -// System.out.println(it.next()); -// } -// System.out.println("booooooooo2"); - -// for(TPHConstraint tphC: allConstraints) { -// } -// Predicate filterUndConstraints = ab -> resSet.resolveType((TypePlaceholder)(ab.TA1)).resolvedType instanceof TypePlaceholder; -// System.out.println(filterUndConstraints); -// Predicate the = x -> resSet.resolveType((TypePlaceholder)(x.TA1)).resolvedType instanceof TypePlaceholder; -// ResultPair rp = y -> resSet.resolveType((TypePlaceholder)(y.TA1)).getResultPair(); - -// (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) + List oldConsList = new ArrayList<>(oldCons); + List oldConsListConverted = new ArrayList<>(); + for(Pair pair: oldConsList) { + Relation r = null; + if(pair.GetOperator() == PairOperator.SMALLERDOT) { + r = Relation.EXTENDS; + } else if(pair.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + } + oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); + } + List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); - return null; + + + return tempMC; } - - - } From af9943be28647d5156f5326be26737077c3cf0a7 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 5 Mar 2021 21:47:22 +0100 Subject: [PATCH 056/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 8ea4638a..4d5f4c18 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -505,9 +505,9 @@ public class FamilyOfGeneratedGenerics { MethodAndTPH methAndTphs = methodAndTPH; List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> orConsList = new ArrayList<>(); - List>> orConsListConverted = new ArrayList<>(); + List>> orConsListConverted = new ArrayList<>(); for(int i=0; i> orConsInternal = new ArrayList<>(); + HashMap> orConsInternal = new HashMap<>(); List orConsWithEQUAL = new ArrayList(); List orConsWithEXTENDS = new ArrayList(); for(Constraint con: orCons.get(i)) { @@ -524,8 +524,8 @@ public class FamilyOfGeneratedGenerics { } } } - orConsInternal.add(orConsWithEXTENDS); - orConsInternal.add(orConsWithEQUAL); + orConsInternal.put(Relation.EXTENDS, orConsWithEXTENDS); + orConsInternal.put(Relation.EQUAL, orConsWithEQUAL); orConsListConverted.add(orConsInternal); } @@ -542,9 +542,22 @@ public class FamilyOfGeneratedGenerics { } List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); - - - + for(int i=0; i extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); + List equalList = orConsListConverted.get(i).get(Relation.EQUAL); + for(TPHConstraint ex: extendsList) { + for(TPHConstraint eq: equalList) { + MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS); + for(TPHConstraint tc: tcOfoldCons) { + if(tc.getLeft()==mc.getLeft() && tc.getRight()==mc.getRight() && tc.getRel()==mc.getRel()) { + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } + } + } + } + } + } return tempMC; } From 55ee8ab61af6d84836f2565d5160e37c4dcd0ed0 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 12 Mar 2021 11:43:55 +0100 Subject: [PATCH 057/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 4d5f4c18..53c7d1ac 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -35,7 +35,7 @@ public class FamilyOfGeneratedGenerics { this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph); - this.methodConstraintsWithPosition = getMethodConstraintsWithPosition(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons); + this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons); } public static List getClassConstraints(List cs, HashMap>> posOfTphs) { //Inputparameter List constraintsSet weg @@ -137,6 +137,8 @@ public class FamilyOfGeneratedGenerics { List newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet); List newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons); + System.out.println(newMCList); + System.out.println(newMCList2); } } @@ -561,5 +563,47 @@ public class FamilyOfGeneratedGenerics { return tempMC; } + public static HashMap> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { + HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); + List newMCList = new ArrayList<>(); + List newMCList2 = new ArrayList<>(); + List methodsAddedToHashMap = new ArrayList<>(); + for(MethodAndTPH method: listOfMethodsAndTph){ + String currentMethod = method.getId(); + boolean containsCurrentMethod = false; + if(!containsCurrentMethod) { + methodsAddedToHashMap.add(currentMethod); + containsCurrentMethod = true; + List listToAdd = new ArrayList<>(); + HashMap>> posOfTPHsForThisMethod = new HashMap<>(); + for(String s: posOfTphs.keySet()) { + for(PairTphMethod pair: posOfTphs.get(s)) { + if(pair.snd == currentMethod && pair.snd != null) { + posOfTPHsForThisMethod.put(s,posOfTphs.get(s)); + } + } + } + + newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet); + for(int i=0; i Date: Fri, 12 Mar 2021 12:30:41 +0100 Subject: [PATCH 058/101] modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java --- .../java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index 6bd8bcab..0e3c9ed8 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -4,6 +4,7 @@ public class TPHConstraint { protected String left; protected String right; protected Relation rel; + protected int variance; //noch nicht benutzt public enum Relation{ EXTENDS, EQUAL } From 4acb820202379272a152eddd4b1669472069a754 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 12 Mar 2021 17:08:40 +0100 Subject: [PATCH 059/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 53c7d1ac..ca6940be 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -543,6 +543,7 @@ public class FamilyOfGeneratedGenerics { oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); } List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); + Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons); for(int i=0; i extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); @@ -563,6 +564,38 @@ public class FamilyOfGeneratedGenerics { return tempMC; } + public static Set buildTransitiveClosureForCP(Set constraint) { + Set iterSet = new HashSet<>(constraint); + Set runSet = new HashSet<>(constraint); + Set tcSet = new HashSet<>(constraint); + boolean addedConToList = false; +// for (TPHConstraint cons: iterList) { + Iterator itIterSet = iterSet.iterator(); + while(itIterSet.hasNext()) { + Pair pairIterSet = itIterSet.next(); +// for (TPHConstraint cons2: runList) { + Iterator itRunSet = runSet.iterator(); + while (itRunSet.hasNext()) { + Pair pairRunSet = itRunSet.next(); +// if(cons.getRight() == cons2.getLeft()) { + if(pairIterSet.TA2 == pairRunSet.TA1) { +// TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS); + Pair p = new Pair(pairIterSet.TA1, pairRunSet.TA2); +// if (!checkForDuplicates(consToAdd,tcList)) { + if(!tcSet.contains(p)) { +// tcList.add(consToAdd); + tcSet.add(p); + addedConToList = true; + if (addedConToList) { + return buildTransitiveClosureForCP(tcSet); + } + } + } + } + } + return tcSet; + } + public static HashMap> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); List newMCList = new ArrayList<>(); From 4f1aadef60a6a885b405b2338bb358a78ccb3018 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 12 Mar 2021 18:21:46 +0100 Subject: [PATCH 060/101] modified: src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java --- .../syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java index d20d451d..61cfd060 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java @@ -16,4 +16,6 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{ public abstract A acceptTV(TypeVisitor visitor); public abstract void accept(ResultSetVisitor visitor); + public abstract boolean equals(Object o); + } From f69554c6a11782eb922a6173bb00dae15c72f67c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 12 Mar 2021 18:29:51 +0100 Subject: [PATCH 061/101] equals in in Type eingefuegt --- .../dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java | 6 ++++++ .../de/dhbwstuttgart/syntaxtree/type/GenericRefType.java | 6 ++++++ src/main/java/de/dhbwstuttgart/syntaxtree/type/RefType.java | 4 ++-- .../syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java | 1 + .../de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java | 6 ++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java index 5f282e46..663bc9dc 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java @@ -53,4 +53,10 @@ public class ExtendsWildcardType extends WildcardType{ public void accept(ResultSetVisitor visitor) { visitor.visit(this); } + + @Override + public boolean equals(Object o) { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java index a14813e7..4ca2ebd6 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java @@ -32,5 +32,11 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric public void accept(ResultSetVisitor visitor) { visitor.visit(this); } + + @Override + public boolean equals(Object o) { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefType.java index 3e86275a..26f25fcf 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -77,8 +77,8 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric if(obj instanceof RefType){ boolean ret = true; - if(!super.equals(obj)) - return false; + //if(!(super.equals(obj))) PL 2020-03-12 muss vll. einkommentiert werden + // return false; if(parameter==null || parameter.size()==0){ ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java index 61cfd060..22c8ab4b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java @@ -16,6 +16,7 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{ public abstract A acceptTV(TypeVisitor visitor); public abstract void accept(ResultSetVisitor visitor); + @Override public abstract boolean equals(Object o); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java index 625fb01b..6a61b9cb 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java @@ -64,4 +64,10 @@ public class SuperWildcardType extends WildcardType{ public void accept(ResultSetVisitor visitor) { visitor.visit(this); } + + @Override + public boolean equals(Object o) { + // TODO Auto-generated method stub + return false; + } } From bb5692da8eb13d7d8a667dd91ba144b5f75682cf Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 12 Mar 2021 18:35:29 +0100 Subject: [PATCH 062/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index ca6940be..c1b44353 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -578,9 +578,9 @@ public class FamilyOfGeneratedGenerics { while (itRunSet.hasNext()) { Pair pairRunSet = itRunSet.next(); // if(cons.getRight() == cons2.getLeft()) { - if(pairIterSet.TA2 == pairRunSet.TA1) { + if(pairIterSet.TA2 == pairRunSet.TA1 && pairIterSet.OperatorSmallerDot() && pairRunSet.OperatorSmallerDot()) { // TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS); - Pair p = new Pair(pairIterSet.TA1, pairRunSet.TA2); + Pair p = new Pair(pairIterSet.TA1, pairRunSet.TA2, PairOperator.SMALLERDOT); // if (!checkForDuplicates(consToAdd,tcList)) { if(!tcSet.contains(p)) { // tcList.add(consToAdd); @@ -593,9 +593,29 @@ public class FamilyOfGeneratedGenerics { } } } + System.out.println("tcSet: " + tcSet); return tcSet; } + public static boolean checkForDuplicatesForSets(Pair pair, Set set) { + Set tempSet = set; + boolean hasSame = false; +// for (TPHConstraint tphC: tempList) { + Iterator it = set.iterator(); + while (it.hasNext()) { + Pair p = it.next(); +// hasSame = constraint.getLeft() == tphC.getLeft() && +// constraint.getRight() == tphC.getRight() && +// constraint.getRel() == tphC.getRel(); //constraint already in ArrayList if true + hasSame = pair.TA1 == pair.TA1 && + pair.TA2 == p.TA2 && + pair.OperatorSmallerDot() && p.OperatorSmallerDot(); //constraint already in Set if true + if (hasSame) + return true; + } + return false; + } + public static HashMap> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); List newMCList = new ArrayList<>(); From 8e89c9b5e826a87361e2d4a8312d54ab23757d4b Mon Sep 17 00:00:00 2001 From: AluAli Date: Sat, 13 Mar 2021 01:26:20 +0100 Subject: [PATCH 063/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 84 ++++++++++++++----- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index c1b44353..3901963a 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -503,7 +503,9 @@ public class FamilyOfGeneratedGenerics { } public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { - List tempMC= new ArrayList<>(); + List tempMC = new ArrayList<>(); + Set tempSet = new HashSet<>(); + Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); MethodAndTPH methAndTphs = methodAndTPH; List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> orConsList = new ArrayList<>(); @@ -542,29 +544,73 @@ public class FamilyOfGeneratedGenerics { } oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); } - List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); - Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons); +// List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); +// Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons); - for(int i=0; i extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); - List equalList = orConsListConverted.get(i).get(Relation.EQUAL); - for(TPHConstraint ex: extendsList) { - for(TPHConstraint eq: equalList) { - MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS); - for(TPHConstraint tc: tcOfoldCons) { - if(tc.getLeft()==mc.getLeft() && tc.getRight()==mc.getRight() && tc.getRel()==mc.getRel()) { - if(!checkForDuplicates(mc, tempMC)) { - tempMC.add(mc); +// for(int i=0; i extendsSet = new Constraint(); + Constraint equalSet = new Constraint(); + for(Constraint con: orCons.get(i)) { + Iterator it = con.iterator(); + while (it.hasNext()) { + Pair p = it.next(); +// List extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); +// List equalList = orConsListConverted.get(i).get(Relation.EQUAL); + if (p.OperatorSmallerDot()) { + extendsSet.add(p); + } else if (p.OperatorEqual()) { + equalSet.add(p); + } + } +// for (TPHConstraint ex : extendsList) { + Iterator itExtends = extendsSet.iterator(); + while(itExtends.hasNext()) { + Pair pairExtends = itExtends.next(); +// for (TPHConstraint eq : equalList) { + Iterator itEqual = equalSet.iterator(); + while(itEqual.hasNext()) { + Pair pairEqual = itEqual.next(); +// MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS); + Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); +// for (TPHConstraint tc : tcOfoldCons) { + Iterator itTC = tcOfoldConsSet.iterator(); + while(itTC.hasNext()) { + Pair pairTC = itTC.next(); +// if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) { + if(pairTC.TA1 == newPair.TA1 && pairTC.TA2 == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { +// if (!checkForDuplicates(mc, tempMC)) { + if(!checkForDuplicatesForSets(newPair, tempSet)) { + tempSet.add(newPair); + } } } } } } } + + Iterator itTemp = tempSet.iterator(); + while(itTemp.hasNext()) { + Pair p = itTemp.next(); + String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(); + String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(); + Relation r = null; + if(p.GetOperator() == PairOperator.SMALLERDOT) { + r = Relation.EXTENDS; + } else if(p.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + } + MethodConstraint mc = new MethodConstraint(ta1, ta2, r); + System.out.println(mc); + tempMC.add(mc); + } + return tempMC; } - public static Set buildTransitiveClosureForCP(Set constraint) { + + public static Set buildTransitiveClosureForCP(Set constraint, ResultSet resSet) { Set iterSet = new HashSet<>(constraint); Set runSet = new HashSet<>(constraint); Set tcSet = new HashSet<>(constraint); @@ -580,14 +626,14 @@ public class FamilyOfGeneratedGenerics { // if(cons.getRight() == cons2.getLeft()) { if(pairIterSet.TA2 == pairRunSet.TA1 && pairIterSet.OperatorSmallerDot() && pairRunSet.OperatorSmallerDot()) { // TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS); - Pair p = new Pair(pairIterSet.TA1, pairRunSet.TA2, PairOperator.SMALLERDOT); + Pair p = new Pair(resSet.resolveType((TypePlaceholder)(pairIterSet.TA1)).resolvedType, resSet.resolveType((TypePlaceholder)(pairRunSet.TA2)).resolvedType, PairOperator.SMALLERDOT); // if (!checkForDuplicates(consToAdd,tcList)) { - if(!tcSet.contains(p)) { + if(!checkForDuplicatesForSets(p, tcSet)) { // tcList.add(consToAdd); tcSet.add(p); addedConToList = true; if (addedConToList) { - return buildTransitiveClosureForCP(tcSet); + return buildTransitiveClosureForCP(tcSet, resSet); } } } @@ -601,13 +647,13 @@ public class FamilyOfGeneratedGenerics { Set tempSet = set; boolean hasSame = false; // for (TPHConstraint tphC: tempList) { - Iterator it = set.iterator(); + Iterator it = tempSet.iterator(); while (it.hasNext()) { Pair p = it.next(); // hasSame = constraint.getLeft() == tphC.getLeft() && // constraint.getRight() == tphC.getRight() && // constraint.getRel() == tphC.getRel(); //constraint already in ArrayList if true - hasSame = pair.TA1 == pair.TA1 && + hasSame = pair.TA1 == p.TA1 && pair.TA2 == p.TA2 && pair.OperatorSmallerDot() && p.OperatorSmallerDot(); //constraint already in Set if true if (hasSame) From 54de28c3f0e86f883b23babd123c4568305cc3a0 Mon Sep 17 00:00:00 2001 From: AluAli Date: Sat, 13 Mar 2021 13:16:47 +0100 Subject: [PATCH 064/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../bytecode/insertGenerics/FamilyOfGeneratedGenerics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 3901963a..7d6623ba 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -578,7 +578,7 @@ public class FamilyOfGeneratedGenerics { while(itTC.hasNext()) { Pair pairTC = itTC.next(); // if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) { - if(pairTC.TA1 == newPair.TA1 && pairTC.TA2 == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { + if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!) // if (!checkForDuplicates(mc, tempMC)) { if(!checkForDuplicatesForSets(newPair, tempSet)) { tempSet.add(newPair); From 55e44d62de2193c37982f3093ce8be1271a2cf40 Mon Sep 17 00:00:00 2001 From: AluAli Date: Sat, 13 Mar 2021 14:52:38 +0100 Subject: [PATCH 065/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../insertGenerics/FamilyOfGeneratedGenerics.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 7d6623ba..4cde842f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -496,8 +496,9 @@ public class FamilyOfGeneratedGenerics { r = Relation.EQUAL; } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); - System.out.println(mc); - tempMC.add(mc); + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } } return tempMC; } @@ -522,9 +523,14 @@ public class FamilyOfGeneratedGenerics { if(p.GetOperator() == PairOperator.SMALLERDOT) { r = Relation.EXTENDS; orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); + tempMC.add(new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r)); } else if(p.GetOperator() == PairOperator.EQUALSDOT) { r = Relation.EQUAL; orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); + MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r); + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } } } } @@ -602,8 +608,9 @@ public class FamilyOfGeneratedGenerics { r = Relation.EQUAL; } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); - System.out.println(mc); - tempMC.add(mc); + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } } return tempMC; From 6e0e575524e035d7000c90232bb2811c7bffc819 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 15 Mar 2021 11:27:31 +0100 Subject: [PATCH 066/101] new file: src/test/java/insertGenerics/TestLocalVarLambda.java --- .../insertGenerics/TestLocalVarLambda.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/insertGenerics/TestLocalVarLambda.java diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java new file mode 100644 index 00000000..bc830b49 --- /dev/null +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -0,0 +1,54 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestLocalVarLambda { + + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestLocalVarLambda"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + return new TestResultSet(); + } +} From 539cacef86c9709fff95d00bef34438d77d1c0eb Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 19 Mar 2021 08:50:04 +0100 Subject: [PATCH 067/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 76 +++++++++++++++---- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 4cde842f..5aafb37a 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -181,11 +181,11 @@ public class FamilyOfGeneratedGenerics { if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); } - }else if(pair.fst == PositionFinder.Position.FIELD){ + /*}else if(pair.fst == PositionFinder.Position.FIELD){ ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS); if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); - } + }*/ } } } @@ -496,8 +496,10 @@ public class FamilyOfGeneratedGenerics { r = Relation.EQUAL; } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); - if(!checkForDuplicates(mc, tempMC)) { - tempMC.add(mc); + if(mc.getRel() != Relation.EQUAL) { + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } } } return tempMC; @@ -523,14 +525,17 @@ public class FamilyOfGeneratedGenerics { if(p.GetOperator() == PairOperator.SMALLERDOT) { r = Relation.EXTENDS; orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); - tempMC.add(new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r)); - } else if(p.GetOperator() == PairOperator.EQUALSDOT) { - r = Relation.EQUAL; - orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r); if(!checkForDuplicates(mc, tempMC)) { tempMC.add(mc); } + } else if(p.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); + /*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r); + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + }*/ } } } @@ -586,8 +591,10 @@ public class FamilyOfGeneratedGenerics { // if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) { if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!) // if (!checkForDuplicates(mc, tempMC)) { - if(!checkForDuplicatesForSets(newPair, tempSet)) { - tempSet.add(newPair); + if(newPair.TA1 != newPair.TA2) { + if (!checkForDuplicatesForSets(newPair, tempSet)) { + tempSet.add(newPair); + } } } } @@ -608,8 +615,10 @@ public class FamilyOfGeneratedGenerics { r = Relation.EQUAL; } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); - if(!checkForDuplicates(mc, tempMC)) { - tempMC.add(mc); + if(mc.getRel() != Relation.EQUAL) { + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } } } @@ -669,10 +678,33 @@ public class FamilyOfGeneratedGenerics { return false; } + public static List hasNoSupertypeForMethodTypesNew(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH) { + List tempMC = new ArrayList<>(); + List allCons = allConstraints; + MethodAndTPH methAndTphs = methodAndTPH; + for(String tph: posOfTphs.keySet()) { + for(int i=0; i> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); List newMCList = new ArrayList<>(); List newMCList2 = new ArrayList<>(); + List hasNoSupType = new ArrayList<>(); + List mcWithoutCc = new ArrayList<>(); + List methodsAddedToHashMap = new ArrayList<>(); for(MethodAndTPH method: listOfMethodsAndTph){ String currentMethod = method.getId(); @@ -704,7 +736,25 @@ public class FamilyOfGeneratedGenerics { tempMethodConstraintsWithPosition.put(currentMethod, newMCList2); }*/ - tempMethodConstraintsWithPosition.put(currentMethod, listToAdd); + hasNoSupType = hasNoSupertypeForMethodTypesNew(cs,posOfTphs,method); + for (MethodConstraint cons: hasNoSupType) { + if (!checkForDuplicates(cons, listToAdd)) { + listToAdd.add(cons); + } + } + + mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd); + + tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc); + } + for(String curMeth: tempMethodConstraintsWithPosition.keySet()){ + for(int i=0; i Date: Fri, 19 Mar 2021 14:23:07 +0100 Subject: [PATCH 068/101] 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 Date: Fri, 19 Mar 2021 14:42:22 +0100 Subject: [PATCH 069/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 39f1b3cc..1d3921dc 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -519,6 +519,7 @@ public class FamilyOfGeneratedGenerics { List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> orConsList = new ArrayList<>(); List>> orConsListConverted = new ArrayList<>(); + //gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf ( for(int i=0; i> orConsInternal = new HashMap<>(); List orConsWithEQUAL = new ArrayList(); @@ -550,6 +551,8 @@ public class FamilyOfGeneratedGenerics { orConsListConverted.add(orConsInternal); } + // oldCons sind alle Und- und Oder-Constraints + // zunächst in meine Datenstruktur(Ali) konvertieren List oldConsList = new ArrayList<>(oldCons); List oldConsListConverted = new ArrayList<>(); for(Pair pair: oldConsList) { @@ -561,10 +564,8 @@ public class FamilyOfGeneratedGenerics { } oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); } -// List tcOfoldCons = buildTransitiveClosure(oldConsListConverted); -// Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons); -// for(int i=0; i extendsSet = new Constraint(); Constraint equalSet = new Constraint(); @@ -572,31 +573,23 @@ public class FamilyOfGeneratedGenerics { Iterator it = con.iterator(); while (it.hasNext()) { Pair p = it.next(); -// List extendsList = orConsListConverted.get(i).get(Relation.EXTENDS); -// List equalList = orConsListConverted.get(i).get(Relation.EQUAL); if (p.OperatorSmallerDot()) { extendsSet.add(p); } else if (p.OperatorEqual()) { equalSet.add(p); } } -// for (TPHConstraint ex : extendsList) { Iterator itExtends = extendsSet.iterator(); while(itExtends.hasNext()) { Pair pairExtends = itExtends.next(); -// for (TPHConstraint eq : equalList) { Iterator itEqual = equalSet.iterator(); while(itEqual.hasNext()) { Pair pairEqual = itEqual.next(); -// MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS); Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); -// for (TPHConstraint tc : tcOfoldCons) { Iterator itTC = tcOfoldConsSet.iterator(); while(itTC.hasNext()) { Pair pairTC = itTC.next(); -// if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) { if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!) -// if (!checkForDuplicates(mc, tempMC)) { if(newPair.TA1 != newPair.TA2) { if (!checkForDuplicatesForSets(newPair, tempSet)) { tempSet.add(newPair); @@ -609,6 +602,7 @@ public class FamilyOfGeneratedGenerics { } } + // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) Iterator itTemp = tempSet.iterator(); while(itTemp.hasNext()) { Pair p = itTemp.next(); From b147430fb6620526ede7fb19a736c03f777f394e Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 19 Mar 2021 15:05:40 +0100 Subject: [PATCH 070/101] kommentierte neue Regeln --- .../insertGenerics/FamilyOfGeneratedGenerics.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 1d3921dc..ed4566f2 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -512,12 +512,11 @@ public class FamilyOfGeneratedGenerics { } public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { - List tempMC = new ArrayList<>(); - Set tempSet = new HashSet<>(); + List tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali) + Set tempSet = new HashSet<>(); //für Ergebnisse basierend auf der alten Datenstruktur Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); MethodAndTPH methAndTphs = methodAndTPH; List>> orCons = methAndTphs.constraints.getOderConstraints(); - List>> orConsList = new ArrayList<>(); List>> orConsListConverted = new ArrayList<>(); //gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf ( for(int i=0; i extendsSet = new Constraint(); Constraint equalSet = new Constraint(); + //für jede einzelne OrConstraint-Menge gehe durch for(Constraint con: orCons.get(i)) { Iterator it = con.iterator(); + //für jeden Eintrag der Menge while (it.hasNext()) { Pair p = it.next(); if (p.OperatorSmallerDot()) { @@ -589,8 +590,8 @@ public class FamilyOfGeneratedGenerics { Iterator itTC = tcOfoldConsSet.iterator(); while(itTC.hasNext()) { Pair pairTC = itTC.next(); - if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!) - if(newPair.TA1 != newPair.TA2) { + if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //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!) + if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA if (!checkForDuplicatesForSets(newPair, tempSet)) { tempSet.add(newPair); } From ba8df8b37624cc385276240b28bb8138ce126083 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 19 Mar 2021 18:27:50 +0100 Subject: [PATCH 071/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index ed4566f2..cf9abbfd 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -520,9 +520,9 @@ public class FamilyOfGeneratedGenerics { List>> orConsListConverted = new ArrayList<>(); //gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf ( for(int i=0; i> orConsInternal = new HashMap<>(); List orConsWithEQUAL = new ArrayList(); List orConsWithEXTENDS = new ArrayList(); + HashMap> orConsInternal = new HashMap<>(); for(Constraint con: orCons.get(i)) { Iterator it = con.iterator(); while(it.hasNext()) { @@ -564,10 +564,13 @@ public class FamilyOfGeneratedGenerics { oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); } - // Berechnung der Regel + // dies ist das "R" aus dem ersten Teil, wird im zweiten Teil gebraucht + TypePlaceholder tphR = null; + + // Berechnung des ersten Teils der Regel + Constraint extendsSet = new Constraint(); + Constraint equalSet = new Constraint(); for(int i=0; i extendsSet = new Constraint(); - Constraint equalSet = new Constraint(); //für jede einzelne OrConstraint-Menge gehe durch for(Constraint con: orCons.get(i)) { Iterator it = con.iterator(); @@ -586,6 +589,7 @@ public class FamilyOfGeneratedGenerics { Iterator itEqual = equalSet.iterator(); while(itEqual.hasNext()) { Pair pairEqual = itEqual.next(); + tphR = (TypePlaceholder) (pairEqual.TA2); Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); Iterator itTC = tcOfoldConsSet.iterator(); while(itTC.hasNext()) { @@ -601,6 +605,25 @@ public class FamilyOfGeneratedGenerics { } } } + // Berechnung des zweiten Teils der Regel + Iterator itEqual = equalSet.iterator(); + while(itEqual.hasNext()) { + Pair pairEqual = itEqual.next(); + // prüfe, ob das "R" von vorhin in einem EqualConstraint links auftaucht + if(tphR == pairEqual.TA1) { + tempSet.add(); + } + } + Iterator itExtends = equalSet.iterator(); + while(itExtends.hasNext()) { + Pair pairExtends = itExtends.next(); + // prüfe, ob das "R" von vorhin in einem EqualConstraint links auftaucht + if(tphR == pairExtends.TA1) { + tempSet.add(); + } + + } + } // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) From d08e598649e865466a460f497b3292b753c6026a Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 19 Mar 2021 22:02:23 +0100 Subject: [PATCH 072/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 94 ++++++++++++++----- 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index cf9abbfd..11c2a7c3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -513,8 +513,10 @@ public class FamilyOfGeneratedGenerics { public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { List tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali) - Set tempSet = new HashSet<>(); //für Ergebnisse basierend auf der alten Datenstruktur + Set tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils basierend auf der alten Datenstruktur + Set tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils basierend auf der alten Datenstruktur Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); + List tcOfCs = buildTransitiveClosure(allConstraints); MethodAndTPH methAndTphs = methodAndTPH; List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> orConsListConverted = new ArrayList<>(); @@ -531,10 +533,10 @@ public class FamilyOfGeneratedGenerics { if(p.GetOperator() == PairOperator.SMALLERDOT) { r = Relation.EXTENDS; orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); - MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r); + /*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r); if(!checkForDuplicates(mc, tempMC)) { tempMC.add(mc); - } + }*/ } else if(p.GetOperator() == PairOperator.EQUALSDOT) { r = Relation.EQUAL; orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r)); @@ -566,11 +568,13 @@ public class FamilyOfGeneratedGenerics { // dies ist das "R" aus dem ersten Teil, wird im zweiten Teil gebraucht TypePlaceholder tphR = null; + Constraint extendsSetAllOfOr = new Constraint(); + Constraint equalSetAllOfOr = new Constraint(); // Berechnung des ersten Teils der Regel - Constraint extendsSet = new Constraint(); - Constraint equalSet = new Constraint(); for(int i=0; i extendsSet = new Constraint(); + Constraint equalSet = new Constraint(); //für jede einzelne OrConstraint-Menge gehe durch for(Constraint con: orCons.get(i)) { Iterator it = con.iterator(); @@ -579,8 +583,10 @@ public class FamilyOfGeneratedGenerics { Pair p = it.next(); if (p.OperatorSmallerDot()) { extendsSet.add(p); + extendsSetAllOfOr.add(p); } else if (p.OperatorEqual()) { equalSet.add(p); + equalSetAllOfOr.add(p); } } Iterator itExtends = extendsSet.iterator(); @@ -605,28 +611,52 @@ public class FamilyOfGeneratedGenerics { } } } - // Berechnung des zweiten Teils der Regel + + + /*// Berechnung des zweiten Teils der Regel Iterator itEqual = equalSet.iterator(); while(itEqual.hasNext()) { Pair pairEqual = itEqual.next(); - // prüfe, ob das "R" von vorhin in einem EqualConstraint links auftaucht - if(tphR == pairEqual.TA1) { - tempSet.add(); - } - } - Iterator itExtends = equalSet.iterator(); - while(itExtends.hasNext()) { - Pair pairExtends = itExtends.next(); - // prüfe, ob das "R" von vorhin in einem EqualConstraint links auftaucht - if(tphR == pairExtends.TA1) { - tempSet.add(); - } + Iterator itExtends = equalSet.iterator(); + while(itExtends.hasNext()) { + Pair pairExtends = itExtends.next(); + Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); + Iterator itTC = tcOfoldConsSet.iterator(); + while(itTC.hasNext()) { + Pair pairTC = itTC.next(); - } + // prüfe, ob das "R" von vorhin in einem EqualConstraint links auftaucht + if(tphR == pairEqual.TA1) { +// tempSet.add(); + } + } + } + }*/ } + // Berechnung des zweiten Teils der Regel + Iterator itExtends2 = extendsSetAllOfOr.iterator(); + while(itExtends2.hasNext()) { + Pair pairExtends2 = itExtends2.next(); + Iterator 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); + } + } + } + } + } - // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) + // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil Iterator itTemp = tempSet.iterator(); while(itTemp.hasNext()) { Pair p = itTemp.next(); @@ -639,13 +669,35 @@ 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); } } } + // aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für zweiten Teil + Iterator itTemp2 = tempSet2.iterator(); + while(itTemp2.hasNext()) { + Pair p = itTemp2.next(); + String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(); + String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(); + Relation r = null; + if (p.GetOperator() == PairOperator.SMALLERDOT) { + r = Relation.EXTENDS; + } else if (p.GetOperator() == PairOperator.EQUALSDOT) { + r = Relation.EQUAL; + } + for(TPHConstraint tphCons: tcOfCs) { + if(ta1 == tphCons.getLeft() && ta2 == tphCons.getRight() && r==Relation.EXTENDS) { + MethodConstraint mc = new MethodConstraint(ta1, ta2, r); + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } + } + } + } + return tempMC; } From e147a8ce85b2167b5bc0951adf92177ee409ea66 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 23 Mar 2021 12:02:58 +0100 Subject: [PATCH 073/101] toString geaendert, um Tests generieren zu koennen: modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java geaendert, um GenerateGenerics direkt teste zu koennen, sollte ggf. wieder rueckgaenig gemacht werden modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java angepasset Tests: modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java --- .../bytecode/constraint/TPHConstraint.java | 26 +++++++++++ .../GeneratedGenericsFinder.java | 10 +++++ .../insertGenerics/ClassConstraint.java | 9 ++++ .../FamilyOfGeneratedGenerics.java | 19 ++++++++ .../insertGenerics/MethodConstraint.java | 10 +++++ .../de/dhbwstuttgart/core/JavaTXCompiler.java | 7 +++ .../insertGenerics/TestLocalVarLambda.java | 26 +++++++++++ .../insertGenerics/TestTPHsAndGenerics.java | 45 +++++++++++++++++-- src/test/java/insertGenerics/TestTwoArgs.java | 43 ++++++++++++++++++ 9 files changed, 191 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index 0e3c9ed8..ae51c18e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -49,6 +49,23 @@ public class TPHConstraint { return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight()); } + @Override + public int hashCode() { + return (left+right).hashCode(); + } + + @Override + public boolean equals (Object o) { + if (o instanceof TPHConstraint) { + TPHConstraint o_tphcons = (TPHConstraint)o; + return (left+right).equals(o_tphcons.getLeft()+o_tphcons.getRight()); + } + else { + return false; + } + } + + /* @Override public String toString() { if(rel == Relation.EXTENDS) { @@ -57,4 +74,13 @@ public class TPHConstraint { return left + " = " + right; } } + */ + public String toString() { + if(rel == Relation.EXTENDS) { + return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; + } + else { + return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; + } + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 595f874e..e25958d1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -79,6 +79,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { private JavaClassName className; private Resolver resolver; + /** * @param sf * @param listOfResultSets @@ -93,6 +94,14 @@ public class GeneratedGenericsFinder implements ASTVisitor { return generatedGenericsForSF; } + /** + * returns the family of Generated Generics + * insbesondere fuer Testzwecke + */ + public FamilyOfGeneratedGenerics getFogg() { + return fogg; + } + /* * (non-Javadoc) * @@ -140,6 +149,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); + System.out.println(fogg); ///* //Fayez Ansatz Anfang diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java index 3f1d19d2..afbae005 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.bytecode.insertGenerics; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; public class ClassConstraint extends TPHConstraint { //private TPHConstraint constraint; @@ -12,4 +13,12 @@ public class ClassConstraint extends TPHConstraint { /*public ClassConstraint(TPHConstraint constraint) { this.constraint = constraint; }*/ + public String toString() { + if(rel == Relation.EXTENDS) { + return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; + } + else { + return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; + } + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 5aafb37a..a5d01d03 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -760,6 +760,25 @@ public class FamilyOfGeneratedGenerics { return tempMethodConstraintsWithPosition; } + + public String toString() { + String ret = + "List classConstraintsTest = new ArrayList<>();\n"; + for(ClassConstraint cC: classConstraints) { + ret = ret + "classConstraintsTest.add(" + cC.toString() + ");\n"; + } + ret = ret + "HashMap> methodConstraintsWithPositionTest = new HashMap<>();\n"; + ret = ret + "List lmc;\n"; + for (String methName : methodConstraintsWithPosition.keySet()) { + String consSet = ""; + ret = ret + "lmc = new ArrayList<>();\n"; + for (MethodConstraint methConstrs : methodConstraintsWithPosition.get(methName)) { + consSet = consSet + "lmc.add(" + methConstrs + ");\n"; + } + ret = ret + consSet + "methodConstraintsWithPositionTest.put(\""+ methName + "\", lmc);\n"; + } + return ret; + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java index d68f7d3f..c0000f20 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java @@ -1,9 +1,19 @@ package de.dhbwstuttgart.bytecode.insertGenerics; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; public class MethodConstraint extends TPHConstraint { public MethodConstraint(String left, String right, Relation rel) { super(left, right, rel); } + + public String toString() { + if(rel == Relation.EXTENDS) { + return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; + } + else { + return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; + } + } } diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 8425d180..eb220f4f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.BytecodeGen; import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError; import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.environment.DirectoryClassLoader; import de.dhbwstuttgart.exceptions.DebugException; @@ -78,7 +79,12 @@ public class JavaTXCompiler { Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); private final ClassLoader classLoader; + + //nur fuer Testzwecke of Generated Generics + //wieder loeschen PL 2021-03-22 + public FamilyOfGeneratedGenerics fogg; + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile), null); } @@ -872,6 +878,7 @@ public class JavaTXCompiler { SourceFile sf = sourceFiles.get(f); GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult); GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics(); + this.fogg = sResFinder.getFogg(); result.add(simplifyResOfSF); } return result; diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index bc830b49..043a9797 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,24 @@ public class TestLocalVarLambda { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + 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)); + methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(computedClassCons, expectedClassCons); + + assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index e49ed344..6aebd04f 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -1,7 +1,11 @@ package insertGenerics; - import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; - import de.dhbwstuttgart.core.JavaTXCompiler; + import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; +import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; @@ -10,7 +14,9 @@ package insertGenerics; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; - import java.io.File; +import static org.junit.Assert.assertEquals; + +import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URL; @@ -19,7 +25,9 @@ package insertGenerics; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; - import java.util.HashSet; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -46,6 +54,35 @@ public class TestTPHsAndGenerics { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(computedClassCons, expectedClassCons); + + assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index 0b2b87e3..d106e5c7 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -1,6 +1,13 @@ package insertGenerics; +import static org.junit.Assert.*; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -19,6 +26,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +54,40 @@ public class TestTwoArgs { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("AP", "Z", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("Z", "P", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS)); + lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(computedClassCons, expectedClassCons); + + assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From 8c6027645f229917559eb385e6ff88579d30f41f Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 24 Mar 2021 10:22:57 +0100 Subject: [PATCH 074/101] modified: src/test/java/insertGenerics/TestLocalVarLambda.java Alternative Typvarnamen eingefuegt. --- .../insertGenerics/TestLocalVarLambda.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index 043a9797..d83e6d21 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -56,14 +56,24 @@ public class TestLocalVarLambda { List classConstraintsTest = new ArrayList<>(); HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); - 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)); - methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; + + List lmc; + lmc = new ArrayList<>(); + + if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) { + 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)); + } + 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)); + } + methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); + Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); From e5816bac22323d59fa7fd534e6c6c8091274aa51 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 24 Mar 2021 11:35:15 +0100 Subject: [PATCH 075/101] modified: src/test/java/insertGenerics/TestAny.java modified: src/test/java/insertGenerics/TestGGFinder.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java modified: src/test/java/insertGenerics/TestTwoArgs2.java Tests fuer GeneratedGenerics eingefuegt --- src/test/java/insertGenerics/TestAny.java | 30 ++++++++++++++ .../java/insertGenerics/TestGGFinder.java | 35 ++++++++++++++++ .../insertGenerics/TestLocalVarLambda.java | 4 +- .../insertGenerics/TestTPHsAndGenerics.java | 4 +- src/test/java/insertGenerics/TestTwoArgs.java | 4 +- .../java/insertGenerics/TestTwoArgs2.java | 41 +++++++++++++++++++ 6 files changed, 112 insertions(+), 6 deletions(-) diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java index 6c6d2a95..e40c205e 100644 --- a/src/test/java/insertGenerics/TestAny.java +++ b/src/test/java/insertGenerics/TestAny.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,12 +14,16 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -40,6 +48,28 @@ public class TestAny { } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "O", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc); + lmc = new ArrayList<>(); + methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); for(File f : compiler.sourceFiles.keySet()){ SourceFile sf = compiler.sourceFiles.get(f); diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index 3b9e378e..55e9a09a 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,33 @@ public class TestGGFinder { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Y", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("voidm(TPH YTPH Z)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index d83e6d21..ea8071d7 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -77,9 +77,9 @@ public class TestLocalVarLambda { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 6aebd04f..3c243171 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -79,9 +79,9 @@ public class TestTPHsAndGenerics { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index d106e5c7..e492c49f 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -84,9 +84,9 @@ public class TestTwoArgs { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java index 6522187a..42a5a833 100644 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ b/src/test/java/insertGenerics/TestTwoArgs2.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,39 @@ public class TestTwoArgs2 { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AA", "U", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From bc378f2fe956fda4a3970fafff0812c0667ffd1b Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Mar 2021 00:41:03 +0100 Subject: [PATCH 076/101] modified: src/test/java/insertGenerics/AllTests.java modified: src/test/java/insertGenerics/TestTwoCalls.java modified: src/test/java/insertGenerics/TestVector.java --- src/test/java/insertGenerics/AllTests.java | 44 ++++++++++++++++++- .../java/insertGenerics/TestTwoCalls.java | 29 ++++++++++++ src/test/java/insertGenerics/TestVector.java | 27 ++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/test/java/insertGenerics/AllTests.java b/src/test/java/insertGenerics/AllTests.java index 42fa736f..f4f09992 100644 --- a/src/test/java/insertGenerics/AllTests.java +++ b/src/test/java/insertGenerics/AllTests.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -35,7 +43,41 @@ public class AllTests { @Test public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { className = "TestMutualRecursion"; - execute(new File(rootDirectory+className+".jav")); + JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav")); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALmain(TPH AGTPH AH)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); } @Test diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index 6d107b16..a6157ecc 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,27 @@ public class TestTwoCalls { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc); + lmc = new ArrayList<>(); + 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)); + methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index a585abe5..a020b279 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,25 @@ public class TestVector { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); + lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); + lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); + lmc = new ArrayList<>(); + methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From 705d0b6a73a76a6b75ee3ab6ac58f009077ec044 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Mar 2021 18:56:38 +0100 Subject: [PATCH 077/101] renamed: src/test/java/insertGenerics/AllTests.java -> src/test/java/insertGenerics/TestMutualRecursion.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestVector.java Tests angepasst an die GeneratedGenerics --- ...AllTests.java => TestMutualRecursion.java} | 10 +--- .../insertGenerics/TestTPHsAndGenerics.java | 58 +++++++++++++------ src/test/java/insertGenerics/TestVector.java | 1 + 3 files changed, 44 insertions(+), 25 deletions(-) rename src/test/java/insertGenerics/{AllTests.java => TestMutualRecursion.java} (90%) diff --git a/src/test/java/insertGenerics/AllTests.java b/src/test/java/insertGenerics/TestMutualRecursion.java similarity index 90% rename from src/test/java/insertGenerics/AllTests.java rename to src/test/java/insertGenerics/TestMutualRecursion.java index f4f09992..30778032 100644 --- a/src/test/java/insertGenerics/AllTests.java +++ b/src/test/java/insertGenerics/TestMutualRecursion.java @@ -31,7 +31,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class AllTests { +public class TestMutualRecursion { private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; @@ -41,7 +41,7 @@ public class AllTests { private static String className; @Test - public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { className = "TestMutualRecursion"; JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav")); List results = compiler.typeInference(); @@ -98,12 +98,6 @@ public class AllTests { execute(new File(rootDirectory+className+".jav")); } - @Test - public void TestContraVariant() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - className = "TestContraVariant"; - execute(new File(rootDirectory+className+".jav")); - } - private static class TestResultSet{ } diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 3c243171..9254100f 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -56,26 +56,50 @@ public class TestTPHsAndGenerics { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); - lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new ArrayList<>(); - lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new ArrayList<>(); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; + + List lmc; + lmc = new ArrayList<>(); + + if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { + classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + } + else { + classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + } + Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index a020b279..b902e93e 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -63,6 +63,7 @@ public class TestVector { lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; From d276c7c0445b48f9e35b981c5c75dc065b12a3cf Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Mar 2021 19:55:16 +0100 Subject: [PATCH 078/101] modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java toString wieder korrigiert modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java modified: src/test/java/insertGenerics/TestAny.java List -> Set Bei allen anderen Tests fehlt es noch --- .../bytecode/constraint/TPHConstraint.java | 11 +---------- .../insertGenerics/ClassConstraint.java | 8 -------- .../FamilyOfGeneratedGenerics.java | 19 ------------------- .../insertGenerics/MethodConstraint.java | 9 --------- src/test/java/insertGenerics/TestAny.java | 13 ++++++++----- 5 files changed, 9 insertions(+), 51 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index ae51c18e..7e857600 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -65,7 +65,7 @@ public class TPHConstraint { } } - /* + @Override public String toString() { if(rel == Relation.EXTENDS) { @@ -74,13 +74,4 @@ public class TPHConstraint { return left + " = " + right; } } - */ - public String toString() { - if(rel == Relation.EXTENDS) { - return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; - } - else { - return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; - } - } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java index afbae005..130f0ac6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java @@ -13,12 +13,4 @@ public class ClassConstraint extends TPHConstraint { /*public ClassConstraint(TPHConstraint constraint) { this.constraint = constraint; }*/ - public String toString() { - if(rel == Relation.EXTENDS) { - return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; - } - else { - return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; - } - } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 21b2c502..11c2a7c3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -832,25 +832,6 @@ public class FamilyOfGeneratedGenerics { return tempMethodConstraintsWithPosition; } - - public String toString() { - String ret = - "List classConstraintsTest = new ArrayList<>();\n"; - for(ClassConstraint cC: classConstraints) { - ret = ret + "classConstraintsTest.add(" + cC.toString() + ");\n"; - } - ret = ret + "HashMap> methodConstraintsWithPositionTest = new HashMap<>();\n"; - ret = ret + "List lmc;\n"; - for (String methName : methodConstraintsWithPosition.keySet()) { - String consSet = ""; - ret = ret + "lmc = new ArrayList<>();\n"; - for (MethodConstraint methConstrs : methodConstraintsWithPosition.get(methName)) { - consSet = consSet + "lmc.add(" + methConstrs + ");\n"; - } - ret = ret + consSet + "methodConstraintsWithPositionTest.put(\""+ methName + "\", lmc);\n"; - } - return ret; - } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java index c0000f20..89533594 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java @@ -7,13 +7,4 @@ public class MethodConstraint extends TPHConstraint { public MethodConstraint(String left, String right, Relation rel) { super(left, right, rel); } - - public String toString() { - if(rel == Relation.EXTENDS) { - return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)"; - } - else { - return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)"; - } - } } diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java index e40c205e..9ef6d901 100644 --- a/src/test/java/insertGenerics/TestAny.java +++ b/src/test/java/insertGenerics/TestAny.java @@ -54,12 +54,12 @@ public class TestAny { classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; @@ -67,8 +67,11 @@ public class TestAny { Set expectedClassCons = new HashSet<>(classConstraintsTest); assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); for(File f : compiler.sourceFiles.keySet()){ From 86603ae343c1a27840db7bf4ae7d6748e9e3afab Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 26 Mar 2021 10:51:59 +0100 Subject: [PATCH 079/101] modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java equals korrigiert modified: src/test/java/insertGenerics/TestGGFinder.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestMutualRecursion.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java modified: src/test/java/insertGenerics/TestTwoCalls.java modified: src/test/java/insertGenerics/TestVector.java List -> Set vollendet --- .../bytecode/constraint/TPHConstraint.java | 4 +++- .../java/insertGenerics/TestGGFinder.java | 15 +++++++++------ .../insertGenerics/TestLocalVarLambda.java | 11 +++++++---- .../insertGenerics/TestMutualRecursion.java | 16 ++++++++++------ .../insertGenerics/TestTPHsAndGenerics.java | 19 +++++++++++-------- src/test/java/insertGenerics/TestTwoArgs.java | 19 +++++++++++-------- .../java/insertGenerics/TestTwoCalls.java | 14 +++++++++----- src/test/java/insertGenerics/TestVector.java | 15 +++++++++------ 8 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index 7e857600..6cded807 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -58,7 +58,9 @@ public class TPHConstraint { public boolean equals (Object o) { if (o instanceof TPHConstraint) { TPHConstraint o_tphcons = (TPHConstraint)o; - return (left+right).equals(o_tphcons.getLeft()+o_tphcons.getRight()); + return (this.left.equals(o_tphcons.getLeft()) + && this.right.equals(o_tphcons.getRight()) + && this.rel.equals(o_tphcons.rel)); } else { return false; diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index 55e9a09a..e861e6e4 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -56,16 +56,16 @@ public class TestGGFinder { List classConstraintsTest = new ArrayList<>(); classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); @@ -78,7 +78,10 @@ public class TestGGFinder { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index ea8071d7..530ef318 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -55,12 +55,12 @@ public class TestLocalVarLambda { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); FamilyOfGeneratedGenerics fogg = compiler.fogg; - List lmc; - lmc = new ArrayList<>(); + Set lmc; + lmc = new HashSet<>(); if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) { lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS)); @@ -79,7 +79,10 @@ public class TestLocalVarLambda { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestMutualRecursion.java b/src/test/java/insertGenerics/TestMutualRecursion.java index 30778032..fac445ed 100644 --- a/src/test/java/insertGenerics/TestMutualRecursion.java +++ b/src/test/java/insertGenerics/TestMutualRecursion.java @@ -49,18 +49,19 @@ public class TestMutualRecursion { List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS)); lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); @@ -71,8 +72,11 @@ public class TestMutualRecursion { Set expectedClassCons = new HashSet<>(classConstraintsTest); assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 9254100f..2b475bbf 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -56,12 +56,12 @@ public class TestTPHsAndGenerics { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); FamilyOfGeneratedGenerics fogg = compiler.fogg; - List lmc; - lmc = new ArrayList<>(); + Set lmc; + lmc = new HashSet<>(); if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); @@ -74,10 +74,10 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } @@ -92,10 +92,10 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } @@ -105,7 +105,10 @@ public class TestTPHsAndGenerics { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index e492c49f..8016a039 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -61,20 +61,20 @@ public class TestTwoArgs { classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS)); lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); @@ -84,9 +84,12 @@ public class TestTwoArgs { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(expectedClassCons, computedClassCons); + assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index a6157ecc..9d7eba07 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -55,13 +55,13 @@ public class TestTwoCalls { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); 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)); @@ -72,8 +72,12 @@ public class TestTwoCalls { Set expectedClassCons = new HashSet<>(classConstraintsTest); assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index b902e93e..8245ff9d 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -55,14 +55,14 @@ public class TestVector { List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); @@ -70,9 +70,12 @@ public class TestVector { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(expectedClassCons, computedClassCons); + assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); From e3625cb3066594bd8b9c9d09abf53ef147d6dc9b Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 12:29:40 +0100 Subject: [PATCH 080/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/TestTwoCalls.java --- .../FamilyOfGeneratedGenerics.java | 70 +++++++++++++------ .../java/insertGenerics/TestTwoCalls.java | 1 + 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 11c2a7c3..358c6d34 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -518,6 +518,7 @@ public class FamilyOfGeneratedGenerics { Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); List tcOfCs = buildTransitiveClosure(allConstraints); MethodAndTPH methAndTphs = methodAndTPH; + Set undCons = methAndTphs.constraints.getUndConstraints(); List>> orCons = methAndTphs.constraints.getOderConstraints(); List>> 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 extendsSetAllOfOr = new Constraint(); - Constraint equalSetAllOfOr = new Constraint(); +// TypePlaceholder tphR = null; +// Constraint extendsSetAllOfOr = new Constraint(); +// Constraint equalSetAllOfOr = new Constraint(); // Berechnung des ersten Teils der Regel for(int i=0; i itExtends = extendsSet.iterator(); @@ -595,7 +596,7 @@ public class FamilyOfGeneratedGenerics { Iterator 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 itTC = tcOfoldConsSet.iterator(); while(itTC.hasNext()) { @@ -634,28 +635,55 @@ public class FamilyOfGeneratedGenerics { }*/ } + // Berechnung des zweiten Teils der Regel - Iterator itExtends2 = extendsSetAllOfOr.iterator(); - while(itExtends2.hasNext()) { - Pair pairExtends2 = itExtends2.next(); - Iterator 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 extendsSet = new Constraint(); + Constraint equalSet = new Constraint(); + //für jede einzelne OrConstraint-Menge gehe durch + for (Constraint con : orCons.get(i)) { + Iterator it = con.iterator(); + while (it.hasNext()) { + Pair p = it.next(); + if (p.OperatorSmallerDot()) { + extendsSet.add(p); + } else if (p.OperatorEqual()) { + equalSet.add(p); + } + } + Iterator itExtends2 = extendsSet.iterator(); + while(itExtends2.hasNext()) { + Pair pairExtends2 = itExtends2.next(); + Iterator 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 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 itTemp = tempSet.iterator(); while(itTemp.hasNext()) { diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index a6157ecc..518ca0ad 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -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; From f5f639c0f74a1788a3351c8c9c446cccf40581ea Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 15:24:15 +0100 Subject: [PATCH 081/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 358c6d34..3f98a42b 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -664,16 +664,31 @@ public class FamilyOfGeneratedGenerics { 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); +// Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); + boolean isPairInTExTapostrophe = false; +// Constraint allOfOr = new Constraint(); + for(Set> scp: orCons) { + Iterator> itSCP = scp.iterator(); + while(itSCP.hasNext()) { + Constraint cp = itSCP.next(); + Iterator itCP = cp.iterator(); + while(itCP.hasNext()) { + Pair p = itCP.next(); + if(p.OperatorSmallerDot()) { + isPairInTExTapostrophe = tphR == p.TA1; + } + } + } + } + if (rEqRtilde || rExRtilde || isPairInTExTapostrophe) { if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA - if (!checkForDuplicatesForSets(newPair2, tempSet2)) { - tempSet2.add(pairExtends2); + if (!checkForDuplicatesForSets(newPair2, tempSet2)) tempSet2.add(newPair2); - } } + if (!checkForDuplicatesForSets(pairExtends2, tempSet2)) + tempSet2.add(pairExtends2); } } From db149eb5884d2b28be3c9737895d239902668e98 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 26 Mar 2021 16:15:18 +0100 Subject: [PATCH 082/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java klein Korrekturen modified: src/test/java/insertGenerics/TestTwoArgs2.java List -> Set --- .../insertGenerics/FamilyOfGeneratedGenerics.java | 7 +++---- src/test/java/insertGenerics/TestTwoArgs2.java | 15 +++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 3f98a42b..ede2b1b6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -662,8 +662,7 @@ public class FamilyOfGeneratedGenerics { Iterator itUndCons = undCons.iterator(); while (itUndCons.hasNext()) { Pair pairUndCons2 = itUndCons.next(); - boolean rEqRtilde = (tphR == pairUndCons2.TA1); - boolean rExRtilde = (tphR == pairUndCons2.TA1); + boolean rEqExRtilde = (tphR == pairUndCons2.TA1); // Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); boolean isPairInTExTapostrophe = false; // Constraint allOfOr = new Constraint(); @@ -675,14 +674,14 @@ public class FamilyOfGeneratedGenerics { while(itCP.hasNext()) { Pair p = itCP.next(); if(p.OperatorSmallerDot()) { - isPairInTExTapostrophe = tphR == p.TA1; + isPairInTExTapostrophe = isPairInTExTapostrophe || tphR.equals(p.TA1); } } } } - if (rEqRtilde || rExRtilde || isPairInTExTapostrophe) { + if (rEqExRtilde || isPairInTExTapostrophe) { if (newPair2.TA1 != newPair2.TA2) { //eliminieren der Fälle wie AA<.AA if (!checkForDuplicatesForSets(newPair2, tempSet2)) tempSet2.add(newPair2); diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java index 42a5a833..780a4401 100644 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ b/src/test/java/insertGenerics/TestTwoArgs2.java @@ -56,15 +56,15 @@ public class TestTwoArgs2 { List classConstraintsTest = new ArrayList<>(); classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - List lmc; - lmc = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS)); lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS)); @@ -73,7 +73,7 @@ public class TestTwoArgs2 { lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc); - lmc = new ArrayList<>(); + lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc); @@ -84,7 +84,10 @@ public class TestTwoArgs2 { assertEquals(expectedClassCons, computedClassCons); - assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); From ff93b0967e6a5b11490bf40c2e3329b96b2d3753 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 26 Mar 2021 16:27:24 +0100 Subject: [PATCH 083/101] 2 modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java --- .../insertGenerics/TestTPHsAndGenerics.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 2b475bbf..3bf3dee2 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -66,7 +66,7 @@ public class TestTPHsAndGenerics { if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); @@ -80,8 +80,8 @@ public class TestTPHsAndGenerics { lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); - } - else { + } else { + if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) { classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); @@ -98,7 +98,29 @@ public class TestTPHsAndGenerics { lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); + } else { + if (fogg.allConstraints.contains((new MethodConstraint("EIM", "FEA", Relation.EXTENDS)))) { + classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + + lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } + } + + } + Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); From 345b03b775ba33034b7c8b3a1a767bc03ca52605 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 26 Mar 2021 17:27:27 +0100 Subject: [PATCH 084/101] modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java --- src/test/java/insertGenerics/TestTPHsAndGenerics.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 3bf3dee2..f3ff4db3 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -66,7 +66,7 @@ public class TestTPHsAndGenerics { if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); @@ -84,7 +84,7 @@ public class TestTPHsAndGenerics { if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) { classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); @@ -94,7 +94,7 @@ public class TestTPHsAndGenerics { methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + methodConstraintsWithPositionTest.put("TPH Uid2(TPH V)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); From da2a17c794e3d41c2447d1a0ac9a930c1788c0dd Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 18:33:36 +0100 Subject: [PATCH 085/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java --- .../FamilyOfGeneratedGenerics.java | 33 ++++++++++++++++++- .../insertGenerics/TestTPHsAndGenerics.java | 9 ++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index ede2b1b6..097185e0 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -812,6 +812,36 @@ public class FamilyOfGeneratedGenerics { return tempMC; } + + + public static List methodTypesWithoutClassTypesNEW(String tphToCompute, List cs_m, HashMap>> posOfTphs) { + List tempMC = new ArrayList<>(cs_m); + if(tphToCompute==null || tphToCompute.isEmpty()) { + for(TPHConstraint tphCons: tempMC) { + for(String tph: posOfTphs.keySet()){ + for(PairTphMethod p: posOfTphs.get(tph)) { + if(p.fst == PositionFinder.Position.FIELD && tphCons.getLeft() == tph) { + String rightTPH = tphCons.getRight(); + tempMC.remove(tphCons); + methodTypesWithoutClassTypesNEW(rightTPH,tempMC,posOfTphs); + } + } + } + } + } else { + for(TPHConstraint tphCons: tempMC) { + if(tphCons.getLeft() == tphToCompute) { + String newRightTPH = tphCons.getRight(); + tempMC.remove(tphCons); + methodTypesWithoutClassTypesNEW(newRightTPH,tempMC,posOfTphs); + } + } + } + return tempMC; + } + + + public static HashMap> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); List newMCList = new ArrayList<>(); @@ -857,7 +887,8 @@ public class FamilyOfGeneratedGenerics { } } - mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd); +// mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd); + mcWithoutCc = methodTypesWithoutClassTypesNEW(null, listToAdd, posOfTphs); tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc); } diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 3bf3dee2..387204c2 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -100,9 +100,9 @@ public class TestTPHsAndGenerics { methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } else { if (fogg.allConstraints.contains((new MethodConstraint("EIM", "FEA", Relation.EXTENDS)))) { - classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("VK", "EIM", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("EIM", "FEA", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("FEA", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); @@ -112,9 +112,10 @@ public class TestTPHsAndGenerics { methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); + methodConstraintsWithPositionTest.put("TPH FEAid2(TPH V)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } } From 32e9ce92a645f039f0cd66fd4f507b04d1d4bb61 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 19:58:38 +0100 Subject: [PATCH 086/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java --- .../FamilyOfGeneratedGenerics.java | 35 ++++++++----------- src/test/java/insertGenerics/TestTwoArgs.java | 2 ++ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 097185e0..8b8b2852 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -816,28 +816,15 @@ public class FamilyOfGeneratedGenerics { public static List methodTypesWithoutClassTypesNEW(String tphToCompute, List cs_m, HashMap>> posOfTphs) { List tempMC = new ArrayList<>(cs_m); - if(tphToCompute==null || tphToCompute.isEmpty()) { - for(TPHConstraint tphCons: tempMC) { - for(String tph: posOfTphs.keySet()){ - for(PairTphMethod p: posOfTphs.get(tph)) { - if(p.fst == PositionFinder.Position.FIELD && tphCons.getLeft() == tph) { - String rightTPH = tphCons.getRight(); - tempMC.remove(tphCons); - methodTypesWithoutClassTypesNEW(rightTPH,tempMC,posOfTphs); - } - } - } - } - } else { - for(TPHConstraint tphCons: tempMC) { - if(tphCons.getLeft() == tphToCompute) { - String newRightTPH = tphCons.getRight(); - tempMC.remove(tphCons); - methodTypesWithoutClassTypesNEW(newRightTPH,tempMC,posOfTphs); - } + List tempMC2 = new ArrayList<>(cs_m); + for(TPHConstraint tphCons: tempMC) { + if(tphCons.getLeft() == tphToCompute) { + String newRightTPH = tphCons.getRight(); + tempMC2.remove(tphCons); + tempMC2 = methodTypesWithoutClassTypesNEW(newRightTPH,tempMC2,posOfTphs); } } - return tempMC; + return tempMC2; } @@ -888,7 +875,13 @@ public class FamilyOfGeneratedGenerics { } // mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd); - mcWithoutCc = methodTypesWithoutClassTypesNEW(null, listToAdd, posOfTphs); + for(String tph: posOfTphs.keySet()) { + for (PairTphMethod p : posOfTphs.get(tph)) { + if(p.fst == PositionFinder.Position.FIELD) { + mcWithoutCc = methodTypesWithoutClassTypesNEW(tph, listToAdd, posOfTphs); + } + } + } tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc); } diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index 8016a039..faa405e2 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -65,11 +65,13 @@ public class TestTwoArgs { Set lmc; lmc = new HashSet<>(); lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); From 080eb2f6f32837fd2b5f0ef40e662c62f75799f9 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 20:18:45 +0100 Subject: [PATCH 087/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../bytecode/insertGenerics/FamilyOfGeneratedGenerics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 8b8b2852..84658503 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -874,7 +874,7 @@ public class FamilyOfGeneratedGenerics { } } -// mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd); + mcWithoutCc = listToAdd; for(String tph: posOfTphs.keySet()) { for (PairTphMethod p : posOfTphs.get(tph)) { if(p.fst == PositionFinder.Position.FIELD) { From af223a4d8ad4b3f8f9043660f9ecd2a9138190d3 Mon Sep 17 00:00:00 2001 From: AluAli Date: Fri, 26 Mar 2021 20:53:24 +0100 Subject: [PATCH 088/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 84658503..5fbea9bc 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -814,14 +814,17 @@ public class FamilyOfGeneratedGenerics { - public static List methodTypesWithoutClassTypesNEW(String tphToCompute, List cs_m, HashMap>> posOfTphs) { + public static List methodTypesWithoutClassTypesNEW(List tphsToCompute, List cs_m, HashMap>> posOfTphs) { List tempMC = new ArrayList<>(cs_m); List tempMC2 = new ArrayList<>(cs_m); - for(TPHConstraint tphCons: tempMC) { - if(tphCons.getLeft() == tphToCompute) { - String newRightTPH = tphCons.getRight(); - tempMC2.remove(tphCons); - tempMC2 = methodTypesWithoutClassTypesNEW(newRightTPH,tempMC2,posOfTphs); + List toRemove = new ArrayList<>(); + for(String tph: tphsToCompute) { + for(TPHConstraint tphCons: tempMC) { + if(tphCons.getLeft() == tph) { + toRemove.add(tphCons.getRight()); + tempMC2.remove(tphCons); + tempMC2 = methodTypesWithoutClassTypesNEW(toRemove,tempMC2,posOfTphs); + } } } return tempMC2; @@ -875,10 +878,12 @@ public class FamilyOfGeneratedGenerics { } mcWithoutCc = listToAdd; + List tphs = new ArrayList<>(); for(String tph: posOfTphs.keySet()) { for (PairTphMethod p : posOfTphs.get(tph)) { if(p.fst == PositionFinder.Position.FIELD) { - mcWithoutCc = methodTypesWithoutClassTypesNEW(tph, listToAdd, posOfTphs); + tphs.add(tph); + mcWithoutCc = methodTypesWithoutClassTypesNEW(tphs, listToAdd, posOfTphs); } } } From e229093017ce45fc0680b6b98ed8533de0b5cb31 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 29 Mar 2021 09:57:45 +0200 Subject: [PATCH 089/101] new file: src/test/java/insertGenerics/TestContraVariant.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java new file: src/test/java/insertGenerics/TestThreeArgs.java --- .../FamilyOfGeneratedGenerics.java | 3 +- .../insertGenerics/TestContraVariant.java | 104 ++++++++++++++++++ .../insertGenerics/TestTPHsAndGenerics.java | 2 + .../java/insertGenerics/TestThreeArgs.java | 90 +++++++++++++++ 4 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 src/test/java/insertGenerics/TestContraVariant.java create mode 100644 src/test/java/insertGenerics/TestThreeArgs.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 5fbea9bc..cd479b20 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -597,7 +597,8 @@ public class FamilyOfGeneratedGenerics { while(itEqual.hasNext()) { Pair pairEqual = itEqual.next(); // 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 itTC = tcOfoldConsSet.iterator(); while(itTC.hasNext()) { Pair pairTC = itTC.next(); diff --git a/src/test/java/insertGenerics/TestContraVariant.java b/src/test/java/insertGenerics/TestContraVariant.java new file mode 100644 index 00000000..0be39f5c --- /dev/null +++ b/src/test/java/insertGenerics/TestContraVariant.java @@ -0,0 +1,104 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestContraVariant { + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"TestContraVariant.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + } + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("R", "O", Relation.EXTENDS)); + 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("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); + + //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } +} diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index dd47ca52..ff99b2cb 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -79,6 +79,7 @@ public class TestTPHsAndGenerics { methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } else { if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) { @@ -97,6 +98,7 @@ public class TestTPHsAndGenerics { methodConstraintsWithPositionTest.put("TPH Uid2(TPH V)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); } else { if (fogg.allConstraints.contains((new MethodConstraint("EIM", "FEA", Relation.EXTENDS)))) { diff --git a/src/test/java/insertGenerics/TestThreeArgs.java b/src/test/java/insertGenerics/TestThreeArgs.java new file mode 100644 index 00000000..75e50580 --- /dev/null +++ b/src/test/java/insertGenerics/TestThreeArgs.java @@ -0,0 +1,90 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestThreeArgs { + + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestThreeArgs"; + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("P", "R", Relation.EXTENDS)); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc); + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Wm(TPH WTPH ABTPH AC)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); + + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + return new TestResultSet(); + } +} From bf8d4fe6472ba2d43351948d37fa73d850b4b088 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 29 Mar 2021 10:00:04 +0200 Subject: [PATCH 090/101] new file: src/test/resources/insertGenericsJav/TestContraVariant.jav new file: src/test/resources/insertGenericsJav/TestMutualRecursionWithField2.jav new file: src/test/resources/insertGenericsJav/TestMutualRecursionWithField3.jav --- .../insertGenericsJav/TestContraVariant.jav | 12 ++++++++++ .../TestMutualRecursionWithField2.jav | 22 ++++++++++++++++++ .../TestMutualRecursionWithField3.jav | 23 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/test/resources/insertGenericsJav/TestContraVariant.jav create mode 100644 src/test/resources/insertGenericsJav/TestMutualRecursionWithField2.jav create mode 100644 src/test/resources/insertGenericsJav/TestMutualRecursionWithField3.jav diff --git a/src/test/resources/insertGenericsJav/TestContraVariant.jav b/src/test/resources/insertGenericsJav/TestContraVariant.jav new file mode 100644 index 00000000..9349e620 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestContraVariant.jav @@ -0,0 +1,12 @@ +public class TestContraVariant { + + m(x) { + var y; + x = y; + return y; + } + + main(x) { + return m(x); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestMutualRecursionWithField2.jav b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField2.jav new file mode 100644 index 00000000..727e6031 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField2.jav @@ -0,0 +1,22 @@ +public class TestMutualRecursionWithField2 { + a; + + id(b) { + var c = b; + return main(b,c); + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + return m(setA(x),id(y)); + } +} \ No newline at end of file diff --git a/src/test/resources/insertGenericsJav/TestMutualRecursionWithField3.jav b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField3.jav new file mode 100644 index 00000000..24e09890 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestMutualRecursionWithField3.jav @@ -0,0 +1,23 @@ +public class TestMutualRecursionWithField3 { + a; + + id(b) { + var c = b; + return main(b,c); + } + + setA(x) { + a = x; + return a; + } + + m(x,y) { + x = id(y); + return x; + } + + main(x,y) { + var z = m(setA(x),id(y)); + return z; + } +} \ No newline at end of file From d1ad6e218aa04f8a1d4a342d708351db7d306e8d Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 29 Mar 2021 10:45:21 +0200 Subject: [PATCH 091/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java --- .../FamilyOfGeneratedGenerics.java | 24 +++++++++++-------- src/test/java/insertGenerics/TestTwoArgs.java | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index cd479b20..5f691554 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -513,8 +513,8 @@ public class FamilyOfGeneratedGenerics { public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { List tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali) - Set tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils basierend auf der alten Datenstruktur - Set tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils basierend auf der alten Datenstruktur + Set tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils der Bedinung basierend auf der alten Datenstruktur + Set tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils der Bedingung basierend auf der alten Datenstruktur Set tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet); List tcOfCs = buildTransitiveClosure(allConstraints); MethodAndTPH methAndTphs = methodAndTPH; @@ -572,7 +572,7 @@ public class FamilyOfGeneratedGenerics { // Constraint extendsSetAllOfOr = new Constraint(); // Constraint equalSetAllOfOr = new Constraint(); - // Berechnung des ersten Teils der Regel + // Berechnung des ersten Teils der Bedingung der Regel for(int i=0; i extendsSet = new Constraint(); Constraint equalSet = new Constraint(); @@ -597,15 +597,18 @@ public class FamilyOfGeneratedGenerics { while(itEqual.hasNext()) { Pair pairEqual = itEqual.next(); // tphR = (TypePlaceholder) (pairEqual.TA2); + //newPair entspricht \sigma(T'_0) < \sigma(R_0) + //TODO: Überprüfen: newPair und tras clos ohne resolvedType Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); Iterator itTC = tcOfoldConsSet.iterator(); - while(itTC.hasNext()) { + while(itTC.hasNext()) {//ueberpruefen ob newPair in transitiv closure Pair pairTC = itTC.next(); if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //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!) if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA if (!checkForDuplicatesForSets(newPair, tempSet)) { - tempSet.add(newPair); + //TODO: evtl. pairExtends hinzufuegen + tempSet.add(newPair); } } } @@ -637,7 +640,7 @@ public class FamilyOfGeneratedGenerics { } - // Berechnung des zweiten Teils der Regel + // Berechnung des zweiten Teils der Bedingung der Regel for(int i=0; i extendsSet = new Constraint(); Constraint equalSet = new Constraint(); @@ -658,6 +661,7 @@ public class FamilyOfGeneratedGenerics { Iterator itEqual2 = equalSet.iterator(); while (itEqual2.hasNext()) { Pair pairEqual2 = itEqual2.next(); + //TODO: Auf trans.FamilyOfGeneratedGenerics Huelle pruefen Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT); TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2; Iterator itUndCons = undCons.iterator(); @@ -731,7 +735,7 @@ public class FamilyOfGeneratedGenerics { } else if (p.GetOperator() == PairOperator.EQUALSDOT) { r = Relation.EQUAL; } - for(TPHConstraint tphCons: tcOfCs) { + for(TPHConstraint tphCons: tcOfCs) {//TODO: hier werden Elemente der Trans. clo herausgenommen, aber die dazugehoerigen OrCons nicht. if(ta1 == tphCons.getLeft() && ta2 == tphCons.getRight() && r==Relation.EXTENDS) { MethodConstraint mc = new MethodConstraint(ta1, ta2, r); if(!checkForDuplicates(mc, tempMC)) { @@ -815,7 +819,7 @@ public class FamilyOfGeneratedGenerics { - public static List methodTypesWithoutClassTypesNEW(List tphsToCompute, List cs_m, HashMap>> posOfTphs) { + public static List methodTypesWithoutClassTypesNEW(List tphsToCompute, List cs_m) { List tempMC = new ArrayList<>(cs_m); List tempMC2 = new ArrayList<>(cs_m); List toRemove = new ArrayList<>(); @@ -824,7 +828,7 @@ public class FamilyOfGeneratedGenerics { if(tphCons.getLeft() == tph) { toRemove.add(tphCons.getRight()); tempMC2.remove(tphCons); - tempMC2 = methodTypesWithoutClassTypesNEW(toRemove,tempMC2,posOfTphs); + tempMC2 = methodTypesWithoutClassTypesNEW(toRemove,tempMC2); } } } @@ -884,7 +888,7 @@ public class FamilyOfGeneratedGenerics { for (PairTphMethod p : posOfTphs.get(tph)) { if(p.fst == PositionFinder.Position.FIELD) { tphs.add(tph); - mcWithoutCc = methodTypesWithoutClassTypesNEW(tphs, listToAdd, posOfTphs); + mcWithoutCc = methodTypesWithoutClassTypesNEW(tphs, listToAdd); } } } diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index faa405e2..95d1876c 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -80,6 +80,8 @@ public class TestTwoArgs { lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS)); lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS)); lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc); FamilyOfGeneratedGenerics fogg = compiler.fogg; From 9be64e490557477cac6bdef6b671a4e00097fbc5 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 31 Mar 2021 18:18:16 +0200 Subject: [PATCH 092/101] 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 --- .../bytecode/constraint/TPHConstraint.java | 11 ++++ .../FamilyOfGeneratedGenerics.java | 55 +++++++++++++++---- .../bytecode/utilities/MethodAndTPH.java | 5 ++ .../insertGenerics/TestContraVariant.java | 3 +- .../insertGenerics/TestLocalVarLambda.java | 6 +- .../insertGenerics/TestTransitiveClosure.java | 4 +- 6 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java index 6cded807..0533a028 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -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; diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 5f691554..c361f154 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -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>> posOfTPHs = new HashMap<>(); public List classConstraints = new ArrayList<>(); + private HashMap mapMethodsAndTph = new HashMap<>(); public List methodConstraints = new ArrayList<>(); public HashMap> 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 getMethodConstraints(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { + public List getMethodConstraints(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { @@ -114,7 +116,7 @@ public class FamilyOfGeneratedGenerics { return cs_m; } - public static HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { + public HashMap> getMethodConstraintsWithPosition(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); for(MethodAndTPH method: listOfMethodsAndTph){ List 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 firstTransitiveSubtypeForMethodTypes(List allConstraints, List cs_m) { //transitive closure of cs + public List firstTransitiveSubtypeForMethodTypes(List allConstraints, List cs_m) { //transitive closure of cs //TODO: List tempMC= new ArrayList<>(); List 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 secondTransitiveSubtypeForMethodTypes(List allConstraints, List cs_cl, List cs_m) { + public List secondTransitiveSubtypeForMethodTypes(List allConstraints, List cs_cl, List cs_m) { //TODO: List tempMC= new ArrayList<>(); List tcOfCs = buildTransitiveClosure(allConstraints); @@ -369,7 +371,7 @@ public class FamilyOfGeneratedGenerics { /** * nimm die Menge cs_cl aus cs_m raus */ - public static List methodTypesWithoutClassTypes(List cs_cl, List cs_m) { + public List methodTypesWithoutClassTypes(List cs_cl, List cs_m) { // erstelle Kopie der Liste cs_cl List tempCC = new ArrayList<>(); for(ClassConstraint cc: cs_cl) { @@ -415,7 +417,7 @@ public class FamilyOfGeneratedGenerics { return false; } - public static List buildTransitiveClosure(List list) { + public List buildTransitiveClosure(List list) { List iterList = new ArrayList<>(list); List runList = new ArrayList<>(list); List tcList = new ArrayList<>(list); @@ -511,7 +513,7 @@ public class FamilyOfGeneratedGenerics { return tempMC; } - public static List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { + public List secondLineMethodDefinition(List allConstraints, HashMap>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set oldCons) { List tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali) Set tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils der Bedinung basierend auf der alten Datenstruktur Set tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils der Bedingung basierend auf der alten Datenstruktur @@ -572,6 +574,7 @@ public class FamilyOfGeneratedGenerics { // Constraint extendsSetAllOfOr = new Constraint(); // Constraint equalSetAllOfOr = new Constraint(); + // Berechnung des ersten Teils der Bedingung der Regel for(int i=0; i extendsSet = new Constraint(); @@ -660,9 +663,39 @@ public class FamilyOfGeneratedGenerics { Pair pairExtends2 = itExtends2.next(); Iterator 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 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 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> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { + public HashMap> getMethodConstraintsWithPositionNew(List cs, List cs_cl, HashMap>> posOfTphs, List listOfMethodsAndTph, ResultSet resSet, Set oldCons) { HashMap> tempMethodConstraintsWithPosition = new HashMap<>(); List newMCList = new ArrayList<>(); List newMCList2 = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index 892b0894..c5a93f4f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -47,4 +47,9 @@ public class MethodAndTPH { return localTphs; } + @Override + public String toString() { + return id; + } + } diff --git a/src/test/java/insertGenerics/TestContraVariant.java b/src/test/java/insertGenerics/TestContraVariant.java index 0be39f5c..f220f3d5 100644 --- a/src/test/java/insertGenerics/TestContraVariant.java +++ b/src/test/java/insertGenerics/TestContraVariant.java @@ -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); diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index 530ef318..93ff3415 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -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 computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); diff --git a/src/test/java/insertGenerics/TestTransitiveClosure.java b/src/test/java/insertGenerics/TestTransitiveClosure.java index 95c6a0e2..4eaf0527 100644 --- a/src/test/java/insertGenerics/TestTransitiveClosure.java +++ b/src/test/java/insertGenerics/TestTransitiveClosure.java @@ -21,8 +21,8 @@ public class TestTransitiveClosure { @Test public void genericTest() { - List testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList()); - System.out.println(testCons); + //List testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList()); + //System.out.println(testCons); } } From 0cb1f244bcbd0f42a9a21e31d23e785a4032aee2 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 1 Apr 2021 16:59:14 +0200 Subject: [PATCH 093/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java Tests insertGenerics funtionieren modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java reset-Funktion eingefuegt, damit bei jedem Test die Namen der TypepLaceholdert von vorne beginnen modified: src/test/java/insertGenerics/TestContraVariant.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestThreeArgs.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 2 +- .../FamilyOfGeneratedGenerics.java | 32 ++++++++++++------- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 1 + .../syntaxtree/factory/NameGenerator.java | 10 ++++++ .../insertGenerics/TestContraVariant.java | 4 +-- .../insertGenerics/TestTPHsAndGenerics.java | 12 +++---- .../java/insertGenerics/TestThreeArgs.java | 8 +++-- 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 3154c931..2db52ec3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -195,7 +195,7 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(Method method) { inMethod = true; String id = MethodUtility.createID(resolver,method); - Predicate filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) && + Predicate filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) && (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) && (resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder)); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index c361f154..d293fe6c 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -505,9 +505,11 @@ public class FamilyOfGeneratedGenerics { } MethodConstraint mc = new MethodConstraint(ta1, ta2, r); if(mc.getRel() == Relation.EXTENDS) { - if(!checkForDuplicates(mc, tempMC)) { - tempMC.add(mc); - } + if (!mc.getLeft().equals(mc.getRight())) { //eliminieren der Fälle wie AA<.AA + if(!checkForDuplicates(mc, tempMC)) { + tempMC.add(mc); + } + } } } return tempMC; @@ -611,7 +613,7 @@ public class FamilyOfGeneratedGenerics { if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA if (!checkForDuplicatesForSets(newPair, tempSet)) { //TODO: evtl. pairExtends hinzufuegen - tempSet.add(newPair); + //tempSet.add(newPair); } } } @@ -662,6 +664,7 @@ public class FamilyOfGeneratedGenerics { while(itExtends2.hasNext()) { Pair pairExtends2 = itExtends2.next(); Iterator itEqual2 = equalSet.iterator(); + while (itEqual2.hasNext()) { boolean transClo = false; Pair pairEqual2 = itEqual2.next(); @@ -693,15 +696,17 @@ public class FamilyOfGeneratedGenerics { // break; //} //} - if (tcOfCs.contains(newPairTPHConstraint)) { + if (tcOfCs.contains(newPairTPHConstraint)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) { transClo = true; } TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2; Iterator itUndCons = undCons.iterator(); + boolean rEqExRtilde = false; while (itUndCons.hasNext()) { Pair pairUndCons2 = itUndCons.next(); - boolean rEqExRtilde = (tphR == pairUndCons2.TA1); + rEqExRtilde = rEqExRtilde || (tphR == pairUndCons2.TA1); // Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); + } boolean isPairInTExTapostrophe = false; // Constraint allOfOr = new Constraint(); for(Set> scp: orCons) { @@ -716,10 +721,10 @@ public class FamilyOfGeneratedGenerics { } } } + } - - - if ((rEqExRtilde || isPairInTExTapostrophe)) { + + if (transClo && (rEqExRtilde || isPairInTExTapostrophe)) { if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA if (transClo && !checkForDuplicatesForSets(newPair2, tempSet2)) tempSet2.add(newPair2); @@ -727,10 +732,13 @@ public class FamilyOfGeneratedGenerics { if (!checkForDuplicatesForSets(pairExtends2, tempSet2)) tempSet2.add(pairExtends2); } - } - - } + String key = ((TypePlaceholder)pairExtends2.TA2).getName(); + if (posOfTphs.containsKey(key)) { + if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { + tempSet2.add(pairExtends2); + } + } } } } diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index eb220f4f..1b3e67c4 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -102,6 +102,7 @@ public class JavaTXCompiler { } classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader()); environment = new CompilationEnvironment(sources); + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); for (File s : sources) { sourceFiles.put(s, parse(s)); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java index f20ea0cd..1c8dee42 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java @@ -4,6 +4,16 @@ public class NameGenerator { private static String strNextName = "A"; + /** + * Setzt den zu Beginn der Typinferenz auf "A" zurueck. + * Dies ist beio den JUnit-Test noetig + * TypePlaceholder.
Author: Martin Pluemicke + * @return void + */ + public static void reset() { + strNextName = "A"; + } + /** * Berechnet einen neuen, eindeutigen Namen f�r eine neue * TypePlaceholder.
Author: J�rg B�uerle diff --git a/src/test/java/insertGenerics/TestContraVariant.java b/src/test/java/insertGenerics/TestContraVariant.java index f220f3d5..328044fa 100644 --- a/src/test/java/insertGenerics/TestContraVariant.java +++ b/src/test/java/insertGenerics/TestContraVariant.java @@ -57,8 +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", "O", Relation.EXTENDS)); - lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS)); + lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index ff99b2cb..870d8c96 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -70,9 +70,9 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); @@ -89,9 +89,9 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); @@ -108,9 +108,9 @@ public class TestTPHsAndGenerics { lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); + //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS)); diff --git a/src/test/java/insertGenerics/TestThreeArgs.java b/src/test/java/insertGenerics/TestThreeArgs.java index 75e50580..dd93724f 100644 --- a/src/test/java/insertGenerics/TestThreeArgs.java +++ b/src/test/java/insertGenerics/TestThreeArgs.java @@ -59,8 +59,9 @@ public class TestThreeArgs { HashMap> methodConstraintsWithPositionTest = new HashMap<>(); Set lmc; lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "R", Relation.EXTENDS)); - lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc); lmc = new HashSet<>(); lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS)); @@ -84,7 +85,8 @@ public class TestThreeArgs { compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + //liefert Fehler, da Variable "a" nicht initialisiert ist. + //instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); return new TestResultSet(); } } From bbfd8aa203b98b55286b229e0f6eb8d499d190ad Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 1 Apr 2021 17:13:06 +0200 Subject: [PATCH 094/101] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../FamilyOfGeneratedGenerics.java | 143 +++--------------- 1 file changed, 23 insertions(+), 120 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index d293fe6c..fc29b869 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -571,79 +571,6 @@ public class FamilyOfGeneratedGenerics { oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r)); } - // dies ist das "R" aus dem ersten Teil, wird im zweiten Teil gebraucht -// TypePlaceholder tphR = null; -// Constraint extendsSetAllOfOr = new Constraint(); -// Constraint equalSetAllOfOr = new Constraint(); - - - // Berechnung des ersten Teils der Bedingung der Regel - for(int i=0; i extendsSet = new Constraint(); - Constraint equalSet = new Constraint(); - //für jede einzelne OrConstraint-Menge gehe durch - for(Constraint con: orCons.get(i)) { - Iterator it = con.iterator(); - //für jeden Eintrag der Menge - while (it.hasNext()) { - Pair p = it.next(); - if (p.OperatorSmallerDot()) { - extendsSet.add(p); -// extendsSetAllOfOr.add(p); - } else if (p.OperatorEqual()) { - equalSet.add(p); -// equalSetAllOfOr.add(p); - } - } - Iterator itExtends = extendsSet.iterator(); - while(itExtends.hasNext()) { - Pair pairExtends = itExtends.next(); - Iterator itEqual = equalSet.iterator(); - while(itEqual.hasNext()) { - Pair pairEqual = itEqual.next(); -// tphR = (TypePlaceholder) (pairEqual.TA2); - //newPair entspricht \sigma(T'_0) < \sigma(R_0) - //TODO: Überprüfen: newPair und tras clos ohne resolvedType - Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, - resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); - Iterator itTC = tcOfoldConsSet.iterator(); - while(itTC.hasNext()) {//ueberpruefen ob newPair in transitiv closure - Pair pairTC = itTC.next(); - if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //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!) - if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA - if (!checkForDuplicatesForSets(newPair, tempSet)) { - //TODO: evtl. pairExtends hinzufuegen - //tempSet.add(newPair); - } - } - } - } - } - } - } - - - /*// Berechnung des zweiten Teils der Regel - Iterator itEqual = equalSet.iterator(); - while(itEqual.hasNext()) { - Pair pairEqual = itEqual.next(); - Iterator itExtends = equalSet.iterator(); - while(itExtends.hasNext()) { - Pair pairExtends = itExtends.next(); - Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT); - Iterator itTC = tcOfoldConsSet.iterator(); - while(itTC.hasNext()) { - Pair pairTC = itTC.next(); - - // prüfe, ob das "R" von vorhin in einem EqualConstraint links auftaucht - if(tphR == pairEqual.TA1) { -// tempSet.add(); - } - } - } - }*/ - - } // Berechnung des zweiten Teils der Bedingung der Regel for(int i=0; i 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)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) { transClo = true; } @@ -705,34 +608,34 @@ public class FamilyOfGeneratedGenerics { while (itUndCons.hasNext()) { Pair pairUndCons2 = itUndCons.next(); rEqExRtilde = rEqExRtilde || (tphR == pairUndCons2.TA1); -// Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); } - boolean isPairInTExTapostrophe = false; -// Constraint allOfOr = new Constraint(); - for(Set> scp: orCons) { - Iterator> itSCP = scp.iterator(); - while(itSCP.hasNext()) { - Constraint cp = itSCP.next(); - Iterator itCP = cp.iterator(); - while(itCP.hasNext()) { - Pair p = itCP.next(); - if(p.OperatorSmallerDot()) { - isPairInTExTapostrophe = isPairInTExTapostrophe || tphR.equals(p.TA1); - } + boolean isPairInTExTapostrophe = false; + for(Set> scp: orCons) { + Iterator> itSCP = scp.iterator(); + while(itSCP.hasNext()) { + Constraint cp = itSCP.next(); + Iterator itCP = cp.iterator(); + while(itCP.hasNext()) { + Pair p = itCP.next(); + if(p.OperatorSmallerDot()) { + isPairInTExTapostrophe = isPairInTExTapostrophe || tphR.equals(p.TA1); } } + } - } + } - if (transClo && (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)) - tempSet2.add(pairExtends2); - } - } + if (transClo && (rEqExRtilde || isPairInTExTapostrophe)) { + if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA + if (!checkForDuplicatesForSets(newPair2, tempSet2)) { + tempSet2.add(newPair2); + } + } + if (!checkForDuplicatesForSets(pairExtends2, tempSet2)) { + tempSet2.add(pairExtends2); + } + } + } String key = ((TypePlaceholder)pairExtends2.TA2).getName(); if (posOfTphs.containsKey(key)) { if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { From b46415e45a28f42c042a13c8cea1eefdf8588a45 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 1 Apr 2021 19:16:57 +0200 Subject: [PATCH 095/101] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java reset Typevars-Namen wieder rausgenommen modified: src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java modified: src/test/java/insertGenerics/TestAny.java modified: src/test/java/insertGenerics/TestClassField.java modified: src/test/java/insertGenerics/TestContraVariant.java modified: src/test/java/insertGenerics/TestGGFinder.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestMutualRecursion.java modified: src/test/java/insertGenerics/TestReturnVar.java modified: src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics2.java modified: src/test/java/insertGenerics/TestThreeArgs.java modified: src/test/java/insertGenerics/TestTwoArgs.java modified: src/test/java/insertGenerics/TestTwoArgs2.java modified: src/test/java/insertGenerics/TestTwoCalls.java modified: src/test/java/insertGenerics/TestVector.java modified: src/test/java/insertGenerics/TestVoidMeth.java Reset Typevar-Namen in @BeforeClass eingefuegt --- .../java/de/dhbwstuttgart/core/JavaTXCompiler.java | 1 - .../syntaxtree/factory/NameGenerator.java | 2 +- src/test/java/insertGenerics/TestAny.java | 7 +++++++ src/test/java/insertGenerics/TestClassField.java | 7 +++++++ src/test/java/insertGenerics/TestContraVariant.java | 7 +++++++ src/test/java/insertGenerics/TestGGFinder.java | 9 ++++++++- src/test/java/insertGenerics/TestLocalVarLambda.java | 9 ++++++++- src/test/java/insertGenerics/TestMutualRecursion.java | 9 ++++++++- src/test/java/insertGenerics/TestReturnVar.java | 7 +++++++ .../TestSecondLineOfClassConstraints.java | 7 +++++++ src/test/java/insertGenerics/TestTPHsAndGenerics.java | 11 +++++++++-- .../java/insertGenerics/TestTPHsAndGenerics2.java | 7 +++++++ src/test/java/insertGenerics/TestThreeArgs.java | 9 ++++++++- src/test/java/insertGenerics/TestTwoArgs.java | 9 ++++++++- src/test/java/insertGenerics/TestTwoArgs2.java | 9 ++++++++- src/test/java/insertGenerics/TestTwoCalls.java | 9 ++++++++- src/test/java/insertGenerics/TestVector.java | 9 ++++++++- src/test/java/insertGenerics/TestVoidMeth.java | 7 +++++++ 18 files changed, 123 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 1b3e67c4..eb220f4f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -102,7 +102,6 @@ public class JavaTXCompiler { } classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader()); environment = new CompilationEnvironment(sources); - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); for (File s : sources) { sourceFiles.put(s, parse(s)); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java index 1c8dee42..06414b98 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java @@ -6,7 +6,7 @@ public class NameGenerator { /** * Setzt den zu Beginn der Typinferenz auf "A" zurueck. - * Dies ist beio den JUnit-Test noetig + * Dies ist bei JUnit-Test noetig * TypePlaceholder.
Author: Martin Pluemicke * @return void */ diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java index 9ef6d901..e5614515 100644 --- a/src/test/java/insertGenerics/TestAny.java +++ b/src/test/java/insertGenerics/TestAny.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -32,6 +34,11 @@ public class TestAny { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestAny.jav")); diff --git a/src/test/java/insertGenerics/TestClassField.java b/src/test/java/insertGenerics/TestClassField.java index 81480123..a8070976 100644 --- a/src/test/java/insertGenerics/TestClassField.java +++ b/src/test/java/insertGenerics/TestClassField.java @@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import java.io.File; @@ -24,6 +26,11 @@ public class TestClassField { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestClassField.jav")); diff --git a/src/test/java/insertGenerics/TestContraVariant.java b/src/test/java/insertGenerics/TestContraVariant.java index 328044fa..744f18f5 100644 --- a/src/test/java/insertGenerics/TestContraVariant.java +++ b/src/test/java/insertGenerics/TestContraVariant.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -32,6 +34,11 @@ public class TestContraVariant { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestContraVariant.jav")); diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index e861e6e4..49ca4297 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestGGFinder { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestGGFinder"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index 93ff3415..73a316a4 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestLocalVarLambda { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestLocalVarLambda"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestMutualRecursion.java b/src/test/java/insertGenerics/TestMutualRecursion.java index fac445ed..82385060 100644 --- a/src/test/java/insertGenerics/TestMutualRecursion.java +++ b/src/test/java/insertGenerics/TestMutualRecursion.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestMutualRecursion { private static Class classToTest; private static Object instanceOfClass; private static String className; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { className = "TestMutualRecursion"; diff --git a/src/test/java/insertGenerics/TestReturnVar.java b/src/test/java/insertGenerics/TestReturnVar.java index 026c03cd..d4b98474 100644 --- a/src/test/java/insertGenerics/TestReturnVar.java +++ b/src/test/java/insertGenerics/TestReturnVar.java @@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import java.io.File; @@ -24,6 +26,11 @@ public class TestReturnVar { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestReturnVar.jav")); diff --git a/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java b/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java index 0d8093fd..97cd468f 100644 --- a/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java +++ b/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java @@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import java.io.File; @@ -24,6 +26,11 @@ public class TestSecondLineOfClassConstraints { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav")); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 870d8c96..d065151b 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -12,7 +12,9 @@ import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; - import org.junit.Test; + +import org.junit.BeforeClass; +import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -40,7 +42,12 @@ public class TestTPHsAndGenerics { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestTPHsAndGenerics"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics2.java b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java index fc5a90e6..ebf0d9df 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics2.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java @@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import java.io.File; @@ -24,6 +26,11 @@ public class TestTPHsAndGenerics2 { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav")); diff --git a/src/test/java/insertGenerics/TestThreeArgs.java b/src/test/java/insertGenerics/TestThreeArgs.java index dd93724f..ff7951f6 100644 --- a/src/test/java/insertGenerics/TestThreeArgs.java +++ b/src/test/java/insertGenerics/TestThreeArgs.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestThreeArgs { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestThreeArgs"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index 95d1876c..16fbd062 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -15,6 +15,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import java.io.File; @@ -40,7 +42,12 @@ public class TestTwoArgs { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestTwoArgs"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java index 780a4401..467cac40 100644 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ b/src/test/java/insertGenerics/TestTwoArgs2.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestTwoArgs2 { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestTwoArgs2"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index 035e9fb2..adc3bbac 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestTwoCalls { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestTwoCalls"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index 8245ff9d..6a30a456 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +41,12 @@ public class TestVector { private static Class classToTest; private static Object instanceOfClass; private static String className = "TestVector"; - + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { execute(new File(rootDirectory+className+".jav")); diff --git a/src/test/java/insertGenerics/TestVoidMeth.java b/src/test/java/insertGenerics/TestVoidMeth.java index 3f325a6e..9dc8f99b 100644 --- a/src/test/java/insertGenerics/TestVoidMeth.java +++ b/src/test/java/insertGenerics/TestVoidMeth.java @@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; import org.junit.Test; import java.io.File; @@ -24,6 +26,11 @@ public class TestVoidMeth { public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + @Test public void ggFinder() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"TestVoidMeth.jav")); From c8d4301e5e71fe0416260371e75a73a4dfbc426c Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 8 Apr 2021 09:56:49 +0200 Subject: [PATCH 096/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java Alis Ansatz zur Bytecodeerzeugung eingesetzt modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java ToString ausprogramnmiert modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java Einige bytecode-Usecases laufen noch nicht (z.B. Put.jav) Erste Ansaetze versucht. Muss noch erweitert werden. --- .../GeneratedGenericsFinder.java | 4 ++-- .../GenericGeneratorResultsForAllMethods.java | 8 ++++++++ .../GenericsGeneratorResult.java | 4 ++++ .../GenericsGeneratorResultForClass.java | 8 ++++++++ .../MethodAndConstraints.java | 10 ++++++++++ .../insertGenerics/FamilyOfGeneratedGenerics.java | 15 ++++++++++++++- 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index e25958d1..930ba3e3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -169,7 +169,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { if(ggResult != null) { //Hinzufuegen von Fayez ggResult - generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); } // Fayez Ansatz Ende //*/ @@ -198,7 +198,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult - //generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); + generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } System.out.println(ggResultAlternative); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java index 40f7692a..091587ff 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java @@ -29,5 +29,13 @@ public class GenericGeneratorResultsForAllMethods { public List getMethodsAndConstraints() { return methodsAndConstraints; } + + @Override + public String toString() { + String ret = ""; + ret = ret + methodsAndConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y); + //ret = ret + "\n"; + return ret; + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java index c0d1251a..fe23f239 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java @@ -52,4 +52,8 @@ public class GenericsGeneratorResult { this.equalsTPHs = equalsTPHs; } + @Override + public String toString() { + return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString(); + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java index 79eaabd0..0a3626d2 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java @@ -73,4 +73,12 @@ public class GenericsGeneratorResultForClass { return Collections.emptyList(); } } + + @Override + public String toString() { + String ret = "Classconstraints: "; + ret = ret + classConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y); + ret = ret + "\n" + methodsAndTheirConstraints.toString(); + return ret; + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java index 3f034f6d..bf582707 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java @@ -33,4 +33,14 @@ public class MethodAndConstraints { return constraints; } + + @Override + public String toString() { + String ret = methodID + ": "; + ret = ret + constraints.stream().reduce("", + (x,y) -> x + y.toString(), + (x,y) -> x + y); + ret = ret + "\n"; + return ret; + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index fc29b869..33e241e7 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -636,7 +636,20 @@ public class FamilyOfGeneratedGenerics { } } } - String key = ((TypePlaceholder)pairExtends2.TA2).getName(); + Set containedVars = new HashSet<>(); + String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName(); + //TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle + // rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren + posOfTphs.forEach((x,y) -> { + if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { + containedVars.add(x); + }; + } + ); + if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(key, v, Relation.EXTENDS))) + .count() > 0) { + //tempSet2.add(pairExtends2); + } if (posOfTphs.containsKey(key)) { if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { tempSet2.add(pairExtends2); From 3363037854a3fc2a05e01097c2feba23ee75a031 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 9 Apr 2021 09:15:10 +0200 Subject: [PATCH 097/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java Neue Methode addTph modified: src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java Methodcall-Steatements mit Void als Returntyp --- src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java | 4 ++-- .../bytecode/genericsGenerator/GeneratedGenericsFinder.java | 4 ++-- .../bytecode/insertGenerics/FamilyOfGeneratedGenerics.java | 2 +- .../de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java | 6 +++++- .../parser/SyntaxTreeGenerator/StatementGenerator.java | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 2db52ec3..e4f6315e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -92,7 +92,7 @@ public class TPHExtractor extends AbstractASTWalker { if (inMethod && !tphsClass.contains(tphName)) { ArrayList tphs = null; if (!(tphs = methodAndTph.getTphs()).contains(tphName)) { - tphs.add(tphName); + methodAndTph.addTph(tphName); } if (inLocalOrParamOrReturn) { if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) { @@ -173,7 +173,7 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(GenericRefType genericRefType) { String name = genericRefType.getParsedName(); if (inMethod) { - methodAndTph.getTphs().add(name); + methodAndTph.addTph(name); if (inLocalOrParamOrReturn) methodAndTph.getLocalTphs().add(name); }else { diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 930ba3e3..e25958d1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -169,7 +169,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { if(ggResult != null) { //Hinzufuegen von Fayez ggResult - //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); } // Fayez Ansatz Ende //*/ @@ -198,7 +198,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult - generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } System.out.println(ggResultAlternative); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 33e241e7..f99dddad 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -648,7 +648,7 @@ public class FamilyOfGeneratedGenerics { ); if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(key, v, Relation.EXTENDS))) .count() > 0) { - //tempSet2.add(pairExtends2); + tempSet2.add(pairExtends2); } if (posOfTphs.containsKey(key)) { if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index c5a93f4f..caaad1be 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -27,7 +27,11 @@ public class MethodAndTPH { this.id = name; this.constraints = constraints; } - + + public void addTph(String tph) { + tphs.add(tph); + } + public ArrayList getTphs() { return tphs; } diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index c4625a7a..1936b5d2 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -213,7 +213,8 @@ public class StatementGenerator { ArrayList argTypes = argumentList.getArguments().stream() .map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())) .collect(Collectors.toCollection(ArrayList::new)); - MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), + MethodCall ret = new MethodCall(//new Void(new NullToken()), + TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), argTypes, methodInvocationContext.getStart()); return ret; From be9ee49878a0c713bedb3dab54d8f7b85029d762 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 13 Apr 2021 10:03:48 +0200 Subject: [PATCH 098/101] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java modified: src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 6 ++-- .../FamilyOfGeneratedGenerics.java | 20 +++++++++---- .../StatementGenerator.java | 30 +++++++++++++------ .../syntaxtree/statement/MethodCall.java | 5 +--- .../syntaxtree/statement/Statement.java | 11 ++++++- .../typeinference/constraints/Constraint.java | 8 ++++- .../typeinference/typeAlgo/TYPEStmt.java | 8 +++-- .../insertGenerics/TestLocalVarLambda.java | 10 ++++++- 8 files changed, 72 insertions(+), 26 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index e4f6315e..6f443a47 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -209,10 +209,12 @@ public class TPHExtractor extends AbstractASTWalker { csS.getOderConstraints() .forEach(oConSSet -> { Set> setCons = new HashSet<>(); - oConSSet.forEach(OConS -> { setCons.add( + oConSSet.forEach(OConS -> { Constraint newConsPair = new Constraint(); + newConsPair.isStatement = OConS.isStatement; + setCons.add( OConS.stream() .filter(filterUndConstraints) - .collect(Collectors.toCollection(Constraint::new)) ); + .collect(Collectors.toCollection(() -> newConsPair)) ); } ); ret.addOderConstraint(setCons);} ); return ret; diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index f99dddad..22e60fa0 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import java.util.*; import java.util.function.Predicate; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Pair; @@ -590,8 +591,9 @@ public class FamilyOfGeneratedGenerics { Iterator itExtends2 = extendsSet.iterator(); while(itExtends2.hasNext()) { Pair pairExtends2 = itExtends2.next(); + Set containedVars = new HashSet<>(methodAndTPH.getTphs()); + String pairExtends2RHSName = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName(); Iterator itEqual2 = equalSet.iterator(); - while (itEqual2.hasNext()) { boolean transClo = false; Pair pairEqual2 = itEqual2.next(); @@ -635,23 +637,29 @@ public class FamilyOfGeneratedGenerics { tempSet2.add(pairExtends2); } } + else { + containedVars.remove(((TypePlaceholder)newPair2.TA2).getName()); + } + } - Set containedVars = new HashSet<>(); - String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName(); + + //String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName(); //TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle // rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren + /* posOfTphs.forEach((x,y) -> { if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { containedVars.add(x); }; } ); - if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(key, v, Relation.EXTENDS))) + */ + if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(pairExtends2RHSName, v, Relation.EXTENDS))) .count() > 0) { tempSet2.add(pairExtends2); } - if (posOfTphs.containsKey(key)) { - if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { + if (posOfTphs.containsKey(pairExtends2RHSName)) { + if (posOfTphs.get(pairExtends2RHSName).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { tempSet2.add(pairExtends2); } } diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 1936b5d2..90ba659c 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -213,10 +213,10 @@ public class StatementGenerator { ArrayList argTypes = argumentList.getArguments().stream() .map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())) .collect(Collectors.toCollection(ArrayList::new)); - MethodCall ret = new MethodCall(//new Void(new NullToken()), - TypePlaceholder.fresh(methodInvocationContext.getStart()), + MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), argTypes, methodInvocationContext.getStart()); + ret.setStatement(); return ret; } @@ -303,33 +303,45 @@ public class StatementGenerator { ArrayList argTypes = args.getArguments().stream() .map(x -> TypePlaceholder.fresh(newExpression.getStart())) .collect(Collectors.toCollection(ArrayList::new)); - return new NewClass(newClass, args, null, argTypes, newExpression.getStart()); + Statement ret = new NewClass(newClass, args, null, argTypes, newExpression.getStart()); + ret.setStatement(); + return ret; } private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) { Expression argument = convert(stmt.unaryExpression()); Token offset = stmt.getStart(); - return new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset); - } + Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset); + ret.setStatement(); + return ret; + } private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) { - return new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()), + Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()), TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); + ret.setStatement(); + return ret; } private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { - return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), + Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); + ret.setStatement(); + return ret; } private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { - return new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()), + Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()), TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); + ret.setStatement(); + return ret; } private Statement convert(Java8Parser.AssignmentContext stmt) { AssignLeftSide leftHandSide = convert(stmt.leftHandSide()); - return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart()); + Statement ret = new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart()); + ret.setStatement(); + return ret; } private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 75267619..4ef09d86 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -24,13 +24,9 @@ public class MethodCall extends Statement public final ArgumentList arglist; - /* - * noetig fuer Bytecodegenerierung - */ public RefTypeOrTPHOrWildcardOrGeneric receiverType; public final ArrayList argTypes; - public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList argTypes, Token offset){ super(retType,offset); @@ -40,6 +36,7 @@ public class MethodCall extends Statement this.receiverType = receiverType; this.argTypes = argTypes; } + @Override public void accept(StatementVisitor visitor) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java index fc13cda1..aad50736 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -6,11 +6,20 @@ import org.antlr.v4.runtime.Token; public abstract class Statement extends Expression { - + /* zeigt an, dass eine StatementExpression als Statement benutzt wird + */ + private boolean isStatement = false; public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) { super(type, offset); } + public void setStatement() { + isStatement=true; + } + + public boolean getStatement() { + return isStatement; + } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index 8715fe55..6ebb9404 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -9,6 +9,12 @@ import java.util.Set; public class Constraint
extends HashSet { private static final long serialVersionUID = 1L; private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt + + /* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt + * es Probleme beim Generated Generics + */ + public boolean isStatement = false; + private Constraint extendConstraint = null; public Constraint() { @@ -41,7 +47,7 @@ public class Constraint extends HashSet { } public String toString() { - return super.toString() + " isInherited = " + isInherited + return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) + "\n" ; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index b3ba00de..2860e71b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.type.*; +import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.FunNClass; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; @@ -180,6 +181,7 @@ public class TYPEStmt implements StatementVisitor{ ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : x) .collect(Collectors.toCollection(() -> new Constraint(oneMethodConstraint.isInherited()))); + extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement; oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint); @@ -594,9 +596,11 @@ public class TYPEStmt implements StatementVisitor{ //methodConstraint.add(new Pair(forMethod.receiverType, retType, // PairOperator.EQUALSDOT)); //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE - + + + methodConstraint.isStatement = forMethod.getStatement(); methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), - PairOperator.EQUALSDOT)); + PairOperator.EQUALSDOT)); methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver)); return methodConstraint; } diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index 73a316a4..a3592a24 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -76,7 +76,15 @@ public class TestLocalVarLambda { lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS)); methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); } - else { + else if (fogg.allConstraints.contains((new MethodConstraint("O", "DIV", Relation.EXTENDS)))) { + lmc.add(new MethodConstraint("O", "DIV", Relation.EXTENDS)); + lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("DIV", "N", Relation.EXTENDS)); + lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Nm(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)); From b40cb49b9f61c1ef6d9c6011c5b832eaedad3191 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 19 Apr 2021 14:22:40 +0200 Subject: [PATCH 099/101] In PairTPHsmallerTPH origPair eingefuegt, was das OriginalPair darstellt, entweder vor oder waehrend der Unikation modified: src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java new file: src/main/java/de/dhbwstuttgart/typeinference/result/PairNoResult.java noetig da als oriPairs auch Paare nicht solved form vorkommen koennen modified: src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java modified: src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairVisitor.java --- .../syntaxtree/factory/UnifyTypeFactory.java | 6 ++-- .../typeinference/result/PairNoResult.java | 32 +++++++++++++++++++ .../result/PairTPHsmallerTPH.java | 11 +++++++ .../result/ResultPairVisitor.java | 3 ++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/result/PairNoResult.java diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index a698ce3b..468f9647 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.WildcardType; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.result.PairNoResult; import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH; import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType; import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH; @@ -208,6 +209,7 @@ public class UnifyTypeFactory { } public static ResultPair convert(UnifyPair mp, Map tphs) { + if (mp == null) { return null;} //kann bei basePairs passieren RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs); RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs); if(tl instanceof TypePlaceholder){ @@ -218,7 +220,7 @@ public class UnifyTypeFactory { //Einfach ignorieren TODO: Das hier muss ausgebessert werden: //return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType()); }else{ - return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr); + return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr, convert(mp.getBasePair(), tphs)); } }else if(tr instanceof RefType){ return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr); @@ -227,7 +229,7 @@ public class UnifyTypeFactory { }else if(tr instanceof GenericRefType){ return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr); }else throw new NotImplementedException(); - }else throw new NotImplementedException(); + }else return new PairNoResult(tl, tr);//throw new NotImplementedException(); } public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map tphs) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/PairNoResult.java b/src/main/java/de/dhbwstuttgart/typeinference/result/PairNoResult.java new file mode 100644 index 00000000..63b3137c --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/PairNoResult.java @@ -0,0 +1,32 @@ +package de.dhbwstuttgart.typeinference.result; + +import de.dhbwstuttgart.exceptions.NotImplementedException; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; + +/** + * enthaelt alle Paare, die in einem Ergebnis nicht vorkommen koennen + * sie sind noetig fuer origPairs in PairTPHsmallerTPH, da hier auch + * Paare vorkommen koennen die keine Result sind (z.B. bei FunN$$) + */ +public class PairNoResult extends ResultPair{ + //public final TypePlaceholder left; + //public final TypePlaceholder right; + + /* + * urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde + * wichtig fuer generated Generics + */ + ResultPair origPair; + + public PairNoResult(RefTypeOrTPHOrWildcardOrGeneric left, RefTypeOrTPHOrWildcardOrGeneric right){ + super(left, right); + } + + /* noch nicht implementiert. */ + @Override + public void accept(ResultPairVisitor visitor) { + throw new NotImplementedException(); + //visitor.visit(this); + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java b/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java index 8d586f4b..1df94e6b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java @@ -9,6 +9,12 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class PairTPHsmallerTPH extends ResultPair{ public final TypePlaceholder left; public final TypePlaceholder right; + + /* + * urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde + * wichtig fuer generated Generics + */ + ResultPair origPair; public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){ super(left, right); @@ -16,6 +22,11 @@ public class PairTPHsmallerTPH extends ResultPair{ this.right = right; } + public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right, ResultPair origPair){ + this(left, right); + this.origPair = origPair; + } + @Override public void accept(ResultPairVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairVisitor.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairVisitor.java index 18427731..e1372336 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairVisitor.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairVisitor.java @@ -4,4 +4,7 @@ public interface ResultPairVisitor { void visit(PairTPHsmallerTPH p); void visit(PairTPHequalRefTypeOrWildcardType p); void visit(PairTPHEqualTPH p); + + //bisher nicht umgesetzt + //void visit(PairNoResult p); } From 1b9e824b8697095572c77e82bc23a9e413578361 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 19 Apr 2021 16:18:31 +0200 Subject: [PATCH 100/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../genericsGenerator/GeneratedGenericsFinder.java | 4 ++-- .../insertGenerics/FamilyOfGeneratedGenerics.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index e25958d1..930ba3e3 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -169,7 +169,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { if(ggResult != null) { //Hinzufuegen von Fayez ggResult - generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); } // Fayez Ansatz Ende //*/ @@ -198,7 +198,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult - //generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); + generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } System.out.println(ggResultAlternative); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 22e60fa0..ed46e816 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -638,7 +638,7 @@ public class FamilyOfGeneratedGenerics { } } else { - containedVars.remove(((TypePlaceholder)newPair2.TA2).getName()); + //containedVars.remove(((TypePlaceholder)newPair2.TA2).getName()); } } @@ -654,11 +654,13 @@ public class FamilyOfGeneratedGenerics { } ); */ + //Referenzbeispiel Put.jav if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(pairExtends2RHSName, v, Relation.EXTENDS))) .count() > 0) { - tempSet2.add(pairExtends2); + System.out.println(); + //tempSet2.add(pairExtends2); } - if (posOfTphs.containsKey(pairExtends2RHSName)) { + if (posOfTphs.containsKey(pairExtends2RHSName)) {//Refrenzbeispiel TestVector.jav if (posOfTphs.get(pairExtends2RHSName).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { tempSet2.add(pairExtends2); } From 18d9edfeead60c4295182012637b44bb68328555 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 21 May 2021 09:52:22 +0200 Subject: [PATCH 101/101] modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java new file: src/test/java/insertGenerics/TestVectorArg.java modified: src/test/resources/bytecode/javFiles/Fac.jav new file: src/test/resources/insertGenericsJav/TestVectorArg.jav --- .../GeneratedGenericsFinder.java | 4 +- .../java/insertGenerics/TestVectorArg.java | 92 +++++++++++++++++++ src/test/resources/bytecode/javFiles/Fac.jav | 2 +- .../insertGenericsJav/TestVectorArg.jav | 12 +++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/test/java/insertGenerics/TestVectorArg.java create mode 100644 src/test/resources/insertGenericsJav/TestVectorArg.jav diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java index 930ba3e3..e25958d1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java @@ -169,7 +169,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { if(ggResult != null) { //Hinzufuegen von Fayez ggResult - //generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); + generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); } // Fayez Ansatz Ende //*/ @@ -198,7 +198,7 @@ public class GeneratedGenericsFinder implements ASTVisitor { ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult - generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); + //generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); System.out.println(generatedGenericsForSF); } System.out.println(ggResultAlternative); diff --git a/src/test/java/insertGenerics/TestVectorArg.java b/src/test/java/insertGenerics/TestVectorArg.java new file mode 100644 index 00000000..45509288 --- /dev/null +++ b/src/test/java/insertGenerics/TestVectorArg.java @@ -0,0 +1,92 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; + +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TestVectorArg { + + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; + private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + private static ClassLoader loader; + private static Class classToTest; + private static Object instanceOfClass; + private static String className = "TestVectorArg"; + + @BeforeClass + public static void resetNamesOfTypePlaceholder() { + de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); + } + + @Test + public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + execute(new File(rootDirectory+className+".jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + Set lmc; + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); + lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); + lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); + lmc = new HashSet<>(); + lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + //assertEquals(expectedClassCons, computedClassCons); + + HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); + fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); + + //assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + return new TestResultSet(); + } +} diff --git a/src/test/resources/bytecode/javFiles/Fac.jav b/src/test/resources/bytecode/javFiles/Fac.jav index bde593d4..28650b45 100644 --- a/src/test/resources/bytecode/javFiles/Fac.jav +++ b/src/test/resources/bytecode/javFiles/Fac.jav @@ -3,7 +3,7 @@ import java.lang.Integer; public class Fac { - getFac(java.lang.Integer n){ + getFac(n){ var res = 1; var i = 1; while(i<=n) { diff --git a/src/test/resources/insertGenericsJav/TestVectorArg.jav b/src/test/resources/insertGenericsJav/TestVectorArg.jav new file mode 100644 index 00000000..ca29f820 --- /dev/null +++ b/src/test/resources/insertGenericsJav/TestVectorArg.jav @@ -0,0 +1,12 @@ +import java.util.Vector; + +public class TestVectorArg { + + add(v, e) { + v.addElement(e); + } + + main(v, e) { + add(v, e); + } +} \ No newline at end of file