diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ab23142b7..7973a053b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -27,7 +27,6 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; -import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; import de.dhbwstuttgart.typeinference.unify.model.FunNType; @@ -45,7 +44,6 @@ import de.dhbwstuttgart.util.Pair; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import org.apache.commons.io.output.NullWriter; -import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; @@ -58,9 +56,6 @@ import java.io.Writer; */ public class TypeUnifyTask extends RecursiveTask>> { - private static final long serialVersionUID = 1L; - private static int i = 0; - private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? /** @@ -79,10 +74,6 @@ public class TypeUnifyTask extends RecursiveTask>> { public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; protected WriterActiveObject logFile; protected ForkJoinPool pool; - /** - * The implementation of setOps that will be used during the unification - */ - protected ISetOperations setOps = new GuavaSetOperations(); /** * The implementation of the standard unify that will be used during the unification @@ -104,9 +95,6 @@ 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; @@ -115,8 +103,6 @@ public class TypeUnifyTask extends RecursiveTask>> { Integer noAllErasedElements = 0; - static Integer noou = 0; - static int noBacktracking; static int noLoop; @@ -161,7 +147,6 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); - this.nextSetElement = nextSetElement; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; @@ -175,7 +160,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("thNo2 " + thNo); try { if(log){ - this.logFile = new WriterActiveObject(new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo)), pool); + this.logFile = new WriterActiveObject(new FileWriter(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo), pool); }else{ this.logFile = new WriterActiveObject(new OutputStreamWriter(new NullOutputStream()), pool); } @@ -204,7 +189,6 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Vererbt alle Variancen - * @param eq The set of constraints */ /* PL 2018-05- 17 verschoben nach JavaTXCompiler private void varianceInheritance(Set eq) { @@ -236,15 +220,11 @@ public class TypeUnifyTask extends RecursiveTask>> { */ protected Set> compute() { - if (one) { - //System.out.println("two"); - } - one = true; Set neweq = new HashSet<>(eq); /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ oderConstraintsField.stream() .filter(x -> x.size()==1) - .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); + .map(y -> y.stream().findFirst().get()).forEach(neweq::addAll); ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); @@ -258,9 +238,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (isUndefinedPairSetSet(res)) { //fuer debug-Zwecke - ArrayList al = res.stream().map(x -> x.stream().collect(Collectors.toCollection(ArrayList::new))) - .collect(Collectors.toCollection(ArrayList::new)); - throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>(); + throw new TypeinferenceException("Unresolved constraints: " + res, new NullToken()); //return new HashSet<>(); } else { return res; @@ -298,7 +276,7 @@ public class TypeUnifyTask extends RecursiveTask>> { rekTiefe++; nOfUnify++; - writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); + writeLog(nOfUnify + " Unifikation: " + eq.toString()); writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); /* @@ -310,9 +288,9 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * ? extends ? extends Theta rausfiltern */ - Set doubleExt = eq.stream().filter(x -> (x.wrongWildcard())).map(x -> { x.setUndefinedPair(); return x;}) + Set doubleExt = eq.stream().filter(UnifyPair::wrongWildcard).peek(UnifyPair::setUndefinedPair) .collect(Collectors.toCollection(HashSet::new)); - if (doubleExt.size() > 0) { + if (!doubleExt.isEmpty()) { Set> ret = new HashSet<>(); ret.add(doubleExt); return ret; @@ -327,10 +305,10 @@ public class TypeUnifyTask extends RecursiveTask>> { return (lhs = x.getLhsType()) instanceof PlaceholderType && !((rhs = x.getRhsType()) instanceof PlaceholderType) && rhs.getTypeParams().occurs((PlaceholderType)lhs);}) - .map(x -> { x.setUndefinedPair(); return x;}) + .peek(UnifyPair::setUndefinedPair) .collect(Collectors.toCollection(HashSet::new)); writeLog("ocurrPairs: " + ocurrPairs); - if (ocurrPairs.size() > 0) { + if (!ocurrPairs.isEmpty()) { Set> ret = new HashSet<>(); ret.add(ocurrPairs); return ret; @@ -350,10 +328,10 @@ public class TypeUnifyTask extends RecursiveTask>> { eqSubst = rules.subst(eq0, oderConstraints); } while (eqSubst.isPresent()); - eq0.forEach(x -> x.disableCondWildcards()); + eq0.forEach(UnifyPair::disableCondWildcards); - writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString() + "\n" - + nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString()); + writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq + "\n" + + nOfUnify + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints); /* * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs @@ -375,7 +353,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //System.out.println(eq2s); - if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. + if(!eq1s.isEmpty()) { // Do not add empty sets or the cartesian product will always be empty. Set> wrap = new HashSet<>(); wrap.add(eq1s); topLevelSets.add(wrap); // Add Eq1' @@ -387,7 +365,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType) .collect(Collectors.toSet()); - if(bufferSet.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. + if(!bufferSet.isEmpty()) { // Do not add empty sets or the cartesian product will always be empty. Set> wrap = new HashSet<>(); wrap.add(bufferSet); topLevelSets.add(wrap); @@ -397,7 +375,6 @@ public class TypeUnifyTask extends RecursiveTask>> { // Sets that originate from pair pattern matching // Sets of the "second level" Set undefinedPairs = new HashSet<>(); - if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); @@ -405,8 +382,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //nicht ausgewertet Faculty Beispiel im 1. Schritt //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren //Typen getestet werden. - writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); - if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); + writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput); // If pairs occured that did not match one of the cartesian product cases, // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { @@ -416,7 +392,7 @@ public class TypeUnifyTask extends RecursiveTask>> { + "BasePair; " + up.getBasePair()); } Set> error = new HashSet<>(); - undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); + undefinedPairs = undefinedPairs.stream().peek(UnifyPair::setUndefinedPair).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); undefinedPairs.forEach(x -> writeLog("AllSubst: " +x.getAllSubstitutions().toString())); return error; @@ -449,9 +425,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden for(Set>> secondLevelSet : secondLevelSets) { - for (Set> secondlevelelem : secondLevelSet) { - topLevelSets.add(secondlevelelem); - } + topLevelSets.addAll(secondLevelSet); } //System.out.println(topLevelSets); //System.out.println(); @@ -479,14 +453,12 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> eqPrimePrimeSet = new HashSet<>(); - Set forks = new HashSet<>(); - //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG //for(Set> setToFlatten : eqPrimeSet) { // Flatten the cartesian product //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set eqPrime = new HashSet<>(); - setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); + setToFlatten.stream().forEach(eqPrime::addAll); /* * Step 5: Substitution @@ -496,8 +468,6 @@ public class TypeUnifyTask extends RecursiveTask>> { String ocString = oderConstraints.toString(); List>> newOderConstraints = new ArrayList<>(oderConstraints); Optional> eqPrimePrime = rules.subst(eqPrime, newOderConstraints); - Set> unifyres1 = null; - Set> unifyres2 = null; if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints); //writeLog("nach Subst: " + eqPrimePrime); /* @@ -526,8 +496,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else */ {// sequentiell (Step 6b is included) - if (printtag) System.out.println("nextStep: " + eqPrimePrime); - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + if (eqPrime.equals(eq) && eqPrimePrime.isEmpty() && oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst @@ -541,8 +510,8 @@ public class TypeUnifyTask extends RecursiveTask>> { // System.err.println("log-File nicht vorhanden"); //} eqPrimePrimeSet.add(eqPrime); - if (finalresult && isSolvedForm(eqPrime)) { - writeLog("eqPrime:" + eqPrime.toString()+"\n"); + if (isSolvedForm(eqPrime)) { + writeLog("eqPrime:" + eqPrime +"\n"); /* methodconstraintsets werden zum Ergebnis hinzugefuegt * Anfang @@ -553,8 +522,8 @@ public class TypeUnifyTask extends RecursiveTask>> { //Substitutionen in methodcontraintsets werdne ausgeführt eqPrimePrimeSet = eqPrimePrimeSet.stream().map( x -> { Optional> help = rules.subst(x); - return help.isPresent() ? - help.get(): + return help.isPresent() ? + help.get(): x; }).collect(Collectors.toSet()); /* * Ende @@ -562,16 +531,16 @@ public class TypeUnifyTask extends RecursiveTask>> { urm.notify(eqPrimePrimeSet); - writeStatistics("Result: " + eqPrimePrimeSet.toString()); + writeStatistics("Result: " + eqPrimePrimeSet); } } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); + Set> unifyres = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); + Set> unifyres = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); eqPrimePrimeSet.addAll(unifyres); @@ -596,7 +565,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) { - writeLog("Result1 " + eqPrimePrimeSet.toString()); + writeLog("Result1 " + eqPrimePrimeSet); } return eqPrimePrimeSet; } @@ -620,19 +589,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //statistics //writeStatistics("\nNumber of Constraints (" + rekTiefe + "): " + topLevelSets.size()); - - Set> oneElems = new HashSet<>(); - oneElems.addAll(topLevelSets.stream() - .filter(x -> x.size()==1) - .map(y -> y.stream().findFirst().get()) - .collect(Collectors.toCollection(HashSet::new))); + + Set> oneElems = topLevelSets.stream() + .filter(x -> x.size() == 1) + .map(y -> y.stream().findFirst().get()).collect(Collectors.toSet()); //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, methodSignatureConstraint); - return result; + if (optNextSet.isEmpty()) {//Alle Elemente sind 1-elementig + return unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); } Set> nextSet = optNextSet.get(); @@ -659,13 +625,13 @@ public class TypeUnifyTask extends RecursiveTask>> { * 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; + ArrayList zeroNextElem = new ArrayList<>(nextSetasList.getFirst()); + UnifyPair fstBasePair = zeroNextElem.removeFirst().getBasePair(); + boolean oderConstraint = false; if (fstBasePair != null) { - Boolean sameBase = true; - for (UnifyPair ele : nextSetasList.get(0)) {//check ob a <. ty base oder ob Ueberladung + boolean sameBase = true; + for (UnifyPair ele : nextSetasList.getFirst()) {//check ob a <. ty base oder ob Ueberladung sameBase = sameBase && ele.getBasePair() != null && ele.getBasePair().equals(fstBasePair); } if (sameBase) { //angefuegt PL 2020-02-30 @@ -690,10 +656,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //Varianz-Bestimmung Oder-Constraints if (oderConstraint) { - if (printtag) System.out.println("nextSetasList " + nextSetasList); - Optional optVariance = - nextSetasList.iterator() - .next() + Optional optVariance = + nextSetasList + .getFirst() .stream() .filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType && ! (x.getRhsType() instanceof PlaceholderType) && @@ -712,53 +677,13 @@ public class TypeUnifyTask extends RecursiveTask>> { /* Varianzbestimmung Ende */ //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 oneElems */ - Set sameEqSet = new HashSet<>(); - - //optOrigPair enthaelt ggf. das Paar a = ty \in nextSet - Optional optOrigPair = null; - if (!oderConstraint) { - optOrigPair = nextSetElem.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(); - writeLog("optOrigPair: " + optOrigPair); - if (optOrigPair.isPresent()) { - UnifyPair origPair = optOrigPair.get(); - UnifyType tyVar; - if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { - tyVar = origPair.getRhsType(); - } - UnifyType tyVarEF = tyVar; - 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)); - } - } - /* sameEqSet-Bestimmung Ende */ - - int hilf = 0; - Set a = null; - while (nextSetasList.size() > 0) { + + Set a; + while (!nextSetasList.isEmpty()) { //statistics //writeStatistics(" Actual Number of elements( " + nextSetasList.get(0).stream().findFirst().get().getBasePair() +"): (" + rekTiefe + "): " + nextSetasList.size()); - Set a_last = a; /* Liste der Faelle für die parallele Verarbeitung * Enthaelt Elemente, die nicht in Relation zu aktuellem Fall in der @@ -850,7 +775,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } Nextvar an Hand Varianzbestimmung auskommentieren Ende */ - a = nextSetasList.remove(0); //statisticsList + a = nextSetasList.removeFirst(); //statisticsList //writeStatistics(a.toString()); if (oderConstraint) {//Methodconstraints werden abgespeichert für die Bytecodegenerierung von Methodenaufrufen @@ -858,12 +783,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //System.out.println("ERSTELLUNG: " +methodSignatureConstraint); } - i++; - Set> elems = new HashSet>(oneElems); + Set> elems = new HashSet<>(oneElems); writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); //Ergebnisvariable für den aktuelle Thread - Set> res = new HashSet<>(); + Set> res; //Menge der Ergebnisse der geforkten Threads Set>> add_res = new HashSet<>(); @@ -903,25 +827,15 @@ public class TypeUnifyTask extends RecursiveTask>> { "nextSetasListRest: " + nextSetasListRest.toString()); while (!nextSetasList.isEmpty()) { - Set nSaL = nextSetasList.remove(0); + Set nSaL = nextSetasList.removeFirst(); //nextSetasList.remove(nSaL); writeLog("1 RM" + nSaL.toString()); - if (!oderConstraint) { - - /* statistics sameEq wird nicht betrachtet ANGFANG - //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht - if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) { - nSaL = null; - noShortendElements++; - continue; - } - statistics sameEq wird nicht betrachtet ENDE */ - } - else { + if (oderConstraint) { nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); } + Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -941,7 +855,7 @@ public class TypeUnifyTask extends RecursiveTask>> { forkOrig.writeLog("final Orig 1"); forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); - writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + writeLog("JoinOrig " + Integer.valueOf(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); /* FORK ENDE */ @@ -952,9 +866,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //noOfThread++; //noOfThread--; an das Ende von compute verschoben - writeLog("Join " + new Integer(fork.thNo).toString() + "\n" + + writeLog("Join " + Integer.valueOf(fork.thNo).toString() + "\n" + "fork_res: " + fork_res.toString() + "\n" + - new Boolean((isUndefinedPairSetSet(fork_res))).toString()); + Boolean.valueOf((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); @@ -983,21 +897,11 @@ public class TypeUnifyTask extends RecursiveTask>> { "nextSetasListRest: " + nextSetasListRest.toString()); while (!nextSetasList.isEmpty()) { - Set nSaL = nextSetasList.remove(0); + Set nSaL = nextSetasList.removeFirst(); //nextSetasList.remove(nSaL); writeLog("-1 RM" + nSaL.toString()); - if (!oderConstraint) { - /* statistics sameEq wird nicht betrachtet ANGFANG - //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht - if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) { - nSaL = null; - noShortendElements++; - continue; - } - statistics sameEq wird nicht betrachtet ENDE */ - } - else { + if(oderConstraint){ nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); } Set newEq = new HashSet<>(eq); @@ -1018,7 +922,7 @@ public class TypeUnifyTask extends RecursiveTask>> { forkOrig.writeLog("final Orig -1"); forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); - writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + writeLog("JoinOrig " + Integer.valueOf(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); /* FORK ENDE */ @@ -1028,17 +932,17 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> fork_res = fork.join(); //noOfThread++; - writeLog("Join " + new Integer(fork.thNo).toString()); + writeLog("Join " + Integer.valueOf(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben writeLog("fork_res: " + fork_res.toString()); - writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); + writeLog(Boolean.valueOf((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); } fork.writeLog("final -1"); fork.closeLogFile(); - }; + } //noOfThread++; } else { @@ -1060,7 +964,7 @@ public class TypeUnifyTask extends RecursiveTask>> { "nextSetasListRest: " + nextSetasListRest.toString()); while (!nextSetasList.isEmpty()) { - Set nSaL = nextSetasList.remove(0); + Set nSaL = nextSetasList.removeFirst(); //nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03 Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); @@ -1081,7 +985,7 @@ public class TypeUnifyTask extends RecursiveTask>> { forkOrig.writeLog("final Orig 2"); forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); - writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + writeLog("JoinOrig " + Integer.valueOf(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); //vermutlich falsch @@ -1091,7 +995,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> fork_res = fork.join(); //noOfThread++; - writeLog("Join " + new Integer(fork.thNo).toString()); + writeLog("Join " + Integer.valueOf(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); fork.writeLog("final 2"); @@ -1217,9 +1121,6 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = par_res; - if (!par_res.isEmpty() && par_res.iterator().next() instanceof WildcardType) { - //System.out.println(""); - } } else { if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) @@ -1374,7 +1275,7 @@ public class TypeUnifyTask extends RecursiveTask>> { auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) { - int nofstred= 0; + int nofstred; Set abhSubst = res.stream() .map(b -> b.stream() @@ -1396,16 +1297,6 @@ public class TypeUnifyTask extends RecursiveTask>> { .collect(Collectors.toCollection(HashSet::new)); //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); int len = nextSetasList.size(); - Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results - Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() - .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen - su.add(x.getGroundBasePair()); // urspruengliches Paar - su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen - return new Pair<>(su, x.getGroundBasePair());}) - .collect(Collectors.toCollection(HashSet::new)); - if (res.size() > 1) { - //System.out.println(); - } /* statistics no erase writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList); if (!oderConstraint) {//PL 2023-02-08 eingefuegt: Bei oderconstraints sind Subststitutionen nicht als Substitutionen in idesem Sinne zu sehen @@ -1459,168 +1350,9 @@ public class TypeUnifyTask extends RecursiveTask>> { return 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 - 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, new HashSet<>()); - 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, new HashSet<>()); - 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 couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { - return reducedUndefResSubstGroundedBasePair.stream() - .map(pair -> { - Set reducedAbhSubst = pair.getKey(); - reducedAbhSubst.addAll(nextElem); - Optional> substRes = rules.subst(reducedAbhSubst); - if (!substRes.isPresent()) { - return true; - } - //PL 2018-10-12 - //Evtl. zurest applyTypeUnification aufrufen - //evtl auch unify aufrufen - else { - UnifyPair checkPair = substRes.get().stream() - .filter(x -> x.getGroundBasePair().equals(pair.getValue().get())).findFirst().get(); - if (((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) - && (checkPair.getPairOp() == PairOperator.SMALLERDOT || checkPair.getPairOp() == PairOperator.SMALLERDOTWC)) - { - /* - Set setCheckPair = new HashSet<>(); - setCheckPair.add(checkPair); - Set setReturnCheckPair = applyTypeUnificationRules(setCheckPair, fc); - UnifyPair checkPair1 = setReturnCheckPair.iterator().next(); - Set up = new HashSet<>(); - up.add(checkPair1); - Set undef = new HashSet<>(); - */ - PairOperator pairOp = checkPair.getPairOp(); - UnifyType lhsType = checkPair.getLhsType(); - UnifyType rhsType = checkPair.getRhsType(); - ///* Case 1: (a <. Theta') - if ((((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) - // Case 2: (a <.? ? ext Theta') - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - // Case 3: (a <.? ? sup Theta') - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - - // Case 4 was replaced by an inference rule - // Case 4: (a <.? Theta') - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType) - // Case 5: (Theta <. a) - || ((pairOp == PairOperator.SMALLERDOT) && rhsType instanceof PlaceholderType) - // Case 6 was replaced by an inference rule. - // Case 6: (? ext Theta <.? a) - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType) - // Case 7 was replaced by an inference rule - // Case 7: (? sup Theta <.? a) - || (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType) - // Case 8: (Theta <.? a) - || (pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - //reduceWildcardLow - || (pairOp == PairOperator.SMALLERDOTWC && (lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) - //reduceWildcardLowRight - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof ExtendsType)) - //reduceWildcardUp - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && (rhsType instanceof SuperType)) - //reduceWildcardUpRight - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof SuperType)) - //reduceFunN - || (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.EQUALSDOT)) - //PL 2017-10-03 hinzugefuegt - //da Regel auch fuer EQUALSDOT anwendbar - && (lhsType instanceof FunNType) && (rhsType instanceof FunNType)) - //greaterFunN - || ((pairOp== PairOperator.SMALLERDOT) && (lhsType instanceof FunNType) && (rhsType instanceof PlaceholderType)) - //smallerFunN - || ((pairOp == PairOperator.SMALLERDOT) && (lhsType instanceof PlaceholderType && rhsType instanceof FunNType)) - //reduceTph - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof PlaceholderType && rhsType instanceof ReferenceType)) - //reduceTphExt - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ExtendsType) && rhsType instanceof PlaceholderType) - //reduceTphSup - || ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && rhsType instanceof PlaceholderType)) { - return true; - } - // Case unknown: If a pair fits no other case, then the type unification has failed. - // Through application of the rules, every pair should have one of the above forms. - // Pairs that do not have one of the aboves form are contradictory. - else { - writeLog("Second erase:" +checkPair.toString()); - return false; - } - //*/ - } else { - //Pair type <. ? extends ? extends type betrachten TODO PL 2018-10-09 - }} - return true;}).reduce((xx, yy) -> xx || yy).get(); - } - protected boolean isUndefinedPairSet(Set s) { - if (s.size() >= 1 ) { - Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y)); - return ret; + if (!s.isEmpty()) { + return s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x, y)-> (x && y)); } else { return false; @@ -1628,9 +1360,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } protected boolean isUndefinedPairSetSet(Set> s) { - if (s.size() >= 1) { - Boolean ret = s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x,y)-> (x && y)); - return ret; + if (!s.isEmpty()) { + return s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x, y)-> (x && y)); } return false; @@ -1675,7 +1406,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ - LinkedHashSet targetSet = new LinkedHashSet(); + LinkedHashSet targetSet = new LinkedHashSet<>(); LinkedList eqQueue = new LinkedList<>(); /* @@ -1818,7 +1549,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList eq2sAsListFourth = new ArrayList<>(); ArrayList eq2sAsListBack = new ArrayList<>(); ArrayList eq2sAsList = new ArrayList<>(); - Boolean first = true; + boolean first = true; while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben UnifyPair up = eq2sprimeit.next(); if ((up.getLhsType() instanceof PlaceholderType && @@ -1861,13 +1592,13 @@ public class TypeUnifyTask extends RecursiveTask>> { { List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind .filter(x -> x.stream() - .filter(y -> - y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) - && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) - || ((z.getRhsType() instanceof PlaceholderType) - && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) - ).findFirst().isPresent() - ).findFirst().isPresent()).collect(Collectors.toList()); + .anyMatch(y -> + y.stream().anyMatch(z -> ((z.getLhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) + || ((z.getRhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) + ) + )).collect(Collectors.toList()); if (!oderConstraintsVariance.isEmpty()) { Set> ret = oderConstraintsVariance.get(0); oderConstraintsOutput.remove(ret); @@ -1906,7 +1637,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet if (!oderConstraintsOutput.isEmpty()) { - Set> ret = oderConstraintsOutput.remove(0); + Set> ret = oderConstraintsOutput.removeFirst(); //if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M")) // System.out.println("M"); //Set retFlat = new HashSet<>(); @@ -1934,11 +1665,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution hinzufuegen */ - Set consideredElements = new HashSet<>(); for(UnifyPair pair : eq2sAsList) { - if (consideredElements.contains(pair)) { - continue; - } PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); UnifyType rhsType = pair.getRhsType(); @@ -1947,9 +1674,6 @@ public class TypeUnifyTask extends RecursiveTask>> { if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); - if (((PlaceholderType)(pair.getLhsType())).getName().equals("AR")) { - //System.out.println("AR"); - } Set> x1 = unifyCase1(pair, fc); if (pairOp == PairOperator.SMALLERNEQDOT) { Set remElem = new HashSet<>(); @@ -2026,7 +1750,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } result.get(0).add(x1ResPrime); ZU LOESCHEN ENDE */ - result.get(0).add(x1); + result.getFirst().add(x1); if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC => Abbruch } @@ -2036,14 +1760,14 @@ public class TypeUnifyTask extends RecursiveTask>> { s1.add(pair); Set> s2 = new HashSet<>(); s2.add(s1); - result.get(0).add(s2); + result.getFirst().add(s2); } } // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase2(pair, fc); + Set> x1 = unifyCase2(pair); result.get(1).add(x1); if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC @@ -2060,7 +1784,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase3(pair, fc); + Set> x1 = unifyCase3(pair); result.get(2).add(x1); if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC @@ -2109,7 +1833,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase8(pair, fc); + Set> x1 = unifyCase8(pair); result.get(7).add(x1); if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC @@ -2134,8 +1858,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Filter empty sets or sets that only contain an empty set. - return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new))) - .filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new)); + return result.stream().map(x -> x.stream().filter(y -> !y.isEmpty()).collect(Collectors.toCollection(HashSet::new))) + .filter(x -> !x.isEmpty()).collect(Collectors.toCollection(HashSet::new)); } //TODO: Wenn Theta' nicht im FC muss ein Fehler produziert werden PL 18-04-20 @@ -2149,10 +1873,6 @@ public class TypeUnifyTask extends RecursiveTask>> { if (thetaPrime instanceof ExtendsType) { thetaPrime = ((ExtendsType)thetaPrime).getExtendedType(); } - - if (thetaPrime instanceof SuperType) { - //HIER MUSS NOCH WAS UEBERLEGT WERDEN - } Set> result = new HashSet<>(); @@ -2186,7 +1906,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set csPHRenamed = cs.stream().map(x -> { BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; HashMap hm = x.getInvolvedPlaceholderTypes().stream() - .reduce(new HashMap(), + .reduce(new HashMap<>(), (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); return x.accept(new freshPlaceholder(), hm); }).collect(Collectors.toCollection(HashSet::new)); @@ -2194,13 +1914,13 @@ public class TypeUnifyTask extends RecursiveTask>> { IMatch match = new Match(); for(UnifyType c : csPHRenamed) { //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. - Set thetaQs = new HashSet<>(); + Set thetaQs; //TODO smaller wieder reinnehmen? //thetaQs.add(c);// - thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); + thetaQs = new HashSet<>(fc.smaller(c, new HashSet<>())); ArrayList ml = new ArrayList<>(); ml.add(new UnifyPair(c, thetaPrime, PairOperator.EQUALSDOT)); - if (!(match.match(ml)).isPresent()) { + if ((match.match(ml)).isEmpty()) { thetaQs.remove(c); } writeLog("thetaQs von " + c + ": " + thetaQs.toString()); @@ -2231,7 +1951,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(UnifyType tqp : thetaQPrimes) {//PL 2020-03-08 umbauen in der Schleife wird nur unifizierbarer Typ gesucht break am Ende Collection tphs = tqp.getInvolvedPlaceholderTypes(); Optional opt = stdUnify.unify(tqp, thetaPrime); - if (!opt.isPresent()) { + if (opt.isEmpty()) { continue; } Unifier unifier = opt.get(); @@ -2277,17 +1997,16 @@ public class TypeUnifyTask extends RecursiveTask>> { if(allGen) { UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); - Iterator upit = up.getRhsType().getTypeParams().iterator(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt - while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt + for (UnifyType unifyType : up.getRhsType().getTypeParams()) + unifyType.accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } else { UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); - Iterator upit = up.getRhsType().getTypeParams().iterator(); - distributeVariance dv = new distributeVariance(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt - while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt + for (UnifyType unifyType : up.getRhsType().getTypeParams()) + unifyType.accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } resultPrime.addAll(substitutionSet); @@ -2306,14 +2025,14 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 2: (a <.? ? ext Theta') */ - private Set> unifyCase2(UnifyPair pair, IFiniteClosure fc) { + private Set> unifyCase2(UnifyPair pair) { PlaceholderType a = (PlaceholderType) pair.getLhsType(); ExtendsType extThetaPrime = (ExtendsType) pair.getRhsType(); Set> result = new HashSet<>(); - UnifyType aPrime = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); - ((PlaceholderType)aPrime).disableWildcardtable(); + PlaceholderType aPrime = PlaceholderType.freshPlaceholder(); + aPrime.setVariance(a.getVariance()); + aPrime.disableWildcardtable(); UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); @@ -2331,15 +2050,15 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 3: (a <.? ? sup Theta') */ - private Set> unifyCase3(UnifyPair pair, IFiniteClosure fc) { + private Set> unifyCase3(UnifyPair pair) { PlaceholderType a = (PlaceholderType) pair.getLhsType(); a.reversVariance(); SuperType subThetaPrime = (SuperType) pair.getRhsType(); Set> result = new HashSet<>(); - UnifyType aPrime = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); - ((PlaceholderType)aPrime).disableWildcardtable(); + PlaceholderType aPrime = PlaceholderType.freshPlaceholder(); + aPrime.setVariance(a.getVariance()); + aPrime.disableWildcardtable(); UnifyType supAPrime = new SuperType(aPrime); UnifyType thetaPrime = subThetaPrime.getSuperedType(); Set resultPrime = new HashSet<>(); @@ -2398,13 +2117,13 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)freshTphs[i]).setVariance(a.getVariance()); Set fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt int i_ef = i; BiFunction f = (x,y) -> { - ArrayList termList = new ArrayList(); + ArrayList termList = new ArrayList<>(); termList.add(new UnifyPair(y,thetaS.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); return ((match.match(termList).isPresent()) || x); }; @@ -2436,7 +2155,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 8: (Theta <.? a) */ - private Set> unifyCase8(UnifyPair pair, IFiniteClosure fc) { + private Set> unifyCase8(UnifyPair pair) { UnifyType theta = pair.getLhsType(); PlaceholderType a = (PlaceholderType) pair.getRhsType(); Set> result = new HashSet<>(); @@ -2446,10 +2165,10 @@ public class TypeUnifyTask extends RecursiveTask>> { result.add(resultPrime); //writeLog(resultPrime.toString()); - UnifyType freshTph = PlaceholderType.freshPlaceholder(); + PlaceholderType freshTph = PlaceholderType.freshPlaceholder(); - ((PlaceholderType)freshTph).setVariance(a.getVariance()); - ((PlaceholderType)freshTph).disableWildcardtable(); + freshTph.setVariance(a.getVariance()); + freshTph.disableWildcardtable(); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); @@ -2500,7 +2219,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } void writeLog(String str) { - if (log && finalresult) { + if (log) { if(parallel){ logFile.write("Thread no.:" + thNo + "\n" + "parallel:" + parallel + "\n" @@ -2516,7 +2235,6 @@ public class TypeUnifyTask extends RecursiveTask>> { } void writeStatistics(String str) { - if (finalresult) { try { statisticsFile.write("Thread No. " + thNo + ": " + str + "\n"); statisticsFile.flush(); @@ -2526,5 +2244,4 @@ public class TypeUnifyTask extends RecursiveTask>> { System.err.println("kein StatisticsFile"); } } - } }