forked from JavaTX/JavaCompilerCore
Compare commits
33 Commits
unify-test
...
bytecode2
Author | SHA1 | Date | |
---|---|---|---|
|
c68d773486 | ||
|
00bbd5279f | ||
|
6c783a18c7 | ||
|
8c195601d5 | ||
|
37f8f2e1e0 | ||
|
0903efda0d | ||
|
c2030123d5 | ||
|
d1637b8eb9 | ||
|
9abda637a1 | ||
|
82c0837d1f | ||
|
a41e9804a0 | ||
|
25c685c705 | ||
|
3ecb202a90 | ||
|
efdb58e67c | ||
|
eed8f32cb7 | ||
|
87d0a46ba5 | ||
|
5b75250fcf | ||
|
7f29b39195 | ||
|
7a4bc32974 | ||
|
dfddc44f29 | ||
|
347d86a379 | ||
|
d77f2176f2 | ||
|
4f39eccecb | ||
|
669e7f111f | ||
|
32d12677bf | ||
|
92b2f5c9cc | ||
|
c1e6526b43 | ||
|
0194e30206 | ||
|
3c36c61077 | ||
|
857d63322e | ||
|
b801e144c3 | ||
|
f6669f8c13 | ||
|
2b7aef5e87 |
22
PlugInBau.txt
Normal file
22
PlugInBau.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Repositories: Branches: JavaCompilerCore: simplyRes
|
||||||
|
JavaCompilerPlugin: copy_libs
|
||||||
|
JavaCompilerCore > mvn install -Dskip.test=true
|
||||||
|
|
||||||
|
[INFO] Installing /Users/pl/workspace_oxygen/JavaCompilerCore/target/JavaTXcompiler-0.2.jar to /Users/pl/.m2/repository/de/dhbwstuttgart/JavaTXcompiler/0.2/JavaTXcompiler-0.2.jar
|
||||||
|
[INFO] Installing /Users/pl/workspace_oxygen/JavaCompilerCore/pom.xml to /Users/pl/.m2/repository/de/dhbwstuttgart/JavaTXcompiler/0.2/JavaTXcompiler-0.2.pom
|
||||||
|
[INFO] Installing /Users/pl/workspace_oxygen/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar to /Users/pl/.m2/repository/de/dhbwstuttgart/JavaTXcompiler/0.2/JavaTXcompiler-0.2-jar-with-dependencies.jar
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] BUILD SUCCESS
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] Total time: 23.279 s
|
||||||
|
[INFO] Finished at: 2019-09-17T09:31:30+02:00
|
||||||
|
[INFO] -------------------------------------
|
||||||
|
|
||||||
|
JavaCompilerCore > cd target
|
||||||
|
|
||||||
|
JavaCompilerCore/target > cp JavaTXcompiler-0.2.jar ../../Plugin_JCC/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/lib/JavaTXcompiler.jar
|
||||||
|
|
||||||
|
Im Eclipse: Plugin_JCC/JavaCompilerPlugin> mvn install
|
||||||
|
|
||||||
|
Plugin_JCC/JavaCompilerPlugin/releng/JavaCompilerPlugin.Update/target > cp JavaCompilerPlugin.Update-0.1.0-SNAPSHOT.zip ~/webdav/public_html/javatx/javatx_XXXXXX.zip
|
||||||
|
|
2
pom.xml
2
pom.xml
@@ -14,7 +14,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.0</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@@ -61,7 +61,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
assign.accept(bytecodeGenMethod);
|
assign.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(assign.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(assign.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +70,9 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
binary.accept(bytecodeGenMethod);
|
binary.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0)) {
|
if(argListMethCall.get(0)) {
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(binary.getType()));
|
||||||
} else {
|
} else {
|
||||||
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolver().getResolvedType(binary.getType()));
|
||||||
}
|
}
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
castExpr.accept(bytecodeGenMethod);
|
castExpr.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(castExpr.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(castExpr.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
fieldVar.accept(bytecodeGenMethod);
|
fieldVar.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(fieldVar.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(fieldVar.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
instanceOf.accept(bytecodeGenMethod);
|
instanceOf.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(instanceOf.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(instanceOf.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
localVar.accept(bytecodeGenMethod);
|
localVar.accept(bytecodeGenMethod);
|
||||||
if(!bytecodeGenMethod.isBinaryExp) {
|
if(!bytecodeGenMethod.isBinaryExp) {
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(localVar.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(localVar.getType()));
|
||||||
}
|
}
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
methodCall.accept(bytecodeGenMethod);
|
methodCall.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(methodCall.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
methodCall.accept(bytecodeGenMethod);
|
methodCall.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(methodCall.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
aThis.accept(bytecodeGenMethod);
|
aThis.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(aThis.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(aThis.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
unaryExpr.accept(bytecodeGenMethod);
|
unaryExpr.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(unaryExpr.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(unaryExpr.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
|||||||
literal.accept(bytecodeGenMethod);
|
literal.accept(bytecodeGenMethod);
|
||||||
|
|
||||||
if(argListMethCall.get(0))
|
if(argListMethCall.get(0))
|
||||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(literal.getType()));
|
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(literal.getType()));
|
||||||
argListMethCall.remove(0);
|
argListMethCall.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,10 +3,8 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
@@ -16,17 +14,18 @@ import org.objectweb.asm.Opcodes;
|
|||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
@@ -73,7 +72,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class BytecodeGen implements ASTVisitor {
|
public class BytecodeGen implements ASTVisitor {
|
||||||
@@ -83,7 +81,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
String type;
|
String type;
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
||||||
String className;
|
private String className;
|
||||||
|
private String pkgName;
|
||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private Collection<ResultSet> listOfResultSets;
|
private Collection<ResultSet> listOfResultSets;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
@@ -96,7 +95,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
private String superClass;
|
private String superClass;
|
||||||
|
|
||||||
private ArrayList<String> tphsClass;
|
private List<String> tphsClass;
|
||||||
|
|
||||||
// stores parameter, local vars and the next index on the local variable table,
|
// stores parameter, local vars and the next index on the local variable table,
|
||||||
// which use for aload_i, astore_i,...
|
// which use for aload_i, astore_i,...
|
||||||
@@ -106,9 +105,6 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
private int constructorPos = 0;
|
private int constructorPos = 0;
|
||||||
|
|
||||||
private final TPHExtractor tphExtractor = new TPHExtractor();
|
|
||||||
private final ArrayList<GenericInsertPair> commonPairs = new ArrayList<>();
|
|
||||||
|
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||||
byte[] bytecode;
|
byte[] bytecode;
|
||||||
HashMap<String, byte[]> classFiles;
|
HashMap<String, byte[]> classFiles;
|
||||||
@@ -116,34 +112,29 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
|
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
private HashMap<String, SimplifyResult> simplifyResults = new HashMap<>();
|
|
||||||
private List<HashMap<String, SimplifyResult>> simplifyResultsList = new ArrayList<>();
|
|
||||||
|
|
||||||
private final ArrayList<String> fieldNameSignature = new ArrayList<>();
|
private final ArrayList<String> fieldNameSignature = new ArrayList<>();
|
||||||
|
|
||||||
public List<HashMap<String, SimplifyResult>> getSimplifyResultsList() {
|
private List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||||
return simplifyResultsList;
|
private GenericsGeneratorResultForClass generatedGenerics;
|
||||||
}
|
|
||||||
|
|
||||||
public void setSimplifyResultsList(List<HashMap<String, SimplifyResult>> simplifyResultsList) {
|
private Resolver resolver;
|
||||||
this.simplifyResultsList = simplifyResultsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String, byte[]> classFiles, Collection<ResultSet> listOfResultSets, SourceFile sf,
|
public BytecodeGen(HashMap<String, byte[]> classFiles, Collection<ResultSet> listOfResultSets, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles, SourceFile sf,
|
||||||
String path) {
|
String path) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
|
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.pkgName = sf.getPkgName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(SourceFile sourceFile) {
|
public void visit(SourceFile sourceFile) {
|
||||||
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, simplifyResultsForAllSourceFiles, sf, path);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
simplifyResultsList.add(classGen.getSimplifyResults());
|
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +143,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
* Associates the bytecode of the class that was build with the classWriter
|
* Associates the bytecode of the class that was build with the classWriter
|
||||||
* {@link #cw} with the class name in the map {@link #classFiles}
|
* {@link #cw} with the class name in the map {@link #classFiles}
|
||||||
*
|
*
|
||||||
* @param name name of the class with which the the bytecode is to be associated
|
* @param name name of the class with which the bytecode is to be associated
|
||||||
*/
|
*/
|
||||||
private void writeClass(String name) {
|
private void writeClass(String name) {
|
||||||
bytecode = cw.toByteArray();
|
bytecode = cw.toByteArray();
|
||||||
@@ -179,73 +170,32 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
fieldInitializations = classOrInterface.getfieldInitializations();
|
fieldInitializations = classOrInterface.getfieldInitializations();
|
||||||
|
|
||||||
// resultSet = listOfResultSets.get(0);
|
// resultSet = listOfResultSets.get(0);
|
||||||
boolean isConsWithNoParamsVisited = false;
|
|
||||||
boolean isVisited = false;
|
boolean isVisited = false;
|
||||||
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
||||||
|
generatedGenerics = simplifyResultsForAllSourceFiles.stream().map(sr->sr.getSimplifyResultsByName(pkgName, className)).findFirst().get();
|
||||||
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||||
//for (ResultSet rs : listOfResultSets) {
|
//for (ResultSet rs : listOfResultSets) {
|
||||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||||
resultSet = listOfResultSetsList.get(i);
|
resultSet = listOfResultSetsList.get(i);
|
||||||
tphExtractor.setResultSet(resultSet);
|
resolver = new Resolver(resultSet);
|
||||||
|
// tphExtractor.setResultSet(resultSet);
|
||||||
|
|
||||||
|
|
||||||
// Nur einmal ausführen!!
|
// Nur einmal ausführen!!
|
||||||
if (!isVisited) {
|
if (!isVisited) {
|
||||||
classOrInterface.accept(tphExtractor);
|
|
||||||
|
|
||||||
getCommonTPHS(tphExtractor);
|
|
||||||
|
|
||||||
tphsClass = new ArrayList<>();
|
|
||||||
for (String t : tphExtractor.allTPHS.keySet()) {
|
|
||||||
if (!tphExtractor.allTPHS.get(t))
|
|
||||||
tphsClass.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
String sig = null;
|
String sig = null;
|
||||||
/*
|
/*
|
||||||
* if class has generics then creates signature Signature looks like:
|
* if class has generics then creates signature Signature looks like:
|
||||||
* <E:Ljava/...>Superclass
|
* <E:Ljava/...>Superclass
|
||||||
*/
|
*/
|
||||||
if (classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty()
|
if (classOrInterface.getGenerics().iterator().hasNext() || classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
||||||
|| classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
|| !generatedGenerics.getClassConstraints().isEmpty()) {
|
||||||
|| !tphsClass.isEmpty()) {
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify
|
|
||||||
.simplifyConstraintsClass(tphExtractor, tphsClass);
|
|
||||||
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
|
||||||
for (TPHConstraint cons : constraints.keySet()) {
|
|
||||||
String right = null;
|
|
||||||
boolean isToAdd = false;
|
|
||||||
for (String tph : tphsClass) {
|
|
||||||
if (cons.getLeft().equals(tph)) {
|
|
||||||
|
|
||||||
consClass.add(cons);
|
List<GenericsGeneratorResult> consClass = generatedGenerics.getClassConstraints();
|
||||||
try {
|
//
|
||||||
right = getTPH(cons.getRight());
|
Signature signature = new Signature(classOrInterface, genericsAndBounds, consClass);
|
||||||
isToAdd = true;
|
sig = signature.createSignatureForClassOrInterface();
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isToAdd) {
|
|
||||||
tphsClass.add(right);
|
|
||||||
removeFromMethod(right);
|
|
||||||
right = null;
|
|
||||||
isToAdd = false;
|
|
||||||
}
|
|
||||||
// if(right != null) {
|
|
||||||
// tphsClass.add(right);
|
|
||||||
// removeFromMethod(right);
|
|
||||||
// right = null;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
SimplifyResult sRes = new SimplifyResult(consClass, tphsClass, new HashMap<>());
|
|
||||||
simplifyResults.put(className, sRes);
|
|
||||||
|
|
||||||
Signature signature = new Signature(classOrInterface, genericsAndBounds, commonPairs, tphsClass,
|
|
||||||
consClass);
|
|
||||||
sig = signature.toString();
|
|
||||||
System.out.println("Signature: => " + sig);
|
System.out.println("Signature: => " + sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,12 +210,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Constructor c : classOrInterface.getConstructors()) {
|
for (Constructor c : classOrInterface.getConstructors()) {
|
||||||
// if(!isConsWithNoParamsVisited) {
|
|
||||||
c.accept(this);
|
c.accept(this);
|
||||||
// }
|
|
||||||
|
|
||||||
// if(!c.getParameterList().iterator().hasNext())
|
|
||||||
// isConsWithNoParamsVisited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Method m : classOrInterface.getMethods()) {
|
for (Method m : classOrInterface.getMethods()) {
|
||||||
@@ -276,69 +221,20 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromMethod(String name) {
|
|
||||||
for (MethodAndTPH m : tphExtractor.ListOfMethodsAndTph) {
|
|
||||||
ArrayList<String> toRemove = new ArrayList<>();
|
|
||||||
for (String tph : m.getTphs()) {
|
|
||||||
if (tph.equals(name)) {
|
|
||||||
toRemove.add(tph);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!toRemove.isEmpty()) {
|
|
||||||
m.getTphs().removeAll(toRemove);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTPH(String name) {
|
|
||||||
for (String tph : tphExtractor.allTPHS.keySet()) {
|
|
||||||
if (tph.equals(name))
|
|
||||||
return tph;
|
|
||||||
}
|
|
||||||
throw new NoSuchElementException("TPH " + name + " does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
|
||||||
// Gemeinsame TPHs
|
|
||||||
ArrayList<String> cTPHs = new ArrayList<>();
|
|
||||||
// Alle TPHs der Felder speichern
|
|
||||||
for (String tph : tphExtractor.allTPHS.keySet()) {
|
|
||||||
if (!tphExtractor.allTPHS.get(tph))
|
|
||||||
cTPHs.add(tph);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Constructor field) {
|
public void visit(Constructor field) {
|
||||||
System.out.println("ResultSet: ");
|
|
||||||
resultSet.results.forEach(a -> {
|
|
||||||
System.out.println(a.getLeft().toString() + " = " + a.getRight().toString());
|
|
||||||
});
|
|
||||||
System.out.println("---------------");
|
|
||||||
|
|
||||||
// stores generics and their bounds of method
|
// stores generics and their bounds of method
|
||||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||||
|
|
||||||
field.getParameterList().accept(this);
|
field.getParameterList().accept(this);
|
||||||
|
|
||||||
String methParamTypes = field.name + "%%";
|
String id = MethodUtility.createID(resolver, field);
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = field.getParameterList().iterator();
|
if (methodNameAndParamsT.contains(id)) {
|
||||||
while (itr.hasNext()) {
|
|
||||||
FormalParameter fp = itr.next();
|
|
||||||
methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";";
|
|
||||||
// methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature())+";";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (methodNameAndParamsT.contains(methParamTypes)) {
|
|
||||||
System.out.println("ignore - Method: " + field.name + " , paramsType: " + methParamTypes);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
methodNameAndParamsT.add(methParamTypes);
|
methodNameAndParamsT.add(id);
|
||||||
System.out.println("Method: " + field.name + " , paramsType: " + methParamTypes);
|
System.out.println("Constructor: " + field.name + " , paramsType: " + id);
|
||||||
|
|
||||||
String desc = null;
|
String desc = null;
|
||||||
boolean hasGen = false;
|
boolean hasGen = false;
|
||||||
@@ -353,10 +249,11 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
}
|
}
|
||||||
String sig = null;
|
String sig = null;
|
||||||
if (hasGen) {
|
if (hasGen) {
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,
|
List<GenericsGeneratorResult> constraints = generatedGenerics.getClassConstraints();
|
||||||
tphsClass);
|
Signature signature = new Signature(genericsAndBounds,
|
||||||
Signature signature = new Signature(field, genericsAndBounds, methodParamsAndTypes, resultSet, constraints);
|
methodParamsAndTypes, resultSet, constraints);
|
||||||
sig = signature.toString();
|
|
||||||
|
sig = signature.createSignatureForConstructor(field);
|
||||||
}
|
}
|
||||||
if (field.getParameterList().iterator().hasNext())
|
if (field.getParameterList().iterator().hasNext())
|
||||||
System.out.println(field.getParameterList().iterator().next().getType().acceptTV(new TypeToDescriptor()));
|
System.out.println(field.getParameterList().iterator().next().getType().acceptTV(new TypeToDescriptor()));
|
||||||
@@ -387,24 +284,19 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
// stored in pos 0
|
// stored in pos 0
|
||||||
// else it will be stored in pos 1 and this will be stored in pos 0
|
// else it will be stored in pos 1 and this will be stored in pos 0
|
||||||
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
// String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
|
||||||
String methParamTypes = retType + method.name + "%%";
|
|
||||||
method.getParameterList().accept(this);
|
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
String id = MethodUtility.createID(resolver, method);
|
||||||
while (itr.hasNext()) {
|
|
||||||
FormalParameter fp = itr.next();
|
|
||||||
methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";";
|
|
||||||
// methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature())+";";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (methodNameAndParamsT.contains(methParamTypes)) {
|
if (methodNameAndParamsT.contains(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
methodNameAndParamsT.add(methParamTypes);
|
methodNameAndParamsT.add(id);
|
||||||
System.out.println("Method: " + method.name + " , paramsType: " + methParamTypes);
|
System.out.println("Method: " + method.name + " , paramsType: " + id);
|
||||||
// stores generics and their bounds of method
|
// stores generics and their bounds of method
|
||||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||||
|
|
||||||
|
method.getParameterList().accept(this);
|
||||||
|
|
||||||
String methDesc = null;
|
String methDesc = null;
|
||||||
|
|
||||||
// Method getModifiers() ?
|
// Method getModifiers() ?
|
||||||
@@ -443,29 +335,17 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
// zwite operand muss weggelassen werden
|
// zwite operand muss weggelassen werden
|
||||||
if (hasGen || resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString())
|
if (hasGen || resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString())
|
||||||
.equals("TPH")) {
|
.equals("TPH")) {
|
||||||
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
|
||||||
tphExtractor.allCons.forEach(c -> System.out.println(c.toString()));
|
|
||||||
System.out.println("----------------");
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name,
|
|
||||||
tphExtractor, tphsClass);
|
|
||||||
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
|
||||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,
|
|
||||||
methodParamsAndTypes, resultSet, constraints);
|
|
||||||
sig = signature.toString();
|
|
||||||
if (simplifyResults.containsKey(className)) {
|
|
||||||
simplifyResults.get(className).getMethodsConstraints().put(methParamTypes, constraints);
|
|
||||||
} else {
|
|
||||||
SimplifyResult sRes = new SimplifyResult(new ArrayList<>(), new ArrayList<>(), new HashMap<>());
|
|
||||||
sRes.getMethodsConstraints().put(methParamTypes, constraints);
|
|
||||||
simplifyResults.put(className, sRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
List<GenericsGeneratorResult> constraints = generatedGenerics.getMethodConstraintsByID(id);
|
||||||
|
List<GenericsGeneratorResult> classConstraints = generatedGenerics.getClassConstraints();
|
||||||
|
Signature signature = new Signature(genericsAndBoundsMethod, genericsAndBounds,
|
||||||
|
methodParamsAndTypes, resultSet, constraints,classConstraints);
|
||||||
|
sig = signature.createSignatureForMethod(method);
|
||||||
}
|
}
|
||||||
System.out.println(method.getName() + " ==> " + sig);
|
System.out.println(method.getName() + " ==> " + sig);
|
||||||
NormalMethod meth = new NormalMethod(method, genericsAndBounds, genericsAndBoundsMethod, hasGen);
|
NormalMethod meth = new NormalMethod(method, genericsAndBounds, genericsAndBoundsMethod, hasGen);
|
||||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||||
|
|
||||||
// System.out.println(methDesc);
|
|
||||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + acc, method.getName(), methDesc, sig, null);
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + acc, method.getName(), methDesc, sig, null);
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
@@ -476,10 +356,6 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, SimplifyResult> getSimplifyResults() {
|
|
||||||
return simplifyResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
paramsAndLocals = new HashMap<>();
|
paramsAndLocals = new HashMap<>();
|
||||||
@@ -550,7 +426,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
}
|
}
|
||||||
des += ";";
|
des += ";";
|
||||||
System.out.println(des);
|
System.out.println(des);
|
||||||
String sig = resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature());
|
String sig = resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature(generatedGenerics.getClassConstraints()));
|
||||||
System.out.println(sig);
|
System.out.println(sig);
|
||||||
if (sig.charAt(sig.length() - 1) != (";").charAt(0)) {
|
if (sig.charAt(sig.length() - 1) != (";").charAt(0)) {
|
||||||
sig += ";";
|
sig += ";";
|
||||||
|
@@ -1,9 +1,5 @@
|
|||||||
package de.dhbwstuttgart.bytecode;
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.invoke.CallSite;
|
import java.lang.invoke.CallSite;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
@@ -14,11 +10,10 @@ import java.net.URLClassLoader;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.*;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
|
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
|
||||||
@@ -30,27 +25,15 @@ import org.objectweb.asm.Label;
|
|||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodCallHelper;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@@ -58,11 +41,12 @@ import javassist.NotFoundException;
|
|||||||
|
|
||||||
public class BytecodeGenMethod implements StatementVisitor {
|
public class BytecodeGenMethod implements StatementVisitor {
|
||||||
|
|
||||||
|
private Resolver resolver;
|
||||||
private Method m;
|
private Method m;
|
||||||
private MethodVisitor mv;
|
private MethodVisitor mv;
|
||||||
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||||
private String className;
|
private String className;
|
||||||
private int lamCounter = -1;
|
private int lamCounter;
|
||||||
private ClassWriter cw;
|
private ClassWriter cw;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
@@ -101,6 +85,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
|
this.resolver = new Resolver(resultSet);
|
||||||
this.m = m;
|
this.m = m;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.paramsAndLocals = paramsAndLocals;
|
this.paramsAndLocals = paramsAndLocals;
|
||||||
@@ -111,6 +96,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.lamCounter = -1;
|
||||||
this.constructorPos = constructorPos;
|
this.constructorPos = constructorPos;
|
||||||
if(block != null)
|
if(block != null)
|
||||||
this.blockFieldInit = block;
|
this.blockFieldInit = block;
|
||||||
@@ -126,6 +112,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
|
this.resolver = new Resolver(resultSet);
|
||||||
this.m = m;
|
this.m = m;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.paramsAndLocals = paramsAndLocals;
|
this.paramsAndLocals = paramsAndLocals;
|
||||||
@@ -136,17 +123,19 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.lamCounter = -1;
|
||||||
if (!isInterface)
|
if (!isInterface)
|
||||||
this.m.block.accept(this);
|
this.m.block.accept(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(String className, ClassWriter cw, LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds) {
|
HashMap<String, String> genericsAndBounds) {
|
||||||
|
this.className = className;
|
||||||
|
this.cw = cw;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
|
this.resolver = new Resolver(resultSet);
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.isInterface = isInterface;
|
this.isInterface = isInterface;
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
@@ -172,21 +161,22 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
lambdaExpression.methodBody.accept(this);
|
lambdaExpression.methodBody.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Resolver getResolver() {
|
||||||
|
return resolver;
|
||||||
|
}
|
||||||
|
|
||||||
public void isBinary(boolean isBinary) {
|
public void isBinary(boolean isBinary) {
|
||||||
this.isBinaryExp =isBinary;
|
this.isBinaryExp =isBinary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
|
||||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Block block) {
|
public void visit(Block block) {
|
||||||
for (Statement stmt : block.getStatements()) {
|
for (Statement stmt : block.getStatements()) {
|
||||||
stmt.accept(this);
|
stmt.accept(this);
|
||||||
if(stmt instanceof MethodCall) {
|
if(stmt instanceof MethodCall) {
|
||||||
String ret = getResolvedType(((MethodCall) stmt).getType());
|
String ret = resolver.getResolvedType(((MethodCall) stmt).getType());
|
||||||
if(!ret.equals("void"))
|
if(!ret.equals(CONSTANTS.VOID))
|
||||||
mv.visitInsn(Opcodes.POP);
|
mv.visitInsn(Opcodes.POP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +210,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
||||||
|
|
||||||
if (isBinaryExp) {
|
if (isBinaryExp) {
|
||||||
doUnboxing(getResolvedType(localVar.getType()));
|
doUnboxing(resolver.getResolvedType(localVar.getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,16 +238,20 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
} else {
|
} else {
|
||||||
assign.rightSide.accept(this);
|
assign.rightSide.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statement = new AssignStmt(assign.rightSide);
|
||||||
|
isBinaryExp = statement.isExprBinary();
|
||||||
|
|
||||||
if (isBinaryExp) {
|
if (isBinaryExp) {
|
||||||
BinaryExpr binary = (BinaryExpr) assign.rightSide;
|
BinaryExpr binary = (BinaryExpr) assign.rightSide;
|
||||||
String binaryType = getResolvedType(binary.getType());
|
String binaryType = resolver.getResolvedType(binary.getType());
|
||||||
doBoxing(binaryType);
|
doBoxing(binaryType);
|
||||||
isBinaryExp = false;
|
isBinaryExp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("ASSIGN TYPE R: " + getResolvedType(assign.rightSide.getType()));
|
System.out.println("ASSIGN TYPE R: " + resolver.getResolvedType(assign.rightSide.getType()));
|
||||||
String typeOfRightSide = getResolvedType(assign.rightSide.getType());
|
String typeOfRightSide = resolver.getResolvedType(assign.rightSide.getType());
|
||||||
if(typeOfRightSide.contains("<")) {
|
if(typeOfRightSide.contains(CONSTANTS.ANGLEBRACKET)) {
|
||||||
mv.visitTypeInsn(Opcodes.CHECKCAST, typeOfRightSide.substring(0, typeOfRightSide.indexOf('<')));
|
mv.visitTypeInsn(Opcodes.CHECKCAST, typeOfRightSide.substring(0, typeOfRightSide.indexOf('<')));
|
||||||
}
|
}
|
||||||
assign.lefSide.accept(this);
|
assign.lefSide.accept(this);
|
||||||
@@ -268,11 +262,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(BinaryExpr binary) {
|
public void visit(BinaryExpr binary) {
|
||||||
isParentBinary = true;
|
isParentBinary = true;
|
||||||
String lexpType = getResolvedType(binary.lexpr.getType());
|
String lexpType = resolver.getResolvedType(binary.lexpr.getType());
|
||||||
String rexpType = getResolvedType(binary.rexpr.getType());
|
String rexpType = resolver.getResolvedType(binary.rexpr.getType());
|
||||||
|
|
||||||
String largerType = getLargerType(lexpType, rexpType);
|
String largerType = getLargerType(lexpType, rexpType);
|
||||||
String typeOfBinary = getResolvedType(binary.getType());
|
String typeOfBinary = resolver.getResolvedType(binary.getType());
|
||||||
|
|
||||||
if (typeOfBinary.equals(Type.getInternalName(String.class))) {
|
if (typeOfBinary.equals(Type.getInternalName(String.class))) {
|
||||||
mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(StringBuilder.class));
|
mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(StringBuilder.class));
|
||||||
@@ -291,6 +285,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
binary.lexpr.accept(this);
|
binary.lexpr.accept(this);
|
||||||
|
|
||||||
|
if(lexpType.equals(Type.getInternalName(String.class))) {
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append",
|
||||||
|
"(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
}
|
||||||
|
|
||||||
if (!lexpType.equals(rexpType) && !lexpType.equals(largerType))
|
if (!lexpType.equals(rexpType) && !lexpType.equals(largerType))
|
||||||
doCast(lexpType, largerType);
|
doCast(lexpType, largerType);
|
||||||
|
|
||||||
@@ -298,7 +297,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
needDUP = true;
|
needDUP = true;
|
||||||
|
|
||||||
binary.rexpr.accept(this);
|
binary.rexpr.accept(this);
|
||||||
|
if(rexpType.equals(Type.getInternalName(String.class))) {
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append",
|
||||||
|
"(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
}
|
||||||
isParentBinary = false;
|
isParentBinary = false;
|
||||||
|
|
||||||
if (!lexpType.equals(rexpType) && !rexpType.equals(largerType))
|
if (!lexpType.equals(rexpType) && !rexpType.equals(largerType))
|
||||||
@@ -362,11 +364,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doCast(String sourceType, String dest) {
|
private void doCast(String sourceType, String dest) {
|
||||||
switch (dest) {
|
switch (dest) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.I2L);
|
mv.visitInsn(Opcodes.I2L);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
if (sourceType.equals(Type.getInternalName(Long.class))) {
|
if (sourceType.equals(Type.getInternalName(Long.class))) {
|
||||||
mv.visitInsn(Opcodes.L2D);
|
mv.visitInsn(Opcodes.L2D);
|
||||||
} else if (sourceType.equals(Type.getInternalName(Float.class))) {
|
} else if (sourceType.equals(Type.getInternalName(Float.class))) {
|
||||||
@@ -376,15 +378,15 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
if (sourceType.equals(Type.getInternalName(Long.class))) {
|
if (sourceType.equals(Type.getInternalName(Long.class))) {
|
||||||
mv.visitInsn(Opcodes.L2F);
|
mv.visitInsn(Opcodes.L2F);
|
||||||
} else {
|
} else {
|
||||||
mv.visitInsn(Opcodes.I2F);
|
mv.visitInsn(Opcodes.I2F);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// braucht man eigentlic nicht, muss getestet werden
|
// braucht man eigentlich nicht, muss getestet werden
|
||||||
case "java/lang/String":
|
case CONSTANTS.REFTYPE_STRING:
|
||||||
if (sourceType.equals(Type.getInternalName(Double.class))) {
|
if (sourceType.equals(Type.getInternalName(Double.class))) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf",
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf",
|
||||||
"(D)Ljava/lang/String;", false);
|
"(D)Ljava/lang/String;", false);
|
||||||
@@ -407,15 +409,15 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
private void doVisitRelOpInsn(Operator op, String typeOfBinary, Label branchLabel, Label endLabel) {
|
private void doVisitRelOpInsn(Operator op, String typeOfBinary, Label branchLabel, Label endLabel) {
|
||||||
System.out.println("TypeOfBinary: " + typeOfBinary);
|
System.out.println("TypeOfBinary: " + typeOfBinary);
|
||||||
switch (typeOfBinary) {
|
switch (typeOfBinary) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LCMP);
|
mv.visitInsn(Opcodes.LCMP);
|
||||||
doVisitIfInRelOp(op, branchLabel, endLabel);
|
doVisitIfInRelOp(op, branchLabel, endLabel);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DCMPG);
|
mv.visitInsn(Opcodes.DCMPG);
|
||||||
doVisitIfInRelOp(op, branchLabel, endLabel);
|
doVisitIfInRelOp(op, branchLabel, endLabel);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FCMPG);
|
mv.visitInsn(Opcodes.FCMPG);
|
||||||
doVisitIfInRelOp(op, branchLabel, endLabel);
|
doVisitIfInRelOp(op, branchLabel, endLabel);
|
||||||
break;
|
break;
|
||||||
@@ -479,13 +481,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doVisitModOpInsn(String typeOfBinary) {
|
private void doVisitModOpInsn(String typeOfBinary) {
|
||||||
switch (typeOfBinary) {
|
switch (typeOfBinary) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LREM);
|
mv.visitInsn(Opcodes.LREM);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DREM);
|
mv.visitInsn(Opcodes.DREM);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FREM);
|
mv.visitInsn(Opcodes.FREM);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -496,13 +498,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doVisitDivOpInsn(String typeOfBinary) {
|
private void doVisitDivOpInsn(String typeOfBinary) {
|
||||||
switch (typeOfBinary) {
|
switch (typeOfBinary) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LDIV);
|
mv.visitInsn(Opcodes.LDIV);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DDIV);
|
mv.visitInsn(Opcodes.DDIV);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FDIV);
|
mv.visitInsn(Opcodes.FDIV);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -513,13 +515,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doVisitMulOpInsn(String typeOfBinary) {
|
private void doVisitMulOpInsn(String typeOfBinary) {
|
||||||
switch (typeOfBinary) {
|
switch (typeOfBinary) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LMUL);
|
mv.visitInsn(Opcodes.LMUL);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DMUL);
|
mv.visitInsn(Opcodes.DMUL);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FMUL);
|
mv.visitInsn(Opcodes.FMUL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -530,13 +532,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doVisitSubOpInsn(String typeOfBinary) {
|
private void doVisitSubOpInsn(String typeOfBinary) {
|
||||||
switch (typeOfBinary) {
|
switch (typeOfBinary) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LSUB);
|
mv.visitInsn(Opcodes.LSUB);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DSUB);
|
mv.visitInsn(Opcodes.DSUB);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FSUB);
|
mv.visitInsn(Opcodes.FSUB);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -548,24 +550,28 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doVisitAddOpInsn(String typeOfBinary) {
|
private void doVisitAddOpInsn(String typeOfBinary) {
|
||||||
switch (typeOfBinary) {
|
switch (typeOfBinary) {
|
||||||
case "java/lang/Byte":
|
case CONSTANTS.REFTYPE_BYTE:
|
||||||
mv.visitInsn(Opcodes.IADD);
|
mv.visitInsn(Opcodes.IADD);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case CONSTANTS.REFTYPE_SHORT:
|
||||||
mv.visitInsn(Opcodes.IADD);
|
mv.visitInsn(Opcodes.IADD);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Integer":
|
case CONSTANTS.REFTYPE_INTEGER:
|
||||||
mv.visitInsn(Opcodes.IADD);
|
mv.visitInsn(Opcodes.IADD);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LADD);
|
mv.visitInsn(Opcodes.LADD);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DADD);
|
mv.visitInsn(Opcodes.DADD);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FADD);
|
mv.visitInsn(Opcodes.FADD);
|
||||||
break;
|
break;
|
||||||
|
case CONSTANTS.REFTYPE_STRING:
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", CONSTANTS.TO_STRING, "()Ljava/lang/String;",
|
||||||
|
false);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -575,16 +581,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
this.lamCounter++;
|
this.lamCounter++;
|
||||||
|
|
||||||
String typeErasure = "(";
|
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
itr.next();
|
|
||||||
typeErasure += "L" + Type.getInternalName(Object.class) + ";";
|
|
||||||
}
|
|
||||||
|
|
||||||
typeErasure += ")L" + Type.getInternalName(Object.class) + ";";
|
ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path);
|
||||||
|
|
||||||
generateBCForFunN(lambdaExpression, typeErasure);
|
|
||||||
|
|
||||||
|
|
||||||
Lambda lam = new Lambda(lambdaExpression);
|
Lambda lam = new Lambda(lambdaExpression);
|
||||||
@@ -597,7 +596,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
|
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
|
||||||
mt.toMethodDescriptorString(), false);
|
mt.toMethodDescriptorString(), false);
|
||||||
String methodName = "lambda$new$" + this.lamCounter;
|
String desugaredMethodName = CONSTANTS.DESUGAREDMETHODNAME + this.lamCounter;
|
||||||
|
|
||||||
// Für die Parameter-Typen und Return-Typ braucht man die Bounds (für die
|
// Für die Parameter-Typen und Return-Typ braucht man die Bounds (für die
|
||||||
// Typlöschung)
|
// Typlöschung)
|
||||||
@@ -608,37 +607,22 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// real Type
|
// real Type
|
||||||
Type arg3 = Type.getMethodType(lamDesc);
|
Type arg3 = Type.getMethodType(lamDesc);
|
||||||
|
|
||||||
int staticOrSpecial = 0;
|
int staticOrSpecial, staticOrInstance = 0, indexOfFirstParamLam = 0;
|
||||||
int staticOrInstance = 0;
|
|
||||||
int indexOfFirstParamLam = 0;
|
|
||||||
this.kindOfLambda = new KindOfLambda(lambdaExpression);
|
this.kindOfLambda = new KindOfLambda(lambdaExpression);
|
||||||
|
|
||||||
if (kindOfLambda.isInstanceCapturingLambda()) {
|
if (kindOfLambda.isInstanceCapturingLambda()) {
|
||||||
// if(!kindOfLambda.getArgumentList().contains(BytecodeGen.THISTYPE))
|
|
||||||
// kindOfLambda.getArgumentList().add(0, BytecodeGen.THISTYPE);
|
|
||||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
for(String v : kindOfLambda.getUsedVars()) {
|
loadUsedVarsInLambda();
|
||||||
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(v));
|
|
||||||
}
|
|
||||||
staticOrSpecial = Opcodes.H_INVOKESPECIAL;
|
staticOrSpecial = Opcodes.H_INVOKESPECIAL;
|
||||||
indexOfFirstParamLam = 1;
|
indexOfFirstParamLam = 1;
|
||||||
} else {
|
} else {
|
||||||
staticOrSpecial = Opcodes.H_INVOKESTATIC;
|
staticOrSpecial = Opcodes.H_INVOKESTATIC;
|
||||||
staticOrInstance = Opcodes.ACC_STATIC;
|
staticOrInstance = Opcodes.ACC_STATIC;
|
||||||
}
|
}
|
||||||
String newDesc = "(";
|
String newDesc = addUsedVarsToDesugaredMethodDescriptor(lamDesc);
|
||||||
int pos = 0;
|
|
||||||
if(kindOfLambda.isHasThis()) {
|
|
||||||
pos = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i=pos;i<kindOfLambda.getArgumentList().size();i++) {
|
|
||||||
String t = "L" + getResolvedType(kindOfLambda.getArgumentList().get(i)) + ";";
|
|
||||||
newDesc += t;
|
|
||||||
}
|
|
||||||
newDesc += lamDesc.substring(1);
|
|
||||||
// first check if capturing lambda then invokestatic or invokespecial
|
// first check if capturing lambda then invokestatic or invokespecial
|
||||||
Handle arg2 = new Handle(staticOrSpecial, this.className, methodName, newDesc, false);
|
Handle arg2 = new Handle(staticOrSpecial, this.className, desugaredMethodName, newDesc, false);
|
||||||
// Descriptor of functional interface methode
|
// Descriptor of functional interface methode
|
||||||
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
||||||
// Desc: (this/nothing)TargetType
|
// Desc: (this/nothing)TargetType
|
||||||
@@ -646,11 +630,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
mv.visitInvokeDynamicInsn("apply", fiMethodDesc, bootstrap, arg1, arg2, arg3);
|
mv.visitInvokeDynamicInsn("apply", fiMethodDesc, bootstrap, arg1, arg2, arg3);
|
||||||
if(constructorPos<2) {
|
if(constructorPos<2) {
|
||||||
MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE + staticOrInstance + Opcodes.ACC_SYNTHETIC,
|
MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE + staticOrInstance + Opcodes.ACC_SYNTHETIC,
|
||||||
methodName, newDesc, null, null);
|
desugaredMethodName, newDesc, null, null);
|
||||||
|
|
||||||
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
||||||
|
|
||||||
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
new BytecodeGenMethod(className, cw,lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||||
classFiles,this.path, lamCounter, sf, genericsAndBoundsMethod,
|
classFiles,this.path, lamCounter, sf, genericsAndBoundsMethod,
|
||||||
genericsAndBounds);
|
genericsAndBounds);
|
||||||
|
|
||||||
@@ -662,48 +646,40 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// generateBCForFunN(lambdaExpression, typeErasure);
|
// generateBCForFunN(lambdaExpression, typeErasure);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc) {
|
private String addUsedVarsToDesugaredMethodDescriptor(String lamDesc) {
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
String newDesc = "(";
|
||||||
|
int pos = 0;
|
||||||
|
if(kindOfLambda.isThisUsed()) {
|
||||||
|
pos = 1;
|
||||||
|
}
|
||||||
|
|
||||||
SignatureWriter methSig = new SignatureWriter();
|
for(int i=pos;i<kindOfLambda.getArgumentList().size();i++) {
|
||||||
|
String t = "L" + resolver.getResolvedType(kindOfLambda.getArgumentList().get(i)) + ";";
|
||||||
|
newDesc += t;
|
||||||
|
}
|
||||||
|
newDesc += lamDesc.substring(1);
|
||||||
|
return newDesc;
|
||||||
|
}
|
||||||
|
|
||||||
int numberOfParams = 0;
|
private void loadUsedVarsInLambda() {
|
||||||
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
for(String v : kindOfLambda.getUsedVars()) {
|
||||||
|
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createDescriptorWithTypeErasure(LambdaExpression lambdaExpression) {
|
||||||
|
String typeErasure = "(";
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
numberOfParams++;
|
|
||||||
// getBounds
|
|
||||||
paramVisitor.visitTypeVariable("T" + numberOfParams);
|
|
||||||
itr.next();
|
itr.next();
|
||||||
}
|
typeErasure += "L" + Type.getInternalName(Object.class) + ";";
|
||||||
methSig.visitReturnType().visitTypeVariable("R");
|
|
||||||
// ")"+lam.getReturn.getBounds
|
|
||||||
Signature sig = new Signature(numberOfParams);
|
|
||||||
String name = "Fun" + numberOfParams + "$$";
|
|
||||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
|
||||||
Type.getInternalName(Object.class), null);
|
|
||||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
|
||||||
methSig.toString(), null);
|
|
||||||
mvApply.visitEnd();
|
|
||||||
writeClassFile(classWriter.toByteArray(), name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeClassFile(byte[] bytecode, String name) {
|
typeErasure += ")L" + Type.getInternalName(Object.class) + ";";
|
||||||
FileOutputStream output;
|
return typeErasure;
|
||||||
try {
|
|
||||||
System.out.println("generating " + name + ".class file...");
|
|
||||||
output = new FileOutputStream(
|
|
||||||
new File(path + name + ".class"));
|
|
||||||
output.write(bytecode);
|
|
||||||
output.close();
|
|
||||||
System.out.println(name + ".class file generated");
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(CastExpr castExpr) {
|
public void visit(CastExpr castExpr) {
|
||||||
@@ -730,11 +706,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
fieldVar.receiver.accept(this);
|
fieldVar.receiver.accept(this);
|
||||||
// test (if)
|
// test (if)
|
||||||
if (!fieldVar.receiver.getClass().equals(StaticClassName.class)) {
|
if (!fieldVar.receiver.getClass().equals(StaticClassName.class)) {
|
||||||
mv.visitFieldInsn(Opcodes.GETFIELD, getResolvedType(fieldVar.receiver.getType()), fieldName, fieldDesc);
|
mv.visitFieldInsn(Opcodes.GETFIELD, resolver.getResolvedType(fieldVar.receiver.getType()), fieldName, fieldDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBinaryExp) {
|
if (isBinaryExp) {
|
||||||
doUnboxing(getResolvedType(fieldVar.getType()));
|
doUnboxing(resolver.getResolvedType(fieldVar.getType()));
|
||||||
}
|
}
|
||||||
// mv.visitFieldInsn(Opcodes.GETSTATIC,
|
// mv.visitFieldInsn(Opcodes.GETSTATIC,
|
||||||
// fieldVar.receiver.getType().toString().replace(".", "/"),
|
// fieldVar.receiver.getType().toString().replace(".", "/"),
|
||||||
@@ -753,7 +729,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
isBinaryExp = statement.isExprBinary();
|
isBinaryExp = statement.isExprBinary();
|
||||||
ifStmt.expr.accept(this);
|
ifStmt.expr.accept(this);
|
||||||
if(!(ifStmt.expr instanceof BinaryExpr)) {
|
if(!(ifStmt.expr instanceof BinaryExpr)) {
|
||||||
doUnboxing(getResolvedType(ifStmt.expr.getType()));
|
doUnboxing(resolver.getResolvedType(ifStmt.expr.getType()));
|
||||||
Label branchLabel = new Label();
|
Label branchLabel = new Label();
|
||||||
Label endLabel = new Label();
|
Label endLabel = new Label();
|
||||||
mv.visitJumpInsn(Opcodes.IFEQ, branchLabel);
|
mv.visitJumpInsn(Opcodes.IFEQ, branchLabel);
|
||||||
@@ -771,7 +747,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
boolean parentBinary = isParentBinary;
|
boolean parentBinary = isParentBinary;
|
||||||
System.out.println("In MethodCall = " + methodCall.name);
|
System.out.println("In MethodCall = " + methodCall.name);
|
||||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
String receiverName = resolver.getResolvedType(methodCall.receiver.getType());
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
java.lang.reflect.Method methodRefl = null;
|
java.lang.reflect.Method methodRefl = null;
|
||||||
String clazz = receiverName.replace("/", ".");
|
String clazz = receiverName.replace("/", ".");
|
||||||
@@ -780,8 +756,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
||||||
|
|
||||||
boolean toCreate = false;
|
|
||||||
|
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
||||||
// 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)
|
||||||
ClassLoader cLoader2;
|
ClassLoader cLoader2;
|
||||||
@@ -789,9 +763,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
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());
|
||||||
try {
|
try {
|
||||||
if (receiverName.contains("<")) {
|
clazz = getRawClassName(receiverName, clazz);
|
||||||
clazz = clazz.substring(0, receiverName.indexOf("<"));
|
|
||||||
}
|
|
||||||
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
@@ -805,18 +777,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String superClazz = superClass.replace("/", ".");
|
String superClazz = superClass.replace("/", ".");
|
||||||
if(superClass.contains("<")) {
|
superClazz = getRawClassName(superClass, superClazz);
|
||||||
superClazz = superClazz.substring(0, superClass.indexOf("<"));
|
|
||||||
}
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
||||||
System.out.println("Methods of " + superClass + " ");
|
System.out.println("Methods of " + superClass + " ");
|
||||||
|
|
||||||
for(java.lang.reflect.Method m : methods) {
|
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
||||||
if(methodCall.name.equals(m.getName())) {
|
|
||||||
methodRefl = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} catch (Exception e3) {
|
} catch (Exception e3) {
|
||||||
@@ -832,7 +797,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null) {
|
||||||
toCreate = !receiverName.equals(className) && helper.isInCurrPkg(clazz);
|
boolean toCreate = !receiverName.equals(className) && helper.isInCurrPkg(clazz);
|
||||||
if(toCreate) {
|
if(toCreate) {
|
||||||
try {
|
try {
|
||||||
mDesc = helper.getDesc(clazz);
|
mDesc = helper.getDesc(clazz);
|
||||||
@@ -840,8 +805,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if(!helper.isInCurrPkg(clazz)){
|
} else if(!helper.isInCurrPkg(clazz)){
|
||||||
if(clazz.contains("$$")) {
|
if(clazz.contains(CONSTANTS.$$)) {
|
||||||
mDesc = helper.generateBCForFunN();
|
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
||||||
|
helper.generateBCForFunN(mDesc);
|
||||||
|
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
@@ -873,18 +840,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
} else if(methodRefl != null) {
|
} else if(methodRefl != null) {
|
||||||
System.out.println(methodCall.name + " -> Refl != null");
|
System.out.println(methodCall.name + " -> Refl != null");
|
||||||
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
||||||
for(Parameter p:methodRefl.getParameters()) {
|
getBoolListOfType(methodRefl, argListMethCall);
|
||||||
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
|
||||||
argListMethCall.add(p.getType().isPrimitive());
|
|
||||||
}
|
|
||||||
System.out.println("Receiver = " + methodRefl.getAnnotatedReceiverType().getType().toString());
|
System.out.println("Receiver = " + methodRefl.getAnnotatedReceiverType().getType().toString());
|
||||||
mDesc = getMethodDesc(methodRefl);
|
mDesc = getMethodDesc(methodRefl);
|
||||||
for (Expression al : methodCall.arglist.getArguments()) {
|
visitArgumentListOfMethodCallFromStandardAPI(methodCall, argListMethCall);
|
||||||
statement = new ArgumentExpr(al);
|
|
||||||
ArgumentVisitor argV = new ArgumentVisitor(argListMethCall,this);
|
|
||||||
al.accept(argV);
|
|
||||||
statement = null;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
}
|
}
|
||||||
@@ -893,54 +852,69 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
|
|
||||||
// methodCall.arglist.accept(this);
|
// methodCall.arglist.accept(this);
|
||||||
|
visitInvokeInsn(methodCall, receiverName, methodRefl, clazz, mDesc, receiverRefl);
|
||||||
|
|
||||||
|
|
||||||
|
if(methodRefl != null && !methodRefl.getReturnType().isPrimitive()) {
|
||||||
|
if(methodRefl.getReturnType().equals(Object.class)) {
|
||||||
|
helper.createCheckCast(methodCall,mv);
|
||||||
|
}
|
||||||
|
/*if(isBinaryExp) {
|
||||||
|
doUnboxing(resolver.getResolvedType(methodCall.getType()));
|
||||||
|
}*/
|
||||||
|
if(parentBinary || isBinaryExp) {
|
||||||
|
doUnboxing(resolver.getResolvedType(methodCall.getType()));
|
||||||
|
}
|
||||||
|
} else if(receiverName.contains(CONSTANTS.$$) && !methCallType.equals(Type.getInternalName(Object.class))) {
|
||||||
|
helper.createCheckCast(methodCall,mv);
|
||||||
|
}
|
||||||
|
System.out.println("ISParent Binary = "+isParentBinary +" -> " + parentBinary);
|
||||||
|
if(methodRefl == null && (parentBinary || !isReturnStmt)) {
|
||||||
|
if(isBinaryExp)
|
||||||
|
doUnboxing(resolver.getResolvedType(methodCall.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getBoolListOfType(java.lang.reflect.Method methodRefl, List<Boolean> argListMethCall) {
|
||||||
|
for(Parameter p:methodRefl.getParameters()) {
|
||||||
|
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
||||||
|
argListMethCall.add(p.getType().isPrimitive());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void visitArgumentListOfMethodCallFromStandardAPI(MethodCall methodCall, List<Boolean> argListMethCall) {
|
||||||
|
for (Expression al : methodCall.arglist.getArguments()) {
|
||||||
|
statement = new ArgumentExpr(al);
|
||||||
|
ArgumentVisitor argV = new ArgumentVisitor(argListMethCall,this);
|
||||||
|
al.accept(argV);
|
||||||
|
statement = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void visitInvokeInsn(MethodCall methodCall, String receiverName, java.lang.reflect.Method methodRefl, String clazz, String mDesc, String receiverRefl) {
|
||||||
// is methodCall.receiver functional Interface)?
|
// is methodCall.receiver functional Interface)?
|
||||||
if (varsFunInterface.contains(methodCall.receiver.getType()) || (methodRefl!= null && receiverRefl.contains("interface"))) {
|
if (varsFunInterface.contains(methodCall.receiver.getType()) || (methodRefl!= null && receiverRefl.contains("interface")) ||
|
||||||
|
receiverName.contains(CONSTANTS.$$)) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, clazz.replace(".", "/"), methodCall.name,
|
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, clazz.replace(".", "/"), methodCall.name,
|
||||||
mDesc, true);
|
mDesc, true);
|
||||||
} else {
|
} else {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazz.replace(".", "/"), methodCall.name,
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazz.replace(".", "/"), methodCall.name,
|
||||||
mDesc, isInterface);
|
mDesc, isInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl != null && !methodRefl.getReturnType().isPrimitive()) {
|
|
||||||
if(methodRefl.getReturnType().equals(Object.class)) {
|
|
||||||
String checkCast = getResolvedType(methodCall.getType());
|
|
||||||
if(!checkCast.contains("TPH ")) {
|
|
||||||
int pos = checkCast.length();
|
|
||||||
if(checkCast.contains("<"))
|
|
||||||
pos = checkCast.indexOf("<");
|
|
||||||
mv.visitTypeInsn(Opcodes.CHECKCAST,checkCast.substring(0,pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isBinaryExp)
|
|
||||||
doUnboxing(getResolvedType(methodCall.getType()));
|
|
||||||
}
|
|
||||||
System.out.println("ISParent Binary = "+isParentBinary +" -> " + parentBinary);
|
|
||||||
if(methodRefl == null && (parentBinary || !isReturnStmt)) {
|
|
||||||
if(isBinaryExp)
|
|
||||||
doUnboxing(getResolvedType(methodCall.getType()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getRawClassName(String receiverName, String clazz) {
|
||||||
|
if (receiverName.contains(CONSTANTS.ANGLEBRACKET)) {
|
||||||
|
clazz = clazz.substring(0, receiverName.indexOf(CONSTANTS.ANGLEBRACKET));
|
||||||
}
|
}
|
||||||
|
return clazz;
|
||||||
private String getDescForMethInCurrPkg(String name) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInCurrPkg(String superClass) {
|
|
||||||
for(ClassOrInterface cl : sf.KlassenVektor) {
|
|
||||||
if(superClass.equals(cl.getClassName().toString()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getTypes(List<Expression> arguments) {
|
private String[] getTypes(List<Expression> arguments) {
|
||||||
String[] types = new String[arguments.size()];
|
String[] types = new String[arguments.size()];
|
||||||
for(int i = 0; i<arguments.size(); ++i) {
|
for(int i = 0; i<arguments.size(); ++i) {
|
||||||
String t = getResolvedType(arguments.get(i).getType());
|
String t = resolver.getResolvedType(arguments.get(i).getType());
|
||||||
types[i] = t;
|
types[i] = t;
|
||||||
}
|
}
|
||||||
return types;
|
return types;
|
||||||
@@ -1043,15 +1017,24 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
mv.visitInsn(Opcodes.DUP);
|
mv.visitInsn(Opcodes.DUP);
|
||||||
// creates Descriptor
|
// creates Descriptor
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
String d = "(";
|
String d = createDescriptorForInitMethod(methodCall);
|
||||||
for (Expression e : methodCall.arglist.getArguments()) {
|
|
||||||
d = d + "L" + getResolvedType(e.getType()) + ";";
|
|
||||||
}
|
|
||||||
d += ")V";
|
|
||||||
|
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, methodCall.name.replace(".", "/"), "<init>", d, isInterface);
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, methodCall.name.replace(".", "/"), "<init>", d, isInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createDescriptorForInitMethod(NewClass methodCall) {
|
||||||
|
String d = "(";
|
||||||
|
for (Expression e : methodCall.arglist.getArguments()) {
|
||||||
|
String type = resolver.getResolvedType(e.getType());
|
||||||
|
if(type.contains("TPH ")){
|
||||||
|
type = Type.getInternalName(Object.class);
|
||||||
|
}
|
||||||
|
d = d + "L" + type + ";";
|
||||||
|
}
|
||||||
|
d += ")V";
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NewArray newArray) {
|
public void visit(NewArray newArray) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
@@ -1068,7 +1051,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
unaryExpr.expr.accept(this);
|
unaryExpr.expr.accept(this);
|
||||||
Operation op = unaryExpr.operation;
|
Operation op = unaryExpr.operation;
|
||||||
|
|
||||||
String typeOfUnary = getResolvedType(unaryExpr.getType());
|
String typeOfUnary = resolver.getResolvedType(unaryExpr.getType());
|
||||||
|
|
||||||
boolean isIncOrDec = false;
|
boolean isIncOrDec = false;
|
||||||
|
|
||||||
@@ -1112,13 +1095,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void doVisitNegIns(String typeOfUnary) {
|
private void doVisitNegIns(String typeOfUnary) {
|
||||||
switch (typeOfUnary) {
|
switch (typeOfUnary) {
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitInsn(Opcodes.LNEG);
|
mv.visitInsn(Opcodes.LNEG);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitInsn(Opcodes.DNEG);
|
mv.visitInsn(Opcodes.DNEG);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitInsn(Opcodes.FNEG);
|
mv.visitInsn(Opcodes.FNEG);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1162,7 +1145,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
if (isBinary) {
|
if (isBinary) {
|
||||||
BinaryExpr binary = (BinaryExpr) aReturn.retexpr;
|
BinaryExpr binary = (BinaryExpr) aReturn.retexpr;
|
||||||
doBoxing(getResolvedType(binary.getType()));
|
doBoxing(resolver.getResolvedType(binary.getType()));
|
||||||
// isBinaryExp = false;
|
// isBinaryExp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1218,7 +1201,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Literal literal) {
|
public void visit(Literal literal) {
|
||||||
Object value = literal.value;
|
Object value = literal.value;
|
||||||
String typeOfLiteral = getResolvedType(literal.getType());
|
String typeOfLiteral = resolver.getResolvedType(literal.getType());
|
||||||
System.out.println("typeOfLiteral :=> "+ typeOfLiteral);
|
System.out.println("typeOfLiteral :=> "+ typeOfLiteral);
|
||||||
// Der Wert des Literals wird auf den Stack geladen und
|
// Der Wert des Literals wird auf den Stack geladen und
|
||||||
// geboxt, wenn es nötig ist.
|
// geboxt, wenn es nötig ist.
|
||||||
@@ -1228,31 +1211,31 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// Unboxing: RefType -> prim
|
// Unboxing: RefType -> prim
|
||||||
public void doUnboxing(String type) {
|
public void doUnboxing(String type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "java/lang/String":
|
// case "java/lang/String":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append",
|
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append",
|
||||||
"(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
// "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
//
|
||||||
break;
|
// break;
|
||||||
case "java/lang/Boolean":
|
case "java/lang/Boolean":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case CONSTANTS.REFTYPE_BYTE:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CONSTANTS.REFTYPE_BYTE, "byteValue", "()B", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case CONSTANTS.REFTYPE_SHORT:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CONSTANTS.REFTYPE_SHORT, "shortValue", "()S", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Integer":
|
case "java/lang/Integer":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CONSTANTS.REFTYPE_LONG, "longValue", "()J", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CONSTANTS.REFTYPE_FLOAT, "floatValue", "()F", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CONSTANTS.REFTYPE_DOUBLE, "doubleValue", "()D", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Character":
|
case "java/lang/Character":
|
||||||
break;
|
break;
|
||||||
@@ -1265,19 +1248,19 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private void loadValue(String type, Object value, boolean isOperator) {
|
private void loadValue(String type, Object value, boolean isOperator) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "java/lang/String":
|
case CONSTANTS.REFTYPE_STRING:
|
||||||
mv.visitLdcInsn(String.valueOf(value));
|
mv.visitLdcInsn(String.valueOf(value));
|
||||||
break;
|
break;
|
||||||
case "java/lang/Boolean":
|
case "java/lang/Boolean":
|
||||||
visitBooleanLiteral((Boolean) value);
|
visitBooleanLiteral((Boolean) value);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case CONSTANTS.REFTYPE_BYTE:
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
visitByteLiteral(((Double) value).byteValue(), false);
|
visitByteLiteral(((Double) value).byteValue(), false);
|
||||||
if(value instanceof Integer)
|
if(value instanceof Integer)
|
||||||
visitByteLiteral(((Integer) value).byteValue(), false);
|
visitByteLiteral(((Integer) value).byteValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case CONSTANTS.REFTYPE_SHORT:
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
visitShortLiteral(((Double) value).shortValue(), false);
|
visitShortLiteral(((Double) value).shortValue(), false);
|
||||||
if(value instanceof Integer)
|
if(value instanceof Integer)
|
||||||
@@ -1291,19 +1274,19 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
if(value instanceof Integer)
|
if(value instanceof Integer)
|
||||||
visitIntegerLiteral(((Integer) value).intValue(), false);
|
visitIntegerLiteral(((Integer) value).intValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
visitLongLiteral(((Double) value).longValue(), true);
|
visitLongLiteral(((Double) value).longValue(), true);
|
||||||
if(value instanceof Integer)
|
if(value instanceof Integer)
|
||||||
visitLongLiteral(((Integer) value).longValue(), true);
|
visitLongLiteral(((Integer) value).longValue(), true);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
visitFloatLiteral(((Double) value).floatValue());
|
visitFloatLiteral(((Double) value).floatValue());
|
||||||
if(value instanceof Integer)
|
if(value instanceof Integer)
|
||||||
visitFloatLiteral(((Integer) value).floatValue());
|
visitFloatLiteral(((Integer) value).floatValue());
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
visitDoubleLiteral((Double) value);
|
visitDoubleLiteral((Double) value);
|
||||||
if(value instanceof Integer)
|
if(value instanceof Integer)
|
||||||
@@ -1319,7 +1302,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Boxing
|
// Boxing
|
||||||
if (!type.equals("java/lang/String") && !type.equals("java/lang/Boolean")) {
|
if (!type.equals(CONSTANTS.REFTYPE_STRING) && !type.equals("java/lang/Boolean")) {
|
||||||
if (!this.isBinaryExp && !isOperator)
|
if (!this.isBinaryExp && !isOperator)
|
||||||
doBoxing(type);
|
doBoxing(type);
|
||||||
}
|
}
|
||||||
@@ -1329,30 +1312,30 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// Boxing: prim -> RefType
|
// Boxing: prim -> RefType
|
||||||
public void doBoxing(String type) {
|
public void doBoxing(String type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "java/lang/String":
|
// case "java/lang/String":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;",
|
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;",
|
||||||
false);
|
// false);
|
||||||
break;
|
// break;
|
||||||
case "java/lang/Boolean":
|
case "java/lang/Boolean":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case CONSTANTS.REFTYPE_BYTE:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CONSTANTS.REFTYPE_BYTE, "valueOf", "(B)Ljava/lang/Byte;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case CONSTANTS.REFTYPE_SHORT:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CONSTANTS.REFTYPE_SHORT, "valueOf", "(S)Ljava/lang/Short;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Integer":
|
case "java/lang/Integer":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case CONSTANTS.REFTYPE_LONG:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CONSTANTS.REFTYPE_LONG, "valueOf", "(J)Ljava/lang/Long;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case CONSTANTS.REFTYPE_FLOAT:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CONSTANTS.REFTYPE_FLOAT, "valueOf", "(F)Ljava/lang/Float;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case CONSTANTS.REFTYPE_DOUBLE:
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CONSTANTS.REFTYPE_DOUBLE, "valueOf", "(D)Ljava/lang/Double;", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Character":
|
case "java/lang/Character":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;",
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;",
|
||||||
@@ -1449,7 +1432,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
//TODO: teste, ob man das für unary braucht
|
//TODO: teste, ob man das für unary braucht
|
||||||
if (isBinaryExp) {
|
if (isBinaryExp) {
|
||||||
BinaryExpr binary = (BinaryExpr) al;
|
BinaryExpr binary = (BinaryExpr) al;
|
||||||
String binaryType = getResolvedType(binary.getType());
|
String binaryType = resolver.getResolvedType(binary.getType());
|
||||||
doBoxing(binaryType);
|
doBoxing(binaryType);
|
||||||
}
|
}
|
||||||
statement = null;
|
statement = null;
|
||||||
@@ -1475,8 +1458,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
fDesc +=";";
|
fDesc +=";";
|
||||||
|
|
||||||
|
|
||||||
System.out.println("Receiver = " + getResolvedType(assignLeftSide.field.receiver.getType()));
|
System.out.println("Receiver = " + resolver.getResolvedType(assignLeftSide.field.receiver.getType()));
|
||||||
mv.visitFieldInsn(Opcodes.PUTFIELD, getResolvedType(assignLeftSide.field.receiver.getType()),
|
mv.visitFieldInsn(Opcodes.PUTFIELD, resolver.getResolvedType(assignLeftSide.field.receiver.getType()),
|
||||||
assignLeftSide.field.fieldVarName, fDesc);
|
assignLeftSide.field.fieldVarName, fDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,10 @@ import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
|||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
@@ -38,16 +41,18 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
public class TPHExtractor extends AbstractASTWalker {
|
public class TPHExtractor extends AbstractASTWalker {
|
||||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
||||||
|
public final List<String> tphsClass = new ArrayList<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
|
|
||||||
Boolean inMethod = false;
|
Boolean inMethod = false;
|
||||||
boolean inLocalOrParam = false;
|
boolean inLocalOrParamOrReturn = false;
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
|
private Resolver resolver;
|
||||||
|
|
||||||
public TPHExtractor() {
|
public TPHExtractor() {
|
||||||
|
|
||||||
@@ -55,16 +60,30 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
|
|
||||||
public void setResultSet(ResultSet resultSet) {
|
public void setResultSet(ResultSet resultSet) {
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
|
this.resolver = new Resolver(resultSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Resolver getResolver() {
|
||||||
|
return resolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
// inMethod = false;
|
||||||
|
// classOrInterface.getfieldInitializations().ifPresent(c->c.block.accept(this));
|
||||||
|
// super.visit(classOrInterface);
|
||||||
|
// inMethod = true;
|
||||||
|
// }
|
||||||
@Override
|
@Override
|
||||||
public void visit(TypePlaceholder tph) {
|
public void visit(TypePlaceholder tph) {
|
||||||
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||||
if (inMethod) {
|
if (inMethod) {
|
||||||
methodAndTph.getTphs().add(resolvedTPH.getName());
|
methodAndTph.getTphs().add(resolvedTPH.getName());
|
||||||
if (inLocalOrParam)
|
if (inLocalOrParamOrReturn)
|
||||||
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||||
|
}else {
|
||||||
|
tphsClass.add(resolvedTPH.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
allTPHS.put(resolvedTPH.getName(), inMethod);
|
allTPHS.put(resolvedTPH.getName(), inMethod);
|
||||||
@@ -98,7 +117,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
if (inMethod)
|
if (inMethod)
|
||||||
methodAndTph.getPairs().add(ag);
|
methodAndTph.getPairs().add(ag);
|
||||||
allPairs.add(ag);
|
allPairs.add(ag);
|
||||||
TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName());
|
||||||
if(!containsConstraint(allCons,con))
|
if(!containsConstraint(allCons,con))
|
||||||
allCons.add(con);
|
allCons.add(con);
|
||||||
// }
|
// }
|
||||||
@@ -111,7 +130,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
|
|
||||||
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
||||||
for(TPHConstraint con:allCons) {
|
for(TPHConstraint con:allCons) {
|
||||||
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(con.getRight())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,9 +153,11 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
public void visit(GenericRefType genericRefType) {
|
public void visit(GenericRefType genericRefType) {
|
||||||
String name = genericRefType.getParsedName();
|
String name = genericRefType.getParsedName();
|
||||||
if (inMethod) {
|
if (inMethod) {
|
||||||
|
methodAndTph.getTphs().add(name);
|
||||||
|
if (inLocalOrParamOrReturn)
|
||||||
methodAndTph.getLocalTphs().add(name);
|
methodAndTph.getLocalTphs().add(name);
|
||||||
if (inLocalOrParam)
|
}else {
|
||||||
methodAndTph.getLocalTphs().add(name);
|
tphsClass.add(name);
|
||||||
}
|
}
|
||||||
allTPHS.put(name, inMethod);
|
allTPHS.put(name, inMethod);
|
||||||
}
|
}
|
||||||
@@ -153,8 +174,17 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
methodAndTph = new MethodAndTPH(method.name);
|
String id = MethodUtility.createID(resolver,method);
|
||||||
super.visit(method);
|
methodAndTph = new MethodAndTPH(id);
|
||||||
|
|
||||||
|
inLocalOrParamOrReturn = true;
|
||||||
|
method.getReturnType().accept(this);
|
||||||
|
method.getParameterList().accept(this);
|
||||||
|
inLocalOrParamOrReturn = false;
|
||||||
|
|
||||||
|
if(method.block != null)
|
||||||
|
method.block.accept(this);
|
||||||
|
|
||||||
inMethod = false;
|
inMethod = false;
|
||||||
ListOfMethodsAndTph.add(methodAndTph);
|
ListOfMethodsAndTph.add(methodAndTph);
|
||||||
}
|
}
|
||||||
@@ -162,29 +192,32 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Constructor cons) {
|
public void visit(Constructor cons) {
|
||||||
inMethod = false;
|
inMethod = false;
|
||||||
super.visit(cons);
|
//super.visit(cons);
|
||||||
|
cons.getParameterList().accept(this);
|
||||||
|
if(cons.block != null)
|
||||||
|
cons.block.accept(this);
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
inLocalOrParam = true;
|
// inLocalOrParamOrReturn = inMethod;
|
||||||
super.visit(localVarDecl);
|
super.visit(localVarDecl);
|
||||||
inLocalOrParam = false;
|
// inLocalOrParamOrReturn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVar localVar) {
|
public void visit(LocalVar localVar) {
|
||||||
inLocalOrParam = true;
|
// inLocalOrParamOrReturn = inMethod;
|
||||||
super.visit(localVar);
|
super.visit(localVar);
|
||||||
inLocalOrParam = false;
|
// inLocalOrParamOrReturn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
inLocalOrParam = true;
|
inLocalOrParamOrReturn = inMethod;
|
||||||
super.visit(formalParameters);
|
super.visit(formalParameters);
|
||||||
inLocalOrParam = false;
|
inLocalOrParamOrReturn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -2,8 +2,8 @@ package de.dhbwstuttgart.bytecode.constraint;
|
|||||||
|
|
||||||
public class EqualConstraint extends TPHConstraint {
|
public class EqualConstraint extends TPHConstraint {
|
||||||
|
|
||||||
public EqualConstraint(String left, String right, Relation rel) {
|
public EqualConstraint(String left, String right) {
|
||||||
super(left, right, rel);
|
super(left, right, Relation.EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,8 @@ package de.dhbwstuttgart.bytecode.constraint;
|
|||||||
|
|
||||||
public class ExtendsConstraint extends TPHConstraint {
|
public class ExtendsConstraint extends TPHConstraint {
|
||||||
|
|
||||||
public ExtendsConstraint(String left, String right, Relation rel) {
|
public ExtendsConstraint(String left, String right) {
|
||||||
super(left, right, rel);
|
super(left, right, Relation.EXTENDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,10 @@ public class TPHConstraint {
|
|||||||
return left.equals(tph)||right.equals(tph);
|
return left.equals(tph)||right.equals(tph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equalConstraint(TPHConstraint constraint) {
|
||||||
|
return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if(rel == Relation.EXTENDS) {
|
if(rel == Relation.EXTENDS) {
|
||||||
|
@@ -3,29 +3,27 @@ package de.dhbwstuttgart.bytecode.descriptor;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class DescriptorToString implements DescriptorVisitor{
|
public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||||
ResultSet resultSet;
|
ResultSet resultSet;
|
||||||
|
|
||||||
|
public DescriptorToString() {
|
||||||
|
}
|
||||||
|
|
||||||
public DescriptorToString(ResultSet resultSet) {
|
public DescriptorToString(ResultSet resultSet) {
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String addReturnType(String desc, RefTypeOrTPHOrWildcardOrGeneric returnType, ResultSet resultSet) {
|
private String addReturnType(String desc, RefTypeOrTPHOrWildcardOrGeneric returnType, ResultSet resultSet) {
|
||||||
if(resultSet.resolveType(returnType).resolvedType.toString().equals("void")){
|
if(resultSet.resolveType(returnType).resolvedType.toString().equals(CONSTANTS.VOID)){
|
||||||
desc = desc + ")V";
|
desc = desc + ")V";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")" + "L"+resultSet.resolveType(returnType).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
desc = desc + ")" + "L"+resultSet.resolveType(returnType).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
@@ -53,7 +51,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}else {
|
}else {
|
||||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
if(resType.contains(CONSTANTS.TPH)/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
||||||
// Bound ist immer Object
|
// Bound ist immer Object
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
} else {
|
} else {
|
||||||
@@ -71,15 +69,15 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: generate a class java%% ... %%
|
//TODO: generate a class java%% ... %%
|
||||||
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
|
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains(CONSTANTS.ANGLEBRACKET)){
|
||||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
|
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace(CONSTANTS.ANGLEBRACKET, "$$$").replace(">", "$$$")+ ";";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resultSet.resolveType(method.getReturnType()).resolvedType.toString().equals("void")) {
|
if(resultSet.resolveType(method.getReturnType()).resolvedType.toString().equals(CONSTANTS.VOID)) {
|
||||||
desc += ")V";
|
desc += ")V";
|
||||||
}else {
|
}else {
|
||||||
if(method.hasGen()) {
|
if(method.hasGen()) {
|
||||||
@@ -90,7 +88,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
||||||
}else {
|
}else {
|
||||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
if(resType.contains(CONSTANTS.TPH)/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
||||||
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
} else {
|
} else {
|
||||||
@@ -139,7 +137,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}else {
|
}else {
|
||||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
if(resType.subSequence(0, 4).equals(CONSTANTS.TPH)) {
|
||||||
// Bound ist immer Object
|
// Bound ist immer Object
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
} else {
|
} else {
|
||||||
@@ -162,7 +160,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
while(itr.hasNext()) {
|
while(itr.hasNext()) {
|
||||||
FormalParameter fp = itr.next();
|
FormalParameter fp = itr.next();
|
||||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(d.contains("TPH ") ||d.contains("<")) {
|
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET)) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + "L"+ d + ";";
|
desc = desc + "L"+ d + ";";
|
||||||
@@ -171,7 +169,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
|
|
||||||
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(retType.contains("TPH ")|| retType.contains("<")){
|
if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET)){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")"+"L"+retType+";";
|
desc = desc + ")"+"L"+retType+";";
|
||||||
@@ -187,7 +185,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.contains("TPH ") ||d.contains("<")) {
|
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET)) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc += "L"+ d + ";";
|
desc += "L"+ d + ";";
|
||||||
@@ -196,7 +194,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}
|
}
|
||||||
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(retType.contains("TPH ")|| retType.contains("<")){
|
if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET)){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")"+"L"+retType+";";
|
desc = desc + ")"+"L"+retType+";";
|
||||||
@@ -210,7 +208,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.contains("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET) || methodFromMethodCall.getReceiverName().contains("$$")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||||
@@ -225,9 +223,9 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}
|
}
|
||||||
String retType = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
System.out.println("DescriptorToString retType = " + retType);
|
System.out.println("DescriptorToString retType = " + retType);
|
||||||
if(retType.equals("void")) {
|
if(retType.equals(CONSTANTS.VOID)) {
|
||||||
desc += ")V";
|
desc += ")V";
|
||||||
}else if(retType.contains("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
}else if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET) || methodFromMethodCall.getReceiverName().contains("$$")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
||||||
@@ -242,4 +240,20 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String createDescForFunN(ArgumentList argumentList, String returnType) {
|
||||||
|
Iterator<Expression> itr1 = argumentList.getArguments().iterator();
|
||||||
|
String methDesc = "(";
|
||||||
|
while(itr1.hasNext()) {
|
||||||
|
methDesc += "L" + Type.getInternalName(Object.class) + ";";
|
||||||
|
itr1.next();
|
||||||
|
}
|
||||||
|
if (returnType.equals(CONSTANTS.VOID)){
|
||||||
|
methDesc += ")V";
|
||||||
|
} else {
|
||||||
|
methDesc += ")L" + Type.getInternalName(Object.class) + ";";
|
||||||
|
}
|
||||||
|
return methDesc;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,13 @@ import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
|
||||||
public interface DescriptorVisitor {
|
public interface DescriptorVisitor {
|
||||||
public String visit(NormalMethod method);
|
String visit(NormalMethod method);
|
||||||
public String visit(NormalConstructor constructor);
|
String visit(NormalConstructor constructor);
|
||||||
public String visit(Lambda lambdaExpression);
|
String visit(Lambda lambdaExpression);
|
||||||
public String visit(SamMethod samMethod);
|
String visit(SamMethod samMethod);
|
||||||
public String visit(MethodFromMethodCall methodFromMethodCall);
|
String visit(MethodFromMethodCall methodFromMethodCall);
|
||||||
|
String createDescForFunN(ArgumentList argumentList, String returnType);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.NameReplacementResult;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the result of the constraints simplifier.
|
||||||
|
*
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ConstraintsSimplierResult {
|
||||||
|
private List<GenericsGeneratorResult> genericsGenResults;
|
||||||
|
private List<NameReplacementResult> nameReplacementResults;
|
||||||
|
/**
|
||||||
|
* @param genericsGenResults
|
||||||
|
*/
|
||||||
|
public ConstraintsSimplierResult(List<GenericsGeneratorResult> genericsGenResults,
|
||||||
|
List<NameReplacementResult> nameReplacementResults) {
|
||||||
|
this.genericsGenResults = genericsGenResults;
|
||||||
|
this.setNameReplacementResults(nameReplacementResults);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the genericsGenResults
|
||||||
|
*/
|
||||||
|
public List<GenericsGeneratorResult> getGenericsGenResults() {
|
||||||
|
return genericsGenResults;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param genericsGenResults the genericsGenResults to set
|
||||||
|
*/
|
||||||
|
public void setGenericsGenResults(List<GenericsGeneratorResult> genericsGenResults) {
|
||||||
|
this.genericsGenResults = genericsGenResults;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the nameReplacementResults
|
||||||
|
*/
|
||||||
|
public List<NameReplacementResult> getNameReplacementResults() {
|
||||||
|
return nameReplacementResults;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param nameReplacementResults the nameReplacementResults to set
|
||||||
|
*/
|
||||||
|
public void setNameReplacementResults(List<NameReplacementResult> nameReplacementResults) {
|
||||||
|
this.nameReplacementResults = nameReplacementResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,137 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ConstraintsSimplifier {
|
||||||
|
public static ConstraintsSimplierResult simplifyConstraints(final TPHExtractor tphExtractor, final List<GenericsGeneratorResult> genericsGeneratorResults, final List<String> tphsClass) {
|
||||||
|
|
||||||
|
List<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
|
List<TPHConstraint> equalCons = new ArrayList<>();
|
||||||
|
|
||||||
|
/* Step 1 */
|
||||||
|
List<ConstraintsWithSameLeftSide> foundCons = GenericsGeneratorUtility.findConstraintsWithLeftSameLeftSide(allCons);
|
||||||
|
if(!foundCons.isEmpty()) {
|
||||||
|
List<TPHConstraint> equalCons2 = new ArrayList<>();
|
||||||
|
GenericsGeneratorUtility.simplifyConstraintsWithSameLeftSide(foundCons,tphExtractor,tphsClass,equalCons2);
|
||||||
|
equalCons.addAll(equalCons2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(!simpleCycles.isEmpty()) {
|
||||||
|
// handleSimpleCycles(allCons, simpleCycles,tphExtractor);
|
||||||
|
// equalCons.addAll(GenericsGeneratorUtility.getEqualConstraints(allCons));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
List<Cycle> cycles = findCycles(allCons);
|
||||||
|
|
||||||
|
if(!cycles.isEmpty()) {
|
||||||
|
handleCycle(genericsGeneratorResults, allCons, cycles,tphExtractor);
|
||||||
|
}
|
||||||
|
/* The right hand side of equal constraint is the new name in name replacement result */
|
||||||
|
List<NameReplacementResult> nameReplacementResults = GenericsGeneratorUtility.createNameReplacementResultsFromEqualConstraints(equalCons);
|
||||||
|
getEqualsFromNameReplacementResults(genericsGeneratorResults,nameReplacementResults);
|
||||||
|
ConstraintsSimplierResult result = new ConstraintsSimplierResult(genericsGeneratorResults, nameReplacementResults);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getEqualsFromNameReplacementResults(List<GenericsGeneratorResult> genericsGeneratorResults,
|
||||||
|
List<NameReplacementResult> nameReplacementResults) {
|
||||||
|
genericsGeneratorResults.forEach(g->{
|
||||||
|
String tph = g.getConstraint().getLeft();
|
||||||
|
if (!nameReplacementResults.isEmpty()) {
|
||||||
|
collectAllEquals(nameReplacementResults, g, tph);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nameReplacementResults.isEmpty()) {
|
||||||
|
collectAllEquals(nameReplacementResults, g);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void collectAllEquals(List<NameReplacementResult> nameReplacementResults, GenericsGeneratorResult g) {
|
||||||
|
Set<String> equalsTPHs = g.getEqualsTPHs();
|
||||||
|
Set<String> tphsToAdd = getAllEqualTphs(equalsTPHs, nameReplacementResults);
|
||||||
|
while (!tphsToAdd.isEmpty()){
|
||||||
|
equalsTPHs.addAll(tphsToAdd);
|
||||||
|
tphsToAdd = getAllEqualTphs(equalsTPHs, nameReplacementResults);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<String> getAllEqualTphs(Set<String> equalsTPHs, List<NameReplacementResult> nameReplacementResults) {
|
||||||
|
Set<String> tphsToAdd = new HashSet<>();
|
||||||
|
equalsTPHs.forEach(e->{
|
||||||
|
collectAllEquals(nameReplacementResults, tphsToAdd,e);
|
||||||
|
});
|
||||||
|
return tphsToAdd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void collectAllEquals(List<NameReplacementResult> nameReplacementResults, Set<String> tphsToAdd,
|
||||||
|
String tph) {
|
||||||
|
List<NameReplacementResult> toRemoveList = new ArrayList<>();
|
||||||
|
Optional<NameReplacementResult> nameReplacementResult = nameReplacementResults.stream().filter(n->n.getName().equals(tph)).findFirst();
|
||||||
|
nameReplacementResult.ifPresent(toRemove->{
|
||||||
|
tphsToAdd.addAll(toRemove.getOldNames());
|
||||||
|
toRemoveList.add(toRemove);
|
||||||
|
});
|
||||||
|
if(!toRemoveList.isEmpty()){
|
||||||
|
nameReplacementResults.remove(toRemoveList.get(0));
|
||||||
|
toRemoveList.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param nameReplacementResults
|
||||||
|
* @param g
|
||||||
|
* @param tph
|
||||||
|
*/
|
||||||
|
public static void collectAllEquals(List<NameReplacementResult> nameReplacementResults, GenericsGeneratorResult g,
|
||||||
|
String tph) {
|
||||||
|
List<NameReplacementResult> toRemoveList = new ArrayList<>();
|
||||||
|
Optional<NameReplacementResult> nameReplacementResult = nameReplacementResults.stream().filter(n->n.getName().equals(tph)).findFirst();
|
||||||
|
nameReplacementResult.ifPresent(toRemove->{
|
||||||
|
g.getEqualsTPHs().addAll(toRemove.getOldNames());
|
||||||
|
toRemoveList.add(toRemove);
|
||||||
|
});
|
||||||
|
if(!toRemoveList.isEmpty()){
|
||||||
|
nameReplacementResults.remove(toRemoveList.get(0));
|
||||||
|
toRemoveList.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param genericsGeneratorResults
|
||||||
|
* @param allCons
|
||||||
|
* @param cycles
|
||||||
|
* @param tphExtractor
|
||||||
|
*/
|
||||||
|
public static void handleCycle(List<GenericsGeneratorResult> genericsGeneratorResults,
|
||||||
|
List<TPHConstraint> allCons, List<Cycle> cycles, TPHExtractor tphExtractor) {
|
||||||
|
GenericsGeneratorUtility.modifyRelationForConstraintsInCycle(cycles);
|
||||||
|
List<NameReplacementResult> nameReplacementResults = GenericsGeneratorUtility.substituteTPHSFormCycle(allCons, cycles,tphExtractor);
|
||||||
|
GenericsGeneratorUtility.createResults(genericsGeneratorResults,nameReplacementResults);
|
||||||
|
GenericsGeneratorUtility.removeEqualConstraints(allCons);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param allCons
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Cycle> findCycles(List<TPHConstraint> allCons) {
|
||||||
|
/* find all cycles */
|
||||||
|
CyclesFinder cyclesFinder = new CyclesFinder(allCons);
|
||||||
|
List<Cycle> cycles = cyclesFinder.findCycles();
|
||||||
|
return cycles;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.Cycle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CyclesFinder {
|
||||||
|
private final List<TPHConstraint> allCons;
|
||||||
|
|
||||||
|
public CyclesFinder(List<TPHConstraint> allCons) {
|
||||||
|
this.allCons = allCons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Cycle> findCycles() {
|
||||||
|
List<TPHConstraint> vistedConstraints = new ArrayList<>(allCons.size());
|
||||||
|
List<Cycle> cycles = new ArrayList<>();
|
||||||
|
for (TPHConstraint constraint : allCons) {
|
||||||
|
if(constraint.getRel()==Relation.EQUAL)
|
||||||
|
continue;
|
||||||
|
if (!vistedConstraints.contains(constraint)) {
|
||||||
|
vistedConstraints.add(constraint);
|
||||||
|
checkConstraint(constraint, vistedConstraints, cycles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cycles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkConstraint(TPHConstraint constraint, List<TPHConstraint> vistedConstraints,
|
||||||
|
List<Cycle> cycles) {
|
||||||
|
List<String> tphsInRelation = new LinkedList<>();
|
||||||
|
List<TPHConstraint> maybeCycle = new ArrayList<>();
|
||||||
|
maybeCycle.add(constraint);
|
||||||
|
tphsInRelation.add(constraint.getLeft());
|
||||||
|
tphsInRelation.add(constraint.getRight());
|
||||||
|
Optional<TPHConstraint> nextConstraint = getConstraintInRelation(tphsInRelation, maybeCycle);
|
||||||
|
while (nextConstraint.isPresent()) {
|
||||||
|
if(containsInLongCycle(nextConstraint.get(), cycles)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (isCycle(tphsInRelation)) {
|
||||||
|
addAllToVisitedConstraints(vistedConstraints, maybeCycle);
|
||||||
|
Cycle cycle = new Cycle(maybeCycle);
|
||||||
|
cycles.add(cycle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nextConstraint = getConstraintInRelation(tphsInRelation, maybeCycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// addAllToVisitedConstraints(vistedConstraints, maybeCycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsInLongCycle(TPHConstraint c, List<Cycle> cycles) {
|
||||||
|
for(Cycle cycle : cycles) {
|
||||||
|
if(cycle.containConstraint(c))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAllToVisitedConstraints(List<TPHConstraint> vistedConstraints, List<TPHConstraint> maybeCycle) {
|
||||||
|
for (TPHConstraint con : maybeCycle) {
|
||||||
|
if (!vistedConstraints.contains(con))
|
||||||
|
vistedConstraints.add(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<TPHConstraint> getConstraintInRelation(List<String> tphsInRelation,
|
||||||
|
List<TPHConstraint> maybeCycle) {
|
||||||
|
TPHConstraint constraint = getConstraintByLeftSide(tphsInRelation.get(tphsInRelation.size()-1),maybeCycle);
|
||||||
|
Optional<TPHConstraint> nextConstraint = Optional.ofNullable(constraint);
|
||||||
|
if(nextConstraint.isPresent()) {
|
||||||
|
maybeCycle.add(constraint);
|
||||||
|
tphsInRelation.add(constraint.getRight());
|
||||||
|
}
|
||||||
|
return nextConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TPHConstraint getConstraintByLeftSide(String left, List<TPHConstraint> maybeCycle) {
|
||||||
|
for(TPHConstraint constraint : allCons) {
|
||||||
|
if(constraint.getRel()==Relation.EQUAL)
|
||||||
|
continue;
|
||||||
|
if(maybeCycle.contains(constraint))
|
||||||
|
continue;
|
||||||
|
if(constraint.getLeft().equals(left))
|
||||||
|
return constraint;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCycle(List<String> tphsInRelation) {
|
||||||
|
return tphsInRelation.get(0).equals(tphsInRelation.get(tphsInRelation.size() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,674 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GeneratedGenericsFinder implements ASTVisitor {
|
||||||
|
private final TPHExtractor tphExtractor = new TPHExtractor();
|
||||||
|
private Collection<ResultSet> listOfResultSets;
|
||||||
|
private SourceFile sf;
|
||||||
|
private List<String> tphsClass;
|
||||||
|
private GenericGenratorResultForSourceFile generatedGenericsForSF;
|
||||||
|
private ResultSet resultSet;
|
||||||
|
private final List<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
|
private String pkgName;
|
||||||
|
private String className;
|
||||||
|
private Resolver resolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sf
|
||||||
|
* @param listOfResultSets
|
||||||
|
*/
|
||||||
|
public GeneratedGenericsFinder(SourceFile sf, Collection<ResultSet> listOfResultSets) {
|
||||||
|
this.sf = sf;
|
||||||
|
this.listOfResultSets = listOfResultSets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericGenratorResultForSourceFile findGeneratedGenerics() {
|
||||||
|
sf.accept(this);
|
||||||
|
return generatedGenericsForSF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* SourceFile)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(SourceFile sourceFile) {
|
||||||
|
pkgName = sf.getPkgName();
|
||||||
|
generatedGenericsForSF = new GenericGenratorResultForSourceFile(pkgName);
|
||||||
|
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
|
cl.accept(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* ClassOrInterface)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
className = classOrInterface.getClassName().toString();
|
||||||
|
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
||||||
|
|
||||||
|
boolean isVisited = false;
|
||||||
|
|
||||||
|
ConstraintsSimplierResult simplifiedConstraints = null;
|
||||||
|
GenericsGeneratorResultForClass ggResult = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||||
|
resultSet = listOfResultSetsList.get(i);
|
||||||
|
tphExtractor.setResultSet(resultSet);
|
||||||
|
resolver = new Resolver(resultSet);
|
||||||
|
classOrInterface.accept(tphExtractor);
|
||||||
|
tphsClass = tphExtractor.tphsClass;
|
||||||
|
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);
|
||||||
|
if(!isVisited) {
|
||||||
|
ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints);
|
||||||
|
isVisited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Method m : classOrInterface.getMethods()) {
|
||||||
|
addMethodConstraints(simplifiedConstraints, ggResult, m);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ggResult != null)
|
||||||
|
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param simplifiedConstraints
|
||||||
|
* @param ggResult
|
||||||
|
* @param m
|
||||||
|
*/
|
||||||
|
public void addMethodConstraints(ConstraintsSimplierResult simplifiedConstraints,
|
||||||
|
GenericsGeneratorResultForClass ggResult, Method m) {
|
||||||
|
String id = MethodUtility.createID(resolver, m);
|
||||||
|
boolean isInGGResult = (ggResult != null) && ggResult.contains(id);
|
||||||
|
if(methodNameAndParamsT.contains(id) || isInGGResult)
|
||||||
|
return;
|
||||||
|
methodNameAndParamsT.add(id);
|
||||||
|
Optional<MethodAndTPH> methodAndTPH = GenericsGeneratorUtility.getMethodAndTphs(tphExtractor.ListOfMethodsAndTph,id);
|
||||||
|
methodAndTPH.ifPresent(mt->{
|
||||||
|
MethodAndConstraints methodConstraints = GenericsGenerator.generateConstraintsForMethod(tphExtractor.allCons, mt , simplifiedConstraints, tphsClass);
|
||||||
|
ggResult.getMethodsAndTheirConstraints().getMethodsAndConstraints().add(methodConstraints);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* Method)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Method method) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* ParameterList)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ParameterList formalParameters) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* Constructor)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Constructor field) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.ArgumentList)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ArgumentList argumentList) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.LambdaExpression)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.Assign)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Assign assign) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.BinaryExpr)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(BinaryExpr binary) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.Block)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Block block) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.CastExpr)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(CastExpr castExpr) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.EmptyStmt)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(EmptyStmt emptyStmt) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.FieldVar)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(FieldVar fieldVar) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.ForStmt)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ForStmt forStmt) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.IfStmt)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(IfStmt ifStmt) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.InstanceOf)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(InstanceOf instanceOf) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.LocalVar)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVar localVar) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.LocalVarDecl)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.MethodCall)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(MethodCall methodCall) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.NewClass)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(NewClass methodCall) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.NewArray)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(NewArray newArray) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.Return)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Return aReturn) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.ReturnVoid)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ReturnVoid aReturn) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.StaticClassName)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(StaticClassName staticClassName) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.Super)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Super aSuper) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.This)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(This aThis) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.WhileStmt)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(WhileStmt whileStmt) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.DoStmt)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(DoStmt whileStmt) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.AssignToField)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(AssignToField assignLeftSide) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.parser.
|
||||||
|
* SyntaxTreeGenerator.AssignToLocal)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(AssignToLocal assignLeftSide) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.SuperCall)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(SuperCall superCall) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.ExpressionReceiver)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ExpressionReceiver expressionReceiver) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.UnaryExpr)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(UnaryExpr unaryExpr) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see de.dhbwstuttgart.syntaxtree.StatementVisitor#visit(de.dhbwstuttgart.
|
||||||
|
* syntaxtree.statement.Literal)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Literal literal) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* GenericTypeVar)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(GenericTypeVar genericTypeVar) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* FormalParameter)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(FormalParameter formalParameter) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* GenericDeclarationList)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(GenericDeclarationList genericTypeVars) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.
|
||||||
|
* Field)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(Field field) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.type
|
||||||
|
* .RefType)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(RefType refType) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.type
|
||||||
|
* .SuperWildcardType)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(SuperWildcardType superWildcardType) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.type
|
||||||
|
* .TypePlaceholder)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(TypePlaceholder typePlaceholder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.type
|
||||||
|
* .ExtendsWildcardType)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* de.dhbwstuttgart.syntaxtree.ASTVisitor#visit(de.dhbwstuttgart.syntaxtree.type
|
||||||
|
* .GenericRefType)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void visit(GenericRefType genericRefType) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,255 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GenericsGenerator {
|
||||||
|
/*TODO: When generating generics for a class if we have the following:
|
||||||
|
tphClass < tphMeth1 < tphMeth2
|
||||||
|
then we have to convert tphMeth1, tphMeth2 to tph class and generate the following
|
||||||
|
class constraints: tphClass < tphMeth1, tphMeth1 < tphMeth2, tphMeth2 < Object
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static GenericsGeneratorResultForClass generateConstraints(final String className, final TPHExtractor tphExtractor,
|
||||||
|
final List<String> tphsClass, final ConstraintsSimplierResult simplifiedConstraints) {
|
||||||
|
|
||||||
|
List<GenericsGeneratorResult> classConstraints = generateConstraintsForClass(tphExtractor,
|
||||||
|
simplifiedConstraints, tphsClass);
|
||||||
|
// GenericGeneratorResultsForAllMethods methodsAndConstraints = generateConstraintsForAllMethods(tphExtractor,
|
||||||
|
// simplifiedConstraints, tphsClass);
|
||||||
|
GenericGeneratorResultsForAllMethods methodsAndConstraints = new GenericGeneratorResultsForAllMethods(new ArrayList<>());
|
||||||
|
|
||||||
|
return new GenericsGeneratorResultForClass(className, classConstraints, methodsAndConstraints);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tphExtractor
|
||||||
|
* @param tphsClass
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ConstraintsSimplierResult simplifyConstraints(final TPHExtractor tphExtractor,
|
||||||
|
final List<String> tphsClass) {
|
||||||
|
final List<GenericsGeneratorResult> genericsGeneratorResults = new ArrayList<>();
|
||||||
|
|
||||||
|
ConstraintsSimplierResult simplifiedConstraints = ConstraintsSimplifier.simplifyConstraints(tphExtractor,
|
||||||
|
genericsGeneratorResults, tphsClass);
|
||||||
|
return simplifiedConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static List<GenericsGeneratorResult> generateConstraintsForClass(final TPHExtractor tphExtractor,
|
||||||
|
final ConstraintsSimplierResult simplifiedConstraints, final List<String> tphsClass) {
|
||||||
|
final List<GenericsGeneratorResult> constraints = new ArrayList<>();
|
||||||
|
|
||||||
|
if (tphsClass.isEmpty())
|
||||||
|
return constraints;
|
||||||
|
|
||||||
|
final List<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
|
|
||||||
|
final Set<String> visitedTPHs = new HashSet<>();
|
||||||
|
|
||||||
|
final List<String> methodTPHs = tphExtractor.ListOfMethodsAndTph.stream().map(m -> m.getLocalTphs())
|
||||||
|
.flatMap(l -> l.stream()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
createConstraintsForClassTphs(simplifiedConstraints, tphsClass, constraints, allCons, visitedTPHs, methodTPHs);
|
||||||
|
|
||||||
|
GenericsGeneratorUtility.addTPHsToClassTPHs(constraints, tphsClass);
|
||||||
|
GenericsGeneratorUtility.removeClassTPHsFromMethodTPHs(tphsClass, tphExtractor);
|
||||||
|
|
||||||
|
generateGGConstraintsForTPH(tphsClass, constraints, simplifiedConstraints);
|
||||||
|
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createConstraintsForClassTphs(ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass, List<GenericsGeneratorResult> constraints, List<TPHConstraint> allCons, Set<String> visitedTPHs, List<String> methodTPHs) {
|
||||||
|
List<String> classAndMethodTphs = new ArrayList<>(tphsClass);
|
||||||
|
classAndMethodTphs.addAll(methodTPHs);
|
||||||
|
|
||||||
|
for (String tph : tphsClass) {
|
||||||
|
|
||||||
|
if (visitedTPHs.contains(tph))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
final LinkedList<String> tphsInRel = GenericsGeneratorUtility
|
||||||
|
.createLinkedListForTPHsInRelationClass(allCons, tphsClass, methodTPHs, visitedTPHs, tph);
|
||||||
|
|
||||||
|
generateConstraintsForClassFromList(tphsInRel,simplifiedConstraints,classAndMethodTphs,constraints);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generateConstraintsForClassFromList(LinkedList<String> tphsInRel, ConstraintsSimplierResult simplifiedConstraints, List<String> classAndMethodTphs, List<GenericsGeneratorResult> constraints) {
|
||||||
|
|
||||||
|
if(tphsInRel.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<GenericsGeneratorResult> resultConstraints = new ArrayList<>();
|
||||||
|
String subType = tphsInRel.getFirst();
|
||||||
|
String superType = GenericsGeneratorUtility.getNextClassTph(classAndMethodTphs, tphsInRel);
|
||||||
|
|
||||||
|
int idxOfSuper = tphsInRel.indexOf(superType);
|
||||||
|
int size = tphsInRel.size();
|
||||||
|
while (size > 2 && idxOfSuper < size-1){
|
||||||
|
GenericsGeneratorResult genericsGeneratorResult = getGenericsGeneratorResultForClass(simplifiedConstraints, subType, superType);
|
||||||
|
constraints.add(genericsGeneratorResult);
|
||||||
|
|
||||||
|
tphsInRel = new LinkedList<>(tphsInRel.subList(idxOfSuper, size));
|
||||||
|
subType = tphsInRel.getFirst();
|
||||||
|
superType = GenericsGeneratorUtility.getNextClassTph(classAndMethodTphs, tphsInRel);
|
||||||
|
|
||||||
|
idxOfSuper = tphsInRel.indexOf(superType);
|
||||||
|
size = tphsInRel.size();
|
||||||
|
}
|
||||||
|
GenericsGeneratorResult genericsGeneratorResult = getGenericsGeneratorResultForClass(simplifiedConstraints, subType, superType);
|
||||||
|
constraints.add(genericsGeneratorResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GenericsGeneratorResult getGenericsGeneratorResultForClass(ConstraintsSimplierResult simplifiedConstraints, String subType, String superType) {
|
||||||
|
TPHConstraint constraint = new ExtendsConstraint(subType, superType);
|
||||||
|
|
||||||
|
Set<String> equalSet = GenericsGeneratorUtility
|
||||||
|
.createEqualSet(simplifiedConstraints.getNameReplacementResults(), subType);
|
||||||
|
|
||||||
|
return new GenericsGeneratorResult(constraint, equalSet);
|
||||||
|
}
|
||||||
|
/* TODO Remove this methoda*/
|
||||||
|
private static GenericsGeneratorResult generateGGResultForClass(LinkedList<String> tphsInRel,
|
||||||
|
ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass) {
|
||||||
|
String subType = tphsInRel.getFirst();
|
||||||
|
|
||||||
|
String superType = GenericsGeneratorUtility.getNextClassTph(tphsClass, tphsInRel);
|
||||||
|
|
||||||
|
TPHConstraint constraint = new ExtendsConstraint(subType, superType);
|
||||||
|
|
||||||
|
Set<String> equalSet = GenericsGeneratorUtility
|
||||||
|
.createEqualSet(simplifiedConstraints.getNameReplacementResults(), subType);
|
||||||
|
|
||||||
|
return new GenericsGeneratorResult(constraint, equalSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GenericGeneratorResultsForAllMethods generateConstraintsForAllMethods(
|
||||||
|
final TPHExtractor tphExtractor, ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass) {
|
||||||
|
|
||||||
|
final List<MethodAndConstraints> methodsAndConstraints = new ArrayList<>();
|
||||||
|
final GenericGeneratorResultsForAllMethods results = new GenericGeneratorResultsForAllMethods(
|
||||||
|
methodsAndConstraints);
|
||||||
|
tphExtractor.ListOfMethodsAndTph.forEach(m -> {
|
||||||
|
MethodAndConstraints methAndCons = generateConstraintsForMethod(tphExtractor.allCons, m,
|
||||||
|
simplifiedConstraints, tphsClass);
|
||||||
|
methodsAndConstraints.add(methAndCons);
|
||||||
|
});
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodAndConstraints generateConstraintsForMethod(final List<TPHConstraint> allCons,
|
||||||
|
final MethodAndTPH m, final ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass) {
|
||||||
|
final List<String> localTphs = m.getLocalTphs();
|
||||||
|
|
||||||
|
List<GenericsGeneratorResult> constraints = new ArrayList<>();
|
||||||
|
MethodAndConstraints result = new MethodAndConstraints(m.getId(), constraints);
|
||||||
|
|
||||||
|
if (localTphs.isEmpty())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (localTphs.size() == 1 && tphsClass.isEmpty()) {
|
||||||
|
generateGGConstraintsForTPH(localTphs, constraints, simplifiedConstraints);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Set<String> visitedTPHs = new HashSet<>();
|
||||||
|
|
||||||
|
for (String tph : localTphs) {
|
||||||
|
|
||||||
|
if (visitedTPHs.contains(tph))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
final LinkedList<String> tphsInRel = GenericsGeneratorUtility.createLinkedListForTPHsInRelation(allCons,
|
||||||
|
localTphs, tphsClass, visitedTPHs, tph);
|
||||||
|
if (!tphsInRel.isEmpty()) {
|
||||||
|
GenericsGeneratorUtility.removeNotLocalTphs(tphsInRel, localTphs, tphsClass);
|
||||||
|
if (!GenericsGeneratorUtility.isInResult(tphsInRel.getFirst(), constraints)) {
|
||||||
|
GenericsGeneratorResult constraint = generateGGResult(tphsInRel, simplifiedConstraints);
|
||||||
|
constraints.add(constraint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateGGConstraintsForTPH(localTphs, constraints, simplifiedConstraints);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generateGGConstraintsForTPH(List<String> localTphs,
|
||||||
|
final List<GenericsGeneratorResult> constraints, final ConstraintsSimplierResult simplifiedConstraints) {
|
||||||
|
|
||||||
|
localTphs.forEach(tph -> {
|
||||||
|
boolean isInSimplifiedConstraints = GenericsGeneratorUtility.isTPHInGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(), tph);
|
||||||
|
if (isInSimplifiedConstraints) {
|
||||||
|
GenericsGeneratorResult ggResult = GenericsGeneratorUtility.getGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(), tph).get();
|
||||||
|
// GenericsGeneratorUtility.removeGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(),ggResult);
|
||||||
|
constraints.add(ggResult);
|
||||||
|
} else {
|
||||||
|
boolean isInConstraints = GenericsGeneratorUtility.isTPHInGenericGeneratorResult(constraints, tph);
|
||||||
|
|
||||||
|
if (!isInConstraints) {
|
||||||
|
GenericsGeneratorResult ggResult = generateGGResult(tph, simplifiedConstraints.getNameReplacementResults());
|
||||||
|
constraints.add(ggResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GenericsGeneratorResult generateGGResult(String tph,
|
||||||
|
List<NameReplacementResult> nameReplacementResults) {
|
||||||
|
String superType = Type.getInternalName(Object.class);
|
||||||
|
TPHConstraint constraint = new ExtendsConstraint(tph, superType);
|
||||||
|
Set<String> equalSet = GenericsGeneratorUtility.createEqualSet(nameReplacementResults, tph);
|
||||||
|
|
||||||
|
return new GenericsGeneratorResult(constraint, equalSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GenericsGeneratorResult generateGGResult(final LinkedList<String> tphsInRel,
|
||||||
|
final ConstraintsSimplierResult simplifiedConstraints) {
|
||||||
|
|
||||||
|
String subType = tphsInRel.getFirst();
|
||||||
|
|
||||||
|
if (tphsInRel.size() == 1) {
|
||||||
|
Optional<GenericsGeneratorResult> constraintFromSimplifiedCon = simplifiedConstraints
|
||||||
|
.getGenericsGenResults().stream().filter(g -> g.getConstraint().getLeft().equals(subType))
|
||||||
|
.findFirst();
|
||||||
|
if (constraintFromSimplifiedCon.isPresent())
|
||||||
|
return constraintFromSimplifiedCon.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
String superType = tphsInRel.size() > 1 ? tphsInRel.getLast() : Type.getInternalName(Object.class);
|
||||||
|
|
||||||
|
TPHConstraint constraint = new ExtendsConstraint(subType, superType);
|
||||||
|
|
||||||
|
Set<String> equalSet = GenericsGeneratorUtility
|
||||||
|
.createEqualSet(simplifiedConstraints.getNameReplacementResults(), subType);
|
||||||
|
|
||||||
|
return new GenericsGeneratorResult(constraint, equalSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,571 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.EqualConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.ConstraintsFinder;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.NameReplacer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GenericsGeneratorUtility {
|
||||||
|
/**
|
||||||
|
* Returns a list of type placeholders names of a specified method
|
||||||
|
*
|
||||||
|
* @param methodID The id of the method ReturnTypeMethodName(ParameterTypes)
|
||||||
|
* @param listOfMethodsAndTph List of all methods
|
||||||
|
* @return a list of type placehoders names
|
||||||
|
*/
|
||||||
|
public static List<String> getMethodTPHS(String methodID, ArrayList<MethodAndTPH> listOfMethodsAndTph) {
|
||||||
|
return listOfMethodsAndTph.stream().filter(mt->mt.getId().equals(methodID)).findAny().get().getTphs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a reverse constraint of a specified constraint which is given by its left and right
|
||||||
|
* side
|
||||||
|
*
|
||||||
|
* @param allCons List of all constraints
|
||||||
|
* @param left The left side of the given constraint
|
||||||
|
* @param right The right side of the given constraint
|
||||||
|
* @return An Optional object which contains the reverse constraint if it is exist
|
||||||
|
*/
|
||||||
|
public static Optional<TPHConstraint> getReverseConstraint(List<TPHConstraint> allCons, String left, String right) {
|
||||||
|
return allCons.stream().filter(c->{
|
||||||
|
return c.getRight().equals(left) && c.getLeft().equals(right);
|
||||||
|
}).findAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Substitutes the old name by the new name in all constraints
|
||||||
|
*
|
||||||
|
* @param allCons List of all constraints
|
||||||
|
* @param oldName The name to be replaced
|
||||||
|
* @param newName The new name
|
||||||
|
*/
|
||||||
|
public static void substituteTPH(List<TPHConstraint> allCons, String oldName, String newName) {
|
||||||
|
allCons.stream()
|
||||||
|
.filter(c->c.getRel()==Relation.EXTENDS)
|
||||||
|
.forEach(c->{
|
||||||
|
if(c.getLeft().equals(oldName))
|
||||||
|
c.setLeft(newName);
|
||||||
|
if(c.getRight().equals(oldName))
|
||||||
|
c.setRight(newName);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ConstraintsWithSameLeftSide> findConstraintsWithLeftSameLeftSide(List<TPHConstraint> allCons) {
|
||||||
|
// finder looks for constraints that have the same left hand side
|
||||||
|
// and put them in a list
|
||||||
|
ConstraintsFinder finder = new ConstraintsFinder(allCons);
|
||||||
|
List<ConstraintsWithSameLeftSide> foundCons = finder.findConstraints();
|
||||||
|
return foundCons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void simplifyConstraintsWithSameLeftSide(List<ConstraintsWithSameLeftSide> consWithSameLeftSide,
|
||||||
|
List<TPHConstraint> allCons, List<String> methodTPHS) {
|
||||||
|
List<TPHConstraint> eqCons = new ArrayList<>();
|
||||||
|
|
||||||
|
for (ConstraintsWithSameLeftSide list : consWithSameLeftSide) {
|
||||||
|
NameReplacementResult replRes = modifyNames(allCons, methodTPHS, list);
|
||||||
|
createEqualConstraintsForNames(replRes.getName(), replRes.getOldNames(),eqCons);
|
||||||
|
|
||||||
|
for (TPHConstraint c : allCons) {
|
||||||
|
if (c.getRel() == Relation.EQUAL && replRes.getName().equals(c.getRight())) {
|
||||||
|
eqCons.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateEqualCons(replRes, eqCons);
|
||||||
|
|
||||||
|
TPHConstraint c = list.getConstraints().get(0);
|
||||||
|
allCons.removeAll(list.getConstraints());
|
||||||
|
allCons.add(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void simplifyConstraintsWithSameLeftSide(List<ConstraintsWithSameLeftSide> consWithSameLeftSide,
|
||||||
|
TPHExtractor tphExtractor, List<String> tphsClass, List<TPHConstraint> equalCons) {
|
||||||
|
List<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
|
|
||||||
|
for (ConstraintsWithSameLeftSide list : consWithSameLeftSide) {
|
||||||
|
if(!stillWithSameLeftSide(list))
|
||||||
|
continue;
|
||||||
|
NameReplacementResult replRes = modifyNames(allCons, list, tphExtractor.ListOfMethodsAndTph,tphsClass);
|
||||||
|
createEqualConstraintsForNames(replRes.getName(), replRes.getOldNames(),equalCons);
|
||||||
|
|
||||||
|
for (TPHConstraint c : allCons) {
|
||||||
|
if (c.getRel() == Relation.EQUAL && replRes.getName().equals(c.getRight())) {
|
||||||
|
equalCons.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateEqualCons(replRes, equalCons);
|
||||||
|
|
||||||
|
TPHConstraint c = list.getConstraints().get(0);
|
||||||
|
allCons.removeAll(list.getConstraints());
|
||||||
|
removeConstraintsWithSameLeftAndRightSide(allCons);
|
||||||
|
allCons.add(c);
|
||||||
|
removeDuplicate(allCons);
|
||||||
|
}
|
||||||
|
consWithSameLeftSide.clear();
|
||||||
|
consWithSameLeftSide = findConstraintsWithLeftSameLeftSide(allCons);
|
||||||
|
if(!consWithSameLeftSide.isEmpty())
|
||||||
|
simplifyConstraintsWithSameLeftSide(consWithSameLeftSide,tphExtractor,tphsClass,equalCons);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeDuplicate(List<TPHConstraint> allCons) {
|
||||||
|
List<TPHConstraint> visited = new ArrayList<>();
|
||||||
|
List<Integer> toRemove = new ArrayList<>();
|
||||||
|
checkForDuplicate(allCons, visited, toRemove);
|
||||||
|
removeConstraintsByIndex(allCons, toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeConstraintsByIndex(List<TPHConstraint> allCons, List<Integer> toRemove) {
|
||||||
|
for(int index : toRemove)
|
||||||
|
allCons.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkForDuplicate(List<TPHConstraint> allCons, List<TPHConstraint> visited, List<Integer> toRemove) {
|
||||||
|
for(int i = 0;i<allCons.size();++i){
|
||||||
|
markConstraintIfDuplicate(allCons, visited, toRemove, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void markConstraintIfDuplicate(List<TPHConstraint> allCons, List<TPHConstraint> visited, List<Integer> toRemove, int i) {
|
||||||
|
TPHConstraint constraint = allCons.get(i);
|
||||||
|
if(containsInList(visited,constraint.getLeft(),constraint.getRight())){
|
||||||
|
toRemove.add(i);
|
||||||
|
} else {
|
||||||
|
visited.add(constraint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsInList(List<TPHConstraint> allConstraints, String left, String right) {
|
||||||
|
for(TPHConstraint constraint : allConstraints)
|
||||||
|
if(constraint.getLeft().equals(left) && constraint.getRight().equals(right))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addNewConstraintsWithSameLeftSide(ConstraintsWithSameLeftSide constraintsWithSameLeftSide, List<TPHConstraint> allCons) {
|
||||||
|
allCons.forEach(c->{
|
||||||
|
if (constraintsWithSameLeftSide.getConstraints().get(0).getLeft().equals(c.getLeft())){
|
||||||
|
if(!constraintsWithSameLeftSide.getConstraints().contains(c))
|
||||||
|
constraintsWithSameLeftSide.getConstraints().add(c);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkForNewConstraintsWithSameLeftSide(List<ConstraintsWithSameLeftSide> consWithSameLeftSide, List<TPHConstraint> allCons) {
|
||||||
|
allCons.forEach(c->{
|
||||||
|
Optional<ConstraintsWithSameLeftSide> constraintsWithSameLeftSide = getConstraintsWithSameLeftSide(consWithSameLeftSide, c.getLeft());
|
||||||
|
constraintsWithSameLeftSide.ifPresent(cls->{
|
||||||
|
if(!cls.getConstraints().contains(c))
|
||||||
|
cls.getConstraints().add(c);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<ConstraintsWithSameLeftSide> getConstraintsWithSameLeftSide(List<ConstraintsWithSameLeftSide> consWithSameLeftSide, String left) {
|
||||||
|
return consWithSameLeftSide.stream().filter(csl->isContainedInConsWithLeftSide(csl,left)).findAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isContainedInConsWithLeftSide(ConstraintsWithSameLeftSide csl, String left) {
|
||||||
|
return csl.getConstraints().get(0).getLeft().equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean stillWithSameLeftSide(ConstraintsWithSameLeftSide constraints) {
|
||||||
|
removeUnvalidConstraints(constraints);
|
||||||
|
return constraints.getConstraints().size()>1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeUnvalidConstraints(ConstraintsWithSameLeftSide constraints) {
|
||||||
|
List<TPHConstraint> toRemove = new ArrayList<>();
|
||||||
|
constraints.getConstraints().forEach(c->{
|
||||||
|
if(c.getLeft().equals(c.getRight()))
|
||||||
|
toRemove.add(c);
|
||||||
|
});
|
||||||
|
if(!toRemove.isEmpty())
|
||||||
|
constraints.getConstraints().removeAll(toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeConstraintsWithSameLeftAndRightSide(List<TPHConstraint> allCons) {
|
||||||
|
List<TPHConstraint> toRemove = new ArrayList<>();
|
||||||
|
allCons.forEach(c->{
|
||||||
|
if(c.getLeft().equals(c.getRight()))
|
||||||
|
toRemove.add(c);
|
||||||
|
});
|
||||||
|
allCons.removeAll(toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createEqualConstraintsForNames(String name, List<String> equalNames, List<TPHConstraint> eqCons) {
|
||||||
|
// create an equal constraint for each value in repres
|
||||||
|
for (String eName : equalNames) {
|
||||||
|
EqualConstraint ec = new EqualConstraint(eName, name);
|
||||||
|
eqCons.add(ec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param allCons
|
||||||
|
* @param methodTPHS
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static NameReplacementResult modifyNames(List<TPHConstraint> allCons, List<String> methodTPHS,
|
||||||
|
ConstraintsWithSameLeftSide list) {
|
||||||
|
// generate a new name and replace the right hand side for each constraint
|
||||||
|
// in list with the new name
|
||||||
|
NameReplacer replacer = new NameReplacer(list.getConstraints(), allCons, methodTPHS);
|
||||||
|
// new name -> [all old names]
|
||||||
|
NameReplacementResult replRes = replacer.replaceNames();
|
||||||
|
return replRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NameReplacementResult modifyNames(List<TPHConstraint> allCons, ConstraintsWithSameLeftSide list, List<MethodAndTPH> methodAndTPHs, List<String> tphsClass) {
|
||||||
|
// generate a new name and replace the right hand side for each constraint
|
||||||
|
// in list with the new name
|
||||||
|
NameReplacer replacer = new NameReplacer(list.getConstraints(), allCons, methodAndTPHs, tphsClass);
|
||||||
|
// new name -> [all old names]
|
||||||
|
NameReplacementResult replRes = replacer.replaceNames();
|
||||||
|
return replRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateEqualCons(NameReplacementResult nameReplacementResult, List<TPHConstraint> eqCons) {
|
||||||
|
List<String> oldNames = nameReplacementResult.getOldNames();
|
||||||
|
String newName = nameReplacementResult.getName();
|
||||||
|
for (TPHConstraint c : eqCons) {
|
||||||
|
// if(oldNames.contains(c.getLeft()))
|
||||||
|
// c.setLeft(newName);
|
||||||
|
if (oldNames.contains(c.getRight()))
|
||||||
|
c.setRight(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void modifyRelationForConstraintsInCycle(List<Cycle> cycles) {
|
||||||
|
cycles.stream().map(lc->lc.getConstraints()).flatMap(e->e.stream()).forEach(c->c.setRel(Relation.EQUAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<NameReplacementResult> substituteTPHSFormCycle(List<TPHConstraint> allCons, List<Cycle> cycles, TPHExtractor tphExtractor) {
|
||||||
|
List<NameReplacementResult> results = new ArrayList<>();
|
||||||
|
cycles.forEach(lc->{
|
||||||
|
Set<String> names = getNamesFromCycle(lc);
|
||||||
|
String newName = names.stream().findFirst().get();
|
||||||
|
|
||||||
|
List<String> equalNames = new ArrayList<>(names);
|
||||||
|
|
||||||
|
Stream<ArrayList<String>> tphsOfMethods = tphExtractor.ListOfMethodsAndTph.stream().map(m->m.getTphs());
|
||||||
|
Stream<ArrayList<String>> localTphsOfMethods = tphExtractor.ListOfMethodsAndTph.stream().map(m->m.getLocalTphs());
|
||||||
|
|
||||||
|
replaceOldNames(newName, equalNames, tphsOfMethods);
|
||||||
|
replaceOldNames(newName, equalNames, localTphsOfMethods);
|
||||||
|
|
||||||
|
NameReplacementResult res = new NameReplacementResult(newName, equalNames);
|
||||||
|
results.add(res);
|
||||||
|
substituteAll(allCons,names,newName);
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param newName
|
||||||
|
* @param names
|
||||||
|
* @param tphsOfMethods
|
||||||
|
*/
|
||||||
|
public static void replaceOldNames(final String newName, final List<String> names, Stream<ArrayList<String>> tphsOfMethods) {
|
||||||
|
tphsOfMethods.forEach(tphsMethod->{
|
||||||
|
if(tphsMethod.removeAll(names))
|
||||||
|
tphsMethod.add(newName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void substituteAll(List<TPHConstraint> allCons, Set<String> names, String newName) {
|
||||||
|
allCons.stream()
|
||||||
|
.filter(c-> c.getRel()==Relation.EXTENDS)
|
||||||
|
.forEach(c->{
|
||||||
|
if(names.contains(c.getLeft())) {
|
||||||
|
c.setLeft(newName);
|
||||||
|
} else if(names.contains(c.getRight())) {
|
||||||
|
c.setRight(newName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> getNamesFromCycle(Cycle lc) {
|
||||||
|
Set<String> names = new HashSet<>();
|
||||||
|
lc.getConstraints().forEach(c->names.add(c.getLeft()));
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createResults(List<GenericsGeneratorResult> genericsGeneratorResults,
|
||||||
|
List<NameReplacementResult> nameReplacementResults) {
|
||||||
|
nameReplacementResults.forEach(n->{
|
||||||
|
Set<String> equals = new HashSet<>(n.getOldNames());
|
||||||
|
TPHConstraint cons = new ExtendsConstraint(n.getName(), Type.getInternalName(Object.class));
|
||||||
|
GenericsGeneratorResult ggRes = new GenericsGeneratorResult(cons, equals);
|
||||||
|
genericsGeneratorResults.add(ggRes);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeEqualConstraints(List<TPHConstraint> allCons) {
|
||||||
|
List<TPHConstraint> equalConstraints = getEqualConstraints(allCons);
|
||||||
|
allCons.removeAll(equalConstraints);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<TPHConstraint> getEqualConstraints(List<TPHConstraint> allCons) {
|
||||||
|
return allCons.stream().filter(c->c.getRel()==Relation.EQUAL).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<NameReplacementResult> createNameReplacementResultsFromEqualConstraints(
|
||||||
|
List<TPHConstraint> equalCons) {
|
||||||
|
List<NameReplacementResult> nameReplacementResults = new ArrayList<>();
|
||||||
|
equalCons.forEach(c->{
|
||||||
|
if(isInNameReplacementResults(nameReplacementResults,c.getRight())) {
|
||||||
|
getNameReplacementByName(nameReplacementResults,c.getRight()).getOldNames().add(c.getLeft());
|
||||||
|
} else {
|
||||||
|
List<String> oldNames = new ArrayList<>();
|
||||||
|
oldNames.add(c.getLeft());
|
||||||
|
NameReplacementResult nrRes = new NameReplacementResult(c.getRight(), oldNames);
|
||||||
|
nameReplacementResults.add(nrRes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return nameReplacementResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NameReplacementResult getNameReplacementByName(List<NameReplacementResult> nameReplacementResults,
|
||||||
|
String name) {
|
||||||
|
return nameReplacementResults.stream().filter(n->n.getName().equals(name)).findFirst().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInNameReplacementResults(List<NameReplacementResult> nameReplacementResults,String name){
|
||||||
|
if(nameReplacementResults.isEmpty())
|
||||||
|
return false;
|
||||||
|
return nameReplacementResults.stream().map(r->r.getName()).filter(n->name.equals(n)).findFirst().isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<TPHConstraint> getConstraintByLeftSide(List<TPHConstraint> allCons, String tph) {
|
||||||
|
return allCons.stream().filter(c->c.getLeft().equals(tph)).findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<TPHConstraint> getConstraintByRightSide(List<TPHConstraint> allCons, String tph) {
|
||||||
|
return allCons.stream().filter(c->c.getRight().equals(tph)).findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTPHInGenericGeneratorResult(final List<GenericsGeneratorResult> constraints, final String tph) {
|
||||||
|
return constraints.stream().filter(g->g.getConstraint().getLeft().equals(tph)).findFirst().isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param allCons
|
||||||
|
* @param tphsMethod
|
||||||
|
* @param tphsClass
|
||||||
|
* @param visitedTPHs
|
||||||
|
* @param tph
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static LinkedList<String> createLinkedListForTPHsInRelation(final List<TPHConstraint> allCons,
|
||||||
|
List<String> tphsMethod, List<String> tphsClass, final Set<String> visitedTPHs, String tph) {
|
||||||
|
|
||||||
|
final LinkedList<String> tphsInRel = new LinkedList<>();
|
||||||
|
List<String> tphsList = new ArrayList<>(tphsMethod);
|
||||||
|
tphsList.addAll(tphsClass);
|
||||||
|
|
||||||
|
boolean isNextSuperTypeFound = findNextSuperTyp(allCons,tphsList ,visitedTPHs, tph, tphsInRel);
|
||||||
|
if(!isNextSuperTypeFound)
|
||||||
|
findNextSubType(allCons, tphsList,visitedTPHs, tph, tphsInRel);
|
||||||
|
return tphsInRel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean findNextSubType(List<TPHConstraint> allCons, List<String> tphsList, Set<String> visitedTPHs, String tph,
|
||||||
|
LinkedList<String> tphsInRel) {
|
||||||
|
Optional<TPHConstraint> con = getConstraintByRightSide(allCons, tph);
|
||||||
|
while (con.isPresent()) {
|
||||||
|
String left = con.get().getLeft();
|
||||||
|
String right = con.get().getRight();
|
||||||
|
|
||||||
|
addTPHsToListFromLeft(tphsInRel, left, right);
|
||||||
|
markAsVisited(visitedTPHs, left);
|
||||||
|
|
||||||
|
if(tphsList.contains(left))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
con = getConstraintByRightSide(allCons, left);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addTPHsToListFromLeft(LinkedList<String> tphsInRel, String left, String right) {
|
||||||
|
if (tphsInRel.isEmpty())
|
||||||
|
tphsInRel.add(right);
|
||||||
|
|
||||||
|
tphsInRel.addFirst(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param allCons
|
||||||
|
* @param tphsList
|
||||||
|
* @param visitedTPHs
|
||||||
|
* @param tph
|
||||||
|
* @param tphsInRel
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean findNextSuperTyp(final List<TPHConstraint> allCons, List<String> tphsList, final Set<String> visitedTPHs, String tph,
|
||||||
|
final LinkedList<String> tphsInRel) {
|
||||||
|
Optional<TPHConstraint> con = getConstraintByLeftSide(allCons, tph);
|
||||||
|
|
||||||
|
markAsVisited(visitedTPHs, tph);
|
||||||
|
|
||||||
|
while (con.isPresent()) {
|
||||||
|
String left = con.get().getLeft();
|
||||||
|
String right = con.get().getRight();
|
||||||
|
addTPHsToList(tphsInRel, left, right);
|
||||||
|
|
||||||
|
if(tphsList.contains(right))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
markAsVisited(visitedTPHs, right);
|
||||||
|
|
||||||
|
con = getConstraintByLeftSide(allCons, right);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void markAsVisited(Set<String> visitedTPHs, String left) {
|
||||||
|
visitedTPHs.add(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param visitedTPHs
|
||||||
|
* @param right
|
||||||
|
* @param left
|
||||||
|
*/
|
||||||
|
public static void markAsVisited(final Set<String> visitedTPHs, String left, String right) {
|
||||||
|
visitedTPHs.add(left);
|
||||||
|
visitedTPHs.add(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tphsInRel
|
||||||
|
* @param right
|
||||||
|
* @param left
|
||||||
|
*/
|
||||||
|
public static void addTPHsToList(final LinkedList<String> tphsInRel, String left, String right) {
|
||||||
|
if (tphsInRel.isEmpty())
|
||||||
|
tphsInRel.add(left);
|
||||||
|
tphsInRel.add(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeNotLocalTphs(final LinkedList<String> tphsInRel, final List<String> localTphs,
|
||||||
|
List<String> tphsClass) {
|
||||||
|
|
||||||
|
while (!localTphs.contains(tphsInRel.peek())) {
|
||||||
|
tphsInRel.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
String last = tphsInRel.peekLast();
|
||||||
|
while (!localTphs.contains(last) && !tphsClass.contains(last)) {
|
||||||
|
tphsInRel.removeLast();
|
||||||
|
last = tphsInRel.peekLast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param nameReplacementResults
|
||||||
|
* @param subType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Set<String> createEqualSet(final List<NameReplacementResult> nameReplacementResults, String subType) {
|
||||||
|
Optional<NameReplacementResult> equals = nameReplacementResults.stream()
|
||||||
|
.filter(n -> n.getName().equals(subType)).findFirst();
|
||||||
|
|
||||||
|
Set<String> equalSet = equals.isPresent() ? new HashSet<>(equals.get().getOldNames()) : new HashSet<>();
|
||||||
|
return equalSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getNextClassTph(List<String> tphsClass, LinkedList<String> tphsInRel) {
|
||||||
|
|
||||||
|
for(int i = 1;i<tphsInRel.size();++i) {
|
||||||
|
String next = tphsInRel.get(i);
|
||||||
|
if(tphsClass.contains(next))
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tphsInRel.getLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addTPHsToClassTPHs(final List<GenericsGeneratorResult> constraints, final List<String> tphsClass) {
|
||||||
|
|
||||||
|
List<String> lefts = constraints.stream().map(r->r.getConstraint()).map(c->c.getLeft()).collect(Collectors.toList());
|
||||||
|
List<String> rights = constraints.stream().map(r->r.getConstraint()).map(c->c.getRight()).collect(Collectors.toList());
|
||||||
|
List<String> leftsAndRights = new ArrayList<>(lefts);
|
||||||
|
leftsAndRights.addAll(rights);
|
||||||
|
List<String> shouldBeClassTphs = leftsAndRights.stream().distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
|
for(String tph : shouldBeClassTphs) {
|
||||||
|
if(!tphsClass.contains(tph))
|
||||||
|
tphsClass.add(tph);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeClassTPHsFromMethodTPHs(List<String> tphsClass, TPHExtractor tphExtractor) {
|
||||||
|
|
||||||
|
tphExtractor.ListOfMethodsAndTph.stream().map(m->m.getTphs()).forEach(tphs->{
|
||||||
|
tphs.removeAll(tphsClass);
|
||||||
|
});
|
||||||
|
|
||||||
|
tphExtractor.ListOfMethodsAndTph.stream().map(m->m.getLocalTphs()).forEach(tphs->{
|
||||||
|
tphs.removeAll(tphsClass);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinkedList<String> createLinkedListForTPHsInRelationClass(List<TPHConstraint> allCons,
|
||||||
|
List<String> tphsClass, List<String> methodTPHs, Set<String> visitedTPHs, String tph) {
|
||||||
|
final LinkedList<String> tphsInRel = new LinkedList<>();
|
||||||
|
|
||||||
|
boolean isNextSuperTypeFound = findNextSuperTyp(allCons,tphsClass ,visitedTPHs, tph, tphsInRel);
|
||||||
|
if(!tphsInRel.isEmpty() && !isNextSuperTypeFound && !methodTPHs.contains(tphsInRel.getLast()))
|
||||||
|
findNextSubType(allCons, tphsClass,visitedTPHs, tph, tphsInRel);
|
||||||
|
return tphsInRel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInResult(String first, List<GenericsGeneratorResult> constraints) {
|
||||||
|
return constraints.stream().map(r->r.getConstraint()).filter(c->c.getLeft().equals(first)).findFirst().isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<GenericsGeneratorResult> getGenericGeneratorResult(List<GenericsGeneratorResult> list,
|
||||||
|
String tph) {
|
||||||
|
return list.stream().filter(g->g.getConstraint().getLeft().equals(tph)).findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeGenericGeneratorResult(List<GenericsGeneratorResult> genericsGenResults,
|
||||||
|
GenericsGeneratorResult ggResult) {
|
||||||
|
genericsGenResults.remove(ggResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<MethodAndTPH> getMethodAndTphs(ArrayList<MethodAndTPH> listOfMethodsAndTph, String id) {
|
||||||
|
return listOfMethodsAndTph.stream().filter(m->m.getId().equals(id)).findFirst();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
|
||||||
|
public class ConstraintsWithSameLeftSide {
|
||||||
|
private List<TPHConstraint> constraints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param constraints
|
||||||
|
*/
|
||||||
|
public ConstraintsWithSameLeftSide(List<TPHConstraint> constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the constraints
|
||||||
|
*/
|
||||||
|
public List<TPHConstraint> getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param constraints the constraints to set
|
||||||
|
*/
|
||||||
|
public void setConstraints(List<TPHConstraint> constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[" + constraints.toString() + "]";
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Cycle {
|
||||||
|
private final List<TPHConstraint> constraints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param constraints
|
||||||
|
*/
|
||||||
|
public Cycle(List<TPHConstraint> constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the constraints
|
||||||
|
*/
|
||||||
|
public List<TPHConstraint> getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containConstraint(TPHConstraint constraint) {
|
||||||
|
for(TPHConstraint c : constraints) {
|
||||||
|
if(c.equalConstraint(constraint))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
constraints.forEach(c->sb.append(c.getLeft()+" -> "));
|
||||||
|
sb.append(constraints.get(constraints.size()-1).getRight());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GenericGeneratorResultsForAllMethods {
|
||||||
|
private final List<MethodAndConstraints> methodsAndConstraints;
|
||||||
|
|
||||||
|
public GenericGeneratorResultsForAllMethods() {
|
||||||
|
this(Collections.emptyList());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param methodsAndConstraints
|
||||||
|
*/
|
||||||
|
public GenericGeneratorResultsForAllMethods(List<MethodAndConstraints> methodsAndConstraints) {
|
||||||
|
this.methodsAndConstraints = methodsAndConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the methodsAndConstraints
|
||||||
|
*/
|
||||||
|
public List<MethodAndConstraints> getMethodsAndConstraints() {
|
||||||
|
return methodsAndConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The simplify results of a source file (package)
|
||||||
|
*
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GenericGenratorResultForSourceFile {
|
||||||
|
private String pkgName;
|
||||||
|
private final List<GenericsGeneratorResultForClass> genericGeneratorResultForAllClasses = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pkgName
|
||||||
|
*/
|
||||||
|
public GenericGenratorResultForSourceFile(String pkgName) {
|
||||||
|
this.pkgName = pkgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GenericsGeneratorResultForClass> getGenericGeneratorResultForAllClasses() {
|
||||||
|
return genericGeneratorResultForAllClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends the simplify results of a class to simplifyResForSF
|
||||||
|
*
|
||||||
|
* @param sResClass simplify results of a class to added
|
||||||
|
*/
|
||||||
|
public void addGenericGeneratorResultClass(GenericsGeneratorResultForClass sResClass) {
|
||||||
|
genericGeneratorResultForAllClasses.add(sResClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {
|
||||||
|
|
||||||
|
if (this.pkgName.equals(pkgName)) {
|
||||||
|
return genericGeneratorResultForAllClasses.stream()
|
||||||
|
.filter(sr -> sr.getClassName().equals(name))
|
||||||
|
.findAny()
|
||||||
|
.orElseThrow(() -> new NoSuchElementException(
|
||||||
|
"Simplify results for the class " + pkgName + "." + name + " are not found"));
|
||||||
|
}
|
||||||
|
throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found");
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GenericsGeneratorResult {
|
||||||
|
private TPHConstraint constraint;
|
||||||
|
/**
|
||||||
|
* contains the names of all type placeholders which are equals to the left side of
|
||||||
|
* the constraint {@link #constraint}.
|
||||||
|
*/
|
||||||
|
private Set<String> equalsTPHs;
|
||||||
|
/**
|
||||||
|
* @param constraint
|
||||||
|
* @param equalsTPHs
|
||||||
|
*/
|
||||||
|
public GenericsGeneratorResult(TPHConstraint constraint, Set<String> equalsTPHs) {
|
||||||
|
this.constraint = constraint;
|
||||||
|
this.equalsTPHs = equalsTPHs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the constraint
|
||||||
|
*/
|
||||||
|
public TPHConstraint getConstraint() {
|
||||||
|
return constraint;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param constraint the constraint to set
|
||||||
|
*/
|
||||||
|
public void setConstraint(TPHConstraint constraint) {
|
||||||
|
this.constraint = constraint;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the equalsTPHs
|
||||||
|
*/
|
||||||
|
public Set<String> getEqualsTPHs() {
|
||||||
|
return equalsTPHs;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param equalsTPHs the equalsTPHs to set
|
||||||
|
*/
|
||||||
|
public void setEqualsTPHs(Set<String> equalsTPHs) {
|
||||||
|
this.equalsTPHs = equalsTPHs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GenericsGeneratorResultForClass {
|
||||||
|
private final String className;
|
||||||
|
private final List<GenericsGeneratorResult> classConstraints;
|
||||||
|
private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints;
|
||||||
|
|
||||||
|
public GenericsGeneratorResultForClass(String className) {
|
||||||
|
this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param className
|
||||||
|
* @param classConstraints
|
||||||
|
* @param methodsAndTheirConstraints
|
||||||
|
*/
|
||||||
|
public GenericsGeneratorResultForClass(String className, List<GenericsGeneratorResult> classConstraints,
|
||||||
|
GenericGeneratorResultsForAllMethods methodsAndTheirConstraints) {
|
||||||
|
this.className = className;
|
||||||
|
this.classConstraints = classConstraints;
|
||||||
|
this.methodsAndTheirConstraints = methodsAndTheirConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the className
|
||||||
|
*/
|
||||||
|
public String getClassName() {
|
||||||
|
return className;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the classConstraints
|
||||||
|
*/
|
||||||
|
public List<GenericsGeneratorResult> getClassConstraints() {
|
||||||
|
return classConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the methodsAndTheirConstraints
|
||||||
|
*/
|
||||||
|
public GenericGeneratorResultsForAllMethods getMethodsAndTheirConstraints() {
|
||||||
|
return methodsAndTheirConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String id) {
|
||||||
|
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().map(mc -> mc.getMethodID())
|
||||||
|
.anyMatch(i -> i.equals(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) {
|
||||||
|
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
|
||||||
|
.findFirst().get().getConstraints();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MethodAndConstraints {
|
||||||
|
private final String methodID;
|
||||||
|
private final List<GenericsGeneratorResult> constraints;
|
||||||
|
/**
|
||||||
|
* @param methodID
|
||||||
|
* @param constraints
|
||||||
|
*/
|
||||||
|
public MethodAndConstraints(String methodID, List<GenericsGeneratorResult> constraints) {
|
||||||
|
this.methodID = methodID;
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the methodID
|
||||||
|
*/
|
||||||
|
public String getMethodID() {
|
||||||
|
return methodID;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the constraints
|
||||||
|
*/
|
||||||
|
public List<GenericsGeneratorResult> getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NameReplacementResult {
|
||||||
|
private String name;
|
||||||
|
private List<String> oldNames;
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* @param oldNames
|
||||||
|
*/
|
||||||
|
public NameReplacementResult(String name, List<String> oldNames) {
|
||||||
|
this.name = name;
|
||||||
|
this.oldNames = oldNames;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param name the name to set
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the oldNames
|
||||||
|
*/
|
||||||
|
public List<String> getOldNames() {
|
||||||
|
return oldNames;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param oldNames the oldNames to set
|
||||||
|
*/
|
||||||
|
public void setOldNames(List<String> oldNames) {
|
||||||
|
this.oldNames = oldNames;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -1,93 +1,166 @@
|
|||||||
package de.dhbwstuttgart.bytecode.signature;
|
package de.dhbwstuttgart.bytecode.signature;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class Signature {
|
public class Signature {
|
||||||
|
private static final char SUPER_CHAR = '-';
|
||||||
|
private static final char EXTENDS_CHAR = '+';
|
||||||
|
private static final String SPECIAL_CHAR_FOR_FUN = "$$";
|
||||||
|
private static final String SPECIAL_CHAR = "$";
|
||||||
private ClassOrInterface classOrInterface;
|
private ClassOrInterface classOrInterface;
|
||||||
private HashMap<String, String> genericsAndBounds;
|
private HashMap<String, String> genericsAndBounds;
|
||||||
private HashMap<String, String> genericsAndBoundsMethod;
|
private HashMap<String, String> genericsAndBoundsMethod;
|
||||||
private SignatureWriter sw;
|
private final SignatureWriter sw = new SignatureWriter();;
|
||||||
private Constructor constructor;
|
private Constructor constructor;
|
||||||
private Method method;
|
private Method method;
|
||||||
private HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
private HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private ArrayList<GenericInsertPair> commonPairs;
|
private Map<TPHConstraint, Set<String>> methodConstraints;
|
||||||
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
private List<GenericsGeneratorResult> consClass;
|
||||||
private ArrayList<String> tphsClass;
|
private List<GenericsGeneratorResult> constraints;
|
||||||
private ArrayList<TPHConstraint> consClass;
|
|
||||||
|
|
||||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
// public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||||
ArrayList<GenericInsertPair> commonPairs, ArrayList<String> tphsClass, ArrayList<TPHConstraint> consClass) {
|
// List<TPHConstraint> consClass) {
|
||||||
this.classOrInterface = classOrInterface;
|
// this.classOrInterface = classOrInterface;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
// this.genericsAndBounds = genericsAndBounds;
|
||||||
this.commonPairs = commonPairs;
|
// this.consClass = consClass;
|
||||||
this.tphsClass = tphsClass;
|
// sw = new SignatureWriter();
|
||||||
this.consClass = consClass;
|
// createSignatureForClassOrInterface();
|
||||||
sw = new SignatureWriter();
|
// }
|
||||||
createSignatureForClassOrInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Signature(Constructor constructor, HashMap<String, String> genericsAndBounds,
|
public Signature(HashMap<String, String> genericsAndBounds,
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet,
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet,
|
||||||
HashMap<TPHConstraint,HashSet<String>> methodConstraints) {
|
List<GenericsGeneratorResult> constraints) {
|
||||||
this.constructor = constructor;
|
//this.constructor = constructor;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.methodConstraints = methodConstraints;
|
this.constraints = constraints;
|
||||||
sw = new SignatureWriter();
|
|
||||||
createSignatureForConsOrMethod(this.constructor,true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,HashMap<String, String> genericsAndBounds,
|
public Signature(int numberOfParams) {
|
||||||
|
createSignatureForFunN(numberOfParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Signature(int numberOfParams, String to, String[] paramTypes) {
|
||||||
|
createSignatureForFunN(numberOfParams, to, paramTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||||
|
List<GenericsGeneratorResult> consClass) {
|
||||||
|
this.classOrInterface = classOrInterface;
|
||||||
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
|
this.consClass = consClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Signature(HashMap<String, String> genericsAndBoundsMethod,
|
||||||
|
HashMap<String, String> genericsAndBounds,
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet,
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet,
|
||||||
HashMap<TPHConstraint,HashSet<String>> methodConstraints) {
|
List<GenericsGeneratorResult> constraints,List<GenericsGeneratorResult> consClass) {
|
||||||
this.method = method;
|
|
||||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.methodConstraints = methodConstraints;
|
this.constraints = constraints;
|
||||||
sw = new SignatureWriter();
|
this.consClass = consClass;
|
||||||
createSignatureForConsOrMethod(this.method,false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(int numberOfParams) {
|
public String createSignatureForConstructor(Constructor constructor) {
|
||||||
sw = new SignatureWriter();
|
visitParams();
|
||||||
createSignatureForFunN(numberOfParams);
|
sw.visitReturnType().visitBaseType('V');
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createSignatureForMethod(Method method) {
|
||||||
|
defineGenerics(method);
|
||||||
|
|
||||||
|
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
|
|
||||||
|
visitParams();
|
||||||
|
visitReturnType(method, ret);
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param method
|
||||||
|
* @param ret
|
||||||
|
*/
|
||||||
|
private void visitReturnType(Method method, String ret) {
|
||||||
|
if (ret.equals("V")) {
|
||||||
|
sw.visitReturnType().visitBaseType('V');
|
||||||
|
} else {
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||||
|
SignatureVisitor sv = sw.visitReturnType();
|
||||||
|
doVisitParamsOrReturn(returnType, sv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void visitParams() {
|
||||||
|
for (String paramName : methodParamsAndTypes.keySet()) {
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||||
|
SignatureVisitor sv = sw.visitParameterType();
|
||||||
|
doVisitParamsOrReturn(t, sv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
*/
|
||||||
|
private void defineGenerics(Method method) {
|
||||||
|
method.getGenerics().forEach(g -> {
|
||||||
|
visitTypeVarsAndTheirBounds(g, genericsAndBoundsMethod);
|
||||||
|
});
|
||||||
|
defineGenericsFromConstraints(constraints,genericsAndBoundsMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSignatureForFunN(int numberOfParams, String to, String[] paramTypes) {
|
||||||
|
defineTypeVariablesForParametersOfFunN(numberOfParams);
|
||||||
|
|
||||||
|
sw.visitFormalTypeParameter("R");
|
||||||
|
visitClassBound(to);
|
||||||
|
// TODO: prüfe ob Return-Type = void,
|
||||||
|
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));
|
||||||
|
sw.visitEnd();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSignatureForFunN(int numberOfParams) {
|
private void createSignatureForFunN(int numberOfParams) {
|
||||||
|
|
||||||
// sw.visitClassBound().visitEnd();
|
defineTypeVariablesForParametersOfFunN(numberOfParams);
|
||||||
|
|
||||||
|
sw.visitFormalTypeParameter("R");
|
||||||
|
// getBounds vom Return-Type
|
||||||
|
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||||
|
sw.visitClassBound().visitEnd();
|
||||||
|
// TODO: prüfe ob Return-Type = void,
|
||||||
|
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));
|
||||||
|
sw.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void defineTypeVariablesForParametersOfFunN(int numberOfParams) {
|
||||||
for (int i = 0; i < numberOfParams; i++) {
|
for (int i = 0; i < numberOfParams; i++) {
|
||||||
int j = i + 1;
|
int j = i + 1;
|
||||||
sw.visitFormalTypeParameter("T" + j);
|
sw.visitFormalTypeParameter("T" + j);
|
||||||
@@ -95,221 +168,42 @@ public class Signature {
|
|||||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||||
sw.visitClassBound().visitEnd();
|
sw.visitClassBound().visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.visitFormalTypeParameter("R");
|
|
||||||
// getBounds vom Return-Type
|
|
||||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
|
||||||
sw.visitClassBound().visitEnd();
|
|
||||||
// TODO: prüfe ob Return-Type = void,
|
|
||||||
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));;
|
|
||||||
sw.visitEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates signature for a method or constructor with @see {@link SignatureWriter}
|
|
||||||
* Signature looks like:
|
|
||||||
* <typevaliables (K:Ljava/lang/Object "Bounds")>(params L.. OR T.. Or basistape)ReturnType
|
|
||||||
*
|
|
||||||
* @param method method or constructor
|
|
||||||
* @param isConstructor true if constructor
|
|
||||||
*/
|
|
||||||
private void createSignatureForConsOrMethod(Method method, boolean isConstructor) {
|
|
||||||
Iterator<? extends GenericTypeVar> itr = method.getGenerics().iterator();
|
|
||||||
// visits all formal type parameter and visits their bounds <T:...;B:...;...>
|
|
||||||
while(itr.hasNext()) {
|
|
||||||
System.out.println("HAS GENERICS!!");
|
|
||||||
GenericTypeVar g = itr.next();
|
|
||||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
|
|
||||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
|
||||||
if(!isConstructor) {
|
|
||||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
|
||||||
ArrayList<TPHConstraint> allConsBeforeSimplify = new ArrayList<>();
|
|
||||||
|
|
||||||
HashMap<TPHConstraint,HashSet<String>> allConstraints = new HashMap<>();
|
|
||||||
|
|
||||||
if(ret.contains("<")) {
|
|
||||||
allConsBeforeSimplify = getAllConstraints((RefType) resultSet.resolveType(method.getReturnType()).resolvedType);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
|
||||||
String pT = t.acceptTV(new TypeToSignature());
|
|
||||||
|
|
||||||
if(pT.contains("<"))
|
|
||||||
allConsBeforeSimplify = getAllConstraints((RefType) t);
|
|
||||||
}
|
|
||||||
boolean doSimplify = false;
|
|
||||||
if(!allConsBeforeSimplify.isEmpty()) {
|
|
||||||
addConstraintsToMap(allConstraints,allConsBeforeSimplify);
|
|
||||||
doSimplify = true;
|
|
||||||
}
|
|
||||||
createTypeVars(allConstraints, doSimplify);
|
|
||||||
|
|
||||||
if(!ret.equals("V")) {
|
|
||||||
if(ret.contains("$") && !ret.contains("$$") && !ret.contains("<")) {
|
|
||||||
if(genericsAndBounds.containsKey(ret)) {
|
|
||||||
genericsAndBoundsMethod.put(ret.substring(1), genericsAndBounds.get(ret.substring(1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// visit each method-parameter to create the signature
|
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
|
||||||
// parameter type deswegen ist true
|
|
||||||
doVisitParamsOrReturn(t,true);
|
|
||||||
}
|
|
||||||
if(isConstructor ||
|
|
||||||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).equals("V")) {
|
|
||||||
sw.visitReturnType().visitBaseType('V');
|
|
||||||
}else {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
|
||||||
// return type deswegen ist false
|
|
||||||
doVisitParamsOrReturn(returnType, false);
|
|
||||||
}
|
|
||||||
// sw.visitEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addConstraintsToMap(HashMap<TPHConstraint, HashSet<String>> allConstraints,
|
|
||||||
ArrayList<TPHConstraint> allConsBeforeSimplify) {
|
|
||||||
for(TPHConstraint tphCons : allConsBeforeSimplify) {
|
|
||||||
allConstraints.put(tphCons, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEqualTPH(HashMap<TPHConstraint, HashSet<String>> methodConstraints, String tph) {
|
|
||||||
for(TPHConstraint cons : methodConstraints.keySet()) {
|
|
||||||
if(methodConstraints.get(cons) != null) {
|
|
||||||
if(methodConstraints.get(cons).contains(tph)) {
|
|
||||||
return cons.getLeft();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tph;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createTypeVars(HashMap<TPHConstraint, HashSet<String>> allConstraints, boolean doSimplify) {
|
|
||||||
allConstraints.putAll(methodConstraints);
|
|
||||||
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> simplifiedConstraints;
|
|
||||||
if(doSimplify) {
|
|
||||||
simplifiedConstraints = Simplify.simplifyContraints(allConstraints);
|
|
||||||
}else {
|
|
||||||
simplifiedConstraints = allConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(TPHConstraint cons : simplifiedConstraints.keySet()) {
|
|
||||||
// need subst.
|
|
||||||
String sub = cons.getLeft()+"$";
|
|
||||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
|
||||||
sw.visitFormalTypeParameter(sub);
|
|
||||||
String bound = cons.getRight();
|
|
||||||
if(bound.equals(Type.getInternalName(Object.class))) {
|
|
||||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
|
||||||
sw.visitClassBound().visitEnd();
|
|
||||||
genericsAndBoundsMethod.put(sub, bound);
|
|
||||||
} else {
|
|
||||||
String boundName = bound+"$";
|
|
||||||
sw.visitClassBound().visitTypeVariable(boundName);
|
|
||||||
genericsAndBoundsMethod.put(sub, boundName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<TPHConstraint> getAllConstraints(RefType ref) {
|
|
||||||
final ArrayList<TPHConstraint> res = new ArrayList<>();
|
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
|
||||||
ResolvedType resType;
|
|
||||||
if(p instanceof WildcardType) {
|
|
||||||
resType = resultSet.resolveType(((WildcardType) p).getInnerType());
|
|
||||||
}else {
|
|
||||||
resType = resultSet.resolveType(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
|
||||||
if(resolved instanceof TypePlaceholder) {
|
|
||||||
//resType.getAdditionalGenerics().forEach(ag ->{
|
|
||||||
resultSet.genIns.forEach(ag ->{
|
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
|
||||||
if(!contains(res,constr)) {
|
|
||||||
res.add(constr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(resolved instanceof WildcardType) {
|
|
||||||
WildcardType resWC = (WildcardType) resolved;
|
|
||||||
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
|
||||||
if(resType2.resolvedType instanceof TypePlaceholder) {
|
|
||||||
//resType2.getAdditionalGenerics().forEach(ag ->{
|
|
||||||
resultSet.genIns.forEach(ag ->{
|
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
|
||||||
if(!contains(res,constr)) {
|
|
||||||
res.add(constr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println("RES GIP === " + res.size());
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
private boolean contains(ArrayList<TPHConstraint> constraints, TPHConstraint constr) {
|
|
||||||
for(int i=0; i<constraints.size();++i) {
|
|
||||||
TPHConstraint p = constraints.get(i);
|
|
||||||
if(constr.getLeft().equals(p.getLeft()) && constr.getRight().equals(p.getRight()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
||||||
* the method signature
|
* the method signature
|
||||||
|
*
|
||||||
* @param t type of parameter or return type
|
* @param t type of parameter or return type
|
||||||
* @param isParameterType true if t is type of parameter
|
* @param sv true if t is type of parameter
|
||||||
*/
|
*/
|
||||||
private void doVisitParamsOrReturn(RefTypeOrTPHOrWildcardOrGeneric t, boolean isParameterType) {
|
private void doVisitParamsOrReturn(RefTypeOrTPHOrWildcardOrGeneric t, SignatureVisitor sv) {
|
||||||
String type = t.acceptTV(new TypeToString());
|
String type = t.acceptTV(new TypeToString());
|
||||||
SignatureVisitor sv;
|
|
||||||
if(isParameterType) {
|
|
||||||
sv = sw.visitParameterType();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sv = sw.visitReturnType();
|
|
||||||
}
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "RT":
|
case "RT":
|
||||||
String sig = t.acceptTV(new TypeToSignature());
|
String sig = t.acceptTV(new TypeToSignature(constraints));
|
||||||
sv.visitClassType(sig.substring(1, sig.length()));
|
sv.visitClassType(sig.substring(1, sig.length()));
|
||||||
break;
|
break;
|
||||||
case "GRT":
|
case "GRT":
|
||||||
GenericRefType g = (GenericRefType) t;
|
GenericRefType g = (GenericRefType) t;
|
||||||
// sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
sv.visitTypeVariable(g.acceptTV(new TypeToSignature(constraints)));
|
||||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
|
||||||
break;
|
break;
|
||||||
case "TPH":
|
case "TPH":
|
||||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||||
// der Fall wenn die Type eine Interface ist, muss betrachtet werden
|
// der Fall wenn der Typ eine Interface ist, muss betrachtet werden
|
||||||
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
|
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
|
||||||
// Interface oder eine Klasse ist.
|
// Interface oder eine Klasse ist.
|
||||||
|
|
||||||
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new
|
||||||
|
// TypeToSignature())
|
||||||
//
|
//
|
||||||
String sig2 = r.acceptTV(new TypeToSignature());
|
String sig2 = r.acceptTV(new TypeToSignature(constraints));
|
||||||
if (r instanceof GenericRefType) {
|
if (r instanceof GenericRefType) {
|
||||||
sv.visitTypeVariable(sig2);
|
sv.visitTypeVariable(sig2);
|
||||||
} else if (!(r instanceof TypePlaceholder)) {
|
} else if (!(r instanceof TypePlaceholder)) {
|
||||||
if(sig2.contains("$$")) {
|
if (sig2.contains(SPECIAL_CHAR_FOR_FUN)) {
|
||||||
System.out.println(" Signature FUN$$: "+r);
|
sv.visitInterface().visitClassType(sig2.substring(1));
|
||||||
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
|
||||||
} else {
|
} else {
|
||||||
// Kann zwischen GenericRefType und RefType nicht unterscheiden
|
// Kann zwischen GenericRefType und RefType nicht unterscheiden
|
||||||
// Deswegen wird immer geprüft, ob der Name in Generic Maps liegt
|
// Deswegen wird immer geprüft, ob der Name in Generic Maps liegt
|
||||||
@@ -324,165 +218,162 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String eqTPH = getEqualTPH(methodConstraints, sig2.substring(1, sig2.length()-1))+"$";
|
String realName = sig2.substring(1, sig2.length() - 1);
|
||||||
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
String toVisit = realName+SPECIAL_CHAR;
|
||||||
sv.visitTypeVariable(eqTPH);
|
if(!genericsAndBounds.containsKey(toVisit)) {
|
||||||
|
Optional<GenericsGeneratorResult> equalTPH = getEqualTPHFromClassConstraints(consClass, realName);
|
||||||
|
if(equalTPH.isPresent()){
|
||||||
|
toVisit = equalTPH.get().getConstraint().getLeft() + SPECIAL_CHAR;
|
||||||
|
} else {
|
||||||
|
toVisit = getEqualTPH(constraints, realName) + SPECIAL_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sv.visitTypeVariable(toVisit);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SWC":
|
case "SWC":
|
||||||
System.out.println("SWC---Signature");
|
|
||||||
SuperWildcardType swc = (SuperWildcardType) t;
|
SuperWildcardType swc = (SuperWildcardType) t;
|
||||||
String sigInner = swc.getInnerType().acceptTV(new TypeToSignature());
|
String sigInner = swc.getInnerType().acceptTV(new TypeToSignature(constraints));
|
||||||
if(swc.getInnerType() instanceof TypePlaceholder) {
|
int length = sigInner.length();
|
||||||
sv.visitTypeArgument('-').visitTypeVariable(sigInner.substring(1, sigInner.length()));
|
visitWildCard(sv, sigInner, length, swc.getInnerType(), SUPER_CHAR);
|
||||||
} else if(swc.getInnerType() instanceof RefType) {
|
|
||||||
if(sigInner.contains("$$")) {
|
|
||||||
sv.visitTypeArgument('-').visitInterface().visitClassType(sigInner.substring(1,sigInner.length()));
|
|
||||||
}else {
|
|
||||||
sv.visitTypeArgument('-').visitClassType(sigInner.substring(1,sigInner.length()));
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
sv.visitTypeArgument('-').visitTypeVariable(sigInner.substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "EWC":
|
case "EWC":
|
||||||
System.out.println("EWC---Signature");
|
|
||||||
ExtendsWildcardType ewc = (ExtendsWildcardType) t;
|
ExtendsWildcardType ewc = (ExtendsWildcardType) t;
|
||||||
String esigInner = ewc.getInnerType().acceptTV(new TypeToSignature());
|
String esigInner = ewc.getInnerType().acceptTV(new TypeToSignature(constraints));
|
||||||
System.out.println(esigInner);
|
int lengthEWCSig = esigInner.length();
|
||||||
if(ewc.getInnerType() instanceof TypePlaceholder) {
|
visitWildCard(sv, esigInner, lengthEWCSig, ewc.getInnerType(), EXTENDS_CHAR);
|
||||||
sv.visitTypeArgument('+').visitTypeVariable(esigInner.substring(1, esigInner.length()));
|
|
||||||
} else if(ewc.getInnerType() instanceof RefType) {
|
|
||||||
if(esigInner.contains("$$")) {
|
|
||||||
sv.visitTypeArgument('+').visitInterface().visitClassType(esigInner.substring(1,esigInner.length()));
|
|
||||||
}else {
|
|
||||||
// sv.visitClassType(esigInner.substring(1,esigInner.length()));
|
|
||||||
sv.visitTypeArgument('+').visitClassType(esigInner.substring(1,esigInner.length()));
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
sv.visitTypeArgument('+').visitTypeVariable(esigInner.substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(!isParameterType)
|
// if (!sv)
|
||||||
sv.visitBaseType('V');
|
// sv.visitBaseType('V');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void visitWildCard(SignatureVisitor sv, String sigInner, int length, RefTypeOrTPHOrWildcardOrGeneric innerType, char superOrExtendsChar) {
|
||||||
|
if (innerType instanceof TypePlaceholder) {
|
||||||
|
sv.visitTypeArgument(superOrExtendsChar).visitTypeVariable(sigInner.substring(1, length));
|
||||||
|
} else if (innerType instanceof RefType) {
|
||||||
|
checkInnerSignatureOfWildCard(sv, sigInner, length, superOrExtendsChar);
|
||||||
|
} else {
|
||||||
|
sv.visitTypeArgument(superOrExtendsChar).visitTypeVariable(sigInner.substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkInnerSignatureOfWildCard(SignatureVisitor sv, String sigInner, int length, char superOrExtendsChar) {
|
||||||
|
if (sigInner.contains(SPECIAL_CHAR_FOR_FUN)) {
|
||||||
|
sv.visitTypeArgument(superOrExtendsChar).visitInterface().visitClassType(sigInner.substring(1, length));
|
||||||
|
} else {
|
||||||
|
sv.visitTypeArgument(superOrExtendsChar).visitClassType(sigInner.substring(1, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<GenericsGeneratorResult> getEqualTPHFromClassConstraints(List<GenericsGeneratorResult> consClass, String tph) {
|
||||||
|
return consClass.stream()
|
||||||
|
.filter(c -> c.getConstraint().getLeft().equals(tph) || c.getEqualsTPHs().contains(tph))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEqualTPH(List<GenericsGeneratorResult> constraints2, String tph) {
|
||||||
|
return constraints2.stream()
|
||||||
|
.filter(c -> c.getConstraint().getLeft().equals(tph) || c.getEqualsTPHs().contains(tph))
|
||||||
|
.findFirst().get().getConstraint().getLeft();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates signature for class or interface with {@link SignatureWriter}
|
* Creates signature for class or interface with {@link SignatureWriter}
|
||||||
* Signature looks like:
|
* Signature looks like: <typevaliables (K:Ljava/lang/Object
|
||||||
* <typevaliables (K:Ljava/lang/Object "Bounds")>superclass
|
* "Bounds")>superclass
|
||||||
*/
|
*/
|
||||||
private void createSignatureForClassOrInterface() {
|
public String createSignatureForClassOrInterface() {
|
||||||
|
defineTypeVariablesForClassOrInterface();
|
||||||
|
|
||||||
|
defineGenericsFromConstraints(consClass,genericsAndBounds);
|
||||||
|
|
||||||
|
String sClass = classOrInterface.getSuperClass().acceptTV(new TypeToSignature());
|
||||||
|
sw.visitSuperclass().visitClassType(sClass.substring(1, sClass.length() - 1));
|
||||||
|
sw.visitEnd();
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void defineTypeVariablesForClassOrInterface() {
|
||||||
Iterator<GenericTypeVar> itr = classOrInterface.getGenerics().iterator();
|
Iterator<GenericTypeVar> itr = classOrInterface.getGenerics().iterator();
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
GenericTypeVar g = itr.next();
|
GenericTypeVar g = itr.next();
|
||||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
visitTypeVarsAndTheirBounds(g, genericsAndBounds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!consClass.isEmpty()) {
|
/**
|
||||||
ArrayList<String> types = new ArrayList<>();
|
* @param genericsAndBounds2
|
||||||
ArrayList<String> superTypes = new ArrayList<>();
|
*
|
||||||
|
*/
|
||||||
|
private void defineGenericsFromConstraints(List<GenericsGeneratorResult> constraints, HashMap<String,String> genericsAndBounds2) {
|
||||||
|
constraints.forEach(c -> {
|
||||||
|
String typeVariable = c.getConstraint().getLeft() + SPECIAL_CHAR;
|
||||||
|
sw.visitFormalTypeParameter(typeVariable);
|
||||||
|
|
||||||
for(TPHConstraint cons : consClass) {
|
String bound = c.getConstraint().getRight();
|
||||||
types.add(cons.getLeft());
|
bound = checkBound(bound);
|
||||||
superTypes.add(cons.getRight());
|
genericsAndBounds2.put(typeVariable, bound);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for(TPHConstraint cons : consClass) {
|
/**
|
||||||
String t = cons.getLeft()+"$";
|
* @param bound
|
||||||
String bound = cons.getRight()+"$";
|
* @return
|
||||||
sw.visitFormalTypeParameter(t);
|
*/
|
||||||
|
private String checkBound(String bound) {
|
||||||
|
if (bound.equals(Type.getInternalName(Object.class))) {
|
||||||
|
visitClassBound(bound);
|
||||||
|
} else {
|
||||||
|
bound += SPECIAL_CHAR;
|
||||||
sw.visitClassBound().visitTypeVariable(bound);
|
sw.visitClassBound().visitTypeVariable(bound);
|
||||||
genericsAndBounds.put(t, bound);
|
}
|
||||||
|
return bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(TPHConstraint cons : consClass) {
|
/**
|
||||||
if(!types.contains(cons.getRight()) && !genericsAndBounds.keySet().contains(cons.getRight()+"$")) {
|
* @param bound
|
||||||
String t = cons.getRight()+"$";
|
*/
|
||||||
String bound = Type.getInternalName(Object.class);
|
private void visitClassBound(String bound) {
|
||||||
sw.visitFormalTypeParameter(t);
|
|
||||||
sw.visitClassBound().visitClassType(bound);
|
sw.visitClassBound().visitClassType(bound);
|
||||||
genericsAndBounds.put(t, bound);
|
|
||||||
sw.visitClassBound().visitEnd();
|
sw.visitClassBound().visitEnd();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
/*if(!commonPairs.isEmpty()) {
|
|
||||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
|
||||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
|
||||||
|
|
||||||
for(GenericInsertPair p : commonPairs) {
|
|
||||||
types.add(p.TA1);
|
|
||||||
superTypes.add(p.TA2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(GenericInsertPair p : commonPairs) {
|
|
||||||
String t = p.TA1.getName()+"$";
|
|
||||||
String bound = p.TA2.getName()+"$";
|
|
||||||
sw.visitFormalTypeParameter(t);
|
|
||||||
sw.visitClassBound().visitTypeVariable(bound);
|
|
||||||
genericsAndBounds.put(t, bound);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(GenericInsertPair p : commonPairs) {
|
|
||||||
if(!types.contains(p.TA2)) {
|
|
||||||
String t = p.TA2.getName()+"$";
|
|
||||||
String bound = Type.getInternalName(Object.class);
|
|
||||||
sw.visitFormalTypeParameter(t);
|
|
||||||
sw.visitClassBound().visitClassType(bound);
|
|
||||||
genericsAndBounds.put(t, bound);
|
|
||||||
sw.visitClassBound().visitEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(TypePlaceholder t : tphsClass) {
|
|
||||||
String n = t.getName()+"$";
|
|
||||||
String bound = Type.getInternalName(Object.class);
|
|
||||||
sw.visitFormalTypeParameter(n);
|
|
||||||
sw.visitClassBound().visitClassType(bound);
|
|
||||||
genericsAndBounds.put(n, bound);
|
|
||||||
sw.visitClassBound().visitEnd();
|
|
||||||
}*/
|
|
||||||
String sClass = classOrInterface.getSuperClass().acceptTV(new TypeToSignature());
|
|
||||||
sw.visitSuperclass().visitClassType(sClass.substring(1, sClass.length()-1));
|
|
||||||
sw.visitEnd();
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Get bounds of type variable
|
* Get bounds of type variable
|
||||||
|
*
|
||||||
* @param g type variable
|
* @param g type variable
|
||||||
* @param genAndBounds
|
* @param genAndBounds
|
||||||
*/
|
*/
|
||||||
private void getBoundsOfTypeVar(GenericTypeVar g, HashMap<String, String> genAndBounds) {
|
private void visitTypeVarsAndTheirBounds(GenericTypeVar g, HashMap<String, String> genAndBounds) {
|
||||||
sw.visitFormalTypeParameter(g.getName());
|
sw.visitFormalTypeParameter(g.getName());
|
||||||
|
|
||||||
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
||||||
while (bItr.hasNext()) {
|
while (bItr.hasNext()) {
|
||||||
RefTypeOrTPHOrWildcardOrGeneric b = bItr.next();
|
RefTypeOrTPHOrWildcardOrGeneric b = bItr.next();
|
||||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||||
// System.out.println("GetBounds: " + boundDesc);
|
|
||||||
// Ensure that <...> extends java.lang.Object OR ...
|
// Ensure that <...> extends java.lang.Object OR ...
|
||||||
if (b instanceof GenericRefType) {
|
if (b instanceof GenericRefType) {
|
||||||
sw.visitClassBound().visitTypeVariable(boundDesc);
|
sw.visitClassBound().visitTypeVariable(boundDesc);
|
||||||
} else {
|
} else {
|
||||||
sw.visitClassBound().visitClassType(boundDesc);
|
visitClassBound(boundDesc);
|
||||||
sw.visitClassBound().visitEnd();
|
|
||||||
}
|
}
|
||||||
genAndBounds.put(g.getName(), boundDesc);
|
genAndBounds.put(g.getName(), boundDesc);
|
||||||
}
|
}
|
||||||
// sw.visitClassBound().visitEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
if(sw == null)
|
||||||
|
return super.toString();
|
||||||
return sw.toString();
|
return sw.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package de.dhbwstuttgart.bytecode.signature;
|
package de.dhbwstuttgart.bytecode.signature;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@@ -12,6 +15,15 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
||||||
|
|
||||||
public class TypeToSignature implements TypeVisitor<String> {
|
public class TypeToSignature implements TypeVisitor<String> {
|
||||||
|
private List<GenericsGeneratorResult> constraints;
|
||||||
|
|
||||||
|
public TypeToSignature() {
|
||||||
|
this.constraints = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeToSignature(List<GenericsGeneratorResult> constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
@@ -33,7 +45,7 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
// } else {
|
// } else {
|
||||||
// params += "L"+param.toString().replace(".", "/");
|
// params += "L"+param.toString().replace(".", "/");
|
||||||
// }
|
// }
|
||||||
params += param.acceptTV(new TypeToSignature());
|
params += param.acceptTV(new TypeToSignature(constraints));
|
||||||
|
|
||||||
if(param instanceof TypePlaceholder)
|
if(param instanceof TypePlaceholder)
|
||||||
params += ";";
|
params += ";";
|
||||||
@@ -48,7 +60,7 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
@Override
|
@Override
|
||||||
public String visit(SuperWildcardType superWildcardType) {
|
public String visit(SuperWildcardType superWildcardType) {
|
||||||
// throw new NotImplementedException();
|
// throw new NotImplementedException();
|
||||||
String sig = "-" + superWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
String sig = "-" + superWildcardType.getInnerType().acceptTV(new TypeToSignature(constraints));
|
||||||
if(superWildcardType.getInnerType() instanceof TypePlaceholder)
|
if(superWildcardType.getInnerType() instanceof TypePlaceholder)
|
||||||
sig += ";";
|
sig += ";";
|
||||||
return sig;
|
return sig;
|
||||||
@@ -57,13 +69,21 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
@Override
|
@Override
|
||||||
public String visit(TypePlaceholder typePlaceholder) {
|
public String visit(TypePlaceholder typePlaceholder) {
|
||||||
// return typePlaceholder.toString().replace(".", "/");
|
// return typePlaceholder.toString().replace(".", "/");
|
||||||
return "T" + typePlaceholder.getName() + "$";
|
String name = typePlaceholder.getName();
|
||||||
|
|
||||||
|
if(!constraints.isEmpty()){
|
||||||
|
Optional<GenericsGeneratorResult> equalName = getEqualTPHFromClassConstraints(constraints, name);
|
||||||
|
if(equalName.isPresent())
|
||||||
|
name = equalName.get().getConstraint().getLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "T" + name + "$";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
// throw new NotImplementedException();
|
// throw new NotImplementedException();
|
||||||
String sig = "+" + extendsWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
String sig = "+" + extendsWildcardType.getInnerType().acceptTV(new TypeToSignature(constraints));
|
||||||
if(extendsWildcardType.getInnerType() instanceof TypePlaceholder)
|
if(extendsWildcardType.getInnerType() instanceof TypePlaceholder)
|
||||||
sig += ";";
|
sig += ";";
|
||||||
return sig;
|
return sig;
|
||||||
@@ -74,4 +94,9 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
return genericRefType.getParsedName().replace(".", "/");
|
return genericRefType.getParsedName().replace(".", "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<GenericsGeneratorResult> getEqualTPHFromClassConstraints(List<GenericsGeneratorResult> listOfConstraints, String tph) {
|
||||||
|
return listOfConstraints.stream()
|
||||||
|
.filter(c -> c.getConstraint().getLeft().equals(tph) || c.getEqualsTPHs().contains(tph))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,94 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class ByteCodeForFunNGenerator {
|
||||||
|
|
||||||
|
public static void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc, String path) {
|
||||||
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
|
|
||||||
|
int numberOfParams = 0;
|
||||||
|
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||||
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
numberOfParams++;
|
||||||
|
// getBounds
|
||||||
|
paramVisitor.visitTypeVariable(CONSTANTS.T + numberOfParams);
|
||||||
|
itr.next();
|
||||||
|
}
|
||||||
|
methSig.visitReturnType().visitTypeVariable(CONSTANTS.R);
|
||||||
|
// ")"+lam.getReturn.getBounds
|
||||||
|
Signature sig = new Signature(numberOfParams);
|
||||||
|
String name = CONSTANTS.FUN + numberOfParams + CONSTANTS.$$;
|
||||||
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
|
Type.getInternalName(Object.class), null);
|
||||||
|
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||||
|
methSig.toString(), null);
|
||||||
|
mvApply.visitEnd();
|
||||||
|
writeClassFile(classWriter.toByteArray(), name, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void generateBCForFunN(ArgumentList argumentList, String methDesc, String path) {
|
||||||
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
|
|
||||||
|
int numberOfParams = 0;
|
||||||
|
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||||
|
Iterator<Expression> itr1 = argumentList.getArguments().iterator();
|
||||||
|
|
||||||
|
while(itr1.hasNext()) {
|
||||||
|
numberOfParams++;
|
||||||
|
// getBounds
|
||||||
|
paramVisitor.visitTypeVariable(CONSTANTS.T + numberOfParams);
|
||||||
|
itr1.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
methSig.visitReturnType().visitTypeVariable(CONSTANTS.R);
|
||||||
|
// ")"+lam.getReturn.getBounds
|
||||||
|
Signature sig = new Signature(numberOfParams);
|
||||||
|
String name = CONSTANTS.FUN + numberOfParams + CONSTANTS.$$;
|
||||||
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
|
Type.getInternalName(Object.class), null);
|
||||||
|
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||||
|
methSig.toString(), null);
|
||||||
|
mvApply.visitEnd();
|
||||||
|
writeClassFile(classWriter.toByteArray(), name, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void writeClassFile(byte[] bytecode, String name, String path) {
|
||||||
|
FileOutputStream output;
|
||||||
|
try {
|
||||||
|
System.out.println("generating " + name + ".class file...");
|
||||||
|
output = new FileOutputStream(
|
||||||
|
new File(path + name + CONSTANTS.EXTENSIONCLASS));
|
||||||
|
output.write(bytecode);
|
||||||
|
output.close();
|
||||||
|
System.out.println(name + ".class file generated");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
public interface CONSTANTS {
|
||||||
|
|
||||||
|
String VOID = "void";
|
||||||
|
String TPH = "TPH ";
|
||||||
|
String ANGLEBRACKET = "<";
|
||||||
|
String FUN = "Fun";
|
||||||
|
String EXTENSIONCLASS = ".class";
|
||||||
|
String $$ = "$$";
|
||||||
|
String T = "T";
|
||||||
|
String R = "R";
|
||||||
|
String DESUGAREDMETHODNAME = "lambda$new$";
|
||||||
|
String REFTYPE_BYTE = "java/lang/Byte";
|
||||||
|
String REFTYPE_SHORT = "java/lang/Short";
|
||||||
|
String REFTYPE_INTEGER = "java/lang/Integer";
|
||||||
|
String REFTYPE_LONG = "java/lang/Long";
|
||||||
|
String REFTYPE_DOUBLE = "java/lang/Double";
|
||||||
|
String REFTYPE_FLOAT = "java/lang/Float";
|
||||||
|
String REFTYPE_STRING = "java/lang/String";
|
||||||
|
String TO_STRING = "toString";
|
||||||
|
}
|
@@ -5,25 +5,27 @@ import java.util.List;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.ConstraintsWithSameLeftSide;
|
||||||
|
|
||||||
public class ConstraintsFinder {
|
public class ConstraintsFinder {
|
||||||
private List<TPHConstraint> allConstaints;
|
private List<TPHConstraint> allConstaints;
|
||||||
|
|
||||||
public ConstraintsFinder(List<TPHConstraint> allConstaints) {
|
public ConstraintsFinder(List<TPHConstraint> allConstaints) {
|
||||||
super();
|
|
||||||
this.allConstaints = allConstaints;
|
this.allConstaints = allConstaints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<List<TPHConstraint>> findConstraints() {
|
public List<ConstraintsWithSameLeftSide> findConstraints() {
|
||||||
List<List<TPHConstraint>> result = new ArrayList<>();
|
List<ConstraintsWithSameLeftSide> result = new ArrayList<>();
|
||||||
|
|
||||||
List<TPHConstraint> visitedCons = new ArrayList<>();
|
List<TPHConstraint> visitedCons = new ArrayList<>();
|
||||||
for(TPHConstraint c : allConstaints) {
|
for(TPHConstraint c : allConstaints) {
|
||||||
if(c.getRel() == Relation.EXTENDS) {
|
if(c.getRel() == Relation.EXTENDS) {
|
||||||
// get constraints with the same left side
|
// get constraints with the same left side
|
||||||
List<TPHConstraint> cons = getConstraints(c,visitedCons);
|
List<TPHConstraint> cons = getConstraints(c,visitedCons);
|
||||||
if(cons.size()>1)
|
if(cons.size()>1) {
|
||||||
result.add(cons);
|
ConstraintsWithSameLeftSide consWithSameLeftSide = new ConstraintsWithSameLeftSide(cons);
|
||||||
|
result.add(consWithSameLeftSide);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.bytecode.utilities;
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -19,7 +18,8 @@ public class KindOfLambda implements StatementVisitor{
|
|||||||
private boolean isInstanceCapturingLambda = false;
|
private boolean isInstanceCapturingLambda = false;
|
||||||
private List<RefTypeOrTPHOrWildcardOrGeneric> argumentList = new ArrayList<>();
|
private List<RefTypeOrTPHOrWildcardOrGeneric> argumentList = new ArrayList<>();
|
||||||
private ArrayList<String> usedVars = new ArrayList<>();
|
private ArrayList<String> usedVars = new ArrayList<>();
|
||||||
private boolean hasThis = false;
|
private ArrayList<String> varsFromInnerLambdas = new ArrayList<>();
|
||||||
|
private boolean thisUsed = false;
|
||||||
private ArrayList<String> definedLocals = new ArrayList<>();
|
private ArrayList<String> definedLocals = new ArrayList<>();
|
||||||
|
|
||||||
public KindOfLambda(LambdaExpression lambdaExpression) {
|
public KindOfLambda(LambdaExpression lambdaExpression) {
|
||||||
@@ -40,19 +40,20 @@ public class KindOfLambda implements StatementVisitor{
|
|||||||
return argumentList;
|
return argumentList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHasThis() {
|
public boolean isThisUsed() {
|
||||||
return hasThis;
|
return thisUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ArgumentList argumentList) {
|
public void visit(ArgumentList argumentList) {
|
||||||
// TODO Auto-generated method stub
|
argumentList.getArguments().forEach(a->a.accept(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
|
lambdaExpression.params.getFormalparalist().forEach(p->varsFromInnerLambdas.add(p.getName()));
|
||||||
|
lambdaExpression.methodBody.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,9 +112,11 @@ public class KindOfLambda implements StatementVisitor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVar localVar) {
|
public void visit(LocalVar localVar) {
|
||||||
if(!contain(params, localVar.name) && !definedLocals.contains(localVar.name)) {
|
boolean addVar = !contain(params, localVar.name) && !definedLocals.contains(localVar.name) &&
|
||||||
|
!varsFromInnerLambdas.contains(localVar.name) && !usedVars.contains(localVar.name);
|
||||||
|
if(addVar) {
|
||||||
argumentList.add(localVar.getType());
|
argumentList.add(localVar.getType());
|
||||||
if(hasThis) {
|
if(thisUsed) {
|
||||||
usedVars.add(1, localVar.name);
|
usedVars.add(1, localVar.name);
|
||||||
} else {
|
} else {
|
||||||
usedVars.add(0, localVar.name);
|
usedVars.add(0, localVar.name);
|
||||||
@@ -141,12 +144,13 @@ public class KindOfLambda implements StatementVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
|
methodCall.arglist.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NewClass methodCall) {
|
public void visit(NewClass methodCall) {
|
||||||
// TODO Auto-generated method stub
|
methodCall.receiver.accept(this);
|
||||||
|
methodCall.arglist.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -190,8 +194,8 @@ public class KindOfLambda implements StatementVisitor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(This aThis) {
|
public void visit(This aThis) {
|
||||||
if(!hasThis) {
|
if(!thisUsed) {
|
||||||
hasThis = true;
|
thisUsed = true;
|
||||||
this.argumentList.add(0,aThis.getType());
|
this.argumentList.add(0,aThis.getType());
|
||||||
}
|
}
|
||||||
if(!isInstanceCapturingLambda) {
|
if(!isInstanceCapturingLambda) {
|
||||||
|
@@ -9,7 +9,7 @@ import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|||||||
|
|
||||||
public class MethodAndTPH {
|
public class MethodAndTPH {
|
||||||
|
|
||||||
private String name;
|
private String id;
|
||||||
private final ArrayList<String> tphs = new ArrayList<>();
|
private final ArrayList<String> tphs = new ArrayList<>();
|
||||||
//private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
//private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||||
@@ -17,7 +17,7 @@ public class MethodAndTPH {
|
|||||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
|
|
||||||
public MethodAndTPH(String name) {
|
public MethodAndTPH(String name) {
|
||||||
this.name = name;
|
this.id = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getTphs() {
|
public ArrayList<String> getTphs() {
|
||||||
@@ -31,8 +31,8 @@ public class MethodAndTPH {
|
|||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getId() {
|
||||||
return name;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getLocalTphs() {
|
public ArrayList<String> getLocalTphs() {
|
||||||
|
@@ -3,44 +3,20 @@
|
|||||||
*/
|
*/
|
||||||
package de.dhbwstuttgart.bytecode.utilities;
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
|
||||||
import org.objectweb.asm.MethodVisitor;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import javassist.NotFoundException;
|
import javassist.NotFoundException;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author fayez
|
* @author fayez
|
||||||
@@ -98,11 +74,15 @@ public class MethodCallHelper {
|
|||||||
public String getDesc(String className) throws NotInCurrentPackageException, NotFoundException {
|
public String getDesc(String className) throws NotInCurrentPackageException, NotFoundException {
|
||||||
String name = methCall.name;
|
String name = methCall.name;
|
||||||
ClassOrInterface clazz = getClassFromCurrPkg(className);
|
ClassOrInterface clazz = getClassFromCurrPkg(className);
|
||||||
|
String retType = getResolvedType(methCall.getType());
|
||||||
|
ArrayList<String> params = getTypes(methCall.arglist.getArguments());
|
||||||
|
|
||||||
Map<String, String> genAndBoundsClass = getGenericsAndBounds(clazz.getGenerics());
|
Map<String, String> genAndBoundsClass = getGenericsAndBounds(clazz.getGenerics());
|
||||||
modifyGenAndBounds(genAndBoundsClass);
|
modifyGenAndBounds(genAndBoundsClass);
|
||||||
for (Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
if (name.equals(m.getName())) {
|
if (name.equals(m.getName()) && retType.equals(getResolvedType(m.getReturnType()))) {
|
||||||
|
ArrayList<String> paramsOfM = getTypes(m.getParameterList());
|
||||||
|
if(areEquals(params,paramsOfM)) {
|
||||||
Map<String, String> genAndBoundsMethod = getGenericsAndBoundsMethod(m.getGenerics());
|
Map<String, String> genAndBoundsMethod = getGenericsAndBoundsMethod(m.getGenerics());
|
||||||
modifyGenAndBounds(genAndBoundsMethod);
|
modifyGenAndBounds(genAndBoundsMethod);
|
||||||
boolean hasGen = hasGen(m, genAndBoundsClass);
|
boolean hasGen = hasGen(m, genAndBoundsClass);
|
||||||
@@ -111,10 +91,45 @@ public class MethodCallHelper {
|
|||||||
return nm.accept(new DescriptorToString(resultSet));
|
return nm.accept(new DescriptorToString(resultSet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw new NotFoundException("Method " + name + " is not found");
|
throw new NotFoundException("Method " + name + " is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean areEquals(ArrayList<String> params, ArrayList<String> paramsOfM) {
|
||||||
|
if(params.size() != paramsOfM.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(String t : params) {
|
||||||
|
for(String t2 : paramsOfM) {
|
||||||
|
if(!t.equals(t2))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> getTypes(ParameterList parameterList) {
|
||||||
|
Iterator<FormalParameter> itr = parameterList.iterator();
|
||||||
|
ArrayList<String> typeList = new ArrayList<>();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
String t = getResolvedType(fp.getType());
|
||||||
|
typeList.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> getTypes(List<Expression> arguments) {
|
||||||
|
ArrayList<String> types = new ArrayList<>();
|
||||||
|
for(int i = 0; i<arguments.size(); ++i) {
|
||||||
|
String t = getResolvedType(arguments.get(i).getType());
|
||||||
|
types.add(t);
|
||||||
|
}
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasGen(Method m, Map<String, String> genericsAndBounds) {
|
private boolean hasGen(Method m, Map<String, String> genericsAndBounds) {
|
||||||
String retType = resultSet.resolveType(m.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
String retType = resultSet.resolveType(m.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
||||||
@@ -204,52 +219,25 @@ public class MethodCallHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateBCForFunN() {
|
public void generateBCForFunN(String methodDescriptor) {
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ByteCodeForFunNGenerator.generateBCForFunN(methCall.arglist,methodDescriptor,path);
|
||||||
|
|
||||||
SignatureWriter methSig = new SignatureWriter();
|
|
||||||
|
|
||||||
int numberOfParams = 0;
|
|
||||||
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
|
||||||
Iterator<Expression> itr1 = methCall.arglist.getArguments().iterator();
|
|
||||||
String methDesc = "(";
|
|
||||||
while(itr1.hasNext()) {
|
|
||||||
numberOfParams++;
|
|
||||||
// getBounds
|
|
||||||
paramVisitor.visitTypeVariable("T" + numberOfParams);
|
|
||||||
methDesc += "L" + Type.getInternalName(Object.class) + ";";
|
|
||||||
itr1.next();
|
|
||||||
}
|
|
||||||
methDesc += ")L" + Type.getInternalName(Object.class) + ";";
|
|
||||||
|
|
||||||
methSig.visitReturnType().visitTypeVariable("R");
|
|
||||||
// ")"+lam.getReturn.getBounds
|
|
||||||
Signature sig = new Signature(numberOfParams);
|
|
||||||
String name = "Fun" + numberOfParams + "$$";
|
|
||||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
|
||||||
Type.getInternalName(Object.class), null);
|
|
||||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
|
||||||
methSig.toString(), null);
|
|
||||||
mvApply.visitEnd();
|
|
||||||
writeClassFile(classWriter.toByteArray(), name);
|
|
||||||
return methDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeClassFile(byte[] bytecode, String name) {
|
|
||||||
FileOutputStream output;
|
|
||||||
try {
|
|
||||||
System.out.println("generating " + name + ".class file...");
|
|
||||||
output = new FileOutputStream(
|
|
||||||
new File(path + name + ".class"));
|
|
||||||
output.write(bytecode);
|
|
||||||
output.close();
|
|
||||||
System.out.println(name + ".class file generated");
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDescriptorOfApplyMethod(String methodCallType) {
|
||||||
|
return new DescriptorToString().createDescForFunN(methCall.arglist, methodCallType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param methodCall
|
||||||
|
*/
|
||||||
|
public void createCheckCast(MethodCall methodCall, MethodVisitor mv) {
|
||||||
|
String checkCast = getResolvedType(methodCall.getType());
|
||||||
|
if(!checkCast.contains("TPH ")) {
|
||||||
|
int pos = checkCast.length();
|
||||||
|
if(checkCast.contains("<"))
|
||||||
|
pos = checkCast.indexOf("<");
|
||||||
|
mv.visitTypeInsn(Opcodes.CHECKCAST,checkCast.substring(0,pos));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MethodUtility {
|
||||||
|
/**
|
||||||
|
* Creates an ID for a method
|
||||||
|
*
|
||||||
|
* @param resolver type Resolver
|
||||||
|
* @param method for which the ID will be generated
|
||||||
|
* @return ID for the given method.
|
||||||
|
* ID = ReturntypeMethodname(Parametertypes)
|
||||||
|
*/
|
||||||
|
public static String createID(Resolver resolver, Method method) {
|
||||||
|
String id = resolver.getResolvedType(method.getReturnType()) + method.name + "(";
|
||||||
|
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
id += resolver.getResolvedType(fp.getType());
|
||||||
|
}
|
||||||
|
id += ")";
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,13 +4,18 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.NameReplacementResult;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
|
||||||
public class NameReplacer {
|
public class NameReplacer {
|
||||||
|
//TODO rename
|
||||||
private List<TPHConstraint> constraints;
|
private List<TPHConstraint> constraints;
|
||||||
private List<TPHConstraint> allConstraints;
|
private List<TPHConstraint> allConstraints;
|
||||||
|
private List<MethodAndTPH> methodAndTPHs;
|
||||||
|
// TODO rename into tphClass
|
||||||
private List<String> tphs;
|
private List<String> tphs;
|
||||||
private List<String> localTphs;
|
private List<String> localTphs;
|
||||||
|
|
||||||
@@ -22,7 +27,98 @@ public class NameReplacer {
|
|||||||
this.localTphs = localTphs;
|
this.localTphs = localTphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<String>> replaceNames() {
|
public NameReplacer(List<TPHConstraint> constraints, List<TPHConstraint> allConstraints,List<String> tphs) {
|
||||||
|
super();
|
||||||
|
this.constraints = constraints;
|
||||||
|
this.allConstraints = allConstraints;
|
||||||
|
this.tphs = tphs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameReplacer(List<TPHConstraint> constraints, List<TPHConstraint> allConstraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
this.allConstraints = allConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameReplacer(List<TPHConstraint> constraints, List<TPHConstraint> allConstraints, List<MethodAndTPH> methodAndTPHs,
|
||||||
|
List<String> tphsClass) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
this.allConstraints = allConstraints;
|
||||||
|
this.methodAndTPHs = methodAndTPHs;
|
||||||
|
this.tphs = tphsClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameReplacementResult replaceNames() {
|
||||||
|
String newName = NameGenerator.makeNewName();
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
substituteRightSidesWithNewName(newName, names);
|
||||||
|
|
||||||
|
substituteNamesInAllConstraints(newName, names);
|
||||||
|
Stream<ArrayList<String>> tphsOfMethods = methodAndTPHs.stream().map(m->m.getTphs());
|
||||||
|
Stream<ArrayList<String>> localTphsOfMethods = methodAndTPHs.stream().map(m->m.getLocalTphs());
|
||||||
|
|
||||||
|
replaceOldNames(newName, names, tphsOfMethods);
|
||||||
|
replaceOldNames(newName, names, localTphsOfMethods);
|
||||||
|
|
||||||
|
if(tphs.removeAll(names))
|
||||||
|
tphs.add(newName);
|
||||||
|
|
||||||
|
NameReplacementResult res = new NameReplacementResult(newName, names);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param newName
|
||||||
|
* @param names
|
||||||
|
* @param tphsOfMethods
|
||||||
|
*/
|
||||||
|
public void replaceOldNames(final String newName, final List<String> names, Stream<ArrayList<String>> tphsOfMethods) {
|
||||||
|
tphsOfMethods.forEach(tphsMethod->{
|
||||||
|
if(tphsMethod.removeAll(names))
|
||||||
|
tphsMethod.add(newName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameReplacementResult replaceNamesLocal() {
|
||||||
|
String newName = NameGenerator.makeNewName();
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
substituteRightSidesWithNewName(newName, names);
|
||||||
|
|
||||||
|
substituteNamesInAllConstraints(newName, names);
|
||||||
|
|
||||||
|
tphs.removeAll(names);
|
||||||
|
tphs.add(newName);
|
||||||
|
|
||||||
|
NameReplacementResult res = new NameReplacementResult(newName, names);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param newName
|
||||||
|
* @param names
|
||||||
|
*/
|
||||||
|
public void substituteNamesInAllConstraints(String newName, List<String> names) {
|
||||||
|
for(TPHConstraint cons : allConstraints) {
|
||||||
|
if(names.contains(cons.getLeft()))
|
||||||
|
cons.setLeft(newName);
|
||||||
|
if(names.contains(cons.getRight()))
|
||||||
|
cons.setRight(newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param newName
|
||||||
|
* @param names
|
||||||
|
*/
|
||||||
|
public void substituteRightSidesWithNewName(String newName, List<String> names) {
|
||||||
|
for(TPHConstraint cons : constraints) {
|
||||||
|
names.add(cons.getRight());
|
||||||
|
cons.setRight(newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<String>> replaceNamesWithLocals() {
|
||||||
String newName = NameGenerator.makeNewName();
|
String newName = NameGenerator.makeNewName();
|
||||||
ArrayList<String> names = new ArrayList<>();
|
ArrayList<String> names = new ArrayList<>();
|
||||||
for(TPHConstraint cons : constraints) {
|
for(TPHConstraint cons : constraints) {
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Resolver {
|
||||||
|
|
||||||
|
private ResultSet resultSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param resultSet
|
||||||
|
*/
|
||||||
|
public Resolver(ResultSet resultSet) {
|
||||||
|
this.resultSet = resultSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
|
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.utilities;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SimplifyResult {
|
|
||||||
private final ArrayList<TPHConstraint> classConstraints;
|
|
||||||
private final ArrayList<String> tphsClass;
|
|
||||||
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
|
|
||||||
|
|
||||||
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<String> tphsClass,
|
|
||||||
HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints) {
|
|
||||||
super();
|
|
||||||
this.classConstraints = classConstraints;
|
|
||||||
this.tphsClass = tphsClass;
|
|
||||||
this.methodsConstraints = methodsConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<TPHConstraint> getClassConstraints() {
|
|
||||||
return classConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, HashMap<TPHConstraint, HashSet<String>>> getMethodsConstraints() {
|
|
||||||
return methodsConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getTphsClass() {
|
|
||||||
return tphsClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,24 +1,20 @@
|
|||||||
//PL 2018-12-19: typeInferenceOld nach typeInference uebertragen
|
//PL 2018-12-19: typeInferenceOld nach typeInference uebertragen
|
||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
@@ -30,7 +26,6 @@ import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
|
||||||
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 de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
@@ -45,39 +40,30 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
//import org.apache.commons.io.output.NullOutputStream;
|
//import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
|
public static JavaTXCompiler INSTANCE;
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
Boolean resultmodel = true;
|
Boolean resultmodel = true;
|
||||||
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();
|
||||||
|
|
||||||
/**
|
|
||||||
* Äußerste Liste der Source-Files.
|
|
||||||
* Danach Liste der Klassen in Source File.
|
|
||||||
* Danach Map Klassenname
|
|
||||||
*/
|
|
||||||
private List<List<HashMap<String, SimplifyResult>>> simplifyResultsSF = new ArrayList<>();
|
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile));
|
this(Arrays.asList(sourceFile));
|
||||||
|
INSTANCE = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||||
this(sourceFile);
|
this(sourceFile);
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
INSTANCE = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||||
@@ -85,6 +71,7 @@ public class JavaTXCompiler {
|
|||||||
for (File s : sources) {
|
for (File s : sources) {
|
||||||
sourceFiles.put(s, parse(s));
|
sourceFiles.put(s, parse(s));
|
||||||
}
|
}
|
||||||
|
INSTANCE = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||||
@@ -112,16 +99,30 @@ public class JavaTXCompiler {
|
|||||||
Set<ClassOrInterface> allClasses = new HashSet<>();
|
Set<ClassOrInterface> allClasses = new HashSet<>();
|
||||||
|
|
||||||
/* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt
|
/* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt
|
||||||
for (SourceFile sf : sourceFiles.values()) {
|
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
}
|
}
|
||||||
|
allClasses.addAll(importedClasses);
|
||||||
|
|
||||||
|
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||||
|
// PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal
|
||||||
|
// hinzugefuegt werden
|
||||||
|
// List<ClassOrInterface> allClasses = new
|
||||||
|
// ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
|
Set<ClassOrInterface> allClasses = new HashSet<>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt for
|
||||||
|
* (SourceFile sf : sourceFiles.values()) { allClasses.addAll(sf.getClasses());
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||||
for (JavaClassName name : forSourceFile.getImports()) {
|
for (JavaClassName name : forSourceFile.getImports()) {
|
||||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
ClassOrInterface importedClass = ASTFactory
|
||||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||||
importedClasses.add(importedClass);
|
importedClasses.add(importedClass);
|
||||||
allClasses.addAll(importedClasses);
|
allClasses.addAll(importedClasses);
|
||||||
}
|
}
|
||||||
@@ -129,168 +130,152 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public List<ResultSet> typeInferenceOld() throws ClassNotFoundException {
|
* public List<ResultSet> typeInferenceOld() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
* List<ClassOrInterface> allClasses = new
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
* ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten
|
||||||
for(SourceFile sf : this.sourceFiles.values()) {
|
* Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf :
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
* this.sourceFiles.values()) { allClasses.addAll(getAvailableClasses(sf));
|
||||||
allClasses.addAll(sf.getClasses());
|
* allClasses.addAll(sf.getClasses()); }
|
||||||
}
|
*
|
||||||
|
* final ConstraintSet<Pair> cons = getConstraints();
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
*
|
||||||
|
* FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
* System.out.println(finiteClosure); ConstraintSet<UnifyPair> unifyCons =
|
||||||
System.out.println(finiteClosure);
|
* UnifyTypeFactory.convert(cons);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
*
|
||||||
|
* TypeUnify unify = new TypeUnify(); Set<Set<UnifyPair>> results = new
|
||||||
TypeUnify unify = new TypeUnify();
|
* HashSet<>(); try { File logPath = new
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
* File(System.getProperty("user.dir")+"/target/logFiles/"); logPath.mkdirs();
|
||||||
try {
|
* FileWriter logFile = new FileWriter(new File(logPath, "log"));
|
||||||
File logPath = new File(System.getProperty("user.dir")+"/target/logFiles/");
|
* logFile.write("FC:\\" + finiteClosure.toString()+"\n"); for(SourceFile sf :
|
||||||
logPath.mkdirs();
|
* this.sourceFiles.values()) { logFile.write(ASTTypePrinter.print(sf)); }
|
||||||
FileWriter logFile = new FileWriter(new File(logPath, "log"));
|
* logFile.flush(); Set<List<Constraint<UnifyPair>>> cardProd =
|
||||||
logFile.write("FC:\\" + finiteClosure.toString()+"\n");
|
* unifyCons.cartesianProduct(); for (List<Constraint<UnifyPair>> xCons :
|
||||||
for(SourceFile sf : this.sourceFiles.values()) {
|
* cardProd ){ Set<UnifyPair> xConsSet = new HashSet<>(); for
|
||||||
logFile.write(ASTTypePrinter.print(sf));
|
* (Constraint<UnifyPair> constraint : xCons) { xConsSet.addAll(constraint); }
|
||||||
}
|
* //.collect(Collectors.toCollection(ArrayList::new))))
|
||||||
logFile.flush();
|
* System.out.println(xConsSet); Set<String> methodParaTypeVarNames =
|
||||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
* allClasses.stream().map(x -> x.getMethods().stream().map(y ->
|
||||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
* y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType()
|
||||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
* instanceof TypePlaceholder) .map(z ->
|
||||||
for (Constraint<UnifyPair> constraint : xCons) {
|
* ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(
|
||||||
xConsSet.addAll(constraint);
|
* HashSet::new))) .reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return
|
||||||
}
|
* a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet<String>(),
|
||||||
//.collect(Collectors.toCollection(ArrayList::new))))
|
* (a,b) -> { a.addAll(b); return a;} );
|
||||||
System.out.println(xConsSet);
|
*
|
||||||
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
* Set<String> constructorParaTypeVarNames = allClasses.stream().map(x ->
|
||||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
* x.getConstructors().stream().map(y ->
|
||||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
* y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType()
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
* instanceof TypePlaceholder) .map(z ->
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
* ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(
|
||||||
|
* HashSet::new))) .reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return
|
||||||
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist()
|
* a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet<String>(),
|
||||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
* (a,b) -> { a.addAll(b); return a;} );
|
||||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
*
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
* Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
* paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
||||||
|
*
|
||||||
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
* Set<String> returnTypeVarNames = allClasses.stream().map(x ->
|
||||||
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
* x.getMethods().stream().filter(y -> y.getReturnType() instanceof
|
||||||
|
* TypePlaceholder) .map(z ->
|
||||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
* ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.
|
||||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
* toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}
|
||||||
|
* ).get();
|
||||||
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
*
|
||||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
* Set<String> fieldTypeVarNames = allClasses.stream().map(x ->
|
||||||
|
* x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof
|
||||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
* TypePlaceholder) .map(z ->
|
||||||
|
* ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.
|
||||||
xConsSet = xConsSet.stream().map(x -> {
|
* toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}
|
||||||
//Hier muss ueberlegt werden, ob
|
* ).get();
|
||||||
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
*
|
||||||
// mit disableWildcardtable() werden.
|
* returnTypeVarNames.addAll(fieldTypeVarNames);
|
||||||
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
*
|
||||||
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
* xConsSet = xConsSet.stream().map(x -> { //Hier muss ueberlegt werden, ob //1.
|
||||||
//PL 2018-04-23
|
* alle Argument- und Retuntyp-Variablen in allen UnifyPairs // mit
|
||||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
* disableWildcardtable() werden. //2. alle Typvariablen mit Argument- oder
|
||||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
* Retuntyp-Variablen //in Beziehung auch auf disableWildcardtable() gesetzt
|
||||||
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
* werden muessen //PL 2018-04-23 if ((x.getLhsType() instanceof
|
||||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
* PlaceholderType)) { if (paraTypeVarNames.contains(x.getLhsType().getName()))
|
||||||
}
|
* { ((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
* ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } if
|
||||||
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
* (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
* ((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||||
}
|
* ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } } if
|
||||||
}
|
* ((x.getRhsType() instanceof PlaceholderType)) { if
|
||||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
* (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
* ((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||||
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
* ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } if
|
||||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
* (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
}
|
* ((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
* ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } return x;//HIER
|
||||||
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
* DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS
|
||||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
* ANDERE SEITE }).map( y -> { if ((y.getLhsType() instanceof PlaceholderType)
|
||||||
}
|
* && (y.getRhsType() instanceof PlaceholderType)) { if
|
||||||
}
|
* (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
||||||
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||||
}).map( y -> {
|
* ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
|
||||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
* )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
* && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
* ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
|
||||||
}
|
* )).getVariance()); } } return y; } )
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
* .collect(Collectors.toCollection(HashSet::new));
|
||||||
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
* varianceInheritance(xConsSet); Set<Set<UnifyPair>> result =
|
||||||
}
|
* unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
}
|
* //Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
return y; } )
|
* System.out.println("RESULT: " + result); logFile.write("RES: " +
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
* result.toString()+"\n"); logFile.flush(); results.addAll(result); }
|
||||||
varianceInheritance(xConsSet);
|
*
|
||||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
* results = results.stream().map(x -> { Optional<Set<UnifyPair>> res = new
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
* RuleSet().subst(x.stream().map(y -> { if (y.getPairOp() ==
|
||||||
System.out.println("RESULT: " + result);
|
* PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); return y;
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
* //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
logFile.flush();
|
* }).collect(Collectors.toCollection(HashSet::new))); if (res.isPresent())
|
||||||
results.addAll(result);
|
* {//wenn subst ein Erg liefert wurde was veraendert return new
|
||||||
}
|
* TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); } else
|
||||||
|
* return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
results = results.stream().map(x -> {
|
* }).collect(Collectors.toCollection(HashSet::new));
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
* System.out.println("RESULT Final: " + results); logFile.write("RES_FINAL: " +
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
* results.toString()+"\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " +
|
||||||
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
* PlaceholderType.EXISTING_PLACEHOLDERS); logFile.flush(); } catch (IOException
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
* e) { e.printStackTrace(); } return results.stream().map((unifyPairs -> new
|
||||||
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
* ResultSet(UnifyTypeFactory.convert(unifyPairs,
|
||||||
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
* generateTPHMap(cons))))).collect(Collectors.toList()); }
|
||||||
}
|
|
||||||
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
System.out.println("RESULT Final: " + results);
|
|
||||||
logFile.write("RES_FINAL: " + results.toString()+"\n");
|
|
||||||
logFile.flush();
|
|
||||||
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);
|
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return results.stream().map((unifyPairs ->
|
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine
|
||||||
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
* Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
* @param eq The set of constraints
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
private void varianceInheritance(Set<UnifyPair> eq) {
|
* private void varianceInheritance(Set<UnifyPair> eq) { Set<PlaceholderType>
|
||||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
* usedTPH = new HashSet<>(); Set<PlaceholderType> phSet = eq.stream().map(x ->
|
||||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
* { Set<PlaceholderType> pair = new HashSet<>(); if (x.getLhsType() instanceof
|
||||||
Set<PlaceholderType> pair = new HashSet<>();
|
* PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); if
|
||||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
* (x.getRhsType() instanceof PlaceholderType)
|
||||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
* pair.add((PlaceholderType)x.getRhsType()); return pair; }).reduce(new
|
||||||
return pair;
|
* HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d);
|
||||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
* return c;});
|
||||||
|
*
|
||||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
* ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
* phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||||
while(!phSetVariance.isEmpty()) {
|
* while(!phSetVariance.isEmpty()) { PlaceholderType a =
|
||||||
PlaceholderType a = phSetVariance.remove(0);
|
* phSetVariance.remove(0); usedTPH.add(a); //HashMap<PlaceholderType,Integer>
|
||||||
usedTPH.add(a);
|
* ht = new HashMap<>(); //ht.put(a, a.getVariance()); Set<UnifyPair> eq1 = new
|
||||||
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
* HashSet<>(eq); eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType
|
||||||
//ht.put(a, a.getVariance());
|
* && ((PlaceholderType)x.getLhsType()).equals(a))); eq1.stream().forEach(x -> {
|
||||||
Set<UnifyPair> eq1 = new HashSet<>(eq);
|
* x.getRhsType().accept(new distributeVariance(), a.getVariance());}); eq1 =
|
||||||
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
* new HashSet<>(eq); eq1.removeIf(x -> !(x.getRhsType() instanceof
|
||||||
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
|
* PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
||||||
eq1 = new HashSet<>(eq);
|
* eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(),
|
||||||
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
* a.getVariance());}); phSetVariance = new ArrayList<>(phSet);
|
||||||
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
|
* phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); }
|
||||||
phSetVariance = new ArrayList<>(phSet);
|
* }
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile) throws ClassNotFoundException {
|
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
|
||||||
|
throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for (SourceFile sf : this.sourceFiles.values()) {
|
for (SourceFile sf : this.sourceFiles.values()) {
|
||||||
@@ -303,21 +288,20 @@ public class JavaTXCompiler {
|
|||||||
UnifyResultModel urm = null;
|
UnifyResultModel urm = null;
|
||||||
// urm.addUnifyResultListener(resultListener);
|
// urm.addUnifyResultListener(resultListener);
|
||||||
try {
|
try {
|
||||||
logFile = logFile == null ? new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName())) : logFile;
|
logFile = logFile == null
|
||||||
|
? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName()))
|
||||||
|
: logFile;
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
urm = new UnifyResultModel(cons, finiteClosure);
|
urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
urm.addUnifyResultListener(resultListener);
|
urm.addUnifyResultListener(resultListener);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars =
|
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
||||||
x -> {
|
|
||||||
UnifyType lhs, rhs;
|
UnifyType lhs, rhs;
|
||||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
||||||
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
||||||
&& (((PlaceholderType)lhs).isInnerType()
|
&& (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
|
||||||
|| ((PlaceholderType)rhs).isInnerType()))
|
|
||||||
{
|
|
||||||
((PlaceholderType) lhs).setInnerType(true);
|
((PlaceholderType) lhs).setInnerType(true);
|
||||||
((PlaceholderType) rhs).setInnerType(true);
|
((PlaceholderType) rhs).setInnerType(true);
|
||||||
}
|
}
|
||||||
@@ -335,27 +319,58 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream()
|
||||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
.map(y -> y.getParameterList().getFormalparalist().stream()
|
||||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
.filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
.map(z -> ((TypePlaceholder) z.getType()).getName())
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}, (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
})).reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
|
||||||
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist()
|
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream()
|
||||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
.map(y -> y.getParameterList().getFormalparalist().stream()
|
||||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
.filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
.map(z -> ((TypePlaceholder) z.getType()).getName())
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}, (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
})).reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
|
||||||
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
||||||
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
||||||
|
|
||||||
|
Set<String> returnTypeVarNames = allClasses.stream()
|
||||||
|
.map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder) z.getReturnType()).getName())
|
||||||
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce((a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}).get();
|
||||||
|
|
||||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
Set<String> fieldTypeVarNames = allClasses.stream()
|
||||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
.map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder) z.getReturnType()).getName())
|
||||||
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
.reduce((a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}).get();
|
||||||
|
|
||||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
returnTypeVarNames.addAll(fieldTypeVarNames);
|
||||||
|
|
||||||
@@ -386,31 +401,32 @@ public class JavaTXCompiler {
|
|||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
||||||
|
// JEWEILS ANDERE SEITE
|
||||||
});
|
});
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
|
||||||
/* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt
|
/*
|
||||||
do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL
|
||||||
//anderen Seite übertragen
|
* 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
||||||
varianceTPHold = new HashSet<>(varianceTPH);
|
* //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH);
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
* varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y
|
||||||
unifyCons.map( y -> {
|
* -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType()
|
||||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
* instanceof PlaceholderType)) { if
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
* (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
||||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||||
}
|
* ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
* )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
|
||||||
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
* && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||||
}
|
* ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
|
||||||
}
|
* )).getVariance()); } } return y; } ); } while
|
||||||
return y; } ); }
|
* (!varianceTPHold.equals(varianceTPH));
|
||||||
while (!varianceTPHold.equals(varianceTPH));
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||||
|
// 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<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
@@ -419,15 +435,14 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
||||||
}
|
usedTasks);
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
}
|
}
|
||||||
return urm;
|
return urm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
@@ -440,28 +455,28 @@ public class JavaTXCompiler {
|
|||||||
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 File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
// new FileWriter(new
|
||||||
|
// 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_"
|
||||||
|
+ sourceFiles.keySet().iterator().next().getName()));
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars =
|
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
||||||
x -> {
|
|
||||||
UnifyType lhs, rhs;
|
UnifyType lhs, rhs;
|
||||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
||||||
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
||||||
&& (((PlaceholderType)lhs).isInnerType()
|
&& (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
|
||||||
|| ((PlaceholderType)rhs).isInnerType()))
|
|
||||||
{
|
|
||||||
((PlaceholderType) lhs).setInnerType(true);
|
((PlaceholderType) lhs).setInnerType(true);
|
||||||
((PlaceholderType) rhs).setInnerType(true);
|
((PlaceholderType) rhs).setInnerType(true);
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
|
||||||
};
|
};
|
||||||
logFile.write(unifyCons.toString());
|
logFile.write("Unify:" + unifyCons.toString());
|
||||||
unifyCons = unifyCons.map(distributeInnerVars);
|
unifyCons = unifyCons.map(distributeInnerVars);
|
||||||
logFile.write(unifyCons.toString());
|
logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
||||||
TypeUnify unify = new TypeUnify();
|
TypeUnify unify = new TypeUnify();
|
||||||
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
||||||
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
||||||
@@ -470,27 +485,58 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream()
|
||||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
.map(y -> y.getParameterList().getFormalparalist().stream()
|
||||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
.filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
.map(z -> ((TypePlaceholder) z.getType()).getName())
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}, (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
})).reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
|
||||||
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist()
|
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream()
|
||||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
.map(y -> y.getParameterList().getFormalparalist().stream()
|
||||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
.filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
.map(z -> ((TypePlaceholder) z.getType()).getName())
|
||||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}, (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
})).reduce(new HashSet<String>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
|
||||||
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
||||||
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
||||||
|
|
||||||
|
Set<String> returnTypeVarNames = allClasses.stream()
|
||||||
|
.map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder) z.getReturnType()).getName())
|
||||||
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce((a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}).get();
|
||||||
|
|
||||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
Set<String> fieldTypeVarNames = allClasses.stream()
|
||||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
.map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder) z.getReturnType()).getName())
|
||||||
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
.reduce((a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}).get();
|
||||||
|
|
||||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
returnTypeVarNames.addAll(fieldTypeVarNames);
|
||||||
|
|
||||||
@@ -521,31 +567,32 @@ public class JavaTXCompiler {
|
|||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
||||||
|
// JEWEILS ANDERE SEITE
|
||||||
});
|
});
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
|
||||||
/* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt
|
/*
|
||||||
do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL
|
||||||
//anderen Seite übertragen
|
* 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
||||||
varianceTPHold = new HashSet<>(varianceTPH);
|
* //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH);
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
* varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y
|
||||||
unifyCons.map( y -> {
|
* -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType()
|
||||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
* instanceof PlaceholderType)) { if
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
* (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
||||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||||
}
|
* ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
* )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
|
||||||
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
* && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||||
}
|
* ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
|
||||||
}
|
* )).getVariance()); } } return y; } ); } while
|
||||||
return y; } ); }
|
* (!varianceTPHold.equals(varianceTPH));
|
||||||
while (!varianceTPHold.equals(varianceTPH));
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||||
|
// 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<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
@@ -559,7 +606,8 @@ public class JavaTXCompiler {
|
|||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
||||||
|
usedTasks);
|
||||||
System.out.println("RESULT Final: " + li.getResults());
|
System.out.println("RESULT Final: " + li.getResults());
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
@@ -567,53 +615,64 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
else {
|
else {
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
// Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(),
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
|
||||||
|
// finiteClosure));
|
||||||
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints,
|
||||||
|
finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString() + "\n");
|
logFile.write("RES: " + result.toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
|
|
||||||
|
|
||||||
results = results.stream().map(x -> {
|
results = results.stream().map(x -> {
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC)
|
||||||
|
y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
return y; // alle Paare a <.? b erden durch a =. b ersetzt
|
return y; // alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
if (res.isPresent()) {// wenn subst ein Erg liefert wurde was veraendert
|
if (res.isPresent()) {// wenn subst ein Erg liefert wurde was veraendert
|
||||||
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
||||||
}
|
} else
|
||||||
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
return x; // wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
System.out.println("RESULT Final: " + results);
|
System.out.println("RESULT Final: " + results);
|
||||||
logFile.write("RES_FINAL: " + results.toString() + "\n");
|
logFile.write("RES_FINAL: " + results.toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);
|
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
}}
|
}
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
}
|
}
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream()
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList());
|
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons)))))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine
|
||||||
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
* Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
* @param eq The set of constraints
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
private Set<PlaceholderType> varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
|
private Set<PlaceholderType> varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
|
||||||
Set<UnifyPair> eq = cons.getAll();
|
Set<UnifyPair> eq = cons.getAll();
|
||||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||||
Set<PlaceholderType> pair = new HashSet<>();
|
Set<PlaceholderType> pair = new HashSet<>();
|
||||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
if (x.getLhsType() instanceof PlaceholderType)
|
||||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
pair.add((PlaceholderType) x.getLhsType());
|
||||||
|
if (x.getRhsType() instanceof PlaceholderType)
|
||||||
|
pair.add((PlaceholderType) x.getRhsType());
|
||||||
return pair;
|
return pair;
|
||||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
}).reduce(new HashSet<>(), (a, b) -> {
|
||||||
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}, (c, d) -> {
|
||||||
|
c.addAll(d);
|
||||||
|
return c;
|
||||||
|
});
|
||||||
|
|
||||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||||
@@ -623,7 +682,8 @@ public class JavaTXCompiler {
|
|||||||
// HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
// HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
||||||
// ht.put(a, a.getVariance());
|
// ht.put(a, a.getVariance());
|
||||||
// ConstraintSet<UnifyPair> eq1 = cons;
|
// ConstraintSet<UnifyPair> eq1 = cons;
|
||||||
//eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
// eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType &&
|
||||||
|
// ((PlaceholderType)x.getLhsType()).equals(a)));
|
||||||
// durch if-Abfrage im foreach geloest
|
// durch if-Abfrage im foreach geloest
|
||||||
cons.forEach(x -> {
|
cons.forEach(x -> {
|
||||||
if (x.getLhsType() instanceof PlaceholderType && ((PlaceholderType) x.getLhsType()).equals(a)) {
|
if (x.getLhsType() instanceof PlaceholderType && ((PlaceholderType) x.getLhsType()).equals(a)) {
|
||||||
@@ -631,39 +691,91 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// ` eq1 = new HashSet<>(eq);
|
// ` eq1 = new HashSet<>(eq);
|
||||||
//eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
// eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType &&
|
||||||
|
// ((PlaceholderType)x.getRhsType()).equals(a)));
|
||||||
// durch if-Abfrage im foreach geloest
|
// durch if-Abfrage im foreach geloest
|
||||||
cons.forEach(x -> {
|
cons.forEach(x -> {
|
||||||
if (x.getRhsType() instanceof PlaceholderType && ((PlaceholderType) x.getRhsType()).equals(a)) {
|
if (x.getRhsType() instanceof PlaceholderType && ((PlaceholderType) x.getRhsType()).equals(a)) {
|
||||||
x.getLhsType().accept(new distributeVariance(), a.getVariance());
|
x.getLhsType().accept(new distributeVariance(), a.getVariance());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
phSetVariance = new ArrayList<>(phSet); //macht vermutlich keinen Sinn PL 2018-10-18, doch, es koennen neue TPHs mit Variancen dazugekommen sein PL 2018-11-07
|
phSetVariance = new ArrayList<>(phSet); // macht vermutlich keinen Sinn PL 2018-10-18, doch, es koennen neue
|
||||||
|
// TPHs mit Variancen dazugekommen sein PL 2018-11-07
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
||||||
}
|
}
|
||||||
return usedTPH;
|
return usedTPH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
|
||||||
|
new GenericsRegistry(null));
|
||||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void generateBytecodForFile(String path, HashMap<String, byte[]> classFiles, SourceFile sf,
|
||||||
|
List<ResultSet> typeinferenceResult) throws IOException {
|
||||||
|
try {
|
||||||
|
List<GenericGenratorResultForSourceFile> genericResults = getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult, genericResults, sf,path);
|
||||||
|
bytecodeGen.visit(sf);
|
||||||
|
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles()
|
||||||
|
throws ClassNotFoundException {
|
||||||
|
List<GenericGenratorResultForSourceFile> result = new ArrayList<>();
|
||||||
|
for (File f : sourceFiles.keySet()) {
|
||||||
|
SourceFile sf = sourceFiles.get(f);
|
||||||
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
|
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
||||||
|
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
||||||
|
result.add(simplifyResOfSF);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles(
|
||||||
|
List<ResultSet> typeinferenceResult) throws ClassNotFoundException {
|
||||||
|
List<GenericGenratorResultForSourceFile> result = new ArrayList<>();
|
||||||
|
for (File f : sourceFiles.keySet()) {
|
||||||
|
SourceFile sf = sourceFiles.get(f);
|
||||||
|
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
||||||
|
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
||||||
|
result.add(simplifyResOfSF);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// um pfad erweitern
|
// um pfad erweitern
|
||||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = getGeneratedGenericResultsForAllSourceFiles(
|
||||||
|
typeinferenceResult);
|
||||||
|
generateBytecode(path, typeinferenceResult, simplifyResultsForAllSourceFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path
|
||||||
|
* @param typeinferenceResult
|
||||||
|
* @param simplifyResultsForAllSourceFiles
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void generateBytecode(String path, List<ResultSet> typeinferenceResult,
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles) throws IOException {
|
||||||
for (File f : sourceFiles.keySet()) {
|
for (File f : sourceFiles.keySet()) {
|
||||||
HashMap<String, byte[]> classFiles = new HashMap<>();
|
HashMap<String, byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles,
|
||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
sf, path);
|
||||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
this.simplifyResultsSF.add(bytecodeGen.getSimplifyResultsList());
|
writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +784,8 @@ public class JavaTXCompiler {
|
|||||||
for (String name : classFiles.keySet()) {
|
for (String name : classFiles.keySet()) {
|
||||||
byte[] bytecode = classFiles.get(name);
|
byte[] bytecode = classFiles.get(name);
|
||||||
System.out.println("generating " + name + ".class file ...");
|
System.out.println("generating " + name + ".class file ...");
|
||||||
//output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class"));
|
// output = new FileOutputStream(new File(System.getProperty("user.dir") +
|
||||||
|
// "/testBytecode/generatedBC/" +name+".class"));
|
||||||
output = new FileOutputStream(new File(path + name + ".class"));
|
output = new FileOutputStream(new File(path + name + ".class"));
|
||||||
output.write(bytecode);
|
output.write(bytecode);
|
||||||
output.close();
|
output.close();
|
||||||
@@ -680,7 +793,4 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<List<HashMap<String, SimplifyResult>>> getSimplifyResults() {
|
|
||||||
return simplifyResultsSF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ public class SyntaxTreeGenerator{
|
|||||||
Set<JavaClassName> imports = new HashSet();
|
Set<JavaClassName> imports = new HashSet();
|
||||||
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields = new HashMap<>(); //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen
|
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields = new HashMap<>(); //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen
|
||||||
|
|
||||||
List<Statement> fieldInitializations = new ArrayList<>();
|
List<Statement> fieldInitializations = new ArrayList<>(); //PL 2019-10-23: Muss für jede Klasse neu initilisiert werden
|
||||||
|
|
||||||
public SyntaxTreeGenerator(JavaClassRegistry reg, GenericsRegistry globalGenerics){
|
public SyntaxTreeGenerator(JavaClassRegistry reg, GenericsRegistry globalGenerics){
|
||||||
//Die Generics müssen während des Bauens des AST erstellt werden,
|
//Die Generics müssen während des Bauens des AST erstellt werden,
|
||||||
@@ -159,6 +159,7 @@ public class SyntaxTreeGenerator{
|
|||||||
|
|
||||||
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
|
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
|
||||||
ClassOrInterface newClass;
|
ClassOrInterface newClass;
|
||||||
|
fieldInitializations = new ArrayList<>(); //PL 2019-10-22: muss für jede Klasse neu initilisiert werden
|
||||||
if(ctx.normalClassDeclaration() != null){
|
if(ctx.normalClassDeclaration() != null){
|
||||||
newClass = convertNormal(ctx.normalClassDeclaration());
|
newClass = convertNormal(ctx.normalClassDeclaration());
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,10 @@ package de.dhbwstuttgart.syntaxtree;
|
|||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
@@ -16,10 +20,20 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
|||||||
private Token offsetOfLastElement;
|
private Token offsetOfLastElement;
|
||||||
private List<GenericTypeVar> gtvs = new ArrayList<>();
|
private List<GenericTypeVar> gtvs = new ArrayList<>();
|
||||||
|
|
||||||
public GenericDeclarationList(List<GenericTypeVar> values, Token endOffset) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public GenericDeclarationList(Iterable<? extends GenericTypeVar> values, Token endOffset) {
|
||||||
|
super(endOffset);
|
||||||
|
gtvs = isListOfGenericTypeVar(values) ? (List<GenericTypeVar>)values : Lists.newArrayList(values);
|
||||||
|
this.offsetOfLastElement = endOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericDeclarationList(ArrayList<GenericTypeVar> values, Token endOffset) {
|
||||||
super(endOffset);
|
super(endOffset);
|
||||||
gtvs = values;
|
gtvs = values;
|
||||||
this.offsetOfLastElement = endOffset;
|
this.offsetOfLastElement = endOffset; }
|
||||||
|
|
||||||
|
private boolean isListOfGenericTypeVar(Iterable<? extends GenericTypeVar> values) {
|
||||||
|
return values instanceof List && ((List<?>)values).size() > 0 && ((List<?>)values).get(0) instanceof GenericTypeVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -19,4 +19,8 @@ public class This extends Expression
|
|||||||
public void accept(StatementVisitor visitor) {
|
public void accept(StatementVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "this: "+ this.getType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,18 @@
|
|||||||
package de.dhbwstuttgart.typedeployment;
|
package de.dhbwstuttgart.typedeployment;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.typeinference.result.*;
|
import de.dhbwstuttgart.typeinference.result.*;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -29,61 +38,89 @@ public class TypeInsertFactory {
|
|||||||
|
|
||||||
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
||||||
ResultSet resultSet) {
|
ResultSet resultSet) {
|
||||||
|
|
||||||
|
try {
|
||||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
ResolvedType resolvedType = resultSet.resolveType(type);
|
||||||
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
||||||
new TypeToInsertString(resolvedType.resolvedType).insert);
|
new TypeToInsertString(resolvedType.resolvedType).insert);
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles();
|
||||||
|
for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
|
||||||
|
GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString());
|
||||||
|
return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet), resolvedType.getResultPair());
|
||||||
|
}
|
||||||
|
|
||||||
return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
|
return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){
|
private static synchronized Set<TypeInsertPoint> createGenericInsert(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl, Method m, ResultSet resultSet){
|
||||||
//Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt:
|
Set<TypeInsertPoint> result = createGenericClassInserts(genericResult, cl);
|
||||||
//Offset zum Einstzen bestimmen:
|
|
||||||
Token offset;
|
for (Method method : cl.getMethods()) {
|
||||||
String insert = "";
|
Resolver resolver = new Resolver(resultSet);
|
||||||
String end;
|
List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method));
|
||||||
if(cl.getGenerics().iterator().hasNext()){
|
createMethodConstraints(method, methodConstraints);
|
||||||
//offset = cl.getGenerics().iterator().next().getOffset();
|
}
|
||||||
offset = cl.getGenerics().getOffset();
|
|
||||||
end=",";
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<TypeInsertPoint> createMethodConstraints(Method method, List<GenericsGeneratorResult> constraints) {
|
||||||
|
Set<TypeInsertPoint> result = new HashSet<>();
|
||||||
|
Token offset = new GenericDeclarationList(method.getGenerics(), new NullToken()).getOffset();
|
||||||
|
|
||||||
|
if (constraints.size() == 0) {
|
||||||
|
result.add(new TypeInsertPoint(offset, ""));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String insert = " <";
|
||||||
|
|
||||||
|
for (GenericsGeneratorResult genericInsertConstraint : constraints) {
|
||||||
|
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
|
||||||
|
insert += genericInsertConstraint.getConstraint().getLeft();
|
||||||
} else {
|
} else {
|
||||||
offset = cl.getGenerics().getOffset();
|
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", ";
|
||||||
insert += "<";
|
|
||||||
end = ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Alle einzusetzenden Generics und deren Bounds bestimmen:
|
|
||||||
HashMap<TypePlaceholder, HashSet<TypePlaceholder>> genericsAndBounds = new HashMap<>();
|
|
||||||
for(GenericInsertPair p : toInsert){
|
|
||||||
if(!genericsAndBounds.containsKey(p.TA1)){
|
|
||||||
genericsAndBounds.put((TypePlaceholder) p.TA1, new HashSet<>());
|
|
||||||
}
|
|
||||||
if(p.TA2 != null){
|
|
||||||
genericsAndBounds.get(p.TA1).add((TypePlaceholder) p.TA2);
|
|
||||||
if(!genericsAndBounds.containsKey(p.TA2)){
|
|
||||||
genericsAndBounds.put((TypePlaceholder) p.TA2, new HashSet<>());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//String zum Einsetzen (Generics mit bounds) generieren:
|
insert = insert.substring(0, insert.length() -2);
|
||||||
Iterator<TypePlaceholder> it = genericsAndBounds.keySet().iterator();
|
insert += ">";
|
||||||
if(! it.hasNext())return new TypeInsertPoint(offset, "");
|
|
||||||
while(it.hasNext()){
|
result.add(new TypeInsertPoint(offset, insert));
|
||||||
TypePlaceholder tph = it.next();
|
return result;
|
||||||
insert += tph.getName();
|
}
|
||||||
Set<TypePlaceholder> bounds = genericsAndBounds.get(tph);
|
|
||||||
if(bounds.size() > 0){
|
private static Set<TypeInsertPoint> createGenericClassInserts(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl) {
|
||||||
insert += " extends ";
|
Set<TypeInsertPoint> result = new HashSet<>();
|
||||||
Iterator<TypePlaceholder> boundIt = bounds.iterator();
|
Token offset = cl.getGenerics().getOffset();
|
||||||
while(boundIt.hasNext()){
|
|
||||||
TypePlaceholder bound = boundIt.next();
|
List<GenericsGeneratorResult> classConstraints = genericResult.getClassConstraints();
|
||||||
insert += bound.getName();
|
|
||||||
if(boundIt.hasNext())insert += " & ";
|
if (classConstraints.size() == 0) {
|
||||||
|
result.add(new TypeInsertPoint(offset, ""));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String insert = " <";
|
||||||
|
|
||||||
|
for (GenericsGeneratorResult genericInsertConstraint : classConstraints) {
|
||||||
|
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
|
||||||
|
insert += genericInsertConstraint.getConstraint().getLeft();
|
||||||
|
} else {
|
||||||
|
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(it.hasNext())insert+=",";
|
|
||||||
}
|
insert = insert.substring(0, insert.length() -2);
|
||||||
return new TypeInsertPoint(offset, insert + end);
|
insert += ">";
|
||||||
|
|
||||||
|
result.add(new TypeInsertPoint(offset, insert));
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,8 +39,8 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
*/
|
*/
|
||||||
|
//writeLog("xxx");
|
||||||
noOfThread--;
|
//noOfThread--;
|
||||||
synchronized (usedTasks) {
|
synchronized (usedTasks) {
|
||||||
if (this.myIsCancelled()) {
|
if (this.myIsCancelled()) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
|
@@ -173,7 +173,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
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));
|
||||||
logFile.write("");
|
logFile.write("");
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
@@ -903,9 +904,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
noOfThread--;
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
writeLog("wait "+ forkOrig.thNo);
|
||||||
|
noOfThread--;
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
|
//noOfThread++;
|
||||||
forkOrig.writeLog("final Orig 1");
|
forkOrig.writeLog("final Orig 1");
|
||||||
forkOrig.closeLogFile();
|
forkOrig.closeLogFile();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
@@ -918,7 +920,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnify2Task fork : forks) {
|
for(TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
noOfThread--;
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
|
//noOfThread++;
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
writeLog("Join " + new Integer(fork.thNo).toString());
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
writeLog("fork_res: " + fork_res.toString());
|
writeLog("fork_res: " + fork_res.toString());
|
||||||
@@ -931,7 +935,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
fork.closeLogFile();
|
fork.closeLogFile();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
noOfThread++;
|
//noOfThread++;
|
||||||
} else {
|
} else {
|
||||||
if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) {
|
if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) {
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
@@ -1006,9 +1010,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
noOfThread--;
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
writeLog("wait "+ forkOrig.thNo);
|
||||||
|
noOfThread--;
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
|
//noOfThread++;
|
||||||
forkOrig.writeLog("final Orig -1");
|
forkOrig.writeLog("final Orig -1");
|
||||||
forkOrig.closeLogFile();
|
forkOrig.closeLogFile();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
@@ -1021,7 +1026,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnify2Task fork : forks) {
|
for(TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
noOfThread--;
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
|
//noOfThread++;
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
writeLog("Join " + new Integer(fork.thNo).toString());
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
writeLog("fork_res: " + fork_res.toString());
|
writeLog("fork_res: " + fork_res.toString());
|
||||||
@@ -1034,7 +1041,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
fork.closeLogFile();
|
fork.closeLogFile();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
noOfThread++;
|
//noOfThread++;
|
||||||
} else {
|
} else {
|
||||||
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
|
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
|
||||||
writeLog("var2einstieg");
|
writeLog("var2einstieg");
|
||||||
@@ -1079,9 +1086,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
noOfThread--;
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
writeLog("wait "+ forkOrig.thNo);
|
||||||
|
noOfThread--;
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
|
//noOfThread++;
|
||||||
forkOrig.writeLog("final Orig 2");
|
forkOrig.writeLog("final Orig 2");
|
||||||
forkOrig.closeLogFile();
|
forkOrig.closeLogFile();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
@@ -1093,7 +1101,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnify2Task fork : forks) {
|
for(TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
noOfThread--;
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
|
//noOfThread++;
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
writeLog("Join " + new Integer(fork.thNo).toString());
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
add_res.add(fork_res);
|
add_res.add(fork_res);
|
||||||
@@ -1101,7 +1111,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
fork.closeLogFile();
|
fork.closeLogFile();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
noOfThread++;
|
//noOfThread++;
|
||||||
} else {
|
} else {
|
||||||
//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
|
||||||
|
@@ -37,14 +37,14 @@ public class BinaryTest {
|
|||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
Method m2 = classToTest.getDeclaredMethod("m2", Integer.class,Integer.class);
|
Method m2 = classToTest.getDeclaredMethod("m2", Integer.class,Integer.class);
|
||||||
Integer res = (Integer) m2.invoke(instanceOfClass, 2,3);
|
Integer res = (Integer) m2.invoke(instanceOfClass, 2,3);
|
||||||
assertEquals(6, res);
|
assertEquals(new Integer(6), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testM3() throws Exception {
|
public void testM3() throws Exception {
|
||||||
Method m3 = classToTest.getDeclaredMethod("m3", Integer.class);
|
Method m3 = classToTest.getDeclaredMethod("m3", Integer.class);
|
||||||
Integer res = (Integer) m3.invoke(instanceOfClass, 2);
|
Integer res = (Integer) m3.invoke(instanceOfClass, 2);
|
||||||
assertEquals(4, res);
|
assertEquals(new Integer(4), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ public class FacTest {
|
|||||||
public void testInteger() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testInteger() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
||||||
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
||||||
assertEquals(result, 6);
|
assertEquals(result, new Integer(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ public class FacultyTest {
|
|||||||
// Integer result = (Integer) apply.invoke(lambda,i);
|
// Integer result = (Integer) apply.invoke(lambda,i);
|
||||||
Integer result = (Integer) getFact.invoke(instanceOfClass,i);
|
Integer result = (Integer) getFact.invoke(instanceOfClass,i);
|
||||||
|
|
||||||
assertEquals(6, result);
|
assertEquals(new Integer(6), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ public class FieldTphConsMethTest {
|
|||||||
Field a = classToTest.getDeclaredField("a");
|
Field a = classToTest.getDeclaredField("a");
|
||||||
a.setAccessible(true);
|
a.setAccessible(true);
|
||||||
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class);
|
Method m = classToTest.getDeclaredMethod("id", Object.class);
|
||||||
Object result = m.invoke(instanceOfClass, 42);
|
Object result = m.invoke(instanceOfClass, 42);
|
||||||
|
|
||||||
assertEquals(42,result);
|
assertEquals(42,result);
|
||||||
|
@@ -8,9 +8,10 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class IdTest {
|
public class IdTest {
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ public class LambdaTest {
|
|||||||
System.out.println(m.invoke(instanceOfClass).toString());
|
System.out.println(m.invoke(instanceOfClass).toString());
|
||||||
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
||||||
|
|
||||||
assertEquals(77, result);
|
assertEquals(i, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -68,7 +68,6 @@ public class MatrixOpTest {
|
|||||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Matrix m3 = m1.mul(vv1);
|
//Matrix m3 = m1.mul(vv1);
|
||||||
// Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
// Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||||
// Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
// Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||||
|
@@ -85,7 +85,6 @@ public class MatrixTest {
|
|||||||
res.addElement(v6);
|
res.addElement(v6);
|
||||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||||
assertEquals(result, instanceOfClass_m3);
|
assertEquals(result, instanceOfClass_m3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,14 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class OLTest {
|
public class OLTest {
|
||||||
private static String path;
|
private static String path;
|
||||||
@@ -30,7 +33,9 @@ public class OLTest {
|
|||||||
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/";
|
||||||
compiler.generateBytecode(pathToClassFile);
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(pathToClassFile,typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("OL");
|
classToTest = loader.loadClass("OL");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
@@ -47,14 +52,14 @@ public class OLTest {
|
|||||||
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||||
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||||
assertEquals(10, result);
|
assertEquals(new Integer(10), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||||
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||||
assertEquals(10.0, result);
|
assertEquals(new Double(10.0), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -73,14 +78,14 @@ public class OLTest {
|
|||||||
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
||||||
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||||
assertEquals(10, result);
|
assertEquals(new Integer(10), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
||||||
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||||
assertEquals(10.0, result);
|
assertEquals(new Double(10.0), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -54,7 +54,7 @@ public class OpTest {
|
|||||||
|
|
||||||
Integer result = (Integer) m.invoke(instanceOfClass, 7,3);
|
Integer result = (Integer) m.invoke(instanceOfClass, 7,3);
|
||||||
|
|
||||||
assertEquals(10, result);
|
assertEquals(new Integer(10), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -38,28 +38,28 @@ public class PostIncTest {
|
|||||||
public void testM1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testM1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
Method m = classToTest.getDeclaredMethod("m");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(1, res);
|
assertEquals(new Integer(1), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m2");
|
Method m = classToTest.getDeclaredMethod("m2");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(0, res);
|
assertEquals(new Integer(0), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testD1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testD1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("d");
|
Method m = classToTest.getDeclaredMethod("d");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(-1, res);
|
assertEquals(new Integer(-1), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("d2");
|
Method m = classToTest.getDeclaredMethod("d2");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(0, res);
|
assertEquals(new Integer(0), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -38,28 +38,28 @@ public class PreIncTest {
|
|||||||
public void testM() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testM() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
Method m = classToTest.getDeclaredMethod("m");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(1, res);
|
assertEquals(new Integer(1), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m2");
|
Method m = classToTest.getDeclaredMethod("m2");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(1, res);
|
assertEquals(new Integer(1), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("d");
|
Method m = classToTest.getDeclaredMethod("d");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(-1, res);
|
assertEquals(new Integer(-1), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("d2");
|
Method m = classToTest.getDeclaredMethod("d2");
|
||||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||||
assertEquals(-1, res);
|
assertEquals(new Integer(-1), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
38
src/test/java/bytecode/SimpleCycleTest.java
Normal file
38
src/test/java/bytecode/SimpleCycleTest.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class SimpleCycleTest {
|
||||||
|
|
||||||
|
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 generateGen() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/SimpleCycle.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("SimpleCycle");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -39,7 +39,7 @@ public class TphTest {
|
|||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
Object result = m.invoke(instanceOfClass, 1,2);
|
Object result = m.invoke(instanceOfClass, 1,2);
|
||||||
|
|
||||||
assertEquals(2,result);
|
assertEquals(1,result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -47,7 +47,7 @@ public class TphTest {
|
|||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
Object result = m.invoke(instanceOfClass, 1, "sss");
|
Object result = m.invoke(instanceOfClass, 1, "sss");
|
||||||
|
|
||||||
assertEquals("sss",result);
|
assertEquals(1,result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
38
src/test/java/bytecode/VectorAddTest.java
Normal file
38
src/test/java/bytecode/VectorAddTest.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class VectorAddTest {
|
||||||
|
|
||||||
|
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/VectorAdd.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("VectorAdd");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -38,21 +38,21 @@ public class WhileTest {
|
|||||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||||
Integer result = (Integer) m.invoke(instanceOfClass, 0);
|
Integer result = (Integer) m.invoke(instanceOfClass, 0);
|
||||||
assertEquals(2, result);
|
assertEquals(new Integer(2), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||||
Double result = (Double) m.invoke(instanceOfClass, 0.0);
|
Double result = (Double) m.invoke(instanceOfClass, 0.0);
|
||||||
assertEquals(2.0, result);
|
assertEquals(new Double(2.0), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
Method m = classToTest.getDeclaredMethod("m", Long.class);
|
Method m = classToTest.getDeclaredMethod("m", Long.class);
|
||||||
Long result = (Long) m.invoke(instanceOfClass, 0l);
|
Long result = (Long) m.invoke(instanceOfClass, 0l);
|
||||||
assertEquals(2l, result);
|
assertEquals(new Long(2l), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -25,11 +25,11 @@ public class YTest {
|
|||||||
public void generateBC() throws Exception {
|
public void generateBC() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Y.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Y.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
// compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
// compiler.generateBytecode(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/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
// classToTest = loader.loadClass("Y");
|
classToTest = loader.loadClass("Y");
|
||||||
/*
|
/*
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
38
src/test/java/bytecode/mathStrucIntegerTest.java
Normal file
38
src/test/java/bytecode/mathStrucIntegerTest.java
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 mathStrucIntegerTest {
|
||||||
|
|
||||||
|
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/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("mathStrucInteger");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor(Integer.class).newInstance("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
38
src/test/java/bytecode/mathStrucTest.java
Normal file
38
src/test/java/bytecode/mathStrucTest.java
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 mathStrucTest {
|
||||||
|
|
||||||
|
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/mathStruc.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("mathStruc");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,77 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package bytecode.simplifyalgo;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Fayez Abu Alia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CycleTest {
|
|
||||||
|
|
||||||
private static TPHExtractor tphExtractor;
|
|
||||||
private static String methName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception {
|
|
||||||
tphExtractor = new TPHExtractor();
|
|
||||||
// A < B
|
|
||||||
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
|
||||||
// B < C
|
|
||||||
TPHConstraint c2 = new ExtendsConstraint("B", "C", Relation.EXTENDS);
|
|
||||||
// C < D
|
|
||||||
TPHConstraint c3 = new ExtendsConstraint("C", "D", Relation.EXTENDS);
|
|
||||||
// D < A
|
|
||||||
TPHConstraint c4 = new ExtendsConstraint("D", "A", Relation.EXTENDS);
|
|
||||||
// name
|
|
||||||
methName = "m";
|
|
||||||
MethodAndTPH mtph = new MethodAndTPH("m");
|
|
||||||
mtph.getTphs().add("A");
|
|
||||||
mtph.getTphs().add("B");
|
|
||||||
mtph.getTphs().add("C");
|
|
||||||
mtph.getTphs().add("D");
|
|
||||||
tphExtractor.ListOfMethodsAndTph.add(mtph);
|
|
||||||
tphExtractor.allCons.add(c1);
|
|
||||||
tphExtractor.allCons.add(c2);
|
|
||||||
tphExtractor.allCons.add(c3);
|
|
||||||
tphExtractor.allCons.add(c4);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
|
||||||
HashSet<String> equals = new HashSet<>();
|
|
||||||
equals.add("A");
|
|
||||||
equals.add("B");
|
|
||||||
equals.add("C");
|
|
||||||
equals.add("D");
|
|
||||||
TPHConstraint k = new ExtendsConstraint("A", Type.getInternalName(Object.class), Relation.EXTENDS);
|
|
||||||
result.put(k, equals);
|
|
||||||
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>());
|
|
||||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
|
||||||
assertTrue(areEquals);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,64 +0,0 @@
|
|||||||
package bytecode.simplifyalgo;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.ConstraintsFinder;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertPlacer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Fayez Abu Alia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class FinderTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testM1() {
|
|
||||||
List<TPHConstraint> allCons = new ArrayList<>();
|
|
||||||
// L < M
|
|
||||||
TPHConstraint c1 = new ExtendsConstraint("L", "M", Relation.EXTENDS);
|
|
||||||
// L < N
|
|
||||||
TPHConstraint c2 = new ExtendsConstraint("L", "N", Relation.EXTENDS);
|
|
||||||
// M < O
|
|
||||||
TPHConstraint c3 = new ExtendsConstraint("M", "O", Relation.EXTENDS);
|
|
||||||
// M < P
|
|
||||||
TPHConstraint c4 = new ExtendsConstraint("M", "P", Relation.EXTENDS);
|
|
||||||
|
|
||||||
allCons.add(c1);
|
|
||||||
allCons.add(c2);
|
|
||||||
allCons.add(c3);
|
|
||||||
allCons.add(c4);
|
|
||||||
List<List<TPHConstraint>> res = new ArrayList<>();
|
|
||||||
List<TPHConstraint> l1 = new ArrayList<>();
|
|
||||||
List<TPHConstraint> l2 = new ArrayList<>();
|
|
||||||
|
|
||||||
l1.add(c1);
|
|
||||||
l1.add(c2);
|
|
||||||
|
|
||||||
l2.add(c3);
|
|
||||||
l2.add(c4);
|
|
||||||
|
|
||||||
res.add(l1);
|
|
||||||
res.add(l2);
|
|
||||||
|
|
||||||
ConstraintsFinder finder = new ConstraintsFinder(allCons);
|
|
||||||
|
|
||||||
assertEquals(finder.findConstraints(), res);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,102 +0,0 @@
|
|||||||
package bytecode.simplifyalgo;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertPlacer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Fayez Abu Alia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SameLeftSide {
|
|
||||||
// Typeplaceholders können nicht definiert werden, da die Konstruktor
|
|
||||||
// private ist => Test geht nicht
|
|
||||||
private static TPHExtractor tphExtractor;
|
|
||||||
private static String methName;
|
|
||||||
private static String methName2;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception {
|
|
||||||
tphExtractor = new TPHExtractor();
|
|
||||||
// A < B
|
|
||||||
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
|
||||||
// A < C
|
|
||||||
TPHConstraint c2 = new ExtendsConstraint("A", "C", Relation.EXTENDS);
|
|
||||||
// B < D
|
|
||||||
TPHConstraint c3 = new ExtendsConstraint("B", "D", Relation.EXTENDS);
|
|
||||||
// C < E
|
|
||||||
TPHConstraint c4 = new ExtendsConstraint("C", "E", Relation.EXTENDS);
|
|
||||||
// name
|
|
||||||
methName = "m1";
|
|
||||||
MethodAndTPH m1 = new MethodAndTPH("m1");
|
|
||||||
|
|
||||||
methName2 = "m2";
|
|
||||||
MethodAndTPH m2 = new MethodAndTPH("m2");
|
|
||||||
|
|
||||||
m1.getTphs().add("A");
|
|
||||||
m1.getTphs().add("B");
|
|
||||||
m1.getTphs().add("D");
|
|
||||||
|
|
||||||
m2.getTphs().add("C");
|
|
||||||
m2.getTphs().add("E");
|
|
||||||
|
|
||||||
tphExtractor.ListOfMethodsAndTph.add(m1);
|
|
||||||
tphExtractor.ListOfMethodsAndTph.add(m2);
|
|
||||||
|
|
||||||
tphExtractor.allCons.add(c1);
|
|
||||||
tphExtractor.allCons.add(c2);
|
|
||||||
tphExtractor.allCons.add(c3);
|
|
||||||
tphExtractor.allCons.add(c4);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testM1() {
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
|
||||||
|
|
||||||
TPHConstraint d = new ExtendsConstraint("D", Type.getInternalName(Object.class), Relation.EXTENDS);
|
|
||||||
TPHConstraint a = new ExtendsConstraint("A", "D", Relation.EXTENDS);
|
|
||||||
TPHConstraint b = new ExtendsConstraint("B", "D", Relation.EXTENDS);
|
|
||||||
result.put(d, new HashSet<>());
|
|
||||||
result.put(a, new HashSet<>());
|
|
||||||
HashSet<String> hs = new HashSet<>();
|
|
||||||
|
|
||||||
result.put(b, hs);
|
|
||||||
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>());
|
|
||||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
|
||||||
assertTrue(areEquals);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testM2() {
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
|
||||||
|
|
||||||
TPHConstraint e = new ExtendsConstraint("E", Type.getInternalName(Object.class), Relation.EXTENDS);
|
|
||||||
TPHConstraint c = new ExtendsConstraint("C", "E", Relation.EXTENDS);
|
|
||||||
|
|
||||||
result.put(e, new HashSet<>());
|
|
||||||
HashSet<String> hs = new HashSet<>();
|
|
||||||
hs.add("B");
|
|
||||||
result.put(c, hs);
|
|
||||||
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName2, tphExtractor,new ArrayList<>());
|
|
||||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
|
||||||
assertTrue(areEquals);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,80 +0,0 @@
|
|||||||
package bytecode.simplifyalgo;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Fayez Abu Alia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SimpleCycle {
|
|
||||||
private static TPHExtractor tphExtractor;
|
|
||||||
private static String methName;
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception {
|
|
||||||
tphExtractor = new TPHExtractor();
|
|
||||||
// A < B
|
|
||||||
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
|
||||||
// B < A
|
|
||||||
TPHConstraint c2 = new ExtendsConstraint("B", "A", Relation.EXTENDS);
|
|
||||||
// name
|
|
||||||
methName = "m";
|
|
||||||
tphExtractor.allCons.add(c1);
|
|
||||||
tphExtractor.allCons.add(c2);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
|
||||||
HashSet<String> equals = new HashSet<>();
|
|
||||||
equals.add("A");
|
|
||||||
equals.add("B");
|
|
||||||
TPHConstraint k = new ExtendsConstraint("B", Type.getInternalName(Object.class), Relation.EXTENDS);
|
|
||||||
result.put(k, equals);
|
|
||||||
|
|
||||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>());
|
|
||||||
boolean areEquals = areMapsEqual(result, sim);
|
|
||||||
assertTrue(areEquals);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean areMapsEqual(HashMap<TPHConstraint, HashSet<String>> m1, HashMap<TPHConstraint, HashSet<String>> m2) {
|
|
||||||
|
|
||||||
for(TPHConstraint c : m1.keySet()) {
|
|
||||||
for(TPHConstraint c2 : m2.keySet()) {
|
|
||||||
if(c.getLeft().equals(c2.getLeft()) && c.getRight().equals(c2.getRight()) && c.getRel()==c2.getRel()) {
|
|
||||||
HashSet<String> eq1 = m1.get(c);
|
|
||||||
HashSet<String> eq2 = m2.get(c2);
|
|
||||||
|
|
||||||
if((eq1 == null && eq2 != null) || (eq1 != null && eq2 == null))
|
|
||||||
return false;
|
|
||||||
if(eq1 != null) {
|
|
||||||
if(eq1.size() != eq2.size())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for(String tph:eq1) {
|
|
||||||
if(!eq2.contains(tph))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,6 +1,6 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Long;
|
//import java.lang.Long;
|
||||||
import java.lang.Short;
|
//import java.lang.Short;
|
||||||
|
|
||||||
public class Faculty {
|
public class Faculty {
|
||||||
public fact;
|
public fact;
|
||||||
@@ -16,6 +16,7 @@ public class Faculty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public getFact(x) {
|
public getFact(x) {
|
||||||
return fact.apply(x);
|
return fact.apply(x);
|
||||||
}
|
}
|
||||||
@@ -48,4 +49,4 @@ public class Faculty {
|
|||||||
// return x * m(x-1);
|
// return x * m(x-1);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
//}
|
||||||
|
@@ -2,10 +2,25 @@ public class FieldTphConsMeth {
|
|||||||
|
|
||||||
a;
|
a;
|
||||||
public FieldTphConsMeth(c) {
|
public FieldTphConsMeth(c) {
|
||||||
a = m(c);
|
a = id(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
m(b) {
|
id(b) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*setA(x) {
|
||||||
|
a = x;
|
||||||
|
return a;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
m(x,y) {
|
||||||
|
x = id(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*m2(x,y) {
|
||||||
|
x = setA(y);
|
||||||
|
return x;
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
@@ -1,7 +1,20 @@
|
|||||||
public class Id {
|
public class Id {
|
||||||
|
// a;
|
||||||
id(b){
|
// id(b){
|
||||||
return b;
|
// return b;
|
||||||
|
// }
|
||||||
|
id2 = x -> x;
|
||||||
|
// id2 = () -> {
|
||||||
|
// var x = m(a);
|
||||||
|
// var y = x;
|
||||||
|
// var z = y;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// m(a){
|
||||||
|
// return a;
|
||||||
|
// }
|
||||||
|
id3 (x) {
|
||||||
|
return id2.apply(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,13 +1,24 @@
|
|||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Double;
|
import java.lang.Double;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
//import java.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
public class OL {
|
public class OL {
|
||||||
|
|
||||||
m(x) { return x + x; }
|
m(x) { return x + x; }
|
||||||
|
|
||||||
|
m(Boolean x) { return x; }
|
||||||
|
|
||||||
|
// if the class contains just this method, then correct BC will be generated.
|
||||||
|
// But if another methods are contained then the generated BC is not correct
|
||||||
|
// m(x) {
|
||||||
|
// //x.add(1);
|
||||||
|
// x.addAll(x);
|
||||||
|
// return x;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OLMain {
|
public class OLMain {
|
||||||
|
25
src/test/resources/bytecode/javFiles/SimpleCycle.jav
Normal file
25
src/test/resources/bytecode/javFiles/SimpleCycle.jav
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
public class SimpleCycle {
|
||||||
|
|
||||||
|
m(a,b,d){
|
||||||
|
/* var g;
|
||||||
|
var h;
|
||||||
|
g = h;
|
||||||
|
h = g;
|
||||||
|
|
||||||
|
var y;
|
||||||
|
var z;
|
||||||
|
y=z;
|
||||||
|
z=y;
|
||||||
|
|
||||||
|
var j = z;
|
||||||
|
var x;
|
||||||
|
b = a;
|
||||||
|
var c = b;
|
||||||
|
var f = d;
|
||||||
|
b = x;
|
||||||
|
var l = c;
|
||||||
|
a = l; */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -7,17 +7,17 @@ public class Sorting{
|
|||||||
a.addAll(b);
|
a.addAll(b);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
sort(in){
|
sort(in){
|
||||||
var firstHalf = in;
|
var firstHalf = in;
|
||||||
var secondHalf = in;
|
var secondHalf = in;
|
||||||
return merge(sort(firstHalf), sort(secondHalf));
|
return merge(sort(firstHalf), sort(secondHalf));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void sort(a){
|
void sort(a){
|
||||||
a = merge(a,a);
|
a = merge(a,a);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,8 @@ public class Tph {
|
|||||||
|
|
||||||
m(a,b){
|
m(a,b){
|
||||||
var c = m2(b);
|
var c = m2(b);
|
||||||
// return a;
|
return a;
|
||||||
return m2(b);
|
// return m2(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
m2(b){
|
m2(b){
|
||||||
|
@@ -1,6 +1,13 @@
|
|||||||
public class Tph2 {
|
public class Tph2 {
|
||||||
|
id = x->x;
|
||||||
|
id3 (x) {
|
||||||
|
return id.apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
m(a,b){
|
m(a,b){
|
||||||
var c = m2(a,b);
|
var c = m2(a,b);
|
||||||
|
//m2(a,b);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,8 @@ public class Tph3 {
|
|||||||
// m2(a,b){
|
// m2(a,b){
|
||||||
// return m(a,b);
|
// return m(a,b);
|
||||||
// }
|
// }
|
||||||
m1(x, y) { m2(x); x = y; }
|
m1(x, y) { m2(x); x = y;
|
||||||
|
}
|
||||||
|
|
||||||
m2(y) { m1(y, y); }
|
m2(y) { m1(y, y); }
|
||||||
}
|
}
|
||||||
|
@@ -2,11 +2,11 @@ public class Tph4{
|
|||||||
m(a,b){
|
m(a,b){
|
||||||
var c = m2(b);
|
var c = m2(b);
|
||||||
var d = m2(c);
|
var d = m2(c);
|
||||||
return a;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
m2(b){
|
m2(b){
|
||||||
return b
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -1,9 +1,11 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
//import java.lang.Byte;
|
import java.lang.Byte;
|
||||||
//import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
//import java.util.Vector;
|
||||||
|
//import java.util.Collection;
|
||||||
|
/*
|
||||||
public class VectorAdd {
|
public class VectorAdd {
|
||||||
|
|
||||||
add(v1, v2) {
|
add(v1, v2) {
|
||||||
@@ -17,3 +19,23 @@ public class VectorAdd {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class VectorAdd {
|
||||||
|
vectorAdd(v1, v2) {
|
||||||
|
var i = 0;
|
||||||
|
var erg = new Vector<>();
|
||||||
|
while (i < v1.size()) {
|
||||||
|
erg.addElement(v1.elementAt(i) + v2.elementAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return erg;
|
||||||
|
}
|
||||||
|
|
||||||
|
//addEle(z) {
|
||||||
|
// var x;
|
||||||
|
// var y;
|
||||||
|
// x.add(y);
|
||||||
|
// z = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -8,9 +8,23 @@ class Y {
|
|||||||
y = f -> t -> f.apply(y.apply(f)).apply(t);
|
y = f -> t -> f.apply(y.apply(f)).apply(t);
|
||||||
//factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
//factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
class fac1 {
|
||||||
|
factorial;
|
||||||
|
|
||||||
|
fac1() {
|
||||||
|
var y;
|
||||||
|
y = new Y<Integer,Integer,Integer,Integer,Integer>().getY();
|
||||||
|
factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
ergibt Parse-Error
|
ergibt Parse-Error
|
||||||
class fac1 {
|
class fac1 {
|
||||||
factorial;
|
factorial;
|
||||||
|
15
src/test/resources/bytecode/javFiles/mathStruc.jav
Normal file
15
src/test/resources/bytecode/javFiles/mathStruc.jav
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class mathStruc {
|
||||||
|
model;
|
||||||
|
|
||||||
|
//Fun1*<Fun2*<A,A,A>, Fun1*<MathStruc <A>,MathStruc <A>>>
|
||||||
|
innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(model,ms.model));
|
||||||
|
|
||||||
|
public mathStruc(m) {
|
||||||
|
model =m;
|
||||||
|
//innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(this.model,ms.model));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
23
src/test/resources/bytecode/javFiles/mathStrucInteger.jav
Normal file
23
src/test/resources/bytecode/javFiles/mathStrucInteger.jav
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class mathStrucInteger {
|
||||||
|
model;
|
||||||
|
|
||||||
|
innerOp = (o) -> (ms) -> new mathStrucInteger<>(o.apply(model,ms.model));
|
||||||
|
|
||||||
|
public mathStrucInteger(m) {
|
||||||
|
model =m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class mathStrucIntegerUse {
|
||||||
|
|
||||||
|
main() {
|
||||||
|
var ms;
|
||||||
|
ms = new mathStrucInteger<>(2);
|
||||||
|
var ms2;
|
||||||
|
ms2 = ms.innerOp.apply((x,y) -> x+y).apply(ms);
|
||||||
|
return ms2;
|
||||||
|
}
|
||||||
|
}
|
91
src/test/resources/bytecode/javFiles/mathStrucMatrixOP.jav
Normal file
91
src/test/resources/bytecode/javFiles/mathStrucMatrixOP.jav
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
//PL 2019-10-24: laeuft nicht durch, zu gross
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class mathStrucMatrixOP {
|
||||||
|
model;
|
||||||
|
|
||||||
|
innerOp = (o) -> (ms) -> new mathStrucMatrixOP<>(o.apply(model,ms.model));
|
||||||
|
|
||||||
|
public mathStrucMatrixOP(m) {
|
||||||
|
model =m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
|
MatrixOP () {
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixOP(vv) {
|
||||||
|
Integer i;
|
||||||
|
i = 0;
|
||||||
|
while(i < vv.size()) {
|
||||||
|
// Boolean a = this.add(vv.elementAt(i));
|
||||||
|
this.add(vv.elementAt(i));
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public mul = (m1, m2) -> {
|
||||||
|
var ret = new MatrixOP();
|
||||||
|
var i = 0;
|
||||||
|
while(i < m1.size()) {
|
||||||
|
var v1 = m1.elementAt(i);
|
||||||
|
var v2 = new Vector<Integer>();
|
||||||
|
var j = 0;
|
||||||
|
while(j < v1.size()) {
|
||||||
|
var erg = 0;
|
||||||
|
var k = 0;
|
||||||
|
while(k < v1.size()) {
|
||||||
|
erg = erg + v1.elementAt(k)
|
||||||
|
* m2.elementAt(k).elementAt(j);
|
||||||
|
k++; }
|
||||||
|
// v2.addElement(new Integer(erg));
|
||||||
|
v2.addElement(erg);
|
||||||
|
j++; }
|
||||||
|
ret.addElement(v2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class mathStrucUseMatrixOP {
|
||||||
|
|
||||||
|
main() {
|
||||||
|
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||||
|
Vector<Integer> v1 = new Vector<Integer>();
|
||||||
|
v1.addElement(2);
|
||||||
|
v1.addElement(2);
|
||||||
|
Vector<Integer> v2 = new Vector<Integer>();
|
||||||
|
v2.addElement(3);
|
||||||
|
v2.addElement(3);
|
||||||
|
vv.addElement(v1);
|
||||||
|
vv.addElement(v2);
|
||||||
|
|
||||||
|
MatrixOP m1 = new MatrixOP(vv);
|
||||||
|
|
||||||
|
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||||
|
Vector<Integer> v3 = new Vector<Integer>();
|
||||||
|
v3.addElement(2);
|
||||||
|
v3.addElement(2);
|
||||||
|
Vector<Integer> v4 = new Vector<Integer>();
|
||||||
|
v4.addElement(3);
|
||||||
|
v4.addElement(3);
|
||||||
|
vv1.addElement(v3);
|
||||||
|
vv1.addElement(v4);
|
||||||
|
|
||||||
|
MatrixOP m2 = new MatrixOP(vv1);
|
||||||
|
|
||||||
|
var mms;
|
||||||
|
mms = new mathStrucMatrixOP<>(m1);
|
||||||
|
var mms2;
|
||||||
|
mms2 = new mathStrucMatrixOP<>(m2);
|
||||||
|
var mms3;
|
||||||
|
mms3 = mms.innerOp.apply(m1.mul).apply(mms2);
|
||||||
|
return mms3;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,5 +4,12 @@ import java.util.Collection;
|
|||||||
class Sorting{
|
class Sorting{
|
||||||
void merge(a, b){
|
void merge(a, b){
|
||||||
a.addAll(b);
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(in){
|
||||||
|
var firstHalf = in;
|
||||||
|
var secondHalf = in;
|
||||||
|
return merge(sort(firstHalf), sort(secondHalf));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user