forked from JavaTX/JavaCompilerCore
Compare commits
1 Commits
generateTe
...
bytecodeGe
Author | SHA1 | Date | |
---|---|---|---|
|
88175f8b48 |
@@ -10,9 +10,6 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.ExtendsConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
@@ -33,9 +30,6 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
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.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@@ -55,10 +49,6 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
boolean inLocalOrParamOrReturn = false;
|
boolean inLocalOrParamOrReturn = false;
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
|
|
||||||
// Alle Constraints in einer Menge (Und- & Oder-Constraints)
|
|
||||||
public Set<Pair> oldConstraints = new HashSet<>();
|
|
||||||
|
|
||||||
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
@@ -88,25 +78,15 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
public void visit(TypePlaceholder tph) {
|
public void visit(TypePlaceholder tph) {
|
||||||
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||||
String tphName = resolvedTPH.getName();
|
if (inMethod) {
|
||||||
if (inMethod && !tphsClass.contains(tphName)) {
|
methodAndTph.getTphs().add(resolvedTPH.getName());
|
||||||
ArrayList<String> tphs = null;
|
if (inLocalOrParamOrReturn)
|
||||||
if (!(tphs = methodAndTph.getTphs()).contains(tphName)) {
|
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||||
tphs.add(tphName);
|
}else {
|
||||||
}
|
tphsClass.add(resolvedTPH.getName());
|
||||||
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<TPHConstraint> cons = new ArrayList<>();
|
// final List<TPHConstraint> cons = new ArrayList<>();
|
||||||
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
||||||
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
@@ -195,31 +175,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
String id = MethodUtility.createID(resolver,method);
|
String id = MethodUtility.createID(resolver,method);
|
||||||
Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) &&
|
methodAndTph = new MethodAndTPH(id);
|
||||||
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
|
|
||||||
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
|
|
||||||
|
|
||||||
Function<ConstraintSet<Pair>, ConstraintSet<Pair>> filterConstrRemainingTVar =
|
|
||||||
csS -> {
|
|
||||||
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
|
||||||
ret.addAllUndConstraint(
|
|
||||||
csS.getUndConstraints()
|
|
||||||
.stream().filter(filterUndConstraints)
|
|
||||||
.collect(Collectors.toCollection(Constraint<Pair>::new)));
|
|
||||||
|
|
||||||
csS.getOderConstraints()
|
|
||||||
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
|
|
||||||
oConSSet.forEach(OConS -> { setCons.add(
|
|
||||||
OConS.stream()
|
|
||||||
.filter(filterUndConstraints)
|
|
||||||
.collect(Collectors.toCollection(Constraint<Pair>::new)) );
|
|
||||||
} );
|
|
||||||
ret.addOderConstraint(setCons);} );
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
ConstraintSet<Pair> filteredConstraints = filterConstrRemainingTVar.apply(method.getConstraints());
|
|
||||||
methodAndTph = new MethodAndTPH(id, filteredConstraints);
|
|
||||||
oldConstraints.addAll(filteredConstraints.getAll());
|
|
||||||
|
|
||||||
inLocalOrParamOrReturn = true;
|
inLocalOrParamOrReturn = true;
|
||||||
method.getReturnType().accept(this);
|
method.getReturnType().accept(this);
|
||||||
@@ -228,7 +184,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
|
|
||||||
if(method.block != null)
|
if(method.block != null)
|
||||||
method.block.accept(this);
|
method.block.accept(this);
|
||||||
|
|
||||||
inMethod = false;
|
inMethod = false;
|
||||||
ListOfMethodsAndTph.add(methodAndTph);
|
ListOfMethodsAndTph.add(methodAndTph);
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,6 @@ public class TPHConstraint {
|
|||||||
protected String left;
|
protected String left;
|
||||||
protected String right;
|
protected String right;
|
||||||
protected Relation rel;
|
protected Relation rel;
|
||||||
protected int variance; //noch nicht benutzt
|
|
||||||
public enum Relation{
|
public enum Relation{
|
||||||
EXTENDS, EQUAL
|
EXTENDS, EQUAL
|
||||||
}
|
}
|
||||||
@@ -49,23 +48,6 @@ public class TPHConstraint {
|
|||||||
return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight());
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if(rel == Relation.EXTENDS) {
|
if(rel == Relation.EXTENDS) {
|
||||||
@@ -74,13 +56,4 @@ public class TPHConstraint {
|
|||||||
return left + " = " + right;
|
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)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -3,14 +3,16 @@
|
|||||||
*/
|
*/
|
||||||
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
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;
|
|
||||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
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.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
@@ -79,7 +81,6 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
private JavaClassName className;
|
private JavaClassName className;
|
||||||
private Resolver resolver;
|
private Resolver resolver;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sf
|
* @param sf
|
||||||
* @param listOfResultSets
|
* @param listOfResultSets
|
||||||
@@ -94,14 +95,6 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
return generatedGenericsForSF;
|
return generatedGenericsForSF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the family of Generated Generics
|
|
||||||
* insbesondere fuer Testzwecke
|
|
||||||
*/
|
|
||||||
public FamilyOfGeneratedGenerics getFogg() {
|
|
||||||
return fogg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
@@ -134,7 +127,6 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
|
|
||||||
ConstraintsSimplierResult simplifiedConstraints = null;
|
ConstraintsSimplierResult simplifiedConstraints = null;
|
||||||
GenericsGeneratorResultForClass ggResult = null;
|
GenericsGeneratorResultForClass ggResult = null;
|
||||||
GenericsGeneratorResultForClass ggResultAlternative = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||||
resultSet = listOfResultSetsList.get(i);
|
resultSet = listOfResultSetsList.get(i);
|
||||||
@@ -143,19 +135,9 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
classOrInterface.accept(tphExtractor);
|
classOrInterface.accept(tphExtractor);
|
||||||
//PL 2020-10-16: Ab hier GGenerics implementieren durch Ali
|
//PL 2020-10-16: Ab hier GGenerics implementieren durch Ali
|
||||||
//Rueckgabe an generatedGenericsForSF
|
//Rueckgabe an generatedGenericsForSF
|
||||||
fogg = new FamilyOfGeneratedGenerics(tphExtractor, resultSet);
|
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);
|
|
||||||
System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition);
|
|
||||||
System.out.println(fogg);
|
|
||||||
|
|
||||||
///*
|
|
||||||
//Fayez Ansatz Anfang
|
|
||||||
tphsClass = tphExtractor.tphsClass;
|
tphsClass = tphExtractor.tphsClass;
|
||||||
//PL 2020-01-15
|
|
||||||
//Es muss ggResult aus fogg gebildet werden
|
|
||||||
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);
|
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);
|
||||||
if(!isVisited) {
|
if(!isVisited) {
|
||||||
ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints);
|
ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints);
|
||||||
@@ -164,45 +146,12 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
|
|
||||||
for(Method m : classOrInterface.getMethods()) {
|
for(Method m : classOrInterface.getMethods()) {
|
||||||
addMethodConstraints(simplifiedConstraints, ggResult, m);
|
addMethodConstraints(simplifiedConstraints, ggResult, m);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ggResult != null)
|
||||||
if(ggResult != null) { //Hinzufuegen von Fayez ggResult
|
|
||||||
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
||||||
}
|
System.out.println("ddd");
|
||||||
// Fayez Ansatz Ende
|
|
||||||
//*/
|
|
||||||
|
|
||||||
//Ali Ansatz Anfang
|
|
||||||
List<GenericsGeneratorResult> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericGeneratorResultsForAllMethods ggRfaM = null;
|
|
||||||
List<MethodAndConstraints> listOfMethAndCons = new ArrayList<>();
|
|
||||||
for(String methID: fogg.methodConstraintsWithPosition.keySet()) {
|
|
||||||
List<GenericsGeneratorResult> 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);
|
|
||||||
}
|
|
||||||
MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR);
|
|
||||||
listOfMethAndCons.add(mac);
|
|
||||||
}
|
|
||||||
ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons);
|
|
||||||
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
|
|
||||||
|
|
||||||
if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult
|
|
||||||
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
|
|
||||||
System.out.println(generatedGenericsForSF);
|
|
||||||
}
|
|
||||||
System.out.println(ggResultAlternative);
|
|
||||||
//Ali Ansatz Ende
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
|
|
||||||
public class ClassConstraint extends TPHConstraint {
|
public class ClassConstraint extends TPHConstraint {
|
||||||
//private TPHConstraint constraint;
|
//private TPHConstraint constraint;
|
||||||
@@ -13,12 +12,4 @@ public class ClassConstraint extends TPHConstraint {
|
|||||||
/*public ClassConstraint(TPHConstraint constraint) {
|
/*public ClassConstraint(TPHConstraint constraint) {
|
||||||
this.constraint = 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)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,44 +1,33 @@
|
|||||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||||
|
|
||||||
|
import com.ibm.icu.text.CurrencyMetaInfo;
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.util.function.Predicate;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
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 de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
public class FamilyOfGeneratedGenerics {
|
public class FamilyOfGeneratedGenerics {
|
||||||
public List<TPHConstraint> allConstraints = new ArrayList<>();
|
public List<TPHConstraint> 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
|
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
|
||||||
public HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
|
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>();
|
||||||
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
||||||
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
||||||
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
public HashMap<MethodConstraint, String> methodsWithPosition = new HashMap<>();
|
||||||
public ResultSet resSet;
|
|
||||||
public Set<Pair> oldCons = new HashSet<>();
|
|
||||||
|
|
||||||
private static final String objectType = Type.getInternalName(Object.class);
|
|
||||||
|
|
||||||
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor, ResultSet resultSet) {
|
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
|
||||||
this.resSet = resultSet;
|
|
||||||
this.oldCons = tphExtractor.oldConstraints;
|
|
||||||
this.allConstraints = tphExtractor.allCons;
|
this.allConstraints = tphExtractor.allCons;
|
||||||
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
||||||
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
||||||
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
// this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs);
|
||||||
this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
|
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
|
||||||
List<ClassConstraint> cs_cl = new ArrayList<>();
|
List<ClassConstraint> cs_cl = new ArrayList<>();
|
||||||
List<ClassConstraint> classConstraints1 = typeOfANodeOfAField(cs, posOfTphs);
|
List<ClassConstraint> classConstraints1 = typeOfANodeOfAField(cs, posOfTphs);
|
||||||
for (ClassConstraint cons: classConstraints1) {
|
for (ClassConstraint cons: classConstraints1) {
|
||||||
@@ -46,20 +35,12 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
cs_cl.add(cons);
|
cs_cl.add(cons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<ClassConstraint> 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
|
for (ClassConstraint cons: classConstraints2) {
|
||||||
boolean addedToConstraintsListForCC2 = false;
|
if (!checkForDuplicates(cons, cs_cl)) {
|
||||||
do {
|
cs_cl.add(cons);
|
||||||
addedToConstraintsListForCC2 = false;
|
|
||||||
List<ClassConstraint> 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);
|
|
||||||
addedToConstraintsListForCC2 = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} while (addedToConstraintsListForCC2);
|
}
|
||||||
|
|
||||||
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs);
|
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs);
|
||||||
for (ClassConstraint cons: classConstraints3) {
|
for (ClassConstraint cons: classConstraints3) {
|
||||||
if (!checkForDuplicates(cons, cs_cl)) {
|
if (!checkForDuplicates(cons, cs_cl)) {
|
||||||
@@ -69,123 +50,86 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return cs_cl;
|
return cs_cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
// public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
List<MethodConstraint> cs_m = new ArrayList<>();
|
// //TODO: Regeln
|
||||||
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
// List<MethodConstraint> cs_m = new ArrayList<>();
|
||||||
for (MethodConstraint cons: methodConstraints1) {
|
// List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||||
if (!checkForDuplicates(cons, cs_m)) {
|
// for (MethodConstraint cons: methodConstraints1) {
|
||||||
|
// if (!checkForDuplicates(cons, cs_m)) {
|
||||||
|
// cs_m.add(cons);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
||||||
|
// for (MethodConstraint cons: methodConstraints2) {
|
||||||
|
// if (!checkForDuplicates(cons, cs_m)) {
|
||||||
|
// cs_m.add(cons);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
|
||||||
|
// for (MethodConstraint cons: methodConstraints3) {
|
||||||
|
// if (!checkForDuplicates(cons, cs_m)) {
|
||||||
|
// cs_m.add(cons);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
|
||||||
|
// for (MethodConstraint cons: methodConstraints4) {
|
||||||
|
// if (!checkForDuplicates(cons, cs_m)) {
|
||||||
|
// cs_m.add(cons);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
||||||
|
// cs_m = methodConstraints5;
|
||||||
|
// return cs_m;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static HashMap<MethodConstraint, String> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
|
//TODO: Regeln
|
||||||
|
HashMap<MethodConstraint, String> cs_m = new HashMap<>();
|
||||||
|
HashMap<MethodConstraint, String> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||||
|
for (MethodConstraint cons: methodConstraints1.keySet()) {
|
||||||
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
||||||
|
cs_m.put(cons,);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HashMap<MethodConstraint, String> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
||||||
|
for (MethodConstraint cons: methodConstraints2.keySet()) {
|
||||||
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
||||||
cs_m.add(cons);
|
cs_m.add(cons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HashMap<MethodConstraint, String> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
|
||||||
// if sth new is added to cs_cl, then do same step again
|
for (MethodConstraint cons: methodConstraints3.keySet()) {
|
||||||
boolean addedToConstraintsListForMC2 = false;
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
||||||
do {
|
|
||||||
addedToConstraintsListForMC2 = false;
|
|
||||||
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
|
||||||
for (MethodConstraint cons : methodConstraints2) {
|
|
||||||
if (!checkForDuplicates(cons, cs_m)) {
|
|
||||||
cs_m.add(cons);
|
|
||||||
addedToConstraintsListForMC2 = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (addedToConstraintsListForMC2);
|
|
||||||
|
|
||||||
// if sth new is added to cs_cl, then do same step again
|
|
||||||
boolean addedToConstraintsListForMC3 = false;
|
|
||||||
do {
|
|
||||||
addedToConstraintsListForMC3 = false;
|
|
||||||
List<MethodConstraint> 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<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, cs_m, posOfTphs, listOfMethodsAndTph);
|
|
||||||
for (MethodConstraint cons: methodConstraints4) {
|
|
||||||
if (!checkForDuplicates(cons, cs_m)) {
|
|
||||||
cs_m.add(cons);
|
cs_m.add(cons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
HashMap<MethodConstraint, String> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs);
|
||||||
|
for (MethodConstraint cons: methodConstraints4.keySet()) {
|
||||||
|
if (!checkForDuplicatesInMethods(cons, cs_m, posOfTphs)) {
|
||||||
|
cs_m.add(cons);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HashMap<MethodConstraint, String> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
||||||
cs_m = methodConstraints5;
|
cs_m = methodConstraints5;
|
||||||
return cs_m;
|
return cs_m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
|
||||||
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
|
||||||
for(MethodAndTPH method: listOfMethodsAndTph){
|
|
||||||
List<String> methodsAddedToHashMap = new ArrayList<>();
|
|
||||||
String currentMethod = method.getId();
|
|
||||||
boolean containsCurrentMethod = false;
|
|
||||||
if(!containsCurrentMethod) {
|
|
||||||
methodsAddedToHashMap.add(currentMethod);
|
|
||||||
containsCurrentMethod = true;
|
|
||||||
List<MethodConstraint> listOfThisMethod = new ArrayList<>();
|
|
||||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph);
|
|
||||||
tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod);
|
|
||||||
|
|
||||||
List<MethodConstraint> newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet);
|
|
||||||
List<MethodConstraint> newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
|
|
||||||
System.out.println(newMCList);
|
|
||||||
System.out.println(newMCList2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
|
|
||||||
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
|
|
||||||
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
|
|
||||||
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
|
|
||||||
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
|
|
||||||
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tempMethodConstraintsWithPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hilfsmethode um TPHs in den Methoden zu finden, die <. Object sein müssen
|
|
||||||
private static boolean compareTphsOfConstraints(String tph, List list) {
|
|
||||||
List<TPHConstraint> tempList = new ArrayList<>(list);
|
|
||||||
for(TPHConstraint tphC: tempList) {
|
|
||||||
if(tph == tphC.getLeft()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Def. FGG: erste Zeile von cs_cl
|
* Def. FGG: erste Zeile von cs_cl
|
||||||
* {T < .T' | T is a type variable in a type of a node of a field}
|
* {T < .T' | T is a type variable in a type of a node of a field}
|
||||||
*/
|
*/
|
||||||
public static List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
|
public static List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
//RuntimeException re = new RuntimeException("enthält EQUALS-Relation");
|
//RuntimeException re = new RuntimeException("enthält EQUALS-Relation");
|
||||||
List<ClassConstraint> tempCC = new ArrayList<>();
|
List<ClassConstraint> tempCC= new ArrayList<>();
|
||||||
for(TPHConstraint allCons: allConstraints){
|
for(TPHConstraint allCons: allConstraints){
|
||||||
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
|
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
|
||||||
for(String tph: posOfTphs.keySet()) {
|
for(String tph: posOfTphs.keySet()) {
|
||||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
if(tph == allCons.getLeft() && posOfTphs.get(tph).fst == PositionFinder.Position.FIELD) {
|
||||||
if(tph == allCons.getLeft() && pair.fst == PositionFinder.Position.FIELD) {
|
ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel());
|
||||||
ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel());
|
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||||
if (!checkForDuplicates(consToAdd, tempCC)) {
|
tempCC.add(consToAdd);
|
||||||
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);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,13 +146,12 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs }
|
* {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs }
|
||||||
*/
|
*/
|
||||||
public static List<ClassConstraint> transitiveSubtypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl) {
|
public static List<ClassConstraint> transitiveSubtypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl) {
|
||||||
List<ClassConstraint> tempCC = new ArrayList<>();
|
List<ClassConstraint> tempCC= new ArrayList<>();
|
||||||
ClassConstraint consToAdd;
|
|
||||||
for(ClassConstraint cCons: cs_cl) {
|
for(ClassConstraint cCons: cs_cl) {
|
||||||
if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) {
|
if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) {
|
||||||
for(TPHConstraint allCons: allConstraints) {
|
for(TPHConstraint allCons: allConstraints) {
|
||||||
if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){
|
if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){
|
||||||
consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
ClassConstraint consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
||||||
if (!checkForDuplicates(consToAdd, tempCC)) {
|
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||||
tempCC.add(consToAdd);
|
tempCC.add(consToAdd);
|
||||||
}
|
}
|
||||||
@@ -224,20 +167,18 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* {T <. Object | ((T is a type variable in a type of a node of a field
|
* {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)}
|
* or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)}
|
||||||
*/
|
*/
|
||||||
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
|
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
List<ClassConstraint> tempCC= new ArrayList<>();
|
List<ClassConstraint> tempCC= new ArrayList<>();
|
||||||
for(TPHConstraint allCons: allConstraints) {
|
for(TPHConstraint allCons: allConstraints) {
|
||||||
for(ClassConstraint cCons: cs_cl) {
|
for(ClassConstraint cCons: cs_cl) {
|
||||||
for(String tph: posOfTphs.keySet()) {
|
for(String tph: posOfTphs.keySet()) {
|
||||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
boolean tvInField = posOfTphs.get(tph).fst == PositionFinder.Position.FIELD;
|
||||||
boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
|
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
|
||||||
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
|
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
|
||||||
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);
|
||||||
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
|
if (!checkForDuplicates(consToAdd, tempCC)){
|
||||||
if (!checkForDuplicates(consToAdd, tempCC)){
|
tempCC.add(consToAdd);
|
||||||
tempCC.add(consToAdd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,18 +191,16 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* Def. FGG: erste Zeile von cs_m
|
* 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}
|
* {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<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) { // cl_\sigma??
|
public static HashMap<MethodConstraint, String> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
|
||||||
//TODO:
|
//TODO:
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
||||||
for(TPHConstraint allCons: allConstraints){
|
for(TPHConstraint allCons: allConstraints){
|
||||||
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
|
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
|
||||||
for(String tph: posOfTphs.keySet()) {
|
for(String tph: posOfTphs.keySet()) {
|
||||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) {
|
||||||
if(tph == allCons.getLeft() && (pair.fst == PositionFinder.Position.METHOD || pair.fst == PositionFinder.Position.CONSTRUCTOR)) {
|
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
||||||
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
tempMC.put(consToAdd, posOfTphs.get(tph).snd);
|
||||||
tempMC.add(consToAdd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,19 +214,19 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* Def. FGG: zweite Zeile von cs_m
|
* 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}
|
* {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs}
|
||||||
*/
|
*/
|
||||||
public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
public static HashMap<MethodConstraint, String> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //transitive closure of cs
|
||||||
//TODO:
|
//TODO:
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
||||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||||
for(MethodConstraint mC1 : cs_m) { //(R <. R')
|
for(MethodConstraint mC1 : cs_m.keySet()) { //(R <. R')
|
||||||
for(MethodConstraint mC2 : cs_m) { //(S <. S')
|
for(MethodConstraint mC2 : cs_m.keySet()) { //(S <. S')
|
||||||
String lSide = mC1.getRight(); //R'
|
String lSide = mC1.getRight(); //R'
|
||||||
String rSide = mC2.getLeft(); //S
|
String rSide = mC2.getLeft(); //S
|
||||||
for(TPHConstraint tphC : tcOfCs) {
|
for(TPHConstraint tphC : tcOfCs) {
|
||||||
if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S)
|
if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S)
|
||||||
MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S)
|
MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S)
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
||||||
tempMC.add(consToAdd);
|
tempMC.put(consToAdd, posOfTphs.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,19 +239,20 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* Def. FGG: dritte Zeile von cs_m
|
* 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}
|
* {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<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
public static HashMap<MethodConstraint, String> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
//TODO:
|
//TODO:
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
||||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||||
for(ClassConstraint cC : cs_cl) {
|
for(ClassConstraint cC : cs_cl) {
|
||||||
for(MethodConstraint mC : cs_m) {
|
for(MethodConstraint mC : cs_m.keySet()) {
|
||||||
String leftSide = mC.getRight();
|
String leftSide = mC.getRight();
|
||||||
String rightSide = cC.getLeft();
|
String rightSide = cC.getLeft();
|
||||||
for(TPHConstraint tphC : tcOfCs) {
|
for(TPHConstraint tphC : tcOfCs) {
|
||||||
if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) {
|
if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) {
|
||||||
MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
|
MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
||||||
tempMC.add(consToAdd);
|
tempMC.put(consToAdd, posOfTphs.get());
|
||||||
|
// System.out.println(consToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -327,32 +267,16 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* {T <. Object | (T is a type variable in a type of a node of the method/constructor m in cl_\sigma),
|
* {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)}
|
* (\existsnot T': T <. T') \in cs)}
|
||||||
*/
|
*/
|
||||||
public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
public static HashMap<MethodConstraint, String> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
//TODO:
|
//TODO:
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
HashMap<MethodConstraint, String> tempMC= new HashMap<>();
|
||||||
for(String tph: posOfTphs.keySet()) {
|
for(String tph: posOfTphs.keySet()) {
|
||||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
for(TPHConstraint allCons: allConstraints) {
|
||||||
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((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) {
|
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
|
||||||
MethodConstraint consToAdd = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
if (!checkForDuplicatesInMethods(consToAdd, tempMC, posOfTphs)) {
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
tempMC.put(consToAdd, posOfTphs.get(tph).snd);
|
||||||
tempMC.add(consToAdd);
|
// System.out.println(consToAdd);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<TPHConstraint> 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, objectType, Relation.EXTENDS);
|
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
|
||||||
tempMC.add(consToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -363,18 +287,15 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
/**
|
/**
|
||||||
* nimm die Menge cs_cl aus cs_m raus
|
* nimm die Menge cs_cl aus cs_m raus
|
||||||
*/
|
*/
|
||||||
public static List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
public static HashMap<MethodConstraint, String> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, HashMap<MethodConstraint, String> cs_m) {
|
||||||
// erstelle Kopie der Liste cs_cl
|
//TODO:
|
||||||
List<TPHConstraint> tempCC = new ArrayList<>();
|
List<TPHConstraint> tempCC = new ArrayList<>();
|
||||||
for(ClassConstraint cc: cs_cl) {
|
for(ClassConstraint cc: cs_cl) {
|
||||||
TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel());
|
TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel());
|
||||||
tempCC.add(tphC);
|
tempCC.add(tphC);
|
||||||
}
|
}
|
||||||
// Transitive Hülle von cs_cl
|
|
||||||
List<TPHConstraint> tcOfCsCl = buildTransitiveClosure(tempCC);
|
|
||||||
|
|
||||||
List<TPHConstraint> tempMC = new ArrayList<>();
|
List<TPHConstraint> tempMC = new ArrayList<>();
|
||||||
for(MethodConstraint mc: cs_m) {
|
for(MethodConstraint mc: cs_m.keySet()) {
|
||||||
TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel());
|
TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel());
|
||||||
tempMC.add(tphC);
|
tempMC.add(tphC);
|
||||||
}
|
}
|
||||||
@@ -382,7 +303,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
tempMC2.addAll(tempMC);
|
tempMC2.addAll(tempMC);
|
||||||
List<MethodConstraint> tempMCToReturn = new ArrayList<>();
|
List<MethodConstraint> tempMCToReturn = new ArrayList<>();
|
||||||
|
|
||||||
for(TPHConstraint cc: tcOfCsCl) {
|
for(TPHConstraint cc: tempCC) {
|
||||||
for(TPHConstraint mc: tempMC) {
|
for(TPHConstraint mc: tempMC) {
|
||||||
if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) {
|
if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) {
|
||||||
tempMC2.remove(mc);
|
tempMC2.remove(mc);
|
||||||
@@ -409,6 +330,20 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkForDuplicatesInMethods(TPHConstraint constraint, HashMap<MethodConstraint, String> hashMap, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
|
HashMap<MethodConstraint, String> tempMap = hashMap;
|
||||||
|
boolean hasSame = false;
|
||||||
|
for (TPHConstraint tphC: tempMap.keySet()) {
|
||||||
|
hasSame = constraint.getLeft() == tphC.getLeft() &&
|
||||||
|
constraint.getRight() == tphC.getRight() &&
|
||||||
|
constraint.getRel() == tphC.getRel() &&
|
||||||
|
posOfTphs.get(); //constraint already in ArrayList if true
|
||||||
|
if (hasSame)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<TPHConstraint> buildTransitiveClosure(List list) {
|
public static List<TPHConstraint> buildTransitiveClosure(List list) {
|
||||||
List<TPHConstraint> iterList = new ArrayList<>(list);
|
List<TPHConstraint> iterList = new ArrayList<>(list);
|
||||||
List<TPHConstraint> runList = new ArrayList<>(list);
|
List<TPHConstraint> runList = new ArrayList<>(list);
|
||||||
@@ -434,28 +369,25 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
public static boolean checkUpperBound(List<TPHConstraint> cs, String tph) {
|
public static boolean checkUpperBound(List<TPHConstraint> cs, String tph) {
|
||||||
for(int i=0; i<cs.size(); i++) {
|
for(int i=0; i<cs.size(); i++) {
|
||||||
if(cs.get(i).getLeft() == tph) {
|
if(cs.get(i).getLeft() == tph) {
|
||||||
//has upper bound
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> positionConverter(HashMap<String, Boolean> allTphs, List<MethodAndTPH> listOfMethodsAndTphs) {
|
public static HashMap<String, PairTphMethod<PositionFinder.Position, String>> positionConverter(HashMap<String, Boolean> allTphs, List<MethodAndTPH> listOfMethodsAndTphs) {
|
||||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> convertedPositions = new HashMap<>();
|
HashMap<String, PairTphMethod<PositionFinder.Position, String>> convertedPositions = new HashMap<>();
|
||||||
for(String tph: allTphs.keySet()) {
|
for(String tph: allTphs.keySet()) {
|
||||||
List<PairTphMethod<PositionFinder.Position, String>> currMeth = new ArrayList<>();
|
|
||||||
if(allTphs.get(tph)) { //if true, then tph is a method-TPH
|
if(allTphs.get(tph)) { //if true, then tph is a method-TPH
|
||||||
for(MethodAndTPH methTph: listOfMethodsAndTphs) {
|
for(MethodAndTPH methTph: listOfMethodsAndTphs) {
|
||||||
if (methTph.getTphs().contains(tph)) {
|
if (methTph.getTphs().contains(tph)) {
|
||||||
currMeth.add(new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId()));
|
convertedPositions.put(tph, new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // else it is in the class-TPH
|
} else { // else it is in the class-TPH
|
||||||
currMeth.add(new PairTphMethod<>(PositionFinder.Position.FIELD, null));
|
convertedPositions.put(tph, new PairTphMethod<>(PositionFinder.Position.FIELD, null));
|
||||||
}
|
}
|
||||||
convertedPositions.put(tph, currMeth);
|
|
||||||
}
|
}
|
||||||
return convertedPositions;
|
return convertedPositions;
|
||||||
}
|
}
|
||||||
@@ -479,306 +411,4 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static List<MethodConstraint> firstLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet) {
|
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
|
||||||
MethodAndTPH methAndTphs = methodAndTPH;
|
|
||||||
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
|
|
||||||
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
|
|
||||||
Iterator<Pair> it = undCons.iterator();
|
|
||||||
while(it.hasNext()) {
|
|
||||||
Pair p = it.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);
|
|
||||||
if(mc.getRel() != Relation.EQUAL) {
|
|
||||||
if(!checkForDuplicates(mc, tempMC)) {
|
|
||||||
tempMC.add(mc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tempMC;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
|
|
||||||
List<MethodConstraint> tempMC = new ArrayList<>();
|
|
||||||
Set<Pair> tempSet = new HashSet<>();
|
|
||||||
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet);
|
|
||||||
MethodAndTPH methAndTphs = methodAndTPH;
|
|
||||||
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
|
|
||||||
List<List<Constraint<Pair>>> orConsList = new ArrayList<>();
|
|
||||||
List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
|
|
||||||
for(int i=0; i<orCons.size(); i++) {
|
|
||||||
HashMap<Relation, List<TPHConstraint>> orConsInternal = new HashMap<>();
|
|
||||||
List<TPHConstraint> orConsWithEQUAL = new ArrayList();
|
|
||||||
List<TPHConstraint> orConsWithEXTENDS = new ArrayList();
|
|
||||||
for(Constraint con: orCons.get(i)) {
|
|
||||||
Iterator<Pair> 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));
|
|
||||||
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);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
orConsInternal.put(Relation.EXTENDS, orConsWithEXTENDS);
|
|
||||||
orConsInternal.put(Relation.EQUAL, orConsWithEQUAL);
|
|
||||||
orConsListConverted.add(orConsInternal);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Pair> oldConsList = new ArrayList<>(oldCons);
|
|
||||||
List<TPHConstraint> 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<TPHConstraint> tcOfoldCons = buildTransitiveClosure(oldConsListConverted);
|
|
||||||
// Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons);
|
|
||||||
|
|
||||||
// for(int i=0; i<orConsListConverted.size(); i++) {
|
|
||||||
for(int i=0; i<orCons.size(); i++) {
|
|
||||||
Constraint<Pair> extendsSet = new Constraint<Pair>();
|
|
||||||
Constraint<Pair> equalSet = new Constraint<Pair>();
|
|
||||||
for(Constraint con: orCons.get(i)) {
|
|
||||||
Iterator<Pair> it = con.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Pair p = it.next();
|
|
||||||
// List<TPHConstraint> extendsList = orConsListConverted.get(i).get(Relation.EXTENDS);
|
|
||||||
// List<TPHConstraint> 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<Pair> itExtends = extendsSet.iterator();
|
|
||||||
while(itExtends.hasNext()) {
|
|
||||||
Pair pairExtends = itExtends.next();
|
|
||||||
// for (TPHConstraint eq : equalList) {
|
|
||||||
Iterator<Pair> 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<Pair> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Pair> 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);
|
|
||||||
if(mc.getRel() != Relation.EQUAL) {
|
|
||||||
if(!checkForDuplicates(mc, tempMC)) {
|
|
||||||
tempMC.add(mc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempMC;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Set<Pair> buildTransitiveClosureForCP(Set constraint, ResultSet resSet) {
|
|
||||||
Set<Pair> iterSet = new HashSet<>(constraint);
|
|
||||||
Set<Pair> runSet = new HashSet<>(constraint);
|
|
||||||
Set<Pair> tcSet = new HashSet<>(constraint);
|
|
||||||
boolean addedConToList = false;
|
|
||||||
// for (TPHConstraint cons: iterList) {
|
|
||||||
Iterator<Pair> itIterSet = iterSet.iterator();
|
|
||||||
while(itIterSet.hasNext()) {
|
|
||||||
Pair pairIterSet = itIterSet.next();
|
|
||||||
// for (TPHConstraint cons2: runList) {
|
|
||||||
Iterator<Pair> itRunSet = runSet.iterator();
|
|
||||||
while (itRunSet.hasNext()) {
|
|
||||||
Pair pairRunSet = itRunSet.next();
|
|
||||||
// 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(resSet.resolveType((TypePlaceholder)(pairIterSet.TA1)).resolvedType, resSet.resolveType((TypePlaceholder)(pairRunSet.TA2)).resolvedType, PairOperator.SMALLERDOT);
|
|
||||||
// if (!checkForDuplicates(consToAdd,tcList)) {
|
|
||||||
if(!checkForDuplicatesForSets(p, tcSet)) {
|
|
||||||
// tcList.add(consToAdd);
|
|
||||||
tcSet.add(p);
|
|
||||||
addedConToList = true;
|
|
||||||
if (addedConToList) {
|
|
||||||
return buildTransitiveClosureForCP(tcSet, resSet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("tcSet: " + tcSet);
|
|
||||||
return tcSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkForDuplicatesForSets(Pair pair, Set set) {
|
|
||||||
Set<Pair> tempSet = set;
|
|
||||||
boolean hasSame = false;
|
|
||||||
// for (TPHConstraint tphC: tempList) {
|
|
||||||
Iterator<Pair> 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 == p.TA1 &&
|
|
||||||
pair.TA2 == p.TA2 &&
|
|
||||||
pair.OperatorSmallerDot() && p.OperatorSmallerDot(); //constraint already in Set if true
|
|
||||||
if (hasSame)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH) {
|
|
||||||
List<MethodConstraint> tempMC = new ArrayList<>();
|
|
||||||
List<TPHConstraint> allCons = allConstraints;
|
|
||||||
MethodAndTPH methAndTphs = methodAndTPH;
|
|
||||||
for(String tph: posOfTphs.keySet()) {
|
|
||||||
for(int i=0; i<posOfTphs.get(tph).size(); i++)
|
|
||||||
if(posOfTphs.get(tph).get(i).fst == PositionFinder.Position.METHOD && posOfTphs.get(tph).get(i).snd == methAndTphs.getId()) {
|
|
||||||
for(TPHConstraint ac: allCons) {
|
|
||||||
if(tph==ac.getRight() && !checkUpperBound(allCons,tph)) {
|
|
||||||
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
|
||||||
if(!checkForDuplicates(mc2, tempMC)) {
|
|
||||||
tempMC.add(mc2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tempMC;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPositionNew(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
|
||||||
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
|
||||||
List<MethodConstraint> newMCList = new ArrayList<>();
|
|
||||||
List<MethodConstraint> newMCList2 = new ArrayList<>();
|
|
||||||
List<MethodConstraint> hasNoSupType = new ArrayList<>();
|
|
||||||
List<MethodConstraint> mcWithoutCc = new ArrayList<>();
|
|
||||||
|
|
||||||
List<String> methodsAddedToHashMap = new ArrayList<>();
|
|
||||||
for(MethodAndTPH method: listOfMethodsAndTph){
|
|
||||||
String currentMethod = method.getId();
|
|
||||||
boolean containsCurrentMethod = false;
|
|
||||||
if(!containsCurrentMethod) {
|
|
||||||
methodsAddedToHashMap.add(currentMethod);
|
|
||||||
containsCurrentMethod = true;
|
|
||||||
List<MethodConstraint> listToAdd = new ArrayList<>();
|
|
||||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> 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<newMCList.size(); i++) {
|
|
||||||
listToAdd.add(newMCList.get(i));
|
|
||||||
}
|
|
||||||
newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
|
|
||||||
for(int i=0; i<newMCList2.size(); i++) {
|
|
||||||
listToAdd.add(newMCList2.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if(!methodsAddedToHashMap.contains(currentMethod)) {
|
|
||||||
tempMethodConstraintsWithPosition.put(currentMethod, newMCList);
|
|
||||||
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
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<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
|
|
||||||
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
|
|
||||||
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
|
|
||||||
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
|
|
||||||
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempMethodConstraintsWithPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
String ret =
|
|
||||||
"List<ClassConstraint> classConstraintsTest = new ArrayList<>();\n";
|
|
||||||
for(ClassConstraint cC: classConstraints) {
|
|
||||||
ret = ret + "classConstraintsTest.add(" + cC.toString() + ");\n";
|
|
||||||
}
|
|
||||||
ret = ret + "HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();\n";
|
|
||||||
ret = ret + "List<MethodConstraint> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,9 @@
|
|||||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
|
|
||||||
public class MethodConstraint extends TPHConstraint {
|
public class MethodConstraint extends TPHConstraint {
|
||||||
public MethodConstraint(String left, String right, Relation rel) {
|
public MethodConstraint(String left, String right, Relation rel) {
|
||||||
super(left, right, 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)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/** A generic class for pairs.
|
|
||||||
*
|
|
||||||
* <p><b>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.</b>
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
public class PairMethodAndConstraint<A, B> {
|
|
||||||
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 <A,B> PairMethodAndConstraint<A,B> of(A a, B b) {
|
|
||||||
return new PairMethodAndConstraint<>(a,b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PairMethodAndConstraint add(A fst, B snd){
|
|
||||||
return new PairMethodAndConstraint<>(fst,snd);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -4,8 +4,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
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.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
@@ -17,15 +15,9 @@ public class MethodAndTPH {
|
|||||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||||
// tphs of local variables and parameters
|
// tphs of local variables and parameters
|
||||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
/*
|
|
||||||
* its Constraints
|
|
||||||
* eingefuegt PL 2021-02-15
|
|
||||||
*/
|
|
||||||
public final ConstraintSet constraints;
|
|
||||||
|
|
||||||
public MethodAndTPH(String name, ConstraintSet<Pair> constraints) {
|
public MethodAndTPH(String name) {
|
||||||
this.id = name;
|
this.id = name;
|
||||||
this.constraints = constraints;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getTphs() {
|
public ArrayList<String> getTphs() {
|
||||||
|
@@ -6,7 +6,6 @@ import de.dhbwstuttgart.bytecode.BytecodeGen;
|
|||||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
@@ -79,12 +78,7 @@ public class JavaTXCompiler {
|
|||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
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();
|
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||||
private final ClassLoader classLoader;
|
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 {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile), null);
|
this(Arrays.asList(sourceFile), null);
|
||||||
}
|
}
|
||||||
@@ -878,7 +872,6 @@ public class JavaTXCompiler {
|
|||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
||||||
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
||||||
this.fogg = sResFinder.getFogg();
|
|
||||||
result.add(simplifyResOfSF);
|
result.add(simplifyResOfSF);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@@ -126,7 +126,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
public void visit(Assign assign) {
|
public void visit(Assign assign) {
|
||||||
assign.lefSide.accept(this);
|
assign.lefSide.accept(this);
|
||||||
assign.rightSide.accept(this);
|
assign.rightSide.accept(this);
|
||||||
assign.rightSide.getType().accept((ASTVisitor) this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -187,10 +186,8 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
methodCall.getArgumentList().accept(this);
|
methodCall.getArgumentList().accept(this);
|
||||||
methodCall.getArgumentList().getArguments().forEach(a -> a.getType().accept((ASTVisitor) this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NewClass methodCall) {
|
public void visit(NewClass methodCall) {
|
||||||
visit((MethodCall) methodCall);
|
visit((MethodCall) methodCall);
|
||||||
@@ -214,7 +211,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return aReturn) {
|
public void visit(Return aReturn) {
|
||||||
aReturn.retexpr.accept(this);
|
aReturn.retexpr.accept(this);
|
||||||
aReturn.getType().accept((ASTVisitor) this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -31,14 +31,8 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
private ExceptionList exceptionlist;
|
private ExceptionList exceptionlist;
|
||||||
private GenericDeclarationList generics;
|
private GenericDeclarationList generics;
|
||||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
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,
|
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||||
GenericDeclarationList gtvDeclarations, Token offset) {
|
GenericDeclarationList gtvDeclarations, Token offset) {
|
||||||
super(offset);
|
super(offset);
|
||||||
@@ -76,10 +70,6 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
return this.returnType;
|
return this.returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet getConstraints() {
|
|
||||||
return this.constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
|
@@ -45,12 +45,6 @@ public class SourceFile extends SyntaxTreeNode{
|
|||||||
public List<ClassOrInterface> getClasses() {
|
public List<ClassOrInterface> getClasses() {
|
||||||
return KlassenVektor;
|
return KlassenVektor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Method> getAllMethods() {
|
|
||||||
List<Method> ret = new ArrayList<>();
|
|
||||||
getClasses().forEach(cl -> ret.addAll(cl.getMethods()));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
|
@@ -258,7 +258,6 @@ public class UnifyTypeFactory {
|
|||||||
ret = TypePlaceholder.fresh(new NullToken());
|
ret = TypePlaceholder.fresh(new NullToken());
|
||||||
tphs.put(t.getName(), ret);
|
tphs.put(t.getName(), ret);
|
||||||
}
|
}
|
||||||
ret.setVariance(t.getVariance());
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,10 +53,4 @@ public class ExtendsWildcardType extends WildcardType{
|
|||||||
public void accept(ResultSetVisitor visitor) {
|
public void accept(ResultSetVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -32,11 +32,5 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
public void accept(ResultSetVisitor visitor) {
|
public void accept(ResultSetVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -77,8 +77,8 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
if(obj instanceof RefType){
|
if(obj instanceof RefType){
|
||||||
boolean ret = true;
|
boolean ret = true;
|
||||||
|
|
||||||
//if(!(super.equals(obj))) PL 2020-03-12 muss vll. einkommentiert werden
|
if(!super.equals(obj))
|
||||||
// return false;
|
return false;
|
||||||
|
|
||||||
if(parameter==null || parameter.size()==0){
|
if(parameter==null || parameter.size()==0){
|
||||||
ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0);
|
ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0);
|
||||||
|
@@ -16,7 +16,4 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
|
|||||||
public abstract <A> A acceptTV(TypeVisitor<A> visitor);
|
public abstract <A> A acceptTV(TypeVisitor<A> visitor);
|
||||||
public abstract void accept(ResultSetVisitor visitor);
|
public abstract void accept(ResultSetVisitor visitor);
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract boolean equals(Object o);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -64,10 +64,4 @@ public class SuperWildcardType extends WildcardType{
|
|||||||
public void accept(ResultSetVisitor visitor) {
|
public void accept(ResultSetVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -20,9 +20,10 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wird im Generate Generics Teil nach der Rueckumwandlung nach dem Unify genutzt
|
* wird bisher nicht genutzt
|
||||||
|
* setVariance muss ggf. auskommentiert werden.
|
||||||
*/
|
*/
|
||||||
private int variance = 0;
|
int variance = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,9 +78,11 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* wird bisher nicht genutzt
|
||||||
public void setVariance(int variance) {
|
public void setVariance(int variance) {
|
||||||
this.variance= variance;
|
this.variance= variance;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public int getVariance() {
|
public int getVariance() {
|
||||||
return this.variance;
|
return this.variance;
|
||||||
|
@@ -23,17 +23,9 @@ public class ConstraintSet<A> {
|
|||||||
oderConstraints.add(methodConstraints);
|
oderConstraints.add(methodConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAllUndConstraint(Constraint<A> allUndConstraints){
|
|
||||||
undConstraints.addAll(allUndConstraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAllOderConstraint(List<Set<Constraint<A>>> allOderConstraints){
|
|
||||||
this.oderConstraints.addAll(allOderConstraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAll(ConstraintSet constraints) {
|
public void addAll(ConstraintSet constraints) {
|
||||||
this.addAllUndConstraint(constraints.undConstraints);
|
this.undConstraints.addAll(constraints.undConstraints);
|
||||||
this.addAllOderConstraint(constraints.oderConstraints);
|
this.oderConstraints.addAll(constraints.oderConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -32,10 +32,8 @@ public class TYPE {
|
|||||||
|
|
||||||
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
ConstraintSet methConstrains;
|
|
||||||
for(Method m : cl.getMethods()){
|
for(Method m : cl.getMethods()){
|
||||||
ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
|
ret.addAll(getConstraintsMethod(m,info, cl));
|
||||||
m.constraints.addAll(methConstrains);
|
|
||||||
}
|
}
|
||||||
for(Constructor m : cl.getConstructors()){
|
for(Constructor m : cl.getConstructors()){
|
||||||
ret.addAll(getConstraintsConstructor(m,info, cl));
|
ret.addAll(getConstraintsConstructor(m,info, cl));
|
||||||
|
@@ -490,7 +490,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return returnExpr) {
|
public void visit(Return returnExpr) {
|
||||||
returnExpr.retexpr.accept(this);
|
returnExpr.retexpr.accept(this);
|
||||||
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT));
|
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -587,13 +587,9 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
||||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
|
methodConstraint.add(forMethod.name.equals("apply") ? //PL 2019-11-29: Tenaerer Operator eingefügt, weil bei Lambda-Ausdrücken keine Suntype FunN$$ existiert
|
||||||
PairOperator.EQUALSDOT));//PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind.
|
new Pair(forMethod.receiver.getType(), retType, PairOperator.EQUALSDOT)
|
||||||
|
: new Pair(forMethod.receiver.getType(), retType, PairOperator.SMALLERDOT));
|
||||||
//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(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||||
PairOperator.EQUALSDOT));
|
PairOperator.EQUALSDOT));
|
||||||
|
@@ -655,6 +655,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
else
|
else
|
||||||
t1.getTypeParams().forEach(x -> occuringTypes.push(x));
|
t1.getTypeParams().forEach(x -> occuringTypes.push(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
|
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
|
||||||
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
|
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
|
||||||
boolean applied = false;
|
boolean applied = false;
|
||||||
@@ -668,7 +669,6 @@ public class RuleSet implements IRuleSet{
|
|||||||
&& pair.getLhsType() instanceof PlaceholderType)
|
&& pair.getLhsType() instanceof PlaceholderType)
|
||||||
lhsType = (PlaceholderType) pair.getLhsType();
|
lhsType = (PlaceholderType) pair.getLhsType();
|
||||||
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
||||||
|
|
||||||
if(lhsType != null
|
if(lhsType != null
|
||||||
//&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
|
//&& !((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.
|
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
|
||||||
|
@@ -34,7 +34,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
System.out.println("two");
|
System.out.println("two");
|
||||||
}
|
}
|
||||||
one = true;
|
one = true;
|
||||||
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField);
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true);
|
||||||
/*if (isUndefinedPairSetSet(res)) {
|
/*if (isUndefinedPairSetSet(res)) {
|
||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
|
@@ -110,9 +110,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
protected boolean parallel;
|
protected boolean parallel;
|
||||||
|
|
||||||
//Gives if unify is not called from checkA
|
|
||||||
private boolean finalresult = true;
|
|
||||||
|
|
||||||
int rekTiefeField;
|
int rekTiefeField;
|
||||||
|
|
||||||
Integer nOfUnify = 0;
|
Integer nOfUnify = 0;
|
||||||
@@ -260,7 +257,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
|
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
|
||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField);
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true);
|
||||||
noOfThread--;
|
noOfThread--;
|
||||||
try {
|
try {
|
||||||
logFile.close();
|
logFile.close();
|
||||||
@@ -302,7 +299,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @param fc The finite closure
|
* @param fc The finite closure
|
||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
|
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||||
// ).collect(Collectors.toCollection(HashSet::new));
|
// ).collect(Collectors.toCollection(HashSet::new));
|
||||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||||
@@ -311,7 +308,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
//.collect(Collectors.toCollection(HashSet::new)));
|
//.collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
/*
|
||||||
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
|
*/
|
||||||
synchronized (usedTasks) {
|
synchronized (usedTasks) {
|
||||||
if (this.myIsCancelled()) {
|
if (this.myIsCancelled()) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
@@ -340,29 +339,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Occurs-Check durchfuehren
|
|
||||||
*/
|
|
||||||
|
|
||||||
Set<UnifyPair> 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<Set<UnifyPair>> ret = new HashSet<>();
|
|
||||||
ret.add(ocurrPairs);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
|
||||||
*/
|
|
||||||
Set<UnifyPair> eq0;
|
Set<UnifyPair> eq0;
|
||||||
Set<UnifyPair> eq0Prime;
|
Set<UnifyPair> eq0Prime;
|
||||||
Optional<Set<UnifyPair>> eqSubst = Optional.of(eq);
|
Optional<Set<UnifyPair>> eqSubst = Optional.of(eq);
|
||||||
@@ -481,12 +457,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
//Aufruf von computeCartesianRecursive ANFANG
|
//Aufruf von computeCartesianRecursive ANFANG
|
||||||
//writeLog("topLevelSets: " + topLevelSets.toString());
|
//writeLog("topLevelSets: " + topLevelSets.toString());
|
||||||
return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe);
|
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
|
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
//Aufruf von computeCartesianRecursive ENDE
|
//Aufruf von computeCartesianRecursive ENDE
|
||||||
|
|
||||||
//keine Ahnung woher das kommt
|
//keine Ahnung woher das kommt
|
||||||
@@ -575,12 +551,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe);
|
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe);
|
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||||
|
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
@@ -611,36 +587,22 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Computes the cartesian product of topLevelSets step by step.
|
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
* @param topLevelSets List of Sets of Sets, where a cartesian product have to be built
|
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||||
* Ex.: [{{a =. Integer}, {a = Object}}, {{a = Vector<b>, b =. Integer}, {a = Vector<b>, 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
|
|
||||||
* @return The set of all principal type unifiers
|
|
||||||
*/
|
|
||||||
Set<Set<UnifyPair>> computeCartesianRecursive(ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
|
|
||||||
|
|
||||||
//oneElems: Alle 1-elementigen Mengen, die nur ein Paar
|
fstElems.addAll(topLevelSets.stream()
|
||||||
//a <. theta, theta <. a oder a =. theta enthalten
|
|
||||||
Set<Set<UnifyPair>> oneElems = new HashSet<>();
|
|
||||||
oneElems.addAll(topLevelSets.stream()
|
|
||||||
.filter(x -> x.size()==1)
|
.filter(x -> x.size()==1)
|
||||||
.map(y -> y.stream().findFirst().get())
|
.map(y -> y.stream().findFirst().get())
|
||||||
.collect(Collectors.toCollection(HashSet::new)));
|
.collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
ArrayList<Set<? extends Set<UnifyPair>>> remainingSets = topLevelSets.stream()
|
||||||
//optNextSet: Eine mehrelementige Menge, wenn vorhanden
|
.filter(x -> x.size()>1)
|
||||||
Optional<Set<? extends Set<UnifyPair>>> optNextSet = topLevelSets.stream().filter(x -> x.size()>1).findAny();
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
|
||||||
if (!optNextSet.isPresent()) {//Alle Elemente sind 1-elementig
|
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||||
Set<Set<UnifyPair>> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||||
Set<? extends Set<UnifyPair>> nextSet = optNextSet.get();
|
|
||||||
//writeLog("nextSet: " + nextSet.toString());
|
//writeLog("nextSet: " + nextSet.toString());
|
||||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||||
/*
|
/*
|
||||||
@@ -655,12 +617,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
int variance = 0;
|
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<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
||||||
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
||||||
Boolean oderConstraint = false;
|
Boolean oderConstraint = false;
|
||||||
@@ -683,15 +639,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//variance = 2;
|
||||||
oderConstraint = true;
|
oderConstraint = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//variance = 2;
|
||||||
oderConstraint = true;
|
oderConstraint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Varianz-Bestimmung Oder-Constraints
|
if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints
|
||||||
if (oderConstraint) {
|
|
||||||
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
||||||
Optional<Integer> optVariance =
|
Optional<Integer> optVariance =
|
||||||
nextSetasList.iterator()
|
nextSetasList.iterator()
|
||||||
@@ -704,22 +661,23 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
||||||
.findAny();
|
.findAny();
|
||||||
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt.
|
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt.
|
||||||
//da kein Receiver existiert also kein x.getGroundBasePair().getLhsType() instanceof PlaceholderType
|
//da kein Receiver existiert also keon x.getGroundBasePair().getLhsType() instanceof PlaceholderType
|
||||||
//Bei Varianz = 2 werden alle Elemente des Kartesischen Produkts abgearbeitet
|
//Es werden alle Elemente des Kartesischen Produkts abgearbeitet
|
||||||
variance = optVariance.isPresent() ? optVariance.get() : 2;
|
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());
|
//writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
||||||
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
||||||
|
|
||||||
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet
|
/* 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<UnifyPair> sameEqSet = new HashSet<>();
|
Set<UnifyPair> sameEqSet = new HashSet<>();
|
||||||
|
|
||||||
//optOrigPair enthaelt ggf. das Paar a = ty \in nextSet
|
|
||||||
Optional<UnifyPair> optOrigPair = null;
|
Optional<UnifyPair> optOrigPair = null;
|
||||||
|
//if (variance != 2) {
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {
|
||||||
optOrigPair = nextSetElem.stream().filter(x -> (
|
optOrigPair = nextSetElem.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
@@ -743,7 +701,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
tyVar = origPair.getRhsType();
|
tyVar = origPair.getRhsType();
|
||||||
}
|
}
|
||||||
UnifyType tyVarEF = tyVar;
|
UnifyType tyVarEF = tyVar;
|
||||||
sameEqSet = oneElems.stream().map(xx -> xx.iterator().next())
|
sameEqSet = fstElems.stream().map(xx -> xx.iterator().next())
|
||||||
.filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType))
|
.filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType))
|
||||||
|| (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType)))))
|
|| (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType)))))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
@@ -752,21 +710,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/* sameEqSet-Bestimmung Ende */
|
/* sameEqSet-Bestimmung Ende */
|
||||||
|
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
while (nextSetasList.size() > 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a_last = a;
|
Set<UnifyPair> 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<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
||||||
|
|
||||||
/* Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt
|
//Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt
|
||||||
* In der Regel ist dies genau ein Element
|
//In der Regel ein Element
|
||||||
* Dieses Element wird später aus nextSetasList geloescht, wenn das jeweils andere Element zum Erfolg
|
|
||||||
* gefuehrt hat.
|
|
||||||
*/
|
|
||||||
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
|
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
|
||||||
|
|
||||||
writeLog("nextSet: " + nextSet.toString());
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
@@ -789,7 +740,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Alle maximale Elemente in nextSetasListRest bestimmen
|
//Alle maximale Elemente in nextSetasListRest bestimmen
|
||||||
//nur für diese wird parallele Berechnung angestossen.
|
|
||||||
nextSetasListRest = oup.maxElements(nextSetasListRest);
|
nextSetasListRest = oup.maxElements(nextSetasListRest);
|
||||||
}
|
}
|
||||||
else if (variance == -1) {
|
else if (variance == -1) {
|
||||||
@@ -810,13 +760,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
||||||
//nur für diese wird parallele Berechnung angestossen.
|
|
||||||
nextSetasListRest = oup.minElements(nextSetasListRest);
|
nextSetasListRest = oup.minElements(nextSetasListRest);
|
||||||
}
|
}
|
||||||
else if (variance == 2) {
|
else if (variance == 2) {
|
||||||
a = nextSetasList.remove(0);
|
a = nextSetasList.remove(0);
|
||||||
|
|
||||||
//Fuer alle Elemente wird parallele Berechnung angestossen.
|
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
}
|
}
|
||||||
else if (variance == 0) {
|
else if (variance == 0) {
|
||||||
@@ -842,32 +789,54 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//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<UnifyPair> a : newSet) {
|
||||||
i++;
|
i++;
|
||||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(oneElems);
|
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||||
writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n");
|
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
|
||||||
//Ergebnisvariable für den aktuelle Thread
|
//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<Set<UnifyPair>> res = new HashSet<>();
|
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||||
|
|
||||||
//Menge der Ergebnisse der geforkten Threads
|
|
||||||
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
||||||
|
|
||||||
/* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird
|
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
* a verworfen und zu nächstem Element von nextSetasList gegangen
|
if (!oderConstraint && !sameEqSet.isEmpty()) {
|
||||||
*/
|
Optional<UnifyPair> optAPair = a.stream().filter(x -> (
|
||||||
if (!oderConstraint && !sameEqSet.isEmpty() && !checkNoContradiction(a, sameEqSet, result)) {
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
a = null;
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
noShortendElements++;
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
continue;
|
/*
|
||||||
}
|
(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);
|
||||||
|
if (!checkA(aPair, sameEqSet, elems, result)) {
|
||||||
|
a = null;
|
||||||
|
noShortendElements++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* 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) {
|
if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) {
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
@@ -896,14 +865,35 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("1 RM" + nSaL.toString());
|
writeLog("1 RM" + nSaL.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oderConstraint) {
|
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||||
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||||
nSaL = null;
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
noShortendElements++;
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
continue;
|
(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);
|
||||||
|
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||||
|
nSaL = null;
|
||||||
|
noShortendElements++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
else {
|
else {
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
}
|
}
|
||||||
@@ -995,14 +985,35 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("-1 RM" + nSaL.toString());
|
writeLog("-1 RM" + nSaL.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||||
nSaL = null;
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
noShortendElements++;
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
continue;
|
(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);
|
||||||
|
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||||
|
nSaL = null;
|
||||||
|
noShortendElements++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
else {
|
else {
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
}
|
}
|
||||||
@@ -1145,12 +1156,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
//noOfThread++;
|
//noOfThread++;
|
||||||
} else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten
|
} 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
|
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);
|
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
//Ab hier alle parallele Berechnungen wieder zusammengeführt.
|
|
||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
result = res;
|
result = res;
|
||||||
@@ -1237,7 +1247,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||||
writeLog("RES Fst: result: " + result.toString() + " res: " + res.toString());
|
writeLog("RES Fst: reuslt: " + result.toString() + " res: " + res.toString());
|
||||||
result.addAll(res);
|
result.addAll(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1249,6 +1259,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//}
|
||||||
|
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
|
||||||
|
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
||||||
|
//}
|
||||||
if (parallel) {
|
if (parallel) {
|
||||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
for (Set<Set<UnifyPair>> par_res : add_res) {
|
||||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||||
@@ -1485,29 +1499,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected Boolean checkA (UnifyPair aPair, Set<UnifyPair> sameEqSet, Set<Set<UnifyPair>> elems, Set<Set<UnifyPair>> 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<UnifyPair> a, Set<UnifyPair> sameEqSet, Set<Set<UnifyPair>> result) {
|
|
||||||
|
|
||||||
//optAPair enthaelt ggf. das Paar a = ty' \in a
|
|
||||||
//unterscheidet sich von optOrigPair, da dort a = ty
|
|
||||||
Optional<UnifyPair> 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);
|
writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet);
|
||||||
for (UnifyPair sameEq : sameEqSet) {
|
for (UnifyPair sameEq : sameEqSet) {
|
||||||
if (sameEq.getLhsType() instanceof PlaceholderType) {
|
if (sameEq.getLhsType() instanceof PlaceholderType) {
|
||||||
@@ -1517,14 +1509,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
||||||
unitedSubst.addAll(sameEq.getAllBases());
|
unitedSubst.addAll(sameEq.getAllBases());
|
||||||
localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
||||||
finalresult = false;
|
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false);
|
||||||
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0);
|
|
||||||
finalresult = true;
|
|
||||||
if (isUndefinedPairSetSet(localRes)) {
|
if (isUndefinedPairSetSet(localRes)) {
|
||||||
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
||||||
result.addAll(localRes);
|
result.addAll(localRes);
|
||||||
}
|
}
|
||||||
writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
//writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1535,25 +1525,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
||||||
unitedSubst.addAll(sameEq.getAllBases());
|
unitedSubst.addAll(sameEq.getAllBases());
|
||||||
localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
||||||
finalresult = false;
|
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false);
|
||||||
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0);
|
|
||||||
finalresult = true;
|
|
||||||
if (isUndefinedPairSetSet(localRes)) {
|
if (isUndefinedPairSetSet(localRes)) {
|
||||||
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
||||||
result.addAll(localRes);
|
result.addAll(localRes);
|
||||||
}
|
}
|
||||||
writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
//writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet);
|
//writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) {
|
protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) {
|
||||||
return reducedUndefResSubstGroundedBasePair.stream()
|
return reducedUndefResSubstGroundedBasePair.stream()
|
||||||
.map(pair -> {
|
.map(pair -> {
|
||||||
@@ -2520,7 +2505,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
synchronized ( this ) {
|
synchronized ( this ) {
|
||||||
if (log && finalresult) {
|
if (log) {
|
||||||
try {
|
try {
|
||||||
logFile.write("Thread no.:" + thNo + "\n");
|
logFile.write("Thread no.:" + thNo + "\n");
|
||||||
logFile.write("noOfThread:" + noOfThread + "\n");
|
logFile.write("noOfThread:" + noOfThread + "\n");
|
||||||
|
@@ -40,8 +40,7 @@ public class AllgemeinTest {
|
|||||||
//String className = "FCTest3";
|
//String className = "FCTest3";
|
||||||
//String className = "Var";
|
//String className = "Var";
|
||||||
//String className = "Put";
|
//String className = "Put";
|
||||||
//String className = "Twice";
|
String className = "Twice";
|
||||||
String className = "TestSubTypless";
|
|
||||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
//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/" + className + ".jav";
|
||||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
/*
|
|
||||||
package insertGenerics;
|
package insertGenerics;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
@@ -13,13 +12,11 @@ import java.util.List;
|
|||||||
public class FamilyOfGeneratedGenericsTest extends TestCase {
|
public class FamilyOfGeneratedGenericsTest extends TestCase {
|
||||||
|
|
||||||
public void testIdentityMethod(){
|
public void testIdentityMethod(){
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
Example method:
|
Example method:
|
||||||
A id(B i) return i;
|
A id(B i) return i;
|
||||||
gives constraint: B <. A and A <. Object, which are method constraints
|
gives constraint: B <. A and A <. Object, which are method constraints
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
|
|
||||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||||
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
|
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
|
||||||
@@ -32,20 +29,17 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||||
assertTrue(classConstraints.isEmpty());
|
assertTrue(classConstraints.isEmpty());
|
||||||
|
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
MethodConstraints should be the same as the input constraint
|
MethodConstraints should be the same as the input constraint
|
||||||
*//*
|
*/
|
||||||
|
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions);
|
||||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions);
|
assertTrue(methodConstraints.size() == 2);
|
||||||
// assertTrue(methodConstraints.size() == 2);
|
assertTrue(methodConstraints.get(0).getLeft().equals("B"));
|
||||||
// assertTrue(methodConstraints.get(0).getLeft().equals("B"));
|
assertTrue(methodConstraints.get(0).getRight().equals("A"));
|
||||||
// assertTrue(methodConstraints.get(0).getRight().equals("A"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassField(){
|
public void testClassField(){
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
class Example{
|
class Example{
|
||||||
A f;
|
A f;
|
||||||
B fReturn(){
|
B fReturn(){
|
||||||
@@ -53,8 +47,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gives constraint: A <. B and B <. Object which are class constraints
|
gives constraint: A <. B and B <. Object which are class constraints
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
|
|
||||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||||
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
||||||
@@ -65,22 +58,18 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn");
|
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn");
|
||||||
tphPositions.put("B", posOfB);
|
tphPositions.put("B", posOfB);
|
||||||
|
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
ClassConstraints should not be the same as the input constraint
|
ClassConstraints should not be the same as the input constraint
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||||
System.out.println(classConstraints);
|
System.out.println(classConstraints);
|
||||||
assertTrue(classConstraints.size() == 2);
|
assertTrue(classConstraints.size() == 2);
|
||||||
//assertTrue(classConstraints.get(0).getLeft().equals("A"));
|
//assertTrue(classConstraints.get(0).getLeft().equals("A"));
|
||||||
//assertTrue(classConstraints.get(0).getRight().equals("B"));
|
//assertTrue(classConstraints.get(0).getRight().equals("B"));
|
||||||
// HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = FamilyOfGeneratedGenerics.getMethodConstraintsWithPosition(inputConstraints,classConstraints,tphPositions,)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSecondLineOfClassConstraints() {
|
public void testSecondLineOfClassConstraints() {
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
class Example() {
|
class Example() {
|
||||||
A a;
|
A a;
|
||||||
B b = a;
|
B b = a;
|
||||||
@@ -94,8 +83,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
|
|
||||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||||
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
||||||
@@ -121,18 +109,17 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
|
|
||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||||
System.out.println(classConstraints);
|
System.out.println(classConstraints);
|
||||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
|
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
|
||||||
// System.out.println(methodConstraints);
|
System.out.println(methodConstraints);
|
||||||
assertFalse(classConstraints.isEmpty());
|
assertFalse(classConstraints.isEmpty());
|
||||||
assertTrue(classConstraints.size() == 6);
|
assertTrue(classConstraints.size() == 6);
|
||||||
// assertFalse(methodConstraints.isEmpty());
|
assertFalse(methodConstraints.isEmpty());
|
||||||
// assertTrue(methodConstraints.size() == 2);
|
assertTrue(methodConstraints.size() == 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTPHsAndGenerics() {
|
public void testTPHsAndGenerics() {
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
class TPHsAndGenerics {
|
class TPHsAndGenerics {
|
||||||
Fun1<A,B> id = x -> x;
|
Fun1<A,B> id = x -> x;
|
||||||
C id2 (D x) {
|
C id2 (D x) {
|
||||||
@@ -146,8 +133,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
|
|
||||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||||
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
|
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
|
||||||
@@ -183,13 +169,13 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
|
|
||||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||||
System.out.println(classConstraints);
|
System.out.println(classConstraints);
|
||||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
|
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
|
||||||
// System.out.println(methodConstraints);
|
System.out.println(methodConstraints);
|
||||||
|
|
||||||
assertFalse(classConstraints.isEmpty());
|
assertFalse(classConstraints.isEmpty());
|
||||||
assertTrue(classConstraints.size() == 3);
|
assertTrue(classConstraints.size() == 3);
|
||||||
// assertFalse(methodConstraints.isEmpty());
|
assertFalse(methodConstraints.isEmpty());
|
||||||
// assertTrue(methodConstraints.size()==9);
|
assertTrue(methodConstraints.size()==9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -209,7 +195,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs);
|
HashMap<String, PairTphMethod<PositionFinder.Position, String>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs);
|
||||||
System.out.println(allTphsNew);
|
System.out.println(allTphsNew);
|
||||||
//was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten?
|
//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?
|
//ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt?
|
||||||
@@ -225,4 +211,4 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}*/
|
}
|
30
src/test/java/insertGenerics/MethodsTest.java
Normal file
30
src/test/java/insertGenerics/MethodsTest.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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<ResultSet> results = compiler.typeInference();
|
||||||
|
|
||||||
|
GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results);
|
||||||
|
ClassOrInterface coiHere = coi;
|
||||||
|
ggf.visit(coiHere);
|
||||||
|
//assert results.size()>0;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,102 +0,0 @@
|
|||||||
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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> 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<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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);
|
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
|
||||||
System.out.println(ASTPrinter.print(sf));
|
|
||||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
|
||||||
assert results.size()>0;
|
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
|
||||||
for(ResultSet resultSet : results){
|
|
||||||
Set<TypeInsert> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,72 +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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> 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<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
|
||||||
assert results.size()>0;
|
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
|
||||||
for(ResultSet resultSet : results){
|
|
||||||
Set<TypeInsert> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -52,10 +52,13 @@ public class TestExample42 {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericTest() {
|
public void genericTest() {
|
||||||
// List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
||||||
// System.out.println("ClassConstraints: " + classConstraints);
|
System.out.println("ClassConstraints: " + classConstraints);
|
||||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
|
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
|
||||||
// System.out.println("MethodConstraints: " + methodConstraints);
|
System.out.println("MethodConstraints: " + methodConstraints);
|
||||||
|
for(MethodConstraint mC: methodConstraints) {
|
||||||
|
System.out.println(mC);
|
||||||
|
}
|
||||||
|
|
||||||
List<TPHConstraint> testCons;
|
List<TPHConstraint> testCons;
|
||||||
}
|
}
|
||||||
|
@@ -51,10 +51,10 @@ public class TestExample42_allInOneMethod {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericTest() {
|
public void genericTest() {
|
||||||
// List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
||||||
// System.out.println("ClassConstraints: " + classConstraints);
|
System.out.println("ClassConstraints: " + classConstraints);
|
||||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),);
|
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
|
||||||
// System.out.println("MethodConstraints: " + methodConstraints);
|
System.out.println("MethodConstraints: " + methodConstraints);
|
||||||
|
|
||||||
List<TPHConstraint> testCons;
|
List<TPHConstraint> testCons;
|
||||||
}
|
}
|
||||||
|
@@ -1,89 +0,0 @@
|
|||||||
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 TestGGFinder {
|
|
||||||
|
|
||||||
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, 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
return new TestResultSet();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,90 +0,0 @@
|
|||||||
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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
|
||||||
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
return new TestResultSet();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,115 +0,0 @@
|
|||||||
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 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/";
|
|
||||||
private static ClassLoader loader;
|
|
||||||
private static Class<?> classToTest;
|
|
||||||
private static Object instanceOfClass;
|
|
||||||
private static String className;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
|
||||||
className = "TestMutualRecursion";
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav"));
|
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TestResultSet{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> 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();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,72 +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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> 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<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
|
||||||
assert results.size()>0;
|
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
|
||||||
for(ResultSet resultSet : results){
|
|
||||||
Set<TypeInsert> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,119 +0,0 @@
|
|||||||
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 TestTPHsAndGenerics {
|
|
||||||
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TestResultSet{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
|
||||||
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
*/
|
|
||||||
return new TestResultSet();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,72 +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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> 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<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
|
||||||
assert results.size()>0;
|
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
|
||||||
for(ResultSet resultSet : results){
|
|
||||||
Set<TypeInsert> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,97 +0,0 @@
|
|||||||
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;
|
|
||||||
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.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TestTwoArgs {
|
|
||||||
|
|
||||||
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, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> 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<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
return new TestResultSet();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,95 +0,0 @@
|
|||||||
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 TestTwoArgs2 {
|
|
||||||
|
|
||||||
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, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
return new TestResultSet();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,83 +0,0 @@
|
|||||||
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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
return new TestResultSet();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,82 +0,0 @@
|
|||||||
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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
|
||||||
List<MethodConstraint> 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<>();
|
|
||||||
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
|
|
||||||
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
|
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
|
||||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
|
||||||
Set<ClassConstraint> 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();
|
|
||||||
return new TestResultSet();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,72 +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 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<ResultSet> results = compiler.typeInference();
|
|
||||||
List<GenericGenratorResultForSourceFile> 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<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
|
||||||
assert results.size()>0;
|
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
|
||||||
for(ResultSet resultSet : results){
|
|
||||||
Set<TypeInsert> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -20,13 +20,13 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TestSecondLineOfClassConstraints {
|
public class TryTest {
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav"));
|
execute(new File(rootDirectory+"TestGGFinder.jav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestResultSet{
|
private static class TestResultSet{
|
||||||
@@ -34,9 +34,25 @@ public class TestSecondLineOfClassConstraints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
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);
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
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<ResultSet> results = compiler.typeInference();
|
List<ResultSet> results = compiler.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
@@ -44,7 +60,9 @@ public class TestSecondLineOfClassConstraints {
|
|||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
|
// System.out.println("---------------------------3");
|
||||||
System.out.println(ASTPrinter.print(sf));
|
System.out.println(ASTPrinter.print(sf));
|
||||||
|
// System.out.println("---------------------------4");
|
||||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||||
assert results.size()>0;
|
assert results.size()>0;
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
Set<String> insertedTypes = new HashSet<>();
|
||||||
@@ -57,7 +75,9 @@ public class TestSecondLineOfClassConstraints {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(String s : insertedTypes){
|
for(String s : insertedTypes){
|
||||||
|
System.out.println("---------------------------51");
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
System.out.println("---------------------------52");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new TestResultSet();
|
return new TestResultSet();
|
@@ -1,13 +0,0 @@
|
|||||||
class TestAny {
|
|
||||||
a;
|
|
||||||
b = a;
|
|
||||||
anyMethod() {
|
|
||||||
var f;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
otherMethod(e) {
|
|
||||||
b = e;
|
|
||||||
e = a;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
class Example{
|
|
||||||
f;
|
|
||||||
fReturn(){
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +1,4 @@
|
|||||||
public class TestGGFinder {
|
class Generics{
|
||||||
a;
|
a;
|
||||||
|
|
||||||
id(b) {
|
id(b) {
|
||||||
|
@@ -1,7 +0,0 @@
|
|||||||
public class TestLocalVarLambda {
|
|
||||||
|
|
||||||
m(x) {
|
|
||||||
var id = z -> z;
|
|
||||||
return id.apply(x);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,22 +0,0 @@
|
|||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
class VarReturn {
|
|
||||||
anyMethod() {
|
|
||||||
var f;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
class Example {
|
|
||||||
a;
|
|
||||||
b = a;
|
|
||||||
anyMethod() {
|
|
||||||
var f;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
otherMethod(e) {
|
|
||||||
e = a;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,15 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,22 +0,0 @@
|
|||||||
public 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));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
public class TestTwoArgs2 {
|
|
||||||
a;
|
|
||||||
|
|
||||||
id(b) {
|
|
||||||
var c = b;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
m(x,y) {
|
|
||||||
x = id(y);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
main(x,y) {
|
|
||||||
return m(id(x),m(x,y));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
public class TestTwoCalls {
|
|
||||||
|
|
||||||
id(b) {
|
|
||||||
var c = b;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
main(x,y) {
|
|
||||||
id(x);
|
|
||||||
return id(y);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
public class TestVector {
|
|
||||||
|
|
||||||
m(v, w) {
|
|
||||||
w.addElement(id(v.elementAt(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
id(x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +0,0 @@
|
|||||||
class VoidMeth {
|
|
||||||
anyMethod() {
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user