forked from JavaTX/JavaCompilerCore
Compare commits
33 Commits
classloade
...
addPackage
Author | SHA1 | Date | |
---|---|---|---|
|
e634f2ca67 | ||
|
c964fa7ce2 | ||
|
941a3bed66 | ||
|
653901ef32 | ||
|
2e03b5b10c | ||
|
670e3ed99f | ||
|
c8ece0a010 | ||
|
c27e1fa4e1 | ||
|
b3b25b7869 | ||
|
9240b0d163 | ||
|
a0a813f87c | ||
|
60b182b9b1 | ||
|
8e2d4e1c70 | ||
|
907ab2fcec | ||
|
eb27003515 | ||
|
71c801c19c | ||
|
ba750187ba | ||
|
ccf5df1f1e | ||
|
3de735ebe3 | ||
|
fd3d4e97a1 | ||
|
6deeb4105f | ||
|
9d4980d9a1 | ||
|
b83e2c10e3 | ||
|
4f10e789d4 | ||
|
8b9f0d6376 | ||
|
3f919be1bf | ||
|
97bdfe1d3a | ||
|
7c7dbf3769 | ||
|
577faa88af | ||
|
8bdb7e7b13 | ||
|
eca187da79 | ||
|
850af6a6ae | ||
|
ed1bb44089 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -26,3 +26,6 @@ manually/
|
|||||||
|
|
||||||
logFiles/**
|
logFiles/**
|
||||||
!logFiles/.gitkeep
|
!logFiles/.gitkeep
|
||||||
|
|
||||||
|
src/main/java/de/dhbwstuttgart/parser/antlr/
|
||||||
|
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
|
||||||
|
4
pom.xml
4
pom.xml
@@ -75,7 +75,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
||||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
<outputDirectory>${project.basedir}/src/main/java/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
||||||
<arguments>
|
<arguments>
|
||||||
<argument>-package</argument>
|
<argument>-package</argument>
|
||||||
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||||
@@ -89,7 +89,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sourceDirectory>src/main/antlr4/sat</sourceDirectory>
|
<sourceDirectory>src/main/antlr4/sat</sourceDirectory>
|
||||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
<outputDirectory>${project.basedir}/src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
||||||
<arguments>
|
<arguments>
|
||||||
<argument>-package</argument>
|
<argument>-package</argument>
|
||||||
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
||||||
|
@@ -8,7 +8,6 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.FieldVisitor;
|
import org.objectweb.asm.FieldVisitor;
|
||||||
@@ -121,10 +120,10 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
private GenericsGeneratorResultForClass generatedGenerics;
|
private GenericsGeneratorResultForClass generatedGenerics;
|
||||||
|
|
||||||
private Resolver resolver;
|
private Resolver resolver;
|
||||||
private final DirectoryClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
public BytecodeGen(HashMap<JavaClassName, byte[]> classFiles, Collection<ResultSet> listOfResultSets, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles, SourceFile sf,
|
public BytecodeGen(HashMap<JavaClassName, byte[]> classFiles, Collection<ResultSet> listOfResultSets, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles, SourceFile sf,
|
||||||
File path, DirectoryClassLoader classLoader) {
|
File path, ClassLoader classLoader) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
|
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
|
||||||
|
@@ -79,13 +79,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
private int constructorPos = 0;
|
private int constructorPos = 0;
|
||||||
|
|
||||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||||
private final DirectoryClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
// generate bytecode for constructor
|
// generate bytecode for constructor
|
||||||
public BytecodeGenMethod(JavaClassName className, String superClass, ResultSet resultSet, Method m, MethodVisitor mv,
|
public BytecodeGenMethod(JavaClassName className, String superClass, ResultSet resultSet, Method m, MethodVisitor mv,
|
||||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles,
|
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles,
|
||||||
SourceFile sf, File path, Block block, int constructorPos, DirectoryClassLoader classLoader) {
|
SourceFile sf, File path, Block block, int constructorPos, ClassLoader classLoader) {
|
||||||
|
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
@@ -111,7 +111,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
public BytecodeGenMethod(JavaClassName className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
public BytecodeGenMethod(JavaClassName className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles, SourceFile sf,File path, DirectoryClassLoader classLoader) {
|
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles, SourceFile sf,File path, ClassLoader classLoader) {
|
||||||
|
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
@@ -135,7 +135,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
public BytecodeGenMethod(JavaClassName className, ClassWriter cw, LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(JavaClassName className, ClassWriter cw, LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles, File path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
int indexOfFirstParamLam, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles, File path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, DirectoryClassLoader classLoader) {
|
HashMap<String, String> genericsAndBounds, ClassLoader classLoader) {
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.cw = cw;
|
this.cw = cw;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
@@ -763,9 +763,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
||||||
|
|
||||||
DirectoryClassLoader cLoader = this.classLoader;
|
ClassLoader cLoader = this.classLoader;
|
||||||
// This will be used if the class is not standard class (not in API)
|
// This will be used if the class is not standard class (not in API)
|
||||||
DirectoryClassLoader cLoader2;
|
ClassLoader cLoader2;
|
||||||
|
|
||||||
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
||||||
|
@@ -77,7 +77,7 @@ public class JavaTXCompiler {
|
|||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
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 DirectoryClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile), null);
|
this(Arrays.asList(sourceFile), null);
|
||||||
@@ -135,50 +135,68 @@ public class JavaTXCompiler {
|
|||||||
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
||||||
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
||||||
//Alle anderen Objekte werden nur kopiert.
|
//Alle anderen Objekte werden nur kopiert.
|
||||||
sf.KlassenVektor.forEach(cl -> {
|
SourceFile sf_new = sf;
|
||||||
ClassOrInterface superclass = null;
|
sf.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, importedClasses, objectClass));
|
||||||
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
allClasses.addAll(sf.getClasses());
|
||||||
superclass = objectClass;
|
}
|
||||||
|
allClasses.addAll(importedClasses);
|
||||||
|
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addMethods(SourceFile sf, ClassOrInterface cl, List<ClassOrInterface> importedClasses, ClassOrInterface objectClass) {
|
||||||
|
if (!cl.areMethodsAdded()) {
|
||||||
|
ClassOrInterface superclass = null;
|
||||||
|
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||||
|
superclass = objectClass;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Optional<ClassOrInterface> optSuperclass =
|
||||||
|
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||||
|
cl.getSuperClass().getName())).findFirst();
|
||||||
|
if (optSuperclass.isPresent()) {
|
||||||
|
superclass = optSuperclass.get();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Optional<ClassOrInterface> optSuperclass =
|
optSuperclass =
|
||||||
importedClasses.stream().filter(x -> x.getClassName().equals(
|
sf.KlassenVektor.stream().filter(x -> x.getClassName().equals(
|
||||||
cl.getSuperClass().getName())).findFirst();
|
cl.getSuperClass().getName())).findFirst();
|
||||||
if (optSuperclass.isPresent()) {
|
if (optSuperclass.isPresent()) {
|
||||||
superclass = optSuperclass.get();
|
superclass = optSuperclass.get();
|
||||||
|
addMethods(sf, superclass, importedClasses, objectClass);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//throw new ClassNotFoundException("");
|
//throw new ClassNotFoundException("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
}
|
||||||
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||||
|
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||||
|
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
||||||
while (paraIt.hasNext()) {
|
while (paraIt.hasNext()) {
|
||||||
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
||||||
}
|
}
|
||||||
Iterator<Method> methodIt = superclass.getMethods().iterator();
|
Iterator<Method> methodIt = superclass.getMethods().iterator();
|
||||||
while(methodIt.hasNext()) {
|
//TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert werden
|
||||||
Method m = methodIt.next();
|
while(methodIt.hasNext()) {
|
||||||
ParameterList newParaList = new ParameterList(
|
Method m = methodIt.next();
|
||||||
|
ParameterList newParaList = new ParameterList(
|
||||||
m.getParameterList()
|
m.getParameterList()
|
||||||
.getFormalparalist()
|
.getFormalparalist()
|
||||||
.stream()
|
.stream()
|
||||||
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
||||||
.collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
.collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
||||||
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||||
//new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
//new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||||
(GenericDeclarationList)m.getGenerics(),
|
(GenericDeclarationList)m.getGenerics(),
|
||||||
m.getOffset()));
|
m.getOffset(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
}
|
}
|
||||||
allClasses.addAll(importedClasses);
|
cl.setMethodsAdded();
|
||||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||||
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
||||||
@@ -517,13 +535,13 @@ public class JavaTXCompiler {
|
|||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||||
// logFile, log);
|
// logFile, log);
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()/*.stream().map(x -> {
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
for (Constraint<UnifyPair> y : x) {
|
for (Constraint<UnifyPair> y : x) {
|
||||||
ret.add(new HashSet<>(y));
|
ret.add(new HashSet<>(y));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
||||||
usedTasks);
|
usedTasks);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -545,11 +563,11 @@ public class JavaTXCompiler {
|
|||||||
final ConstraintSet<Pair> cons = getConstraints();
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
// new FileWriter(new
|
// new FileWriter(new
|
||||||
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
//new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
||||||
+ sourceFiles.keySet().iterator().next().getName()));
|
// + sourceFiles.keySet().iterator().next().getName()));
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
@@ -705,13 +723,13 @@ public class JavaTXCompiler {
|
|||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||||
// logFile, log);
|
// logFile, log);
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()//.stream().map(x -> {
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
/*Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
for (Constraint<UnifyPair> y : x) {
|
for (Constraint<UnifyPair> y : x) {
|
||||||
ret.add(new HashSet<>(y));
|
ret.add(new HashSet<>(y));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||||
if (resultmodel) {
|
if (resultmodel) {
|
||||||
/* UnifyResultModel Anfang */
|
/* UnifyResultModel Anfang */
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
@@ -958,7 +976,7 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
||||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
return typePlaceholder; //TypePlaceholder der vererbert wird kann bei der Vererbung nicht instanziert werden.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -60,7 +60,7 @@ public class CompilationEnvironment {
|
|||||||
this.packageCrawler = new PackageCrawler(librarys);
|
this.packageCrawler = new PackageCrawler(librarys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaClassRegistry getRegistry(File forSourceFile, DirectoryClassLoader classLoader) throws ClassNotFoundException, IOException {
|
public JavaClassRegistry getRegistry(File forSourceFile, ClassLoader classLoader) throws ClassNotFoundException, IOException {
|
||||||
Map<String, Integer> allNames;
|
Map<String, Integer> allNames;
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
||||||
allNames = GatherNames.getNames(tree, packageCrawler, classLoader);
|
allNames = GatherNames.getNames(tree, packageCrawler, classLoader);
|
||||||
@@ -70,7 +70,7 @@ public class CompilationEnvironment {
|
|||||||
return new JavaClassRegistry(allNames);
|
return new JavaClassRegistry(allNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Class> loadDefaultPackageClasses(File forSourceFile, DirectoryClassLoader classLoader) throws IOException, ClassNotFoundException {
|
public static List<Class> loadDefaultPackageClasses(File forSourceFile, ClassLoader classLoader) throws IOException, ClassNotFoundException {
|
||||||
List<Class> ret = new ArrayList<>();
|
List<Class> ret = new ArrayList<>();
|
||||||
String packageName = getPackageName(JavaTXParser.parse(forSourceFile));
|
String packageName = getPackageName(JavaTXParser.parse(forSourceFile));
|
||||||
//Set classLoader to include default package for this specific source file
|
//Set classLoader to include default package for this specific source file
|
||||||
|
@@ -7,23 +7,13 @@ import java.net.URLClassLoader;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DirectoryClassLoader {
|
public class DirectoryClassLoader extends URLClassLoader {
|
||||||
private final URLClassLoader classLoader;
|
|
||||||
|
|
||||||
public DirectoryClassLoader(File directory, java.lang.ClassLoader parent) {
|
public DirectoryClassLoader(File directory, java.lang.ClassLoader parent) {
|
||||||
classLoader = new URLClassLoader(generateURLArray(dirToURL(directory)), parent);
|
super(generateURLArray(dirToURL(directory)), parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectoryClassLoader(List<File> directory, java.lang.ClassLoader parent) {
|
public DirectoryClassLoader(List<File> directory, java.lang.ClassLoader parent) {
|
||||||
classLoader = new URLClassLoader(directory.stream().map(DirectoryClassLoader::dirToURL).collect(Collectors.toList()).toArray(new URL[0]), parent);
|
super(directory.stream().map(DirectoryClassLoader::dirToURL).collect(Collectors.toList()).toArray(new URL[0]), parent);
|
||||||
}
|
|
||||||
|
|
||||||
public DirectoryClassLoader(File directory, DirectoryClassLoader parent) {
|
|
||||||
classLoader = new URLClassLoader(generateURLArray(dirToURL(directory)), parent.classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirectoryClassLoader(List<File> directory, DirectoryClassLoader parent) {
|
|
||||||
classLoader = new URLClassLoader(directory.stream().map(DirectoryClassLoader::dirToURL).collect(Collectors.toList()).toArray(new URL[0]), parent.classLoader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static URL[] generateURLArray(URL url) {
|
private static URL[] generateURLArray(URL url) {
|
||||||
@@ -38,8 +28,4 @@ public class DirectoryClassLoader {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class loadClass(String className) throws ClassNotFoundException {
|
|
||||||
return classLoader.loadClass(className);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
@@ -23,11 +22,11 @@ public class FCGenerator {
|
|||||||
*
|
*
|
||||||
* @param availableClasses - Alle geparsten Klassen
|
* @param availableClasses - Alle geparsten Klassen
|
||||||
*/
|
*/
|
||||||
public static Set<UnifyPair> toUnifyFC(Collection<ClassOrInterface> availableClasses, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
public static Set<UnifyPair> toUnifyFC(Collection<ClassOrInterface> availableClasses, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
return toFC(availableClasses, classLoader).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
|
return toFC(availableClasses, classLoader).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
HashSet<Pair> pairs = new HashSet<>();
|
HashSet<Pair> pairs = new HashSet<>();
|
||||||
//PL 2018-09-18: gtvs vor die for-Schleife gezogen, damit immer die gleichen Typeplaceholder eingesetzt werden.
|
//PL 2018-09-18: gtvs vor die for-Schleife gezogen, damit immer die gleichen Typeplaceholder eingesetzt werden.
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
||||||
@@ -49,7 +48,7 @@ public class FCGenerator {
|
|||||||
* @param forType
|
* @param forType
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
return getSuperTypes(forType, availableClasses, new HashMap<>(), classLoader);
|
return getSuperTypes(forType, availableClasses, new HashMap<>(), classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ public class FCGenerator {
|
|||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses,
|
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses,
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
//Die GTVs, die in forType hinzukommen:
|
//Die GTVs, die in forType hinzukommen:
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> newGTVs = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> newGTVs = new HashMap<>();
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.environment.PackageCrawler;
|
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import java.lang.ClassNotFoundException;
|
import java.lang.ClassNotFoundException;
|
||||||
@@ -76,7 +75,7 @@ public class SyntaxTreeGenerator{
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler, DirectoryClassLoader classLoader) throws ClassNotFoundException{
|
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler, ClassLoader classLoader) throws ClassNotFoundException{
|
||||||
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
|
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
|
||||||
List<ClassOrInterface> classes = new ArrayList<>();
|
List<ClassOrInterface> classes = new ArrayList<>();
|
||||||
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler, classLoader);
|
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler, classLoader);
|
||||||
|
@@ -4,7 +4,6 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8BaseListener;
|
import de.dhbwstuttgart.parser.antlr.Java8BaseListener;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||||
@@ -16,7 +15,7 @@ import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
|||||||
|
|
||||||
public class GatherNames {
|
public class GatherNames {
|
||||||
|
|
||||||
public static Map<String, Integer> getNames(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, DirectoryClassLoader classLoader) throws ClassNotFoundException{
|
public static Map<String, Integer> getNames(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException{
|
||||||
Map<String, Integer> ret = new HashMap<>();
|
Map<String, Integer> ret = new HashMap<>();
|
||||||
String pkgName = getPackageName(ctx);
|
String pkgName = getPackageName(ctx);
|
||||||
String nameString = "";
|
String nameString = "";
|
||||||
@@ -69,7 +68,7 @@ public class GatherNames {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Integer> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
public static Map<String, Integer> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
Map<String, Integer> ret = new HashMap<>();
|
Map<String, Integer> ret = new HashMap<>();
|
||||||
//ret.putAll(packages.getClassNames("java.lang"));
|
//ret.putAll(packages.getClassNames("java.lang"));
|
||||||
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.sat.asp.writer;
|
package de.dhbwstuttgart.sat.asp.writer;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||||
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
||||||
@@ -17,7 +16,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class ASPFactory implements TypeVisitor<String>{
|
public class ASPFactory implements TypeVisitor<String>{
|
||||||
|
|
||||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses, DirectoryClassLoader classLoader) throws ClassNotFoundException{
|
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses, ClassLoader classLoader) throws ClassNotFoundException{
|
||||||
ASPFactory factory = new ASPFactory();
|
ASPFactory factory = new ASPFactory();
|
||||||
factory.convertFC(fcClasses, classLoader);
|
factory.convertFC(fcClasses, classLoader);
|
||||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||||
@@ -33,7 +32,7 @@ public class ASPFactory implements TypeVisitor<String>{
|
|||||||
ASPWriter writer = new ASPWriter();
|
ASPWriter writer = new ASPWriter();
|
||||||
boolean isFCType = false;
|
boolean isFCType = false;
|
||||||
|
|
||||||
private void convertFC(Collection<ClassOrInterface> classes, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
private void convertFC(Collection<ClassOrInterface> classes, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
Set<Pair> fc = FCGenerator.toFC(classes, classLoader);
|
Set<Pair> fc = FCGenerator.toFC(classes, classLoader);
|
||||||
isFCType = true;
|
isFCType = true;
|
||||||
for(Pair fcp : fc){
|
for(Pair fcp : fc){
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.sat.asp.writer;
|
package de.dhbwstuttgart.sat.asp.writer;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||||
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
||||||
@@ -56,7 +55,7 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses, DirectoryClassLoader classLoader) throws ClassNotFoundException{
|
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses, ClassLoader classLoader) throws ClassNotFoundException{
|
||||||
ASPGencayFactory factory = new ASPGencayFactory();
|
ASPGencayFactory factory = new ASPGencayFactory();
|
||||||
factory.convertFC(fcClasses, classLoader);
|
factory.convertFC(fcClasses, classLoader);
|
||||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||||
@@ -70,7 +69,7 @@ public class ASPGencayFactory implements TypeVisitor<String> {
|
|||||||
return factory.writer.getASPFile();
|
return factory.writer.getASPFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void convertFC(Collection<ClassOrInterface> classes, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
private void convertFC(Collection<ClassOrInterface> classes, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
Set<Pair> fc = FCGenerator.toFC(classes, classLoader);
|
Set<Pair> fc = FCGenerator.toFC(classes, classLoader);
|
||||||
isFCType = true;
|
isFCType = true;
|
||||||
for(Pair fcp : fc){
|
for(Pair fcp : fc){
|
||||||
|
@@ -23,6 +23,7 @@ import java.util.Optional;
|
|||||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
*/
|
*/
|
||||||
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||||
|
private Boolean methodAdded = false; //wird benoetigt bei in JavaTXCompiler.getConstraints()
|
||||||
protected int modifiers;
|
protected int modifiers;
|
||||||
protected JavaClassName name;
|
protected JavaClassName name;
|
||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
@@ -68,6 +69,16 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
this.constructors = new ArrayList<>(cl.constructors);
|
this.constructors = new ArrayList<>(cl.constructors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets if it is added
|
||||||
|
public Boolean areMethodsAdded() {
|
||||||
|
return methodAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sets that it is added
|
||||||
|
public void setMethodsAdded() {
|
||||||
|
methodAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Gets class name
|
// Gets class name
|
||||||
public JavaClassName getClassName(){
|
public JavaClassName getClassName(){
|
||||||
return this.name;
|
return this.name;
|
||||||
|
@@ -31,6 +31,7 @@ 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 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) {
|
||||||
@@ -41,6 +42,19 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
this.parameterlist = parameterList;
|
this.parameterlist = parameterList;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.generics = gtvDeclarations;
|
this.generics = gtvDeclarations;
|
||||||
|
this.isInherited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||||
|
GenericDeclarationList gtvDeclarations, Token offset, Boolean isInherited) {
|
||||||
|
super(offset);
|
||||||
|
this.name = name;
|
||||||
|
this.modifier = modifier;
|
||||||
|
this.returnType = returnType;
|
||||||
|
this.parameterlist = parameterList;
|
||||||
|
this.block = block;
|
||||||
|
this.generics = gtvDeclarations;
|
||||||
|
this.isInherited = isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterList getParameterList() {
|
public ParameterList getParameterList() {
|
||||||
|
@@ -3,8 +3,11 @@ package de.dhbwstuttgart.syntaxtree.factory;
|
|||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@@ -35,8 +38,15 @@ public class ASTFactory {
|
|||||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||||
konstruktoren.add(createConstructor(constructor, jreClass));
|
konstruktoren.add(createConstructor(constructor, jreClass));
|
||||||
}
|
}
|
||||||
for(java.lang.reflect.Method method : jreClass.getMethods()){
|
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||||
methoden.add(createMethod(method, jreClass));
|
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||||
|
Set<java.lang.reflect.Method> allInheritedMethods = new HashSet<>(allMethods);
|
||||||
|
allInheritedMethods.removeAll(allDeclaredMethods);
|
||||||
|
for(java.lang.reflect.Method method : allDeclaredMethods){
|
||||||
|
methoden.add(createMethod(method, jreClass, false));
|
||||||
|
}
|
||||||
|
for(java.lang.reflect.Method method : allInheritedMethods){
|
||||||
|
methoden.add(createMethod(method, jreClass, true));
|
||||||
}
|
}
|
||||||
List<Field> felder = new ArrayList<>();
|
List<Field> felder = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
||||||
@@ -102,7 +112,7 @@ public class ASTFactory {
|
|||||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){
|
||||||
String name = jreMethod.getName();
|
String name = jreMethod.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
Type jreRetType;
|
Type jreRetType;
|
||||||
@@ -126,7 +136,7 @@ public class ASTFactory {
|
|||||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
||||||
Token offset = new NullToken();
|
Token offset = new NullToken();
|
||||||
|
|
||||||
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset);
|
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
||||||
|
@@ -7,7 +7,6 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@@ -32,7 +31,7 @@ public class UnifyTypeFactory {
|
|||||||
|
|
||||||
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
||||||
|
|
||||||
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile, DirectoryClassLoader classLoader) throws ClassNotFoundException {
|
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
/*
|
/*
|
||||||
Die transitive Hülle muss funktionieren.
|
Die transitive Hülle muss funktionieren.
|
||||||
Man darf schreiben List<A> extends AL<A>
|
Man darf schreiben List<A> extends AL<A>
|
||||||
@@ -154,8 +153,12 @@ public class UnifyTypeFactory {
|
|||||||
return constraints.map(UnifyTypeFactory::convert);
|
return constraints.map(UnifyTypeFactory::convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NEVER USED
|
||||||
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
|
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
|
||||||
return constraint.stream().map(UnifyTypeFactory::convert).collect(Collectors.toCollection(Constraint::new));
|
Constraint<UnifyPair> unifyPairConstraint = constraint.stream()
|
||||||
|
.map(UnifyTypeFactory::convert)
|
||||||
|
.collect(Collectors.toCollection( () -> new Constraint<UnifyPair> (constraint.isInherited(), convert(constraint.getExtendConstraint()))));
|
||||||
|
return unifyPairConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair convert(Pair p) {
|
public static UnifyPair convert(Pair p) {
|
||||||
|
@@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.type.*;
|
|||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class OutputGenerator implements ASTVisitor{
|
public class OutputGenerator implements ASTVisitor{
|
||||||
private static final String TAB = " ";
|
private static final String TAB = " ";
|
||||||
@@ -123,6 +124,11 @@ public class OutputGenerator implements ASTVisitor{
|
|||||||
f.accept(this);
|
f.accept(this);
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
}
|
}
|
||||||
|
Optional<Constructor> fI;
|
||||||
|
if ((fI = classOrInterface.getfieldInitializations()).isPresent()) {
|
||||||
|
out.append("Initializations:");
|
||||||
|
fI.get().accept(this);
|
||||||
|
}
|
||||||
for(Method m : classOrInterface.getMethods()){
|
for(Method m : classOrInterface.getMethods()){
|
||||||
out.append(tabs);
|
out.append(tabs);
|
||||||
m.accept(this);
|
m.accept(this);
|
||||||
|
@@ -17,13 +17,15 @@ public class MethodAssumption extends Assumption{
|
|||||||
private ClassOrInterface receiver;
|
private ClassOrInterface receiver;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||||
|
private final Boolean isInherited;
|
||||||
|
|
||||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited){
|
||||||
super(scope);
|
super(scope);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.retType = retType;
|
this.retType = retType;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
|
this.isInherited = isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -70,4 +72,8 @@ public class MethodAssumption extends Assumption{
|
|||||||
|
|
||||||
return receiverType;
|
return receiverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isInherited() {
|
||||||
|
return isInherited;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,4 +7,47 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Constraint<A> extends HashSet<A> {
|
public class Constraint<A> extends HashSet<A> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
|
||||||
|
private Constraint<A> extendConstraint = null;
|
||||||
|
|
||||||
|
public Constraint() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint(Boolean isInherited) {
|
||||||
|
this.isInherited = isInherited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint(Boolean isInherited, Constraint<A> extendConstraint) {
|
||||||
|
this.isInherited = isInherited;
|
||||||
|
this.extendConstraint = extendConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsInherited(Boolean isInherited) {
|
||||||
|
this.isInherited = isInherited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isInherited() {
|
||||||
|
return isInherited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint<A> getExtendConstraint() {
|
||||||
|
return extendConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtendConstraint(Constraint<A> c) {
|
||||||
|
extendConstraint = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " isInherited = " + isInherited
|
||||||
|
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||||
|
+ "\n" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toStringBase() {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -45,16 +45,49 @@ public class ConstraintSet<A> {
|
|||||||
return new GuavaSetOperations().cartesianProduct(allConstraints);
|
return new GuavaSetOperations().cartesianProduct(allConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <B> ConstraintSet<B> map(Function<? super A,? extends B> o) {
|
public <B> ConstraintSet<B> map(Function<? super A, ? extends B> o) {
|
||||||
|
Hashtable<Constraint<A>,Constraint<B>> CSA2CSB = new Hashtable<>();
|
||||||
ConstraintSet<B> ret = new ConstraintSet<>();
|
ConstraintSet<B> ret = new ConstraintSet<>();
|
||||||
ret.undConstraints = undConstraints.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new));
|
ret.undConstraints = undConstraints.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new));
|
||||||
List<Set<Constraint<B>>> newOder = new ArrayList<>();
|
List<Set<Constraint<B>>> newOder = new ArrayList<>();
|
||||||
|
/*
|
||||||
|
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||||
|
oderConstraint.forEach(as -> {
|
||||||
|
Constraint<B> newConst = as.stream()
|
||||||
|
.map(o)
|
||||||
|
.collect(Collectors.toCollection(
|
||||||
|
() -> new Constraint<B> (as.isInherited())));
|
||||||
|
CSA2CSB.put(as, newConst);} );
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||||
newOder.add(
|
newOder.add(
|
||||||
oderConstraint.parallelStream().map((Constraint<A> as) ->
|
oderConstraint.parallelStream().map((Constraint<A> as) -> {
|
||||||
as.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new))).collect(Collectors.toSet())
|
|
||||||
|
Constraint<B> newConst = as.stream()
|
||||||
|
.map(o)
|
||||||
|
.collect(Collectors.toCollection((as.getExtendConstraint() != null)
|
||||||
|
? () -> new Constraint<B> (as.isInherited(),
|
||||||
|
as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new)))
|
||||||
|
: () -> new Constraint<B> (as.isInherited())
|
||||||
|
));
|
||||||
|
|
||||||
|
//CSA2CSB.put(as, newConst);
|
||||||
|
|
||||||
|
return newConst;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Constraint<B> bs = CSA2CSB.get(as);
|
||||||
|
if (as.getExtendConstraint() != null) {
|
||||||
|
bs.setExtendConstraint(CSA2CSB.get(as.getExtendConstraint()));
|
||||||
|
}
|
||||||
|
return bs;
|
||||||
|
*/
|
||||||
|
}).collect(Collectors.toSet())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.oderConstraints = newOder;
|
ret.oderConstraints = newOder;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,10 @@ import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
|||||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.*;
|
import de.dhbwstuttgart.typeinference.constraints.*;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -168,7 +170,19 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
Set<Constraint<Pair>> methodConstraints = new HashSet<>();
|
Set<Constraint<Pair>> methodConstraints = new HashSet<>();
|
||||||
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
||||||
GenericsResolver resolver = getResolverInstance();
|
GenericsResolver resolver = getResolverInstance();
|
||||||
methodConstraints.add(generateConstraint(methodCall, m, info, resolver));
|
Constraint<Pair> oneMethodConstraint = generateConstraint(methodCall, m, info, resolver);
|
||||||
|
methodConstraints.add(oneMethodConstraint);
|
||||||
|
|
||||||
|
Constraint<Pair> extendsOneMethodConstraint = oneMethodConstraint.stream()
|
||||||
|
.map(x -> (x.TA1 instanceof TypePlaceholder &&
|
||||||
|
x.GetOperator() == PairOperator.EQUALSDOT &&
|
||||||
|
!(x.TA2 instanceof TypePlaceholder))
|
||||||
|
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||||
|
: x)
|
||||||
|
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||||
|
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||||
|
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||||
|
methodConstraints.add(extendsOneMethodConstraint);
|
||||||
}
|
}
|
||||||
if(methodConstraints.size()<1){
|
if(methodConstraints.size()<1){
|
||||||
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());
|
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());
|
||||||
@@ -560,7 +574,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
|
|
||||||
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
||||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||||
Constraint<Pair> methodConstraint = new Constraint<>();
|
Constraint<Pair> methodConstraint = new Constraint<>(assumption.isInherited());
|
||||||
ClassOrInterface receiverCl = assumption.getReceiver();
|
ClassOrInterface receiverCl = assumption.getReceiver();
|
||||||
/*
|
/*
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
@@ -626,7 +640,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}));
|
}, false));
|
||||||
}
|
}
|
||||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||||
for(Method m : cl.getMethods()){
|
for(Method m : cl.getMethods()){
|
||||||
@@ -635,7 +649,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
|
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
|
||||||
|
|
||||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
||||||
createTypeScope(cl, m)));
|
createTypeScope(cl, m), m.isInherited));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -670,7 +684,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
for(Method m : cl.getConstructors()){
|
for(Method m : cl.getConstructors()){
|
||||||
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
||||||
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
||||||
info), createTypeScope(cl, m)));
|
info), createTypeScope(cl, m), m.isInherited));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,11 +26,15 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the type inference rules.
|
* Implementation of the type inference rules.
|
||||||
@@ -43,6 +47,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
public RuleSet() {
|
public RuleSet() {
|
||||||
super();
|
super();
|
||||||
|
logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleSet(Writer logFile) {
|
RuleSet(Writer logFile) {
|
||||||
@@ -627,7 +632,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Set<UnifyPair>>> oderConstraints) {
|
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Constraint<UnifyPair>>> oderConstraints) {
|
||||||
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
|
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
|
||||||
|
|
||||||
Stack<UnifyType> occuringTypes = new Stack<>();
|
Stack<UnifyType> occuringTypes = new Stack<>();
|
||||||
@@ -674,16 +679,13 @@ public class RuleSet implements IRuleSet{
|
|||||||
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
|
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
|
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
|
||||||
Function<? super Set<UnifyPair>,? extends HashSet<UnifyPair>> applyUni = b -> b.stream().map(
|
Function<? super Constraint<UnifyPair>,? extends Constraint<UnifyPair>> applyUni = b -> b.stream().map(
|
||||||
x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new));
|
x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null)
|
||||||
List<Set<Set<UnifyPair>>> oderConstraintsRet = new ArrayList<>();
|
? () -> new Constraint<UnifyPair>(
|
||||||
for(Set<Set<UnifyPair>> oc : oderConstraints) {
|
b.isInherited(),
|
||||||
//Set<Set<UnifyPair>> ocRet = new HashSet<>();
|
b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)))
|
||||||
//for(Set<UnifyPair> cs : oc) {
|
: () -> new Constraint<UnifyPair>(b.isInherited())
|
||||||
Set<Set<UnifyPair>> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new));
|
));
|
||||||
oderConstraintsRet.add(csRet);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
|
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
|
||||||
/*
|
/*
|
||||||
oderConstraints = oderConstraints.stream().map(
|
oderConstraints = oderConstraints.stream().map(
|
||||||
|
@@ -28,7 +28,7 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
@@ -54,7 +54,7 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
@@ -72,7 +72,7 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
@@ -105,7 +105,7 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
try {
|
||||||
|
@@ -18,7 +18,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> setToFlatten;
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
|
@@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.OrderingExtend;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||||
@@ -101,11 +102,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
protected Set<UnifyPair> eq; //und-constraints
|
protected Set<UnifyPair> eq; //und-constraints
|
||||||
|
|
||||||
protected List<Set<Set<UnifyPair>>> oderConstraintsField;
|
protected List<Set<Constraint<UnifyPair>>> oderConstraintsField;
|
||||||
|
|
||||||
protected IFiniteClosure fc;
|
protected IFiniteClosure fc;
|
||||||
|
|
||||||
protected Ordering<Set<UnifyPair>> oup;
|
protected OrderingExtend<Set<UnifyPair>> oup;
|
||||||
|
|
||||||
protected boolean parallel;
|
protected boolean parallel;
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||||
@@ -173,9 +174,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
thNo = totalnoOfThread;
|
thNo = totalnoOfThread;
|
||||||
writeLog("thNo2 " + thNo);
|
writeLog("thNo2 " + thNo);
|
||||||
try {
|
try {
|
||||||
this.logFile = //new OutputStreamWriter(new NullOutputStream());
|
this.logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
|
//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
|
||||||
new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
|
//new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
|
||||||
logFile.write("");
|
logFile.write("");
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
@@ -247,7 +248,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
oderConstraintsField.stream()
|
oderConstraintsField.stream()
|
||||||
.filter(x -> x.size()==1)
|
.filter(x -> x.size()==1)
|
||||||
.map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x));
|
.map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x));
|
||||||
ArrayList<Set<Set<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, true);
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true);
|
||||||
@@ -292,7 +293,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<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
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());
|
||||||
@@ -357,7 +358,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
// There are up to 10 toplevel set. 8 of 10 are the result of the
|
// There are up to 10 toplevel set. 8 of 10 are the result of the
|
||||||
// cartesian product of the sets created by pattern matching.
|
// cartesian product of the sets created by pattern matching.
|
||||||
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
List<Set<? extends Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
||||||
|
|
||||||
//System.out.println(eq2s);
|
//System.out.println(eq2s);
|
||||||
|
|
||||||
@@ -385,8 +386,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
||||||
if (printtag) System.out.println("eq2s " + eq2s);
|
if (printtag) System.out.println("eq2s " + eq2s);
|
||||||
//writeLog("BufferSet: " + bufferSet.toString()+"\n");
|
//writeLog("BufferSet: " + bufferSet.toString()+"\n");
|
||||||
List<Set<Set<UnifyPair>>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints);
|
||||||
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput);
|
Set<Set<Set<? extends Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput);
|
||||||
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
|
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
|
||||||
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
||||||
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
||||||
@@ -434,8 +435,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden
|
//Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden
|
||||||
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
for(Set<Set<? extends Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||||
for (Set<Set<UnifyPair>> secondlevelelem : secondLevelSet) {
|
for (Set<? extends Set<UnifyPair>> secondlevelelem : secondLevelSet) {
|
||||||
topLevelSets.add(secondlevelelem);
|
topLevelSets.add(secondlevelelem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,7 +451,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
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
|
||||||
@@ -482,7 +483,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//writeLog("vor Subst: " + eqPrime);
|
//writeLog("vor Subst: " + eqPrime);
|
||||||
writeLog("vor Subst: " + oderConstraints);
|
writeLog("vor Subst: " + oderConstraints);
|
||||||
String ocString = oderConstraints.toString();
|
String ocString = oderConstraints.toString();
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime, newOderConstraints);
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime, newOderConstraints);
|
||||||
Set<Set<UnifyPair>> unifyres1 = null;
|
Set<Set<UnifyPair>> unifyres1 = null;
|
||||||
Set<Set<UnifyPair>> unifyres2 = null;
|
Set<Set<UnifyPair>> unifyres2 = null;
|
||||||
@@ -572,23 +573,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
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) {
|
||||||
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||||
|
|
||||||
fstElems.addAll(topLevelSets.stream()
|
fstElems.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<Set<UnifyPair>>> remainingSets = topLevelSets.stream()
|
ArrayList<Set<? extends Set<UnifyPair>>> remainingSets = topLevelSets.stream()
|
||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
|
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
|
||||||
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||||
writeLog("nextSet: " + nextSet.toString());
|
//writeLog("nextSet: " + nextSet.toString());
|
||||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||||
|
/*
|
||||||
try {
|
try {
|
||||||
//List<Set<UnifyPair>>
|
//List<Set<UnifyPair>>
|
||||||
//nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
//nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
||||||
@@ -596,11 +598,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
catch (java.lang.IllegalArgumentException e) {
|
catch (java.lang.IllegalArgumentException e) {
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
int variance = 0;
|
int variance = 0;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if (fstBasePair != null) {
|
if (fstBasePair != null) {
|
||||||
Boolean sameBase = true;
|
Boolean sameBase = true;
|
||||||
@@ -620,50 +624,47 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
variance = 2;
|
//variance = 2;
|
||||||
|
oderConstraint = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//variance = 2;
|
||||||
|
oderConstraint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints
|
||||||
|
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
||||||
|
Optional<Integer> optVariance =
|
||||||
|
nextSetasList.iterator()
|
||||||
|
.next()
|
||||||
|
.stream()
|
||||||
|
.filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType &&
|
||||||
|
! (x.getRhsType() instanceof PlaceholderType) &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT)
|
||||||
|
.map(x ->
|
||||||
|
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
||||||
|
.findAny();
|
||||||
|
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt.
|
||||||
|
//da kein Receiver existiert also keon x.getGroundBasePair().getLhsType() instanceof PlaceholderType
|
||||||
|
//Es werden alle Elemente des Kartesischen Produkts abgearbeitet
|
||||||
|
variance = optVariance.isPresent() ? optVariance.get() : 2;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
variance = 2;
|
|
||||||
}
|
|
||||||
//if (variance == 1 && nextSetasList.size() > 1) {
|
|
||||||
// List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
|
||||||
// for (int ii = 0; ii < nextSetasList.size();ii++) {
|
|
||||||
// al.add(0,nextSetasList.get(ii));
|
|
||||||
// }
|
|
||||||
// nextSetasList = al;
|
|
||||||
//}
|
|
||||||
//Set<UnifyPair> a = nextSetasListIt.next();
|
|
||||||
/*if (nextSetasList.size()>1) {zu loeschen
|
|
||||||
if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D"))
|
|
||||||
System.out.print("");
|
|
||||||
if (variance == 1) {
|
|
||||||
a_next = oup.max(nextSetasList.iterator());
|
|
||||||
}
|
|
||||||
else if (variance == -1) {
|
|
||||||
a_next = oup.min(nextSetasList.iterator());
|
|
||||||
}
|
|
||||||
else if (variance == 0) {
|
|
||||||
a_next = nextSetasList.iterator().next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a_next = nextSetasList.iterator().next();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (!nextSetasList.iterator().hasNext())
|
if (!nextSetasList.iterator().hasNext())
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
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 alle Paare a < ty1 oder ty2 < a aus fstElems */
|
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */
|
||||||
Set<UnifyPair> sameEqSet = new HashSet<>();
|
Set<UnifyPair> sameEqSet = new HashSet<>();
|
||||||
if (variance != 2) {
|
Optional<UnifyPair> optOrigPair = null;
|
||||||
Optional<UnifyPair> optOrigPair = nextSetElem.stream().filter(x -> (
|
//if (variance != 2) {
|
||||||
|
if (!oderConstraint) {
|
||||||
|
optOrigPair = nextSetElem.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
@@ -696,12 +697,23 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
while (nextSetasList.size() > 0) { //(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
|
||||||
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
||||||
//List<Set<UnifyPair>> nextSetasListRestMin = new ArrayList<>();
|
|
||||||
//List<Set<UnifyPair>> nextSetasListRestOder = new ArrayList<>();
|
//Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt
|
||||||
|
//In der Regel ein Element
|
||||||
|
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
|
||||||
|
|
||||||
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
a = oup.max(nextSetasList.iterator());
|
a = oup.max(nextSetasList.iterator());
|
||||||
nextSetasList.remove(a);
|
nextSetasList.remove(a);
|
||||||
|
if (oderConstraint) {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||||
|
}
|
||||||
|
writeLog("nextSetasListOderConstraints 1: " + nextSetasListOderConstraints);
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||||
while (nextSetasListItRest.hasNext()) {
|
while (nextSetasListItRest.hasNext()) {
|
||||||
@@ -711,27 +723,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
nextSetasListRest.remove(a_next);
|
nextSetasListRest.remove(a_next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Alle maximale Elemente in nextSetasListRest bestimmen
|
//Alle maximale Elemente in nextSetasListRest bestimmen
|
||||||
List<Set<UnifyPair>> nextSetasListRestTest;
|
nextSetasListRest = oup.maxElements(nextSetasListRest);
|
||||||
do {
|
|
||||||
nextSetasListRestTest = new ArrayList<Set<UnifyPair>>(nextSetasListRest);
|
|
||||||
if (!nextSetasListRest.isEmpty()) {
|
|
||||||
Set<UnifyPair> max = oup.max(nextSetasListRest.iterator());
|
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest2 = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
|
||||||
while (nextSetasListItRest2.hasNext()) {
|
|
||||||
Set<UnifyPair> a_nextRest = nextSetasListItRest2.next();
|
|
||||||
if (//a.equals(a_next) ||
|
|
||||||
(oup.compare(max, a_nextRest) == 1)) {
|
|
||||||
nextSetasListRest.remove(a_nextRest);
|
|
||||||
}
|
|
||||||
|
|
||||||
}}
|
|
||||||
} while(!nextSetasListRestTest.equals(nextSetasListRest));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (variance == -1) {
|
else if (variance == -1) {
|
||||||
a = oup.min(nextSetasList.iterator());
|
a = oup.min(nextSetasList.iterator());
|
||||||
writeLog("Min: a in " + variance + " "+ a);
|
writeLog("Min: a in " + variance + " "+ a);
|
||||||
|
if (oderConstraint) {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||||
|
}
|
||||||
|
writeLog("nextSetasListOderConstraints -1: " + nextSetasListOderConstraints);
|
||||||
nextSetasList.remove(a);
|
nextSetasList.remove(a);
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||||
@@ -743,50 +745,38 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
||||||
|
nextSetasListRest = oup.minElements(nextSetasListRest);
|
||||||
List<Set<UnifyPair>> nextSetasListRestTest;
|
|
||||||
do {
|
|
||||||
nextSetasListRestTest = new ArrayList<Set<UnifyPair>>(nextSetasListRest);
|
|
||||||
if (!nextSetasListRest.isEmpty()) {
|
|
||||||
Set<UnifyPair> min = oup.min(nextSetasListRest.iterator());
|
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest2 = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
|
||||||
while (nextSetasListItRest2.hasNext()) {
|
|
||||||
Set<UnifyPair> a_nextRest = nextSetasListItRest2.next();
|
|
||||||
if (//a.equals(a_next) ||
|
|
||||||
(oup.compare(min, a_nextRest) == -1)) {
|
|
||||||
nextSetasListRest.remove(a_nextRest);
|
|
||||||
}
|
|
||||||
|
|
||||||
}}
|
|
||||||
} while(!nextSetasListRestTest.equals(nextSetasListRest));
|
|
||||||
}
|
}
|
||||||
else if (variance == 2) {
|
else if (variance == 2) {
|
||||||
a = nextSetasList.remove(0);
|
a = nextSetasList.remove(0);
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
}
|
}
|
||||||
else if (variance == 0) {
|
else if (variance == 0) {
|
||||||
a = nextSetasList.remove(0);
|
//wenn a <. theta dann ist ein maximales Element sehr wahrscheinlich
|
||||||
|
//wenn theta <. a dann ist ein minimales Element sehr wahrscheinlich
|
||||||
|
if (!oderConstraint && optOrigPair != null && optOrigPair.isPresent()) {
|
||||||
|
if (optOrigPair.get().getBasePair().getLhsType() instanceof PlaceholderType) {
|
||||||
|
a = oup.max(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a = oup.min(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
nextSetasList.remove(a);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (oderConstraint) {
|
||||||
|
a = oup.max(nextSetasList.iterator());
|
||||||
|
nextSetasList.remove(a);
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a = nextSetasList.remove(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
||||||
//nextSetasList.remove(a);
|
//nextSetasList.remove(a);
|
||||||
/* zu loeschen
|
|
||||||
if (nextSetasList.size() > 0) {
|
|
||||||
if (nextSetasList.size()>1) {
|
|
||||||
if (variance == 1) {
|
|
||||||
a_next = oup.max(nextSetasList.iterator());
|
|
||||||
}
|
|
||||||
else if (variance == -1) {
|
|
||||||
a_next = oup.min(nextSetasList.iterator());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a_next = nextSetasList.iterator().next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a_next = nextSetasList.iterator().next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//PL 2018-03-01
|
//PL 2018-03-01
|
||||||
//TODO: 1. Maximum und Minimum unterscheiden
|
//TODO: 1. Maximum und Minimum unterscheiden
|
||||||
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
|
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
|
||||||
@@ -803,7 +793,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
||||||
|
|
||||||
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
if (variance != 2 && !sameEqSet.isEmpty()) {
|
if (!oderConstraint && !sameEqSet.isEmpty()) {
|
||||||
Optional<UnifyPair> optAPair = a.stream().filter(x -> (
|
Optional<UnifyPair> optAPair = a.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
@@ -836,7 +826,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -861,10 +851,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
/*
|
/*
|
||||||
(x.getBasePair().getLhsType() instanceof PlaceholderType
|
(x.getBasePair().getLhsType() instanceof PlaceholderType
|
||||||
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|
||||||
@@ -876,21 +867,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||||
).findFirst();
|
).findFirst();
|
||||||
|
|
||||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||||
UnifyPair aPair = optAPair.get();
|
UnifyPair aPair = optAPair.get();
|
||||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||||
nSaL = null;
|
nSaL = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
|
else {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
|
}
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
@@ -942,7 +936,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -966,8 +960,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("-1 RM" + nSaL.toString());
|
writeLog("-1 RM" + nSaL.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||||
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
@@ -982,21 +977,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||||
).findFirst();
|
).findFirst();
|
||||||
|
|
||||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||||
UnifyPair aPair = optAPair.get();
|
UnifyPair aPair = optAPair.get();
|
||||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||||
nSaL = null;
|
nSaL = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
|
else {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
|
}
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
@@ -1049,7 +1047,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -1072,7 +1070,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03
|
nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
@@ -1117,7 +1115,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten
|
//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, finalresult);
|
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||||
}}}
|
}}}
|
||||||
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;
|
||||||
@@ -1248,129 +1246,132 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
System.out.print("");
|
System.out.print("");
|
||||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
/* vorgezogen vor das if
|
|
||||||
if (parallel) {
|
|
||||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
|
||||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
|
||||||
result = par_res;
|
|
||||||
if (par_res.iterator().next() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
|
||||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
|
||||||
|| result.isEmpty()) {
|
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
|
||||||
writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString());
|
|
||||||
result.addAll(par_res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//break;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* nextSetasList = nextSetasListRest; */
|
|
||||||
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
|
|
||||||
*/
|
|
||||||
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||||
writeLog("aParDef: " + aParDef.toString());
|
writeLog("aParDef: " + aParDef.toString());
|
||||||
aParDef.add(a);
|
aParDef.add(a);
|
||||||
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
||||||
while(aParDefIt.hasNext()) {
|
if (oderConstraint) {
|
||||||
Set<UnifyPair> a_new = aParDefIt.next();
|
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||||
while (nextSetasListIt.hasNext()) {
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
if (a_new.equals(a_next) ||
|
while(aParDefIt.hasNext()) {
|
||||||
(oup.compare(a_new, a_next) == 1)) {
|
Set<UnifyPair> a_new = aParDefIt.next();
|
||||||
writeLog("Removed: " + a_next.toString());
|
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList);
|
||||||
nextSetasList.remove(a_next);
|
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
||||||
}
|
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||||
else {
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
writeLog("Not Removed: " + a_next.toString());
|
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||||
System.out.println("");
|
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
|
||||||
|
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
||||||
|
erased.removeAll(notErased);
|
||||||
|
nextSetasList.removeAll(erased);
|
||||||
|
|
||||||
|
writeLog("Removed: " + erased);
|
||||||
|
|
||||||
|
writeLog("Not Removed: " + nextSetasList);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
while(aParDefIt.hasNext()) {
|
||||||
|
//nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28
|
||||||
|
Set<UnifyPair> a_new = aParDefIt.next();
|
||||||
|
List<Set<UnifyPair>> erased = oup.smallerEqThan(a_new, nextSetasList);
|
||||||
|
nextSetasList.removeAll(erased);
|
||||||
|
|
||||||
|
writeLog("Removed: " + erased);
|
||||||
|
|
||||||
|
writeLog("Not Removed: " + nextSetasList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { if (variance == -1) {
|
else { if (variance == -1) {
|
||||||
/* vorgezogen vor das if
|
|
||||||
if (parallel) {
|
|
||||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
|
||||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
|
||||||
result = par_res;
|
|
||||||
if (par_res.iterator().next() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
|
||||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
|
||||||
|| result.isEmpty()) {
|
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
|
||||||
writeLog("RES var-1 ADD:" + result.toString() + " " + par_res.toString());
|
|
||||||
result.addAll(par_res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||||
writeLog("aParDef: " + aParDef.toString());
|
writeLog("aParDef: " + aParDef.toString());
|
||||||
aParDef.add(a);
|
aParDef.add(a);
|
||||||
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
||||||
while(aParDefIt.hasNext()) {
|
if (oderConstraint) {
|
||||||
Set<UnifyPair> a_new = aParDefIt.next();
|
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||||
while (nextSetasListIt.hasNext()) {
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
if (a_new.equals(a_next) ||
|
while(aParDefIt.hasNext()) {
|
||||||
(oup.compare(a_new, a_next) == -1)) {
|
Set<UnifyPair> a_new = aParDefIt.next();
|
||||||
writeLog("Removed: " + a_next.toString());
|
List<Set<UnifyPair>> greaterSetasList = oup.greaterThan(a_new, nextSetasList);
|
||||||
nextSetasList.remove(a_next); //PL geaendert 2019-01-09
|
|
||||||
|
//a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht
|
||||||
|
if (!((Constraint<UnifyPair>)a_new).isInherited()) {
|
||||||
|
greaterSetasList.add(a_new);
|
||||||
}
|
}
|
||||||
else {
|
List<Set<UnifyPair>> notInherited = greaterSetasList.stream()
|
||||||
System.out.println("");
|
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||||
writeLog("Not Removed: " + a_next.toString());
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||||
|
|
||||||
|
//Wenn x nicht vererbt ist, beginnt beim naechstgroesseren Element die naechste Ueberladung
|
||||||
|
notInherited.stream().forEach(x -> { notErased.addAll(oup.greaterEqThan(x, greaterSetasList)); });
|
||||||
|
|
||||||
|
//das kleineste Element ist das Element von dem a_new geerbt hat
|
||||||
|
//muss deshalb geloescht werden
|
||||||
|
Iterator<Set<UnifyPair>> notErasedIt = notErased.iterator();
|
||||||
|
if (notErasedIt.hasNext()) {
|
||||||
|
Set<UnifyPair> min = oup.min(notErasedIt);
|
||||||
|
notErased.remove(min);
|
||||||
|
notErased.remove(((Constraint<UnifyPair>)min).getExtendConstraint());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Set<UnifyPair>> erased = new ArrayList<>(greaterSetasList);
|
||||||
|
erased.removeAll(notErased);
|
||||||
|
nextSetasList.removeAll(erased);
|
||||||
|
|
||||||
|
writeLog("Removed: " + erased);
|
||||||
|
|
||||||
|
writeLog("Not Removed: " + nextSetasList);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while(aParDefIt.hasNext()) {
|
||||||
|
//nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28
|
||||||
|
Set<UnifyPair> a_new = aParDefIt.next();
|
||||||
|
List<Set<UnifyPair>> erased = oup.greaterEqThan(a_new, nextSetasList);
|
||||||
|
|
||||||
|
nextSetasList.removeAll(erased);
|
||||||
|
|
||||||
|
writeLog("Removed: " + erased);
|
||||||
|
|
||||||
|
writeLog("Not Removed: " + nextSetasList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else { if (variance == 0) {
|
else { if (variance == 0) {
|
||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||||
break; }
|
if (!oderConstraint) {
|
||||||
else { if (variance == 2) {
|
break;
|
||||||
/* vorgezogen vor das if
|
|
||||||
if (parallel) {
|
|
||||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
|
||||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
|
||||||
result = par_res;
|
|
||||||
if (par_res.iterator().next() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
|
||||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
|
||||||
|| result.isEmpty()) {
|
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
|
||||||
writeLog("RES var2 ADD:" + result.toString() + " " + par_res.toString());
|
|
||||||
result.addAll(par_res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
*/
|
else {
|
||||||
|
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||||
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
|
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a, nextSetasList);
|
||||||
|
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
||||||
|
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||||
|
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
|
||||||
|
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
||||||
|
erased.removeAll(notErased);
|
||||||
|
nextSetasList.removeAll(erased);
|
||||||
|
|
||||||
|
writeLog("Removed: " + erased);
|
||||||
|
|
||||||
|
writeLog("Not Removed: " + nextSetasList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else { if (variance == 2) {
|
||||||
}}}
|
}}}
|
||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||||
}
|
}
|
||||||
@@ -1389,7 +1390,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
res.stream()
|
res.stream()
|
||||||
.map(b ->
|
.map(b ->
|
||||||
b.stream()
|
b.stream()
|
||||||
.map(x -> x.getAllBases())
|
.map(x -> x.getThisAndAllBases()) //getAllBases durch getThisAndAllBases ersetzt, weil auch im UnifyPair selbst schon ein Fehler liegen kann.
|
||||||
.reduce((y,z) -> { y.addAll(z); return y;}).get())
|
.reduce((y,z) -> { y.addAll(z); return y;}).get())
|
||||||
.reduce((y,z) -> { y.addAll(z); return y;}).get()
|
.reduce((y,z) -> { y.addAll(z); return y;}).get()
|
||||||
);
|
);
|
||||||
@@ -1410,6 +1411,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (res.size() > 1) {
|
if (res.size() > 1) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList);
|
||||||
nextSetasList = nextSetasList.stream().filter(x -> {
|
nextSetasList = nextSetasList.stream().filter(x -> {
|
||||||
//Boolean ret = false;
|
//Boolean ret = false;
|
||||||
//for (PlaceholderType var : vars) {
|
//for (PlaceholderType var : vars) {
|
||||||
@@ -1418,6 +1420,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return (!x.containsAll(durchschnitt));
|
return (!x.containsAll(durchschnitt));
|
||||||
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
writeLog("nextSetasList nach filter-Aufruf: " + nextSetasList);
|
||||||
nofstred = nextSetasList.size();
|
nofstred = nextSetasList.size();
|
||||||
//NOCH NICHT korrekt PL 2018-10-12
|
//NOCH NICHT korrekt PL 2018-10-12
|
||||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||||
@@ -1764,10 +1767,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements
|
* from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements
|
||||||
* (as in case 1 where sigma is added to the innermost set).
|
* (as in case 1 where sigma is added to the innermost set).
|
||||||
*/
|
*/
|
||||||
protected Set<Set<Set<Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, List<Set<Set<UnifyPair>>> oderConstraintsInput, IFiniteClosure fc, Set<UnifyPair> undefined, List<Set<Set<UnifyPair>>> oderConstraintsOutput) {
|
protected Set<Set<Set<? extends Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, List<Set<Constraint<UnifyPair>>> oderConstraintsInput, IFiniteClosure fc, Set<UnifyPair> undefined, List<Set<Constraint<UnifyPair>>> oderConstraintsOutput) {
|
||||||
writeLog("eq2s: " + eq2s.toString());
|
writeLog("eq2s: " + eq2s.toString());
|
||||||
oderConstraintsOutput.addAll(oderConstraintsInput);
|
oderConstraintsOutput.addAll(oderConstraintsInput);
|
||||||
List<Set<Set<Set<UnifyPair>>>> result = new ArrayList<>(9);
|
List<Set<Set<? extends Set<UnifyPair>>>> result = new ArrayList<>(9);
|
||||||
|
|
||||||
// Init all 8 cases + 9. Case: oderConstraints
|
// Init all 8 cases + 9. Case: oderConstraints
|
||||||
for(int i = 0; i < 9; i++)
|
for(int i = 0; i < 9; i++)
|
||||||
@@ -1777,29 +1780,52 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Iterator<UnifyPair> eq2sprimeit = eq2sprime.iterator();
|
Iterator<UnifyPair> eq2sprimeit = eq2sprime.iterator();
|
||||||
ArrayList<UnifyPair> eq2sAsListFst = new ArrayList<>();
|
ArrayList<UnifyPair> eq2sAsListFst = new ArrayList<>();
|
||||||
ArrayList<UnifyPair> eq2sAsListSnd = new ArrayList<>();
|
ArrayList<UnifyPair> eq2sAsListSnd = new ArrayList<>();
|
||||||
|
ArrayList<UnifyPair> eq2sAsListThird = new ArrayList<>();
|
||||||
|
ArrayList<UnifyPair> eq2sAsListFourth = new ArrayList<>();
|
||||||
ArrayList<UnifyPair> eq2sAsListBack = new ArrayList<>();
|
ArrayList<UnifyPair> eq2sAsListBack = new ArrayList<>();
|
||||||
ArrayList<UnifyPair> eq2sAsList = new ArrayList<>();
|
ArrayList<UnifyPair> eq2sAsList = new ArrayList<>();
|
||||||
Boolean first = true;
|
Boolean first = true;
|
||||||
while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben
|
while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben
|
||||||
UnifyPair up = eq2sprimeit.next();
|
UnifyPair up = eq2sprimeit.next();
|
||||||
if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0 && !((PlaceholderType)up.getLhsType()).isInnerType())
|
if ((up.getLhsType() instanceof PlaceholderType &&
|
||||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0) && !((PlaceholderType)up.getRhsType()).isInnerType()) {
|
((PlaceholderType)up.getLhsType()).getVariance() == 1 &&
|
||||||
eq2sAsListFst.add(up);
|
!((PlaceholderType)up.getLhsType()).isInnerType()) ||
|
||||||
|
(up.getRhsType() instanceof PlaceholderType &&
|
||||||
|
((PlaceholderType)up.getRhsType()).getVariance() == -1) &&
|
||||||
|
!((PlaceholderType)up.getRhsType()).isInnerType())
|
||||||
|
{
|
||||||
|
eq2sAsListFst.add(up);
|
||||||
eq2s.remove(up);
|
eq2s.remove(up);
|
||||||
}
|
}
|
||||||
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0 && ((PlaceholderType)up.getLhsType()).isInnerType())
|
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() == 1 && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0) && ((PlaceholderType)up.getRhsType()).isInnerType()) {
|
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() == -1) && ((PlaceholderType)up.getRhsType()).isInnerType()) {
|
||||||
eq2sAsListSnd.add(up);
|
eq2sAsListSnd.add(up);
|
||||||
eq2s.remove(up);
|
eq2s.remove(up);
|
||||||
}
|
}
|
||||||
|
else if ((up.getLhsType() instanceof PlaceholderType &&
|
||||||
|
((PlaceholderType)up.getLhsType()).getVariance() == -1 &&
|
||||||
|
!((PlaceholderType)up.getLhsType()).isInnerType()) ||
|
||||||
|
(up.getRhsType() instanceof PlaceholderType &&
|
||||||
|
((PlaceholderType)up.getRhsType()).getVariance() == -1) &&
|
||||||
|
!((PlaceholderType)up.getRhsType()).isInnerType())
|
||||||
|
{
|
||||||
|
eq2sAsListThird.add(up);
|
||||||
|
eq2s.remove(up);
|
||||||
|
}
|
||||||
|
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() == -1 && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||||
|
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() == 1) && ((PlaceholderType)up.getRhsType()).isInnerType()) {
|
||||||
|
eq2sAsListFourth.add(up);
|
||||||
|
eq2s.remove(up);
|
||||||
|
}
|
||||||
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).isInnerType())
|
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).isInnerType())) {
|
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).isInnerType())) {
|
||||||
eq2sAsListBack.add(up);
|
eq2sAsListBack.add(up);
|
||||||
eq2s.remove(up);
|
eq2s.remove(up);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (eq2sAsListFst.isEmpty()) {
|
//if (eq2sAsListFst.isEmpty())
|
||||||
List<Set<Set<UnifyPair>>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind
|
{
|
||||||
|
List<Set<Constraint<UnifyPair>>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind
|
||||||
.filter(x -> x.stream()
|
.filter(x -> x.stream()
|
||||||
.filter(y ->
|
.filter(y ->
|
||||||
y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType)
|
y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType)
|
||||||
@@ -1809,10 +1835,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
).findFirst().isPresent()
|
).findFirst().isPresent()
|
||||||
).findFirst().isPresent()).collect(Collectors.toList());
|
).findFirst().isPresent()).collect(Collectors.toList());
|
||||||
if (!oderConstraintsVariance.isEmpty()) {
|
if (!oderConstraintsVariance.isEmpty()) {
|
||||||
Set<Set<UnifyPair>> ret = oderConstraintsVariance.get(0);
|
Set<Constraint<UnifyPair>> ret = oderConstraintsVariance.get(0);
|
||||||
oderConstraintsOutput.remove(ret);
|
oderConstraintsOutput.remove(ret);
|
||||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||||
|
|
||||||
|
//Alle wildcard Faelle rausfiltern bei not wildcardable
|
||||||
|
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||||
|
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||||
|
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||||
|
&& y.getPairOp() == PairOperator.EQUALSDOT
|
||||||
|
&& !(y.getRhsType() instanceof PlaceholderType))
|
||||||
|
.findAny()).isPresent()
|
||||||
|
&& optElem.get().getRhsType() instanceof ExtendsType);})
|
||||||
|
.collect(Collectors.toSet());
|
||||||
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
||||||
x_new.remove(y);
|
x_new.remove(y);
|
||||||
y.addSubstitutions(x_new);
|
y.addSubstitutions(x_new);
|
||||||
@@ -1829,16 +1865,28 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
eq2sAsList.addAll(eq2sAsListFst);
|
eq2sAsList.addAll(eq2sAsListFst);
|
||||||
eq2sAsList.addAll(eq2sAsListSnd);
|
eq2sAsList.addAll(eq2sAsListSnd);
|
||||||
|
eq2sAsList.addAll(eq2sAsListThird);
|
||||||
|
eq2sAsList.addAll(eq2sAsListFourth);
|
||||||
eq2sAsList.addAll(eq2s);
|
eq2sAsList.addAll(eq2s);
|
||||||
eq2sAsList.addAll(eq2sAsListBack);
|
eq2sAsList.addAll(eq2sAsListBack);
|
||||||
|
|
||||||
if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet
|
if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet
|
||||||
if (!oderConstraintsOutput.isEmpty()) {
|
if (!oderConstraintsOutput.isEmpty()) {
|
||||||
Set<Set<UnifyPair>> ret = oderConstraintsOutput.remove(0);
|
Set<Constraint<UnifyPair>> ret = oderConstraintsOutput.remove(0);
|
||||||
//if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M"))
|
//if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M"))
|
||||||
// System.out.println("M");
|
// System.out.println("M");
|
||||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||||
|
|
||||||
|
//Alle wildcard Faelle rausfiltern bei not wildcardable
|
||||||
|
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||||
|
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||||
|
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||||
|
&& y.getPairOp() == PairOperator.EQUALSDOT
|
||||||
|
&& !(y.getRhsType() instanceof PlaceholderType))
|
||||||
|
.findAny()).isPresent()
|
||||||
|
&& optElem.get().getRhsType() instanceof ExtendsType);})
|
||||||
|
.collect(Collectors.toSet());
|
||||||
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
||||||
x_new.remove(y);
|
x_new.remove(y);
|
||||||
y.addSubstitutions(x_new);
|
y.addSubstitutions(x_new);
|
||||||
|
@@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +92,7 @@ public interface IRuleSet {
|
|||||||
* @param pairs The set of pairs where the subst rule should apply.
|
* @param pairs The set of pairs where the subst rule should apply.
|
||||||
* @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions.
|
* @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions.
|
||||||
*/
|
*/
|
||||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Set<UnifyPair>>> oderConstraints);
|
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Constraint<UnifyPair>>> oderConstraints);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the subst-Rule to a set of pairs (usually Eq').
|
* Applies the subst-Rule to a set of pairs (usually Eq').
|
||||||
|
@@ -75,6 +75,17 @@ implements IFiniteClosure {
|
|||||||
|
|
||||||
// Build the transitive closure of the inheritance tree
|
// Build the transitive closure of the inheritance tree
|
||||||
for(UnifyPair pair : pairs) {
|
for(UnifyPair pair : pairs) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
logFile.write("Pair: " + pair + "\n");
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if(pair.getPairOp() != PairOperator.SMALLER)
|
if(pair.getPairOp() != PairOperator.SMALLER)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -100,6 +111,10 @@ implements IFiniteClosure {
|
|||||||
// Add edges to build the transitive closure
|
// Add edges to build the transitive closure
|
||||||
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
||||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
||||||
|
|
||||||
|
//PL eingefuegt 2020-05-07 File UnitTest InheritTest.java
|
||||||
|
this.inheritanceGraph.forEach((x,y) -> { if (y.getDescendants().contains(parentNode)) { y.addDescendant(childNode); y.addAllDescendant(childNode.getDescendants());};
|
||||||
|
if (y.getPredecessors().contains(childNode)) { y.addPredecessor(parentNode); y.addAllPredecessor(parentNode.getPredecessors());};} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the alternative representation with strings as keys
|
// Build the alternative representation with strings as keys
|
||||||
@@ -655,6 +670,7 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||||
|
//try {logFile.write("left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||||
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
/*
|
/*
|
||||||
@@ -746,7 +762,10 @@ implements IFiniteClosure {
|
|||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
long greaterLen = greaterRes.stream().filter(delFun).count();
|
long greaterLen = greaterRes.stream().filter(delFun).count();
|
||||||
if (greaterLen == 0) return 1;
|
if (greaterLen == 0) return 1;
|
||||||
else return 0;
|
else {
|
||||||
|
//try {logFile.write("0 left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,6 +45,15 @@ class Node<T> {
|
|||||||
descendant.addPredecessor(this);
|
descendant.addPredecessor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds some directed edges from this node to the descendant (this -> descendant)
|
||||||
|
*/
|
||||||
|
public void addAllDescendant(Set<Node<T>> allDescendants) {
|
||||||
|
for(Node<T> descendant: allDescendants) {
|
||||||
|
addDescendant(descendant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||||
*/
|
*/
|
||||||
@@ -56,6 +65,15 @@ class Node<T> {
|
|||||||
predecessor.addDescendant(this);
|
predecessor.addDescendant(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds some directed edges from the predecessor to this node (predecessor -> this)
|
||||||
|
*/
|
||||||
|
public void addAllPredecessor(Set<Node<T>> allPredecessors) {
|
||||||
|
for(Node<T> predecessor: allPredecessors) {
|
||||||
|
addPredecessor(predecessor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content of this node.
|
* The content of this node.
|
||||||
*/
|
*/
|
||||||
|
@@ -0,0 +1,89 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public abstract class OrderingExtend<T> extends com.google.common.collect.Ordering<T> {
|
||||||
|
|
||||||
|
public List<T> maxElements(Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
while (iterable.iterator().hasNext()) {
|
||||||
|
Set<T> believe = new HashSet<>();
|
||||||
|
|
||||||
|
T max = max(iterable);
|
||||||
|
ret.add(max);
|
||||||
|
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T elem = it.next();
|
||||||
|
if (!(compare(max, elem) == 1) && !max.equals(elem)) {
|
||||||
|
believe.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iterable = believe;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> minElements(Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
while (iterable.iterator().hasNext()) {
|
||||||
|
Set<T> believe = new HashSet<>();
|
||||||
|
|
||||||
|
T min = min(iterable);
|
||||||
|
ret.add(min);
|
||||||
|
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T elem = it.next();
|
||||||
|
if (!(compare(min, elem) == -1) && !min.equals(elem)) {
|
||||||
|
believe.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iterable = believe;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<T> smallerEqThan(T elem, Iterable<T> iterable) {
|
||||||
|
List<T> ret = smallerThan(elem, iterable);
|
||||||
|
ret.add(elem);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> smallerThan(T elem, Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T itElem = it.next();
|
||||||
|
if (!itElem.equals(elem) && compare(elem, itElem) == 1) {
|
||||||
|
ret.add(itElem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> greaterEqThan(T elem, Iterable<T> iterable) {
|
||||||
|
List<T> ret = greaterThan(elem, iterable);
|
||||||
|
ret.add(elem);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> greaterThan(T elem, Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T itElem = it.next();
|
||||||
|
if (!itElem.equals(elem) && (compare(elem, itElem) == -1)) {
|
||||||
|
ret.add(itElem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,22 +4,25 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.Match;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||||
|
|
||||||
protected IFiniteClosure fc;
|
protected IFiniteClosure fc;
|
||||||
|
|
||||||
@@ -42,7 +45,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
}}
|
}}
|
||||||
catch (ClassCastException e) {
|
catch (ClassCastException e) {
|
||||||
try {
|
try {
|
||||||
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() +"\n\n");
|
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() + " " + left.getGroundBasePair() + "\n\n");
|
||||||
((FiniteClosure)fc).logFile.flush();
|
((FiniteClosure)fc).logFile.flush();
|
||||||
}
|
}
|
||||||
catch (IOException ie) {
|
catch (IOException ie) {
|
||||||
@@ -165,16 +168,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
left.add(p4);
|
left.add(p4);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((left.size() == 1) && right.size() == 1) {
|
|
||||||
if (left.iterator().next().getLhsType().getName().equals("AFS")) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
if (((right.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)right.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object")))
|
|
||||||
||((left.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)left.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object"))))
|
|
||||||
{
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<UnifyPair> lefteq = left.stream()
|
Set<UnifyPair> lefteq = left.stream()
|
||||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
@@ -202,6 +196,135 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
||||||
// System.out.print("");
|
// System.out.print("");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//ODER-CONSTRAINT
|
||||||
|
Set<UnifyPair> leftBase = left.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> rightBase = right.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
Set<UnifyPair> lefteqOder = left.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
/*try {
|
||||||
|
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("y: " + y.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("y.getLhsType() : " + y.getLhsType() .toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("y.getRhsType(): " + y.getRhsType().toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("x.getPairOp(): " + x.getPairOp().toString() +"\n\n");
|
||||||
|
}
|
||||||
|
catch (IOException ie) {
|
||||||
|
} */
|
||||||
|
return (y.getLhsType() instanceof PlaceholderType &&
|
||||||
|
!(y.getRhsType() instanceof PlaceholderType) &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> righteqOder = right.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
return (y.getLhsType() instanceof PlaceholderType &&
|
||||||
|
!(y.getRhsType() instanceof PlaceholderType) &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> lefteqRet = left.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
return (y.getRhsType() instanceof PlaceholderType &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> righteqRet = right.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
return (y.getRhsType() instanceof PlaceholderType &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> leftleOder = left.stream()
|
||||||
|
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> rightleOder = right.stream()
|
||||||
|
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
/*
|
||||||
|
synchronized(this) {
|
||||||
|
try {
|
||||||
|
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException ie) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Integer compareEq;
|
||||||
|
if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) {
|
||||||
|
Match m = new Match();
|
||||||
|
if ((compareEq = compareEq(lefteqOder.iterator().next().getGroundBasePair(), righteqOder.iterator().next().getGroundBasePair())) == -1) {
|
||||||
|
ArrayList<UnifyPair> matchList =
|
||||||
|
rightleOder.stream().map(x -> {
|
||||||
|
UnifyPair leftElem = leftleOder.stream()
|
||||||
|
.filter(y -> y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
|
||||||
|
.findAny().get();
|
||||||
|
return new UnifyPair(x.getRhsType(), leftElem.getRhsType(), PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
if (m.match(matchList).isPresent()) {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result1: -1 \n\n"); } catch (IOException ie) {}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result1: 0 \n\n"); } catch (IOException ie) {}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else if (compareEq == 1) {
|
||||||
|
ArrayList<UnifyPair> matchList =
|
||||||
|
leftleOder.stream().map(x -> {
|
||||||
|
UnifyPair rightElem = rightleOder.stream()
|
||||||
|
.filter(y ->
|
||||||
|
y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
|
||||||
|
.findAny().get();
|
||||||
|
return new UnifyPair(x.getRhsType(), rightElem.getRhsType(), PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
if (m.match(matchList).isPresent()) {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result2: 1 \n\n"); } catch (IOException ie) {}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result2: 0 \n\n"); } catch (IOException ie) {}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
synchronized(this) {
|
||||||
|
try {
|
||||||
|
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("result3: 0 \n\n");
|
||||||
|
((FiniteClosure)fc).logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException ie) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -138,6 +138,11 @@ public class UnifyPair {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<UnifyPair> getThisAndAllBases () {
|
||||||
|
Set<UnifyPair> ret = getAllBases();
|
||||||
|
ret.add(this);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
public Set<UnifyPair> getAllBases () {
|
public Set<UnifyPair> getAllBases () {
|
||||||
Set<UnifyPair> ret = new HashSet<>();
|
Set<UnifyPair> ret = new HashSet<>();
|
||||||
if (basePair != null) {
|
if (basePair != null) {
|
||||||
@@ -217,12 +222,14 @@ public class UnifyPair {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (lhs instanceof PlaceholderType) {
|
if (lhs instanceof PlaceholderType) {
|
||||||
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType()
|
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " "
|
||||||
+ " " + ((PlaceholderType)lhs).isWildcardable();
|
+ "WC: " + ((PlaceholderType)lhs).isWildcardable()
|
||||||
|
+ ", IT: " + ((PlaceholderType)lhs).isInnerType();
|
||||||
}
|
}
|
||||||
if (rhs instanceof PlaceholderType) {
|
if (rhs instanceof PlaceholderType) {
|
||||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType()
|
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " "
|
||||||
+ " " + ((PlaceholderType)rhs).isWildcardable();
|
+ "WC: " + ((PlaceholderType)rhs).isWildcardable()
|
||||||
|
+ ", IT: " + ((PlaceholderType)rhs).isInnerType();
|
||||||
}
|
}
|
||||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
||||||
}
|
}
|
||||||
|
64
src/test/java/AllgemeinTest.java
Normal file
64
src/test/java/AllgemeinTest.java
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class AllgemeinTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
//String className = "GenTest";
|
||||||
|
//String className = "Overloading_Generics";
|
||||||
|
//String className = "Generics";
|
||||||
|
//String className = "OverloadingMain";
|
||||||
|
//String className = "OverrideMain";
|
||||||
|
//String className = "OverrideMainRet";
|
||||||
|
//String className = "FCTest1";
|
||||||
|
//String className = "FCTest2";
|
||||||
|
//String className = "Pair";
|
||||||
|
//String className = "FCTest3";
|
||||||
|
//String className = "Var";
|
||||||
|
//String className = "Put";
|
||||||
|
String className = "Twice";
|
||||||
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||||
|
//compiler = new JavaTXCompiler(Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav")));
|
||||||
|
///*
|
||||||
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(path)),
|
||||||
|
Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/")));
|
||||||
|
//*/
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass(className);
|
||||||
|
//classToTest = loader.loadClass("Overloading_Generics");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance("A");
|
||||||
|
//classToTest = loader.loadClass("Overloading_Generics1");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("B");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/test/java/asp/ClingoTest.java
Normal file
52
src/test/java/asp/ClingoTest.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package asp;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||||
|
import de.dhbwstuttgart.sat.asp.Clingo;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.json.Json;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ClingoTest {
|
||||||
|
public static final String tempDirectory = "/tmp/";
|
||||||
|
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
|
||||||
|
@Test
|
||||||
|
public void test() throws IOException, InterruptedException, ClassNotFoundException {
|
||||||
|
String content = "";
|
||||||
|
content = ASPFactory.generateASP(this.getPairs(), this.getFC(), ClassLoader.getSystemClassLoader());
|
||||||
|
|
||||||
|
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
|
||||||
|
writer.println(content);
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp")));
|
||||||
|
String result = clingo.runClingo();
|
||||||
|
System.out.println(result);
|
||||||
|
ResultSet resultSet = ASPParser.parse(result, Arrays.asList(testType));
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric resolvedType = resultSet.resolveType(testType).resolvedType;
|
||||||
|
assert resolvedType.toString().equals(ASTFactory.createObjectType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ClassOrInterface> getFC() {
|
||||||
|
Set<ClassOrInterface> ret = new HashSet<>();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConstraintSet<Pair> getPairs() {
|
||||||
|
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
||||||
|
ret.addUndConstraint(new Pair(testType, ASTFactory.createObjectType(), PairOperator.EQUALSDOT));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
103
src/test/java/asp/UnifyWithoutWildcards.java
Normal file
103
src/test/java/asp/UnifyWithoutWildcards.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package asp;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.sat.asp.Clingo;
|
||||||
|
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.sql.Ref;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class UnifyWithoutWildcards {
|
||||||
|
|
||||||
|
public static final String tempDirectory = "/tmp/";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void adapt() throws InterruptedException, IOException, ClassNotFoundException {
|
||||||
|
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
|
||||||
|
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
|
||||||
|
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
|
||||||
|
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||||
|
ResultSet resultSet = run(testSet);
|
||||||
|
System.out.println(ResultSetPrinter.print(resultSet));
|
||||||
|
assert resultSet.results.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet run(ConstraintSet<Pair> toTest) throws IOException, InterruptedException, ClassNotFoundException {
|
||||||
|
String content = "";
|
||||||
|
content = ASPFactory.generateASP(toTest, this.getFC(), ClassLoader.getSystemClassLoader());
|
||||||
|
|
||||||
|
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
|
||||||
|
writer.println(content);
|
||||||
|
writer.close();
|
||||||
|
Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp")));
|
||||||
|
String result = clingo.runClingo();
|
||||||
|
ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(toTest));
|
||||||
|
return resultSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TPHExtractor implements TypeVisitor<List<TypePlaceholder>>{
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(RefType refType) {
|
||||||
|
ArrayList<TypePlaceholder> ret = new ArrayList<>();
|
||||||
|
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||||
|
ret.addAll(param.acceptTV(this));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(SuperWildcardType superWildcardType) {
|
||||||
|
return superWildcardType.getInnerType().acceptTV(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(TypePlaceholder typePlaceholder) {
|
||||||
|
return Arrays.asList(typePlaceholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
return extendsWildcardType.getInnerType().acceptTV(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TypePlaceholder> visit(GenericRefType genericRefType) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
|
||||||
|
List<TypePlaceholder> ret = new ArrayList<>();
|
||||||
|
toTest.map((Pair p)-> {
|
||||||
|
ret.addAll(p.TA1.acceptTV(new TPHExtractor()));
|
||||||
|
ret.addAll(p.TA2.acceptTV(new TPHExtractor()));
|
||||||
|
return p;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<ClassOrInterface> getFC() {
|
||||||
|
Set<ClassOrInterface> ret = new HashSet<>();
|
||||||
|
ret.add(ASTFactory.createClass(Matrix.class));
|
||||||
|
//ret.add(ASTFactory.createObjectClass());
|
||||||
|
//ret.add(ASTFactory.createClass(java.util.List.class));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
private class Matrix<A> extends HashMap<A,Map<Integer, A>>{}
|
||||||
|
}
|
63
src/test/java/asp/gencay/GeneratorTest.java
Normal file
63
src/test/java/asp/gencay/GeneratorTest.java
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package asp.gencay;
|
||||||
|
|
||||||
|
import asp.UnifyWithoutWildcards;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.sat.asp.Clingo;
|
||||||
|
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPGencayFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
|
||||||
|
public class GeneratorTest extends UnifyWithoutWildcards{
|
||||||
|
@Test
|
||||||
|
public void simple() throws ClassNotFoundException {
|
||||||
|
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||||
|
RefType t1 = new RefType(new JavaClassName("java.util.List"), list1, new NullToken());
|
||||||
|
RefType t2 = new RefType(new JavaClassName("java.util.List"), list2, new NullToken());
|
||||||
|
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||||
|
String resultSet = ASPGencayFactory.generateASP(testSet,
|
||||||
|
new HashSet<>(Arrays.asList(ASTFactory.createClass(List.class))), ClassLoader.getSystemClassLoader());
|
||||||
|
System.out.println(resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void matrix() throws ClassNotFoundException {
|
||||||
|
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
|
||||||
|
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
|
||||||
|
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
|
||||||
|
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||||
|
String resultSet = ASPGencayFactory.generateASP(testSet, this.getFC(), ClassLoader.getSystemClassLoader());
|
||||||
|
System.out.println(resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<ClassOrInterface> getFC() {
|
||||||
|
Set<ClassOrInterface> ret = new HashSet<>();
|
||||||
|
ret.add(ASTFactory.createClass(Matrix.class));
|
||||||
|
//ret.add(ASTFactory.createObjectClass());
|
||||||
|
//ret.add(ASTFactory.createClass(java.util.List.class));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Matrix extends Vector<Vector<Integer>> {}
|
70
src/test/java/asp/typeinference/ASPTest.java
Normal file
70
src/test/java/asp/typeinference/ASPTest.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package asp.typeinference;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ASPTest {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/";
|
||||||
|
private static final List<File> filesToTest = new ArrayList<>();
|
||||||
|
protected File fileToTest = null;
|
||||||
|
|
||||||
|
public ASPTest(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws IOException, ClassNotFoundException {
|
||||||
|
if(fileToTest != null)filesToTest.add(fileToTest);
|
||||||
|
else return;
|
||||||
|
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||||
|
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||||
|
//filesToTest.add(new File(rootDirectory+"test.jav"));
|
||||||
|
filesToTest.add(new File(rootDirectory+"EmptyMethod.jav"));
|
||||||
|
//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"));
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
Set<ClassOrInterface> allClasses = new HashSet<>();
|
||||||
|
for(SourceFile sf : compiler.sourceFiles.values()) {
|
||||||
|
allClasses.addAll(compiler.getAvailableClasses(sf));
|
||||||
|
}
|
||||||
|
for(SourceFile sf : compiler.sourceFiles.values()) {
|
||||||
|
allClasses.addAll(sf.getClasses());
|
||||||
|
}
|
||||||
|
|
||||||
|
final ConstraintSet<Pair> cons = compiler.getConstraints();
|
||||||
|
String asp = ASPFactory.generateASP(cons, allClasses, ClassLoader.getSystemClassLoader());
|
||||||
|
System.out.println(asp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String readFile(String path, Charset encoding)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||||
|
return new String(encoded, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
9
src/test/java/asp/typeinference/GenericsTest.java
Normal file
9
src/test/java/asp/typeinference/GenericsTest.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package asp.typeinference;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class GenericsTest extends ASPTest {
|
||||||
|
public GenericsTest() {
|
||||||
|
this.fileToTest = new File(rootDirectory+"Generics.jav");
|
||||||
|
}
|
||||||
|
}
|
9
src/test/java/asp/typeinference/VectorTest.java
Normal file
9
src/test/java/asp/typeinference/VectorTest.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package asp.typeinference;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class VectorTest extends ASPTest {
|
||||||
|
public VectorTest() {
|
||||||
|
this.fileToTest = new File(rootDirectory+"Vector.jav");
|
||||||
|
}
|
||||||
|
}
|
10
src/test/java/asp/unifywithoutwildcards/ASPTests.java
Normal file
10
src/test/java/asp/unifywithoutwildcards/ASPTests.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package asp.unifywithoutwildcards;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ASPTests {
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
193
src/test/java/bytecode/InheritTest.java
Normal file
193
src/test/java/bytecode/InheritTest.java
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class InheritTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
|
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||||
|
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
|
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||||
|
private static List<ResultSet> typeinferenceResult;
|
||||||
|
private static List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTestAA = loader.loadClass("AA");
|
||||||
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestBB = loader.loadClass("BB");
|
||||||
|
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestCC = loader.loadClass("CC");
|
||||||
|
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestDD = loader.loadClass("DD");
|
||||||
|
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTest = loader.loadClass("Inherit");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInheritClassName() {
|
||||||
|
assertEquals("Inherit", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAAName() {
|
||||||
|
assertEquals("AA", classToTestAA.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBBName() {
|
||||||
|
assertEquals("BB", classToTestBB.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCCName() {
|
||||||
|
assertEquals("CC", classToTestCC.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDDName() {
|
||||||
|
assertEquals("DD", classToTestDD.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC, 5), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD, 5), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassAA);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassBB);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassCC);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassDD);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||||
|
}
|
||||||
|
}
|
211
src/test/java/bytecode/InheritTest2.java
Normal file
211
src/test/java/bytecode/InheritTest2.java
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class InheritTest2 {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
|
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||||
|
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
|
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||||
|
private static List<ResultSet> typeinferenceResult;
|
||||||
|
private static List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTestAA = loader.loadClass("AA");
|
||||||
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestBB = loader.loadClass("BB");
|
||||||
|
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestCC = loader.loadClass("CC");
|
||||||
|
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestDD = loader.loadClass("DD");
|
||||||
|
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit2.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTest = loader.loadClass("Inherit2");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInheritClassName() {
|
||||||
|
assertEquals("Inherit2", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAAName() {
|
||||||
|
assertEquals("AA", classToTestAA.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBBName() {
|
||||||
|
assertEquals("BB", classToTestBB.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCCName() {
|
||||||
|
assertEquals("CC", classToTestCC.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDDName() {
|
||||||
|
assertEquals("DD", classToTestDD.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//PL 2020-05-12: Die folgenden Test funktionieren erst, wenn Generics im Bytecode implementiert sind
|
||||||
|
@Test
|
||||||
|
public void testmainVectorAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassAA);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
try {
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||||
|
}
|
||||||
|
catch (java.lang.reflect.InvocationTargetException e) {
|
||||||
|
testmainVectorCC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassBB);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
try {
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||||
|
}
|
||||||
|
catch (java.lang.reflect.InvocationTargetException e) {
|
||||||
|
testmainVectorCC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassCC);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
String erg;
|
||||||
|
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||||
|
erg.equals("CC")? "CC": "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassDD);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
String erg;
|
||||||
|
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||||
|
erg.equals("CC")? "CC": "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -28,7 +28,7 @@ public class MatrixTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Matrix.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/MatrixAL.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
86
src/test/java/bytecode/PutTest.java
Normal file
86
src/test/java/bytecode/PutTest.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class PutTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTest1;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClass1;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Put.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("Put");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutClassName() {
|
||||||
|
assertEquals("Put", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutElementVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
|
||||||
|
Vector<Integer> v_invoke = new Vector<>();
|
||||||
|
m.invoke(instanceOfClass, 5, v_invoke);
|
||||||
|
Vector<Integer> v = new Vector<>();
|
||||||
|
v.add(5);
|
||||||
|
assertEquals(v, v_invoke);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutElementStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Stack.class);
|
||||||
|
Stack<Integer> s_invoke = new Stack<>();
|
||||||
|
m.invoke(instanceOfClass, 5, s_invoke);
|
||||||
|
assertEquals(new Integer(5), s_invoke.pop());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMainVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("main", Object.class, Vector.class);
|
||||||
|
Vector<Integer> v_invoke = new Vector<>();
|
||||||
|
m.invoke(instanceOfClass, 6, v_invoke);
|
||||||
|
Vector<Integer> v = new Vector<>();
|
||||||
|
v.add(6);
|
||||||
|
assertEquals(v, v_invoke);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMainStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("main", Object.class, Stack.class);
|
||||||
|
Stack<Integer> s_invoke = new Stack<>();
|
||||||
|
m.invoke(instanceOfClass, 6, s_invoke);
|
||||||
|
assertEquals(new Integer(6), s_invoke.pop());
|
||||||
|
}
|
||||||
|
}
|
40
src/test/java/bytecode/mathStrucMatrixOPTest.java.txt
Normal file
40
src/test/java/bytecode/mathStrucMatrixOPTest.java.txt
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class mathStrucMatrixOPTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
//PL 2019-10-24: laeuft nicht durch deshalb ersetzt
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucMatrixOp.jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("mathStrucMatrixOP");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
38
src/test/java/bytecode/mathStrucVectorAddTest.java.txt
Normal file
38
src/test/java/bytecode/mathStrucVectorAddTest.java.txt
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class mathStrucVectorAddTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucVector.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("mathStrucVector");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor(Integer.class).newInstance("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/test/java/packages/mathStrucMatrixOPTest.java.txt
Normal file
51
src/test/java/packages/mathStrucMatrixOPTest.java.txt
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class mathStrucMatrixOPTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
|
||||||
|
|
||||||
|
public mathStrucMatrixOPTest() throws ClassNotFoundException, IOException {
|
||||||
|
/*
|
||||||
|
Generate ToImport class in rootDirectory and in output-Directory
|
||||||
|
*/
|
||||||
|
/* PL 2020-01-07 kann z.Zt. nicht erzeugt werden (siehe Bug 170, http://bugzilla.ba-horb.de/show_bug.cgi?id=170)
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"mathStruc.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/mathStruc.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
*/
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"MatrixOP.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/MatrixOP.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"mathStrucMatrixOP.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "output/de/test/mathStrucMatrixOP.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/mathStrucMatrixOP.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
}
|
12
src/test/resources/AllgemeinTest/FCTest1.jav
Normal file
12
src/test/resources/AllgemeinTest/FCTest1.jav
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.List;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class FCTest1 extends Vector<Vector<Integer>> {
|
||||||
|
fc1() {
|
||||||
|
var y;
|
||||||
|
var z;
|
||||||
|
y.add(z);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
11
src/test/resources/AllgemeinTest/FCTest2.jav
Normal file
11
src/test/resources/AllgemeinTest/FCTest2.jav
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.List;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class FCTest2 extends Vector<Vector<Integer>> {
|
||||||
|
fc2(y) {
|
||||||
|
var z;
|
||||||
|
y.add(z);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
19
src/test/resources/AllgemeinTest/FCTest3.jav
Normal file
19
src/test/resources/AllgemeinTest/FCTest3.jav
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class FCTest3 extends Pair<Vector<Integer>, Vector<Integer>> {
|
||||||
|
|
||||||
|
|
||||||
|
fc2(x) {
|
||||||
|
x.snd().addElement(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fc2a() {
|
||||||
|
var y;
|
||||||
|
y.snd().addElement(2);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
src/test/resources/AllgemeinTest/GenTest.jav
Normal file
10
src/test/resources/AllgemeinTest/GenTest.jav
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
public class GenTest {
|
||||||
|
|
||||||
|
main(x) {
|
||||||
|
var v = new Vector();
|
||||||
|
return 1 + v.elementAt(0);
|
||||||
|
}
|
||||||
|
}
|
9
src/test/resources/AllgemeinTest/Generics.jav
Normal file
9
src/test/resources/AllgemeinTest/Generics.jav
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class Generics {
|
||||||
|
a;
|
||||||
|
id(b) { return b; }
|
||||||
|
setA(x) {
|
||||||
|
a = x;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
m(x,y) { x = id(y); }
|
||||||
|
}
|
9
src/test/resources/AllgemeinTest/OverloadingMain.jav
Normal file
9
src/test/resources/AllgemeinTest/OverloadingMain.jav
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
class OverloadingMain {
|
||||||
|
|
||||||
|
mmMain(x) { var y; return new O1().mm(y); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
20
src/test/resources/AllgemeinTest/Overloading_Generics.jav
Normal file
20
src/test/resources/AllgemeinTest/Overloading_Generics.jav
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
|
||||||
|
public class Overloading_Generics {
|
||||||
|
|
||||||
|
id1 (x) { return x; }
|
||||||
|
|
||||||
|
//Integer id (Integer x) { return x; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Overloading_Generics1 {
|
||||||
|
main(x) {
|
||||||
|
var olg = new Overloading_Generics();
|
||||||
|
return olg.id1(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
25
src/test/resources/AllgemeinTest/OverrideMain.jav
Normal file
25
src/test/resources/AllgemeinTest/OverrideMain.jav
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
class OverrideMain {
|
||||||
|
ovrMain(x) {
|
||||||
|
var overide;
|
||||||
|
overide.ovr(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
[
|
||||||
|
[(TPH L = java.util.Stack<TPH FTM>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH FTN, TPH FTM), (TPH K = void)],
|
||||||
|
[(TPH FTO, TPH FTP), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Stack<TPH FTP>), (TPH K = void)],
|
||||||
|
[(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH K = void), (TPH FTR, TPH FTQ), (TPH L = java.util.Vector<TPH FTQ>)],
|
||||||
|
[(TPH FTT, TPH FTS), (TPH M = ? extends Override2), (TPH L = java.util.Vector<TPH FTS>), (TPH K = void), (TPH N = java.lang.String)],
|
||||||
|
[(TPH L = java.util.Vector<TPH FTV>), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH FTU, TPH FTV), (TPH K = void)],
|
||||||
|
[(TPH FTX, TPH FTW), (TPH M = ? extends Override2), (TPH L = java.util.Vector<TPH FTW>), (TPH K = void), (TPH N = java.lang.String)],
|
||||||
|
[(TPH M = ? extends Override2), (TPH L = java.util.Stack<TPH FTZ>), (TPH K = void), (TPH FTY, TPH FTZ), (TPH N = java.lang.String)],
|
||||||
|
[(TPH FUB, TPH FUA), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Vector<TPH FUA>)],
|
||||||
|
[(TPH N = java.lang.String), (TPH L = java.util.Vector<TPH FUC>), (TPH FUD, TPH FUC), (TPH M = ? extends Override2), (TPH K = void)],
|
||||||
|
[(TPH N = java.lang.String), (TPH FUF, TPH FUE), (TPH M = ? extends Override2), (TPH K = void), (TPH L = java.util.Vector<TPH FUE>)]]
|
||||||
|
|
||||||
|
[[(TPH M = ? extends Override2), (TPH MNX, TPH MNY), (TPH N = java.lang.String), (TPH K = void), (TPH L = java.util.Stack<TPH MNY>)], [(TPH L = java.util.Stack<TPH MOC>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH K = void), (TPH MOB, TPH MOC)], [(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH MNZ, TPH MOA), (TPH L = java.util.Vector<TPH MOA>), (TPH K = void)], [(TPH L = java.util.Vector<TPH MOE>), (TPH K = void), (TPH M = ? extends Override2), (TPH MOD, TPH MOE), (TPH N = java.lang.String)], [(TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String), (TPH MOF, TPH MOG), (TPH L = java.util.Stack<TPH MOG>)], [(TPH L = java.util.Vector<TPH MOI>), (TPH K = void), (TPH MOH, TPH MOI), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH L = java.util.Vector<TPH MOK>), (TPH MOJ, TPH MOK), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH MOL, TPH MOM), (TPH L = java.util.Stack<TPH MOM>), (TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String)], [(TPH L = java.util.Vector<TPH MOO>), (TPH MON, TPH MOO), (TPH N = java.lang.String), (TPH K = void), (TPH M = ? extends Override2)], [(TPH L = java.util.Stack<TPH MOP>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH MOQ, TPH MOP), (TPH K = void)]]
|
||||||
|
*/
|
11
src/test/resources/AllgemeinTest/OverrideMainRet.jav
Normal file
11
src/test/resources/AllgemeinTest/OverrideMainRet.jav
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
class OverrideMainRet {
|
||||||
|
ovrMain() {
|
||||||
|
var overide;
|
||||||
|
var x;
|
||||||
|
overide.ovr(x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
12
src/test/resources/AllgemeinTest/Pair.java
Normal file
12
src/test/resources/AllgemeinTest/Pair.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Pair<T, U> {
|
||||||
|
T x;
|
||||||
|
U y;
|
||||||
|
|
||||||
|
public T fst () {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public U snd () {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
8
src/test/resources/bytecode/javFiles/AA.jav
Normal file
8
src/test/resources/bytecode/javFiles/AA.jav
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
public class AA {
|
||||||
|
m(Integer i) { return "AA"; }
|
||||||
|
|
||||||
|
m2(AA x) { return "AA"; }
|
||||||
|
}
|
3
src/test/resources/bytecode/javFiles/BB.jav
Normal file
3
src/test/resources/bytecode/javFiles/BB.jav
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class BB extends AA { }
|
11
src/test/resources/bytecode/javFiles/CC.jav
Normal file
11
src/test/resources/bytecode/javFiles/CC.jav
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
|
public class CC extends BB {
|
||||||
|
m(Integer i) {
|
||||||
|
return "CC";
|
||||||
|
}
|
||||||
|
|
||||||
|
m2(CC x) { return "CC"; }
|
||||||
|
}
|
4
src/test/resources/bytecode/javFiles/DD.jav
Normal file
4
src/test/resources/bytecode/javFiles/DD.jav
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class DD extends CC { }
|
||||||
|
|
18
src/test/resources/bytecode/javFiles/Inherit.jav
Normal file
18
src/test/resources/bytecode/javFiles/Inherit.jav
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
|
public class Inherit {
|
||||||
|
|
||||||
|
main(d, i) {
|
||||||
|
return d.m(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
main(v, i) {
|
||||||
|
var aa = v.elementAt(0);
|
||||||
|
return aa.m(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
src/test/resources/bytecode/javFiles/Inherit2.jav
Normal file
17
src/test/resources/bytecode/javFiles/Inherit2.jav
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
|
public class Inherit2 {
|
||||||
|
|
||||||
|
main(d) {
|
||||||
|
return d.m2(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
main(v) {
|
||||||
|
var aa = v.elementAt(0);
|
||||||
|
return aa.m2(aa);
|
||||||
|
}
|
||||||
|
}
|
19
src/test/resources/bytecode/javFiles/Put.jav
Normal file
19
src/test/resources/bytecode/javFiles/Put.jav
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
public class Put {
|
||||||
|
|
||||||
|
putElement(ele, v) {
|
||||||
|
v.addElement(ele);
|
||||||
|
}
|
||||||
|
|
||||||
|
putElement(ele, s) {
|
||||||
|
s.push(ele);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main(ele, x) {
|
||||||
|
putElement(ele, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user