forked from JavaTX/JavaCompilerCore
Merge branch 'bytecode2' into plugin
Conflicts: pom.xml src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java src/test/java/asp/ClingoTest.java src/test/java/asp/gencay/GeneratorTest.java src/test/java/bytecode/BinaryTest.java src/test/java/bytecode/FacTest.java src/test/java/bytecode/FacultyTest.java src/test/java/bytecode/FieldTest.java src/test/java/bytecode/FunOLTest.java src/test/java/bytecode/GenTest.java src/test/java/bytecode/GreaterEqualTest.java src/test/java/bytecode/GreaterThanTest.java src/test/java/bytecode/LambdaTest.java src/test/java/bytecode/LambdaVoidTest.java src/test/java/bytecode/LessEqualTest.java src/test/java/bytecode/LessThanTest.java src/test/java/bytecode/MatrixOpTest.java src/test/java/bytecode/MatrixTest.java src/test/java/bytecode/MergeTest.java src/test/java/bytecode/OLTest.java src/test/java/bytecode/OpTest.java src/test/java/bytecode/OverloadingSortingTest.java src/test/java/bytecode/OverloadingTest.java src/test/java/bytecode/PlusTest.java src/test/java/bytecode/PostIncTest.java src/test/java/bytecode/PreIncTest.java src/test/java/bytecode/RelOpsTest.java src/test/java/bytecode/SortingTest.java src/test/java/bytecode/SubMatTest.java src/test/java/bytecode/Tph2Test.java src/test/java/bytecode/Tph3Test.java src/test/java/bytecode/Tph5Test.java src/test/java/bytecode/TphTest.java src/test/java/bytecode/WhileTest.java src/test/java/bytecode/YTest.java src/test/java/bytecode/applyLambdaTest.java src/test/java/parser/GeneralParserTest.java src/test/java/typeinference/UnifyTest.java
This commit is contained in:
commit
d9cda2779f
23
pom.xml
23
pom.xml
@ -1,3 +1,4 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
@ -54,8 +55,6 @@
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>src/</sourceDirectory>
|
||||
<testSourceDirectory>test/</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
@ -68,8 +67,8 @@
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/de/dhbwstuttgart/parser/antlr/</sourceDirectory>
|
||||
<outputDirectory>src/de/dhbwstuttgart/parser/antlr/</outputDirectory>
|
||||
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
||||
<arguments>
|
||||
<argument>-package</argument>
|
||||
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||
@ -82,8 +81,8 @@
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/de/dhbwstuttgart/sat/asp/parser/antlr/</sourceDirectory>
|
||||
<outputDirectory>src/de/dhbwstuttgart/sat/asp/parser/antlr/</outputDirectory>
|
||||
<sourceDirectory>src/main/antlr4/sat</sourceDirectory>
|
||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
||||
<arguments>
|
||||
<argument>-package</argument>
|
||||
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
||||
@ -140,7 +139,7 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-p2-repository-plugin</artifactId>
|
||||
<version>${tycho.version}</version>
|
||||
@ -152,15 +151,7 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugin -->
|
||||
</plugins>
|
||||
</build>
|
||||
<pluginRepositories>
|
||||
|
@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
# A basic script to compile the necessary packages and their subpackages to work with the parser.
|
||||
# Messages are logged to stderr.
|
||||
>&2 echo "Building de.dhbwstuttgart.typecheck..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/typecheck/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.factory..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/factory/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.operator..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/operator/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.statement..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/statement/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.statement.literal..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/statement/literal/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.type..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/type/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.parser..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/parser/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.parser.SyntaxTreeGenerator..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/parser/SyntaxTreeGenerator/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.parser.antlr..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/parser/antlr/*.java
|
||||
echo "Done. Now its your turn to debug:)."
|
@ -6,6 +6,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
@ -62,6 +63,8 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
private String superClass;
|
||||
|
||||
private ArrayList<TypePlaceholder> tphsClass;
|
||||
|
||||
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
// stores generics and their bounds of class
|
||||
@ -131,20 +134,44 @@ public class BytecodeGen implements ASTVisitor {
|
||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||
resultSet = rs;
|
||||
tphExtractor.setResultSet(resultSet);
|
||||
|
||||
// Nur einmal ausführen!!
|
||||
if(!isVisited) {
|
||||
classOrInterface.accept(tphExtractor);
|
||||
|
||||
getCommonTPHS(tphExtractor);
|
||||
|
||||
tphsClass = new ArrayList<>();
|
||||
for(TypePlaceholder t : tphExtractor.allTPHS.keySet()) {
|
||||
if(!tphExtractor.allTPHS.get(t))
|
||||
tphsClass.add(t);
|
||||
}
|
||||
|
||||
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
||||
for(TPHConstraint cons : tphExtractor.allCons) {
|
||||
TypePlaceholder right = null;
|
||||
for(TypePlaceholder tph : tphsClass) {
|
||||
if(cons.getLeft().equals(tph.getName())) {
|
||||
|
||||
consClass.add(cons);
|
||||
right = getTPH(cons.getRight());
|
||||
}
|
||||
}
|
||||
if(right != null) {
|
||||
tphsClass.add(right);
|
||||
removeFromMethod(right.getName());
|
||||
right = null;
|
||||
}
|
||||
}
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
||||
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs);
|
||||
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
||||
|| !tphsClass.isEmpty()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass);
|
||||
sig = signature.toString();
|
||||
System.out.println("Signature: => " + sig);
|
||||
}
|
||||
@ -176,6 +203,31 @@ 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 TypePlaceholder getTPH(String name) {
|
||||
for(TypePlaceholder tph: tphExtractor.allTPHS.keySet()) {
|
||||
if(tph.getName().equals(name))
|
||||
return tph;
|
||||
}
|
||||
throw new NoSuchElementException("TPH "+name +" does not exist");
|
||||
}
|
||||
|
||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
||||
// Gemeinsame TPHs
|
||||
ArrayList<TypePlaceholder> cTPHs = new ArrayList<>();
|
||||
@ -220,7 +272,8 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||
if(genericsAndBounds.containsKey(typeOfParam) ||typeOfParam.substring(0, 4).equals("TPH ")
|
||||
System.out.println(typeOfParam);
|
||||
if(genericsAndBounds.containsKey(typeOfParam) ||typeOfParam.contains("$")
|
||||
|| typeOfParam.contains("<")) {
|
||||
hasGen = true;
|
||||
break;
|
||||
@ -228,7 +281,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
}
|
||||
String sig = null;
|
||||
if(hasGen) {
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor);
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,tphsClass);
|
||||
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
||||
sig = signature.toString();
|
||||
}
|
||||
@ -307,7 +360,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
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);
|
||||
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();
|
||||
@ -388,9 +441,21 @@ public class BytecodeGen implements ASTVisitor {
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
System.out.println("In Field ---");
|
||||
String des = "L";
|
||||
if(resultSet.resolveType(field.getType()).resolvedType instanceof TypePlaceholder) {
|
||||
des += Type.getInternalName(Object.class);
|
||||
} else {
|
||||
des += resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
des +=";";
|
||||
System.out.println(des);
|
||||
String sig = resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
System.out.println(sig);
|
||||
if(sig.charAt(sig.length()-1) != (";").charAt(0)) {
|
||||
sig +=";";
|
||||
}
|
||||
cw.visitField(field.modifier, field.getName(),
|
||||
"L"+resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToDescriptor())+";",
|
||||
resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature()),
|
||||
des, sig,
|
||||
null);
|
||||
}
|
||||
|
||||
|
@ -708,7 +708,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
fieldName = fieldVar.fieldVarName;
|
||||
fieldDesc = "L" + getResolvedType(fieldVar.getType()) + ";";
|
||||
fieldDesc = "L";
|
||||
if(resultSet.resolveType(fieldVar.getType()).resolvedType instanceof TypePlaceholder) {
|
||||
fieldDesc += Type.getInternalName(Object.class);
|
||||
} else {
|
||||
fieldDesc += resultSet.resolveType(fieldVar.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
fieldDesc +=";";
|
||||
|
||||
fieldVar.receiver.accept(this);
|
||||
// test (if)
|
||||
@ -1405,9 +1411,18 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// array slot onto the top of the operand stack.
|
||||
assignLeftSide.field.receiver.accept(this);
|
||||
this.rightSideTemp.accept(this);
|
||||
String fDesc = "L";
|
||||
if(resultSet.resolveType(assignLeftSide.field.getType()).resolvedType instanceof TypePlaceholder) {
|
||||
fDesc += Type.getInternalName(Object.class);
|
||||
} else {
|
||||
fDesc += resultSet.resolveType(assignLeftSide.field.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
fDesc +=";";
|
||||
|
||||
|
||||
System.out.println("Receiver = " + getResolvedType(assignLeftSide.field.receiver.getType()));
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, getResolvedType(assignLeftSide.field.receiver.getType()),
|
||||
assignLeftSide.field.fieldVarName, "L"+getResolvedType(assignLeftSide.field.getType())+";");
|
||||
assignLeftSide.field.fieldVarName, fDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,10 +106,17 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
if(constructor.getGenericsAndBounds().containsKey(fpDesc)){
|
||||
desc += "L"+constructor.getGenericsAndBounds().get(fpDesc)+ ";";
|
||||
}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());
|
||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||
// Bound ist immer Object
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += "L"+resType+ ";";
|
||||
}
|
||||
}
|
||||
}else {
|
||||
// System.out.println("Cons has NOT Gens");
|
||||
// System.out.println("Cons has NO Gens");
|
||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}
|
||||
|
@ -41,11 +41,16 @@ public class Signature {
|
||||
private ResultSet resultSet;
|
||||
private ArrayList<GenericInsertPair> commonPairs;
|
||||
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
||||
private ArrayList<TypePlaceholder> tphsClass;
|
||||
private ArrayList<TPHConstraint> consClass;
|
||||
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,ArrayList<GenericInsertPair> commonPairs) {
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||
ArrayList<GenericInsertPair> commonPairs, ArrayList<TypePlaceholder> tphsClass, ArrayList<TPHConstraint> consClass) {
|
||||
this.classOrInterface = classOrInterface;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.commonPairs = commonPairs;
|
||||
this.tphsClass = tphsClass;
|
||||
this.consClass = consClass;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForClassOrInterface();
|
||||
}
|
||||
@ -367,7 +372,37 @@ public class Signature {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
||||
}
|
||||
if(!commonPairs.isEmpty()) {
|
||||
|
||||
if(!consClass.isEmpty()) {
|
||||
ArrayList<String> types = new ArrayList<>();
|
||||
ArrayList<String> superTypes = new ArrayList<>();
|
||||
|
||||
for(TPHConstraint cons : consClass) {
|
||||
types.add(cons.getLeft());
|
||||
superTypes.add(cons.getRight());
|
||||
}
|
||||
|
||||
for(TPHConstraint cons : consClass) {
|
||||
String t = cons.getLeft()+"$";
|
||||
String bound = cons.getRight()+"$";
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
}
|
||||
|
||||
for(TPHConstraint cons : consClass) {
|
||||
if(!types.contains(cons.getRight())) {
|
||||
String t = cons.getRight()+"$";
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*if(!commonPairs.isEmpty()) {
|
||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
||||
|
||||
@ -395,6 +430,14 @@ public class Signature {
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
@ -8,6 +8,7 @@ import java.util.LinkedList;
|
||||
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;
|
||||
@ -15,7 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class Simplify {
|
||||
|
||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor) {
|
||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor, ArrayList<TypePlaceholder> tphsClass) {
|
||||
// 1. check if there are any simple cycles like L<R and R<L:
|
||||
// a) yes => set L=R and:
|
||||
// * remove both constraints
|
||||
@ -42,7 +43,7 @@ public class Simplify {
|
||||
if(revCon != null) {
|
||||
revCon.setRel(Relation.EQUAL);
|
||||
// the reverse constraint is removed because
|
||||
// otherwise there is twice the same constraint
|
||||
// otherwise there is the same constraint twice
|
||||
// (e.g. A<B and B<A => A=B and B=A)
|
||||
consToRemove.add(revCon);
|
||||
c.setRel(Relation.EQUAL);
|
||||
@ -199,6 +200,7 @@ public class Simplify {
|
||||
// if yes => check if the super type in the method, if not
|
||||
// then ignore it.
|
||||
HashMap<String, String> subAndSuper = new HashMap<>();
|
||||
ArrayList<TPHConstraint> eqCons = new ArrayList<>();
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(subAndSuper.containsKey(c.getLeft())) {
|
||||
LinkedList<String> all = new LinkedList<>();
|
||||
@ -216,9 +218,28 @@ public class Simplify {
|
||||
if(!containTPH(methodTphs, all.getLast()))
|
||||
continue;
|
||||
}
|
||||
if(subAndSuper.containsKey(c.getLeft())) {
|
||||
System.out.println(c.getLeft());
|
||||
String r = c.getRight();
|
||||
String r2 = subAndSuper.get(c.getLeft());
|
||||
EqualConstraint eq = new EqualConstraint(r2, r, Relation.EQUAL);
|
||||
eqCons.add(eq);
|
||||
substituteInMap(subAndSuper,eqCons,allCons,r,r2);
|
||||
}
|
||||
subAndSuper.put(c.getLeft(), c.getRight());
|
||||
}
|
||||
|
||||
System.out.println("SAME LEFT SIDE: ");
|
||||
subAndSuper.forEach((c,hs)->{
|
||||
if(c!=null) {
|
||||
System.out.print(c+ " -> " + hs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
int numOfVisitedPairs = 0;
|
||||
for(String sub : subAndSuper.keySet()) {
|
||||
if(isTPHInConstraint(result,sub))
|
||||
@ -280,17 +301,27 @@ public class Simplify {
|
||||
}
|
||||
|
||||
if(!containTPH(methodTphs, superTphRes)) {
|
||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,superTphRes);
|
||||
if(classTPHSContainsTPH(tphsClass,superTphRes)) {
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||
} else {
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), null);
|
||||
if(!isTPHInConstraint(result, superTphRes))
|
||||
result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), equals);
|
||||
}
|
||||
|
||||
} else {
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,subTphRes);
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||
if(!isTPHInConstraint(result, superTphRes) && !isTphInEqualSet(result,superTphRes)) {
|
||||
HashSet<String> equals2 = getEqualsTphsFromEqualCons(eqCons,superTphRes);
|
||||
result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), equals2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(String tph : methodTphs) {
|
||||
if(!isTPHInConstraint(result, tph)) {
|
||||
result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
if(!isTPHInConstraint(result, tph) && !isTphInEqualSet(result,tph)) {
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,tph);
|
||||
result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class), Relation.EXTENDS), equals);
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,6 +345,51 @@ public class Simplify {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean classTPHSContainsTPH(ArrayList<TypePlaceholder> tphsClass, String superTphRes) {
|
||||
for(TypePlaceholder tph : tphsClass) {
|
||||
if(tph.getName().equals(superTphRes))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isTphInEqualSet(HashMap<TPHConstraint, HashSet<String>> result, String tph) {
|
||||
for(HashSet<String> hs: result.values()) {
|
||||
if(hs.contains(tph))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HashSet<String> getEqualsTphsFromEqualCons(ArrayList<TPHConstraint> eqCons, String tph) {
|
||||
HashSet<String> ee = new HashSet<>();
|
||||
for(TPHConstraint c : eqCons) {
|
||||
if(c.getLeft().equals(tph))
|
||||
ee.add(c.getRight());
|
||||
if(c.getRight().equals(tph))
|
||||
ee.add(c.getLeft());
|
||||
}
|
||||
return ee;
|
||||
}
|
||||
|
||||
private static void substituteInMap(HashMap<String, String> subAndSuper, ArrayList<TPHConstraint> allCons,ArrayList<TPHConstraint> eqCons, String toSubs,
|
||||
String tph) {
|
||||
substituteTPH(allCons, toSubs, tph);
|
||||
if(subAndSuper.containsKey(toSubs) && subAndSuper.containsKey(tph)) {
|
||||
toSubs = subAndSuper.remove(toSubs);
|
||||
EqualConstraint eq = new EqualConstraint(subAndSuper.get(tph), toSubs, Relation.EQUAL);
|
||||
eqCons.add(eq);
|
||||
substituteInMap(subAndSuper, allCons,eqCons,toSubs, subAndSuper.get(tph));
|
||||
} else if(subAndSuper.containsKey(toSubs) && !subAndSuper.containsKey(tph)) {
|
||||
String val = subAndSuper.remove(toSubs);
|
||||
subAndSuper.put(tph, val);
|
||||
} else {
|
||||
for(String k : subAndSuper.keySet()) {
|
||||
subAndSuper.replace(k, toSubs, tph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TPHConstraint getConstraint(String oldRight, String right, ArrayList<TPHConstraint> allCons) {
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getLeft().equals(oldRight) && c.getRight().equals(right))
|
||||
|
@ -120,12 +120,14 @@ public class JavaTXCompiler {
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
//FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log"));
|
||||
//logFile.write("FC:\\" + finiteClosure.toString()+"\n");
|
||||
//for(SourceFile sf : this.sourceFiles.values()) {
|
||||
// logFile.write(ASTTypePrinter.print(sf));
|
||||
//}
|
||||
//logFile.flush();
|
||||
File logPath = new File(System.getProperty("user.dir")+"/target/logFiles/");
|
||||
logPath.mkdirs();
|
||||
FileWriter logFile = new FileWriter(new File(logPath, "log"));
|
||||
logFile.write("FC:\\" + finiteClosure.toString()+"\n");
|
||||
for(SourceFile sf : this.sourceFiles.values()) {
|
||||
logFile.write(ASTTypePrinter.print(sf));
|
||||
}
|
||||
logFile.flush();
|
||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
@ -150,10 +152,10 @@ public class JavaTXCompiler {
|
||||
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();
|
||||
.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 TypePlaceholder)
|
||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}).get();
|
||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||
|
||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
||||
|
||||
@ -188,6 +190,7 @@ public class JavaTXCompiler {
|
||||
})
|
||||
/* PL 2018-11-07 wird in varianceInheritance erledigt
|
||||
.map( y -> {
|
||||
|
||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
||||
@ -200,11 +203,17 @@ public class JavaTXCompiler {
|
||||
*/
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
varianceInheritance(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure);
|
||||
|
||||
|
||||
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result);
|
||||
logFile.write("RES: " + result.toString()+"\n");
|
||||
logFile.flush();
|
||||
results.addAll(result);
|
||||
}
|
||||
|
||||
results = results.stream().map(x -> {
|
||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||
@ -216,6 +225,14 @@ public class JavaTXCompiler {
|
||||
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());
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(integer, binary.getType(), PairOperator.SMALLERDOT));
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
//PL eingefuegt 2018-07-17
|
||||
@ -262,7 +262,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.getType(), longg, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(longg, binary.getType(), PairOperator.SMALLERDOT));
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
//PL eingefuegt 2018-07-17
|
||||
@ -270,7 +270,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.getType(), floatt, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(floatt, binary.getType(), PairOperator.SMALLERDOT));
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
//PL eingefuegt 2018-07-17
|
||||
@ -278,7 +278,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(binary.getType(), doublee, PairOperator.SMALLERDOT));
|
||||
numeric.add(new Pair(doublee, binary.getType(), PairOperator.SMALLERDOT));
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
/* PL auskommentiert Anfang 2018-07-17
|
||||
@ -298,7 +298,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
Constraint<Pair> stringConcat = new Constraint<>();
|
||||
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||
stringConcat.add(new Pair(binary.getType(), string, PairOperator.EQUALSDOT));
|
||||
stringConcat.add(new Pair(string, binary.getType(), PairOperator.EQUALSDOT));
|
||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,16 @@ import java.io.IOException;
|
||||
*/
|
||||
public class RuleSet implements IRuleSet{
|
||||
|
||||
FileWriter logFile;
|
||||
|
||||
public RuleSet() {
|
||||
super();
|
||||
}
|
||||
|
||||
RuleSet(FileWriter logFile) {
|
||||
this.logFile = logFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UnifyPair> reduceUp(UnifyPair pair) {
|
||||
// Check if reduce up is applicable
|
||||
@ -793,6 +799,14 @@ public class RuleSet implements IRuleSet{
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNred: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("logFile-Error");
|
||||
}
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@ -835,6 +849,14 @@ public class RuleSet implements IRuleSet{
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNgreater: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@ -877,6 +899,14 @@ public class RuleSet implements IRuleSet{
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNsmaller: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
|
@ -8,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class TypeUnify {
|
||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true);
|
||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
pool.invoke(unifyTask);
|
||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||
return res;
|
||||
}
|
||||
|
||||
public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false);
|
||||
public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log);
|
||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||
return res;
|
||||
}
|
||||
|
@ -51,7 +51,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static int i = 0;
|
||||
private boolean printtag = false;
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||
FileWriter logFile;
|
||||
|
||||
/**
|
||||
* The implementation of setOps that will be used during the unification
|
||||
@ -88,12 +91,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
rules = new RuleSet();
|
||||
}
|
||||
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) {
|
||||
this.eq = eq;
|
||||
this.fc = fc;
|
||||
this.oup = new OrderingUnifyPair(fc);
|
||||
this.parallel = parallel;
|
||||
rules = new RuleSet();
|
||||
this.logFile = logFile;
|
||||
this.log = log;
|
||||
rules = new RuleSet(logFile);
|
||||
}
|
||||
|
||||
|
||||
@ -153,6 +158,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||
*/
|
||||
nOfUnify++;
|
||||
writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
||||
//eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
/*
|
||||
@ -228,6 +234,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// those pairs are contradictory and the unification is impossible.
|
||||
if(!undefinedPairs.isEmpty()) {
|
||||
noUndefPair++;
|
||||
for (UnifyPair up : undefinedPairs) {
|
||||
writeLog(noUndefPair.toString() + " UndefinedPairs; " + up);
|
||||
writeLog("BasePair; " + up.getBasePair());
|
||||
}
|
||||
Set<Set<UnifyPair>> error = new HashSet<>();
|
||||
undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
error.add(undefinedPairs);
|
||||
@ -316,13 +326,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent()) {
|
||||
//System.out.println("nextStep: " + eqPrimePrime.get());
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true);
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile, log);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
else {
|
||||
//System.out.println("nextStep: " + eqPrime);
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true);
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile, log);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
@ -333,6 +343,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
||||
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
||||
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
||||
try {
|
||||
if (isSolvedForm(eqPrime)) {
|
||||
logFile.write(eqPrime.toString()+"\n");
|
||||
logFile.flush();
|
||||
}
|
||||
}
|
||||
catch (IOException e) { }
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
}
|
||||
else if(eqPrimePrime.isPresent()) {
|
||||
@ -363,7 +380,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
* Step 7: Filter empty sets;
|
||||
*/
|
||||
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet))
|
||||
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
||||
return eqPrimePrimeSet;
|
||||
}
|
||||
|
||||
@ -383,7 +401,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
return result;
|
||||
}
|
||||
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||
try {
|
||||
//List<Set<UnifyPair>>
|
||||
@ -433,9 +451,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
System.out.print("");
|
||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||
System.out.print("");
|
||||
|
||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
Set<UnifyPair> a = null;
|
||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||
Set<UnifyPair> a_last = a;
|
||||
if (variance == 1) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
nextSetasList.remove(a);
|
||||
@ -485,8 +504,56 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
|
||||
if (!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) {
|
||||
|
||||
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a
|
||||
List<PlaceholderType> vars_a = a.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new));
|
||||
Set<UnifyPair> fstElemRes = res.iterator().next();
|
||||
Set<UnifyPair> compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
||||
List<PlaceholderType> varsLast_a = a_last.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new));
|
||||
//erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen
|
||||
Set<UnifyPair> fstElemResult = result.iterator().next();
|
||||
Set<UnifyPair> compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));;
|
||||
|
||||
if (variance == 1) {
|
||||
int resOfCompare = oup.compare(compResult, compRes);
|
||||
if (resOfCompare == -1) {
|
||||
writeLog("Geloescht result: " + result);
|
||||
result = res;
|
||||
} else {
|
||||
if (resOfCompare == 0) {
|
||||
result.addAll(res);
|
||||
} //else {
|
||||
if (resOfCompare == 1) {
|
||||
writeLog("Geloescht res: " + res);
|
||||
//result = result;
|
||||
}}}
|
||||
else { if (variance == -1) {
|
||||
int resOfCompare = oup.compare(compResult, compRes);
|
||||
if (resOfCompare == 1) {
|
||||
writeLog("Geloescht result: " + result);
|
||||
result = res;
|
||||
} else {
|
||||
if (resOfCompare == 0) {
|
||||
result.addAll(res);
|
||||
} else {
|
||||
if (resOfCompare == -1) {
|
||||
writeLog("Geloescht res: " + res);
|
||||
//result = result;
|
||||
}}}}
|
||||
else { if (variance == 0) {
|
||||
result.addAll(res);
|
||||
}}}
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
}
|
||||
else {
|
||||
result.addAll(res);
|
||||
}
|
||||
}
|
||||
//else {
|
||||
//wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren
|
||||
@ -570,11 +637,25 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get();
|
||||
//}
|
||||
return (!x.containsAll(durchschnitt));
|
||||
}).collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
nofstred = nextSetasList.size();
|
||||
//NOCH NICHT korrekt PL 2018-10-12
|
||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||
// .collect(Collectors.toCollection(ArrayList::new));
|
||||
writeLog("res (undef): " + res.toString());
|
||||
writeLog("abhSubst: " + abhSubst.toString());
|
||||
writeLog("a: " + a.toString());
|
||||
writeLog("Durchschnitt: " + durchschnitt.toString());
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
writeLog("Number first erased Elements (undef): " + (len - nofstred));
|
||||
writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size()));
|
||||
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
|
||||
noAllErasedElements = noAllErasedElements + (len - nextSetasList.size());
|
||||
writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
|
||||
noBacktracking++;
|
||||
|
||||
writeLog("Number of Backtracking: " + noBacktracking);
|
||||
System.out.println("");
|
||||
}
|
||||
//if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) {
|
||||
@ -667,6 +748,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// Through application of the rules, every pair should have one of the above forms.
|
||||
// Pairs that do not have one of the aboves form are contradictory.
|
||||
else {
|
||||
writeLog("Second erase:" +checkPair.toString());
|
||||
return false;
|
||||
}
|
||||
//*/
|
||||
@ -1111,7 +1193,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
|
||||
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
|
||||
if(freshTphs.size()-1 < i)
|
||||
if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12
|
||||
freshTphs.add(PlaceholderType.freshPlaceholder());
|
||||
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
|
||||
}
|
||||
@ -1321,4 +1403,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
permuteParams(candidates, idx+1, result, current);
|
||||
}
|
||||
}
|
||||
|
||||
void writeLog(String str) {
|
||||
if (log) {
|
||||
try {
|
||||
logFile.write(str+"\n");
|
||||
logFile.flush();
|
||||
|
||||
}
|
||||
catch (IOException e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
@ -26,7 +27,8 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||
* The finite closure for the type unification
|
||||
* @author Florian Steurer
|
||||
*/
|
||||
public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure {
|
||||
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||
implements IFiniteClosure {
|
||||
|
||||
/**
|
||||
* A map that maps every type to the node in the inheritance graph that contains that type.
|
||||
@ -561,14 +563,53 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
||||
return this.inheritanceGraph.toString();
|
||||
}
|
||||
|
||||
/* entfernt PL 2018-12-11
|
||||
public int compare (UnifyType left, UnifyType right) {
|
||||
return compare(left, right, PairOperator.SMALLERDOT);
|
||||
}
|
||||
*/
|
||||
|
||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||
if ((left instanceof ExtendsType && right instanceof ReferenceType)
|
||||
|| (right instanceof ExtendsType && left instanceof ReferenceType))
|
||||
System.out.println("");
|
||||
/*
|
||||
List<UnifyType> al = new ArrayList<>();
|
||||
PlaceholderType xx =new PlaceholderType("xx");
|
||||
al.add(xx);
|
||||
left = new ExtendsType(new ReferenceType("Vector", new TypeParams(al)));
|
||||
right = new ReferenceType("Vector", new TypeParams(new ArrayList<>(al)));
|
||||
*/
|
||||
/*
|
||||
List<UnifyType> al = new ArrayList<>();
|
||||
PlaceholderType xx =new PlaceholderType("xx");
|
||||
al.add(xx);
|
||||
left = new ExtendsType(xx);
|
||||
right = xx;
|
||||
*/
|
||||
/*
|
||||
List<UnifyType> al = new ArrayList<>();
|
||||
PlaceholderType xx =new PlaceholderType("xx");
|
||||
PlaceholderType yy =new PlaceholderType("yy");
|
||||
al.add(xx);
|
||||
left = yy;
|
||||
right = new ExtendsType(xx);
|
||||
*/
|
||||
//Die Faelle abfangen, bei den Variablen verglichen werden PL 2018-12-11
|
||||
UnifyType ex;
|
||||
if (left instanceof PlaceholderType) {
|
||||
if ((right instanceof WildcardType)
|
||||
&& ((ex = ((WildcardType)right).wildcardedType) instanceof PlaceholderType)
|
||||
&& ((PlaceholderType)left).getName().equals(((PlaceholderType)ex).getName())) {// a <.? ? extends a oder a <.? ? super a
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((right instanceof PlaceholderType) && (left instanceof WildcardType)) {
|
||||
return 0;
|
||||
}
|
||||
UnifyPair up = new UnifyPair(left, right, pairop);
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||
HashSet<UnifyPair> hs = new HashSet<>();
|
||||
|
@ -151,7 +151,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
System.out.print("");
|
||||
//Set<PlaceholderType> varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||
//Set<PlaceholderType> varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||
//filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant)
|
||||
//filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant) andere Substitutioen werden rausgefiltert
|
||||
lefteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//removeIf(x -> !varsright.contains(x.getLhsType()));
|
||||
righteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@ -21,7 +23,7 @@ public final class PlaceholderType extends UnifyType{
|
||||
* Static list containing the names of all existing placeholders.
|
||||
* Used for generating fresh placeholders.
|
||||
*/
|
||||
protected static final HashSet<String> EXISTING_PLACEHOLDERS = new HashSet<String>();
|
||||
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Prefix of auto-generated placeholder names.
|
||||
@ -81,11 +83,12 @@ public final class PlaceholderType extends UnifyType{
|
||||
* A user could later instantiate a type using the same name that is equivalent to this type.
|
||||
* @return A fresh placeholder type.
|
||||
*/
|
||||
public static PlaceholderType freshPlaceholder() {
|
||||
public synchronized static PlaceholderType freshPlaceholder() {
|
||||
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||
// Add random chars while the name is in use.
|
||||
while(EXISTING_PLACEHOLDERS.contains(name));
|
||||
while(EXISTING_PLACEHOLDERS.contains(name)) {
|
||||
name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||
}
|
||||
return new PlaceholderType(name, true);
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,6 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
//import jdk.jfr.StackTrace;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.json.Json;
|
||||
@ -25,9 +22,7 @@ import java.util.*;
|
||||
public class ClingoTest {
|
||||
public static final String tempDirectory = "/tmp/";
|
||||
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws IOException, InterruptedException, ClassNotFoundException {
|
||||
String content = "";
|
||||
content = ASPFactory.generateASP(this.getPairs(), this.getFC());
|
||||
|
@ -27,7 +27,6 @@ import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
||||
@Ignore
|
||||
public class GeneratorTest extends UnifyWithoutWildcards{
|
||||
@Test
|
||||
public void simple() throws ClassNotFoundException {
|
||||
|
@ -23,7 +23,7 @@ public class BinaryTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/BinaryInMeth.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/BinaryInMeth.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -37,13 +37,14 @@ public class BinaryTest {
|
||||
public void test() throws Exception {
|
||||
Method m2 = classToTest.getDeclaredMethod("m2", Integer.class,Integer.class);
|
||||
Integer res = (Integer) m2.invoke(instanceOfClass, 2,3);
|
||||
assertEquals(6, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM3() throws Exception {
|
||||
Method m3 = classToTest.getDeclaredMethod("m3", Integer.class);
|
||||
Integer res = (Integer) m3.invoke(instanceOfClass, 2);
|
||||
assertEquals(Integer.valueOf(4), res);
|
||||
assertEquals(4, res);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class FacTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Fac.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Fac.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -38,7 +38,7 @@ public class FacTest {
|
||||
public void testInteger() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class);
|
||||
Integer result = (Integer) getFac.invoke(instanceOfClass,3);
|
||||
assertEquals(result, Integer.valueOf(6));
|
||||
assertEquals(result, 6);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class FacultyTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/Faculty.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Faculty.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
@ -33,21 +33,25 @@ public class FacultyTest {
|
||||
classToTest = loader.loadClass("Faculty");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
// Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
Field fact = classToTest.getDeclaredField("fact");
|
||||
Method getFact = classToTest.getDeclaredMethod("getFact", Integer.class);
|
||||
// Field fact = classToTest.getDeclaredField("fact");
|
||||
// Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
||||
Class<?> lambda = fact.getType();
|
||||
Method apply = lambda.getMethod("apply", Object.class);
|
||||
//
|
||||
// Class<?> lambda = fact.getType();
|
||||
// System.out.println(fact.getType().getName());
|
||||
// Method apply = lambda.getMethod("apply", Object.class);
|
||||
// System.out.println(lambda.getMethods()[0]);
|
||||
// System.out.println(instanceOfClass.toString());
|
||||
// // Damit man auf die Methode zugreifen kann
|
||||
apply.setAccessible(true);
|
||||
|
||||
// apply.setAccessible(true);
|
||||
// Field value
|
||||
// Object fieldVal = fact.get(instanceOfClass);
|
||||
Integer i = 3;
|
||||
// Method applyFromField = fieldVal.getClass().getDeclaredMethod("apply", Object.class);
|
||||
// applyFromField.setAccessible(true);
|
||||
// Integer result = (Integer) apply.invoke(lambda,i);
|
||||
Integer result = (Integer) getFact.invoke(instanceOfClass,i);
|
||||
|
||||
Integer result = (Integer) apply.invoke(instanceOfClass, i);
|
||||
// Integer result = (Integer) m.invoke(instanceOfClass,i);
|
||||
|
||||
assertEquals(Integer.valueOf(6), result);
|
||||
assertEquals(6, result);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class FieldTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Field.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Field.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
|
43
src/test/java/bytecode/FieldTph.java
Normal file
43
src/test/java/bytecode/FieldTph.java
Normal file
@ -0,0 +1,43 @@
|
||||
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 FieldTph {
|
||||
|
||||
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;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/FieldTph.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("FieldTph");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Field[] fields = classToTest.getFields();
|
||||
assertEquals(1, fields.length);
|
||||
}
|
||||
|
||||
}
|
52
src/test/java/bytecode/FieldTph2Test.java
Normal file
52
src/test/java/bytecode/FieldTph2Test.java
Normal file
@ -0,0 +1,52 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
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 FieldTph2Test {
|
||||
|
||||
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;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/FieldTph2.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("FieldTph2");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
Field a = classToTest.getDeclaredField("a");
|
||||
a.setAccessible(true);
|
||||
|
||||
Method m2 = classToTest.getDeclaredMethod("m2", Object.class);
|
||||
m2.invoke(instanceOfClass, 1);
|
||||
|
||||
Method m = classToTest.getDeclaredMethod("m", Object.class);
|
||||
Object result = m.invoke(instanceOfClass, 1);
|
||||
|
||||
assertEquals(1,result);
|
||||
}
|
||||
|
||||
}
|
49
src/test/java/bytecode/FieldTphConsMethTest.java
Normal file
49
src/test/java/bytecode/FieldTphConsMethTest.java
Normal file
@ -0,0 +1,49 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
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 FieldTphConsMethTest {
|
||||
|
||||
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;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/FieldTphConsMeth.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("FieldTphConsMeth");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
Field a = classToTest.getDeclaredField("a");
|
||||
a.setAccessible(true);
|
||||
|
||||
Method m = classToTest.getDeclaredMethod("m", Object.class);
|
||||
Object result = m.invoke(instanceOfClass, 42);
|
||||
|
||||
assertEquals(42,result);
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,7 @@ public class FunOLTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/FunOL.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/FunOL.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
|
@ -20,7 +20,7 @@ public class GenTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Gen.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Gen.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -25,7 +25,7 @@ public class GreaterEqualTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/GreaterEqual.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/GreaterEqual.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -25,7 +25,7 @@ public class GreaterThanTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/GreaterThan.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/GreaterThan.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
43
src/test/java/bytecode/LambdaCapturetest.java
Normal file
43
src/test/java/bytecode/LambdaCapturetest.java
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
*
|
||||
*/
|
||||
public class LambdaCapturetest {
|
||||
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 generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/LambdaCapture.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("LambdaCapture");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,7 @@ public class LambdaTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Lambda.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Lambda.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
@ -40,10 +40,10 @@ public class LambdaTest {
|
||||
apply.setAccessible(true);
|
||||
|
||||
Integer i = 77;
|
||||
|
||||
System.out.println(m.invoke(instanceOfClass).toString());
|
||||
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
||||
|
||||
assertEquals(Integer.valueOf(77), result);
|
||||
assertEquals(77, result);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class LambdaVoidTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/Lambda.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Lambda.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
|
@ -25,7 +25,7 @@ public class LessEqualTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/LessEqual.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/LessEqual.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -25,7 +25,7 @@ public class LessThanTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/LessThan.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/LessThan.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -28,13 +28,13 @@ public class MatrixOpTest {
|
||||
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/MatrixOP.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/MatrixOP.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("MatrixOP");
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("MatrixOP");
|
||||
/*
|
||||
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v1 = new Vector<Integer> ();
|
||||
|
@ -28,7 +28,7 @@ public class MatrixTest {
|
||||
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/Matrix.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Matrix.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,11 +24,11 @@ public class MergeTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Merge.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Merge.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/";
|
||||
// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
// classToTest = loader.loadClass("Merge");
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
@ -26,7 +26,7 @@ public class OLTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/OL.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/OL.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -47,14 +47,14 @@ public class OLTest {
|
||||
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||
assertEquals(Integer.valueOf(10), result);
|
||||
assertEquals(10, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||
assertEquals(Double.valueOf(10.0), result);
|
||||
assertEquals(10.0, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -73,14 +73,14 @@ public class OLTest {
|
||||
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
||||
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||
assertEquals(Integer.valueOf(10), result);
|
||||
assertEquals(10, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
||||
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||
assertEquals(Double.valueOf(10.0), result);
|
||||
assertEquals(10.0, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -25,7 +25,7 @@ public class OpTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Op.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Op.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -54,7 +54,7 @@ public class OpTest {
|
||||
|
||||
Integer result = (Integer) m.invoke(instanceOfClass, 7,3);
|
||||
|
||||
assertEquals(Integer.valueOf(10), result);
|
||||
assertEquals(10, result);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class OverloadingSortingTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/Sorting.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Sorting.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -27,7 +27,7 @@ public class OverloadingTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Overloading.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Overloading.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,7 +24,7 @@ public class PlusTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Plus.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Plus.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,7 +24,7 @@ public class PostIncTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/PostIncDec.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/PostIncDec.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -38,28 +38,28 @@ public class PostIncTest {
|
||||
public void testM1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(1), res);
|
||||
assertEquals(1, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(0), res);
|
||||
assertEquals(0, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("d");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(-1), res);
|
||||
assertEquals(-1, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("d2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(0), res);
|
||||
assertEquals(0, res);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class PreIncTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/PreInc.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/PreInc.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -38,28 +38,28 @@ public class PreIncTest {
|
||||
public void testM() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(1), res);
|
||||
assertEquals(1, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(1), res);
|
||||
assertEquals(1, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("d");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(-1), res);
|
||||
assertEquals(-1, res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("d2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(-1), res);
|
||||
assertEquals(-1, res);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class RelOpsTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/RelOps.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/RelOps.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -23,7 +23,7 @@ public class SortingTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/Sorting.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Sorting.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
|
@ -17,7 +17,7 @@ public class SubMatTest {
|
||||
|
||||
@Test
|
||||
public void test() throws ClassNotFoundException, IOException {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/SubMatrix.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/SubMatrix.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,7 +24,7 @@ public class Tph2Test {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Tph2.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Tph2.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -21,7 +21,7 @@ public class Tph3Test {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Tph3.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Tph3.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,7 +24,7 @@ public class Tph5Test {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Tph5.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Tph5.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,7 +24,7 @@ public class TphTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Tph.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Tph.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
@ -24,7 +24,7 @@ public class WhileTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/While.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/While.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
@ -38,21 +38,21 @@ public class WhileTest {
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
Integer result = (Integer) m.invoke(instanceOfClass, 0);
|
||||
assertEquals(Integer.valueOf(2), result);
|
||||
assertEquals(2, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||
Double result = (Double) m.invoke(instanceOfClass, 0.0);
|
||||
assertEquals(Double.valueOf(2.0), result);
|
||||
assertEquals(2.0, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m", Long.class);
|
||||
Long result = (Long) m.invoke(instanceOfClass, 0l);
|
||||
assertEquals(Long.valueOf(2l), result);
|
||||
assertEquals(2l, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
@ -23,15 +22,14 @@ public class YTest {
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Y.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Y.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("Y");
|
||||
// compiler = new JavaTXCompiler(fileToTest);
|
||||
// compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
||||
// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
// classToTest = loader.loadClass("Y");
|
||||
/*
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class applyLambdaTest {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/applyLambda.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/applyLambda.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
|
77
src/test/java/bytecode/simplifyalgo/CycleTest.java
Normal file
77
src/test/java/bytecode/simplifyalgo/CycleTest.java
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
102
src/test/java/bytecode/simplifyalgo/SameLeftSide.java
Normal file
102
src/test/java/bytecode/simplifyalgo/SameLeftSide.java
Normal file
@ -0,0 +1,102 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
80
src/test/java/bytecode/simplifyalgo/SimpleCycle.java
Normal file
80
src/test/java/bytecode/simplifyalgo/SimpleCycle.java
Normal file
@ -0,0 +1,80 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
9
src/test/java/javFiles/AddLong.jav
Normal file
9
src/test/java/javFiles/AddLong.jav
Normal file
@ -0,0 +1,9 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Long;
|
||||
|
||||
public class AddLong{
|
||||
Long add(Integer a, Long b) {
|
||||
Long c = a+b;
|
||||
return c;
|
||||
}
|
||||
}
|
3
src/test/java/javFiles/EmptyClass.jav
Normal file
3
src/test/java/javFiles/EmptyClass.jav
Normal file
@ -0,0 +1,3 @@
|
||||
public class EmptyClass{
|
||||
|
||||
}
|
37
src/test/java/javFiles/EmptyMethod.jav
Normal file
37
src/test/java/javFiles/EmptyMethod.jav
Normal file
@ -0,0 +1,37 @@
|
||||
public class EmptyMethod{
|
||||
static String s1 ="";
|
||||
String s2;
|
||||
public void m1(){
|
||||
//String s = "";
|
||||
System.out.println("test");
|
||||
//Integer ab = Math.abs(1);
|
||||
//Math.abs(1);
|
||||
//String lV = "local";
|
||||
//s1 = "1";
|
||||
//s1.concat("2");
|
||||
s2 = s1;
|
||||
//m2();
|
||||
Clazz i = new Clazz();
|
||||
Integer i = new Integer(1);
|
||||
}
|
||||
|
||||
public void m2(){}
|
||||
}
|
||||
|
||||
class Clazz{}
|
||||
/*
|
||||
public class EmptyMethod2{
|
||||
public static test = "5";
|
||||
public void m1(Integer i, String j, Boolean b){
|
||||
//String s = "";
|
||||
EmptyMethod em = new EmptyMethod();
|
||||
em.m1();
|
||||
em.s1 = "";
|
||||
//Integer ab = Math.abs(1);
|
||||
//Math.abs(1);
|
||||
//String lV = "local";
|
||||
//s1 = "1";
|
||||
//s1.concat("2");
|
||||
//s2 = s1;
|
||||
}
|
||||
}*/
|
8
src/test/java/javFiles/Expressions.jav
Normal file
8
src/test/java/javFiles/Expressions.jav
Normal file
@ -0,0 +1,8 @@
|
||||
class Expressions{
|
||||
|
||||
void test(){
|
||||
var x = 2;
|
||||
x = x + 2;
|
||||
}
|
||||
|
||||
}
|
10
src/test/java/javFiles/FC_Matrix.jav
Normal file
10
src/test/java/javFiles/FC_Matrix.jav
Normal file
@ -0,0 +1,10 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class Matrix extends Vector<Vector<Integer>> {
|
||||
|
||||
methode(m) {
|
||||
m.add(1);
|
||||
Matrix i;
|
||||
methode(i);
|
||||
}
|
||||
}
|
15
src/test/java/javFiles/Faculty.jav
Normal file
15
src/test/java/javFiles/Faculty.jav
Normal file
@ -0,0 +1,15 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
class Faculty {
|
||||
|
||||
Integer mul(Integer x, Integer y) {
|
||||
return x;
|
||||
}
|
||||
|
||||
m () {
|
||||
var fact = (Integer x) -> {
|
||||
return mul(x, fact.apply(x));
|
||||
};
|
||||
return fact;
|
||||
}
|
||||
}
|
17
src/test/java/javFiles/FacultyIf.jav
Normal file
17
src/test/java/javFiles/FacultyIf.jav
Normal file
@ -0,0 +1,17 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
class Faculty {
|
||||
|
||||
m () {
|
||||
|
||||
var fact = (Integer x) -> {
|
||||
if (x == 1) {
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
return x * (fact.apply(x-1));
|
||||
}
|
||||
};
|
||||
return fact;
|
||||
}
|
||||
}
|
19
src/test/java/javFiles/FacultyTyped.jav
Normal file
19
src/test/java/javFiles/FacultyTyped.jav
Normal file
@ -0,0 +1,19 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
class Faculty {
|
||||
|
||||
Integer mul(Integer x, Integer y) {
|
||||
return x;
|
||||
}
|
||||
|
||||
Fun1<java.lang.Integer,java.lang.Integer> m () {
|
||||
var fact = (Integer x) -> {
|
||||
return mul(x, fact.apply(x));
|
||||
};
|
||||
return fact;
|
||||
}
|
||||
}
|
||||
|
||||
interface Fun1<A,B>{
|
||||
B apply(A a);
|
||||
}
|
11
src/test/java/javFiles/Fields.jav
Normal file
11
src/test/java/javFiles/Fields.jav
Normal file
@ -0,0 +1,11 @@
|
||||
import java.lang.String;
|
||||
|
||||
class Fields{
|
||||
test2 = "test";
|
||||
test;
|
||||
m(){
|
||||
var test3;
|
||||
return test;
|
||||
}
|
||||
|
||||
}
|
22
src/test/java/javFiles/Generics.jav
Normal file
22
src/test/java/javFiles/Generics.jav
Normal file
@ -0,0 +1,22 @@
|
||||
import java.lang.String;
|
||||
|
||||
class Generics<B> {
|
||||
//<A extends B> A mt1(A a, B b){
|
||||
B mt1(B a, B b){
|
||||
return mt1(a, a);
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
methode(String s){
|
||||
return new Generics<String>().mt1(s,s);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Problem:
|
||||
auto test = new List<String>();
|
||||
auto test2 = new List<Integer>();
|
||||
... //code, welcher möglicherweise test und test2 vertauscht
|
||||
test.add("hallo");
|
||||
*/
|
14
src/test/java/javFiles/IfTest.jav
Normal file
14
src/test/java/javFiles/IfTest.jav
Normal file
@ -0,0 +1,14 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Boolean;
|
||||
import java.lang.Object;
|
||||
|
||||
public class IfTest{
|
||||
Object m1(b) {
|
||||
Integer i;
|
||||
if(b) {
|
||||
return i;
|
||||
}else{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
8
src/test/java/javFiles/Import.jav
Normal file
8
src/test/java/javFiles/Import.jav
Normal file
@ -0,0 +1,8 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class Import {
|
||||
void methode(){
|
||||
Vector v;
|
||||
v.add(v);
|
||||
}
|
||||
}
|
13
src/test/java/javFiles/Lambda.jav
Normal file
13
src/test/java/javFiles/Lambda.jav
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
class Apply { }
|
||||
|
||||
public class Lambda {
|
||||
|
||||
m () {
|
||||
var lam1 = (x) -> {
|
||||
return x;
|
||||
};
|
||||
return lam1.apply(new Apply());
|
||||
}
|
||||
}
|
||||
|
33
src/test/java/javFiles/Lambda2.jav
Normal file
33
src/test/java/javFiles/Lambda2.jav
Normal file
@ -0,0 +1,33 @@
|
||||
import java.lang.String;
|
||||
|
||||
public class Lambda2
|
||||
{
|
||||
public static void main(List<String> args){
|
||||
var listOfStrings = new List<String>();
|
||||
var listOfObjects;
|
||||
listOfObjects = map(listOfStrings, (a) -> a);
|
||||
}
|
||||
|
||||
public map(a , b){
|
||||
b.apply(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
/*
|
||||
public static <I,O> List<O> map(List<I> input, Function<I,O> func) {
|
||||
List<O> output;
|
||||
output = new List<O>();
|
||||
output.add(func.apply(input.get()));
|
||||
return output;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
class List<A>{
|
||||
A get();
|
||||
void add(A);
|
||||
}
|
||||
|
||||
class Function<A,B>{
|
||||
B apply(A a);
|
||||
}
|
24
src/test/java/javFiles/Lambda3.jav
Normal file
24
src/test/java/javFiles/Lambda3.jav
Normal file
@ -0,0 +1,24 @@
|
||||
import java.lang.String;
|
||||
|
||||
public class Lambda2
|
||||
{
|
||||
/*
|
||||
public static <A> List<A> map(List<? extends A> input,
|
||||
Function<? super A, ? extends A> func){
|
||||
input.add(func.apply(input.get()));
|
||||
}
|
||||
*/
|
||||
public map(input,func){
|
||||
input.add(func.apply(input.get()));
|
||||
return map(new List<String>(), func);
|
||||
}
|
||||
}
|
||||
|
||||
class List<A>{
|
||||
A get();
|
||||
void add(A);
|
||||
}
|
||||
|
||||
class Function<A,B>{
|
||||
B apply(A a);
|
||||
}
|
6
src/test/java/javFiles/LambdaField.jav
Normal file
6
src/test/java/javFiles/LambdaField.jav
Normal file
@ -0,0 +1,6 @@
|
||||
public class LambdaField {
|
||||
|
||||
f = x -> x;
|
||||
|
||||
}
|
||||
|
14
src/test/java/javFiles/LambdaRunnable.jav
Normal file
14
src/test/java/javFiles/LambdaRunnable.jav
Normal file
@ -0,0 +1,14 @@
|
||||
import java.lang.Runnable;
|
||||
import java.lang.String;
|
||||
import java.lang.System;
|
||||
|
||||
public class LamRunnable{
|
||||
|
||||
public LamRunnable(){
|
||||
|
||||
|
||||
Runnable lam = () -> {System.out.println("lambda");};
|
||||
lam.run();
|
||||
}
|
||||
}
|
||||
|
20
src/test/java/javFiles/ListenerOverload.jav
Normal file
20
src/test/java/javFiles/ListenerOverload.jav
Normal file
@ -0,0 +1,20 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
class ListenerOverload{
|
||||
|
||||
call(p){
|
||||
call(p.left);
|
||||
call(p.right);
|
||||
}
|
||||
|
||||
call(Integer i){}
|
||||
|
||||
call(String s){}
|
||||
|
||||
}
|
||||
|
||||
class Pair<A,B>{
|
||||
A left;
|
||||
B right;
|
||||
}
|
28
src/test/java/javFiles/Matrix.jav
Normal file
28
src/test/java/javFiles/Matrix.jav
Normal file
@ -0,0 +1,28 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
|
||||
class Matrix extends Vector<Vector<Integer>> {
|
||||
Integer mul1(Integer x, Integer y) { return x;}
|
||||
Integer add1(Integer x, Integer y) { return x;}
|
||||
mul(m) {
|
||||
var ret = new Matrix();
|
||||
var i = 0;
|
||||
while(i < size()) {
|
||||
var v1 = this.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) * m.elementAt(k).elementAt(j);
|
||||
//erg = add1(erg, mul1(v1.elementAt(k),
|
||||
// m.elementAt(k).elementAt(j)));
|
||||
k++; }
|
||||
v2.addElement(new Integer(erg));
|
||||
j++; }
|
||||
ret.addElement(v2);
|
||||
i++; }
|
||||
return ret;
|
||||
}
|
||||
}
|
11
src/test/java/javFiles/Meth_Gen.jav
Normal file
11
src/test/java/javFiles/Meth_Gen.jav
Normal file
@ -0,0 +1,11 @@
|
||||
class Meth_Gen {
|
||||
|
||||
m1(x, y) {
|
||||
m2(x);
|
||||
x = y;
|
||||
}
|
||||
|
||||
m2(y) {
|
||||
m1(y, y);
|
||||
}
|
||||
}
|
14
src/test/java/javFiles/MethodCallGenerics.jav
Normal file
14
src/test/java/javFiles/MethodCallGenerics.jav
Normal file
@ -0,0 +1,14 @@
|
||||
import java.lang.String;
|
||||
|
||||
class Generics<B> {
|
||||
//<A extends B> A mt1(A a, B b){
|
||||
B mt1(B a, B b){
|
||||
return mt1(a, a);
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
methode(String s){
|
||||
return new Generics<String>().mt1(s,s);
|
||||
}
|
||||
}
|
17
src/test/java/javFiles/Methods.jav
Normal file
17
src/test/java/javFiles/Methods.jav
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
class Methods {
|
||||
mt4(a,b,c) { return a.add(b).sub(c) ; }
|
||||
|
||||
mt1(a) {return a;}
|
||||
|
||||
mt2(a) {return a.f; }
|
||||
|
||||
mt3(a) {return a.add(); }
|
||||
}
|
||||
|
||||
class Test {
|
||||
java.lang.Object f;
|
||||
add(){}
|
||||
add(b){return b;}
|
||||
sub(b){}
|
||||
}
|
7
src/test/java/javFiles/MethodsEasy.jav
Normal file
7
src/test/java/javFiles/MethodsEasy.jav
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
class Methods {
|
||||
mt4(a,b,c) { return a.mt3(b).mt3(c) ; }
|
||||
|
||||
mt3(a) {return a.mt3(a); }
|
||||
}
|
||||
|
11
src/test/java/javFiles/Op1.jav
Normal file
11
src/test/java/javFiles/Op1.jav
Normal file
@ -0,0 +1,11 @@
|
||||
public class Op1{
|
||||
public Op1() {
|
||||
|
||||
Runnable lam = () -> {
|
||||
String test = "";
|
||||
String b = "b";
|
||||
test = b;
|
||||
System.out.println(test);};
|
||||
//lam.run();
|
||||
}
|
||||
}
|
5
src/test/java/javFiles/Package.jav
Normal file
5
src/test/java/javFiles/Package.jav
Normal file
@ -0,0 +1,5 @@
|
||||
package strucType.input;
|
||||
|
||||
class Neu
|
||||
{
|
||||
}
|
8
src/test/java/javFiles/Sorting.jav
Normal file
8
src/test/java/javFiles/Sorting.jav
Normal file
@ -0,0 +1,8 @@
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
class Sorting{
|
||||
void merge(a, b){
|
||||
a.addAll(b);
|
||||
}
|
||||
}
|
6
src/test/java/javFiles/Subclass.jav
Normal file
6
src/test/java/javFiles/Subclass.jav
Normal file
@ -0,0 +1,6 @@
|
||||
public class Subclass extends Superclass {
|
||||
|
||||
public void printMethod() {
|
||||
super.printMethod();
|
||||
}
|
||||
}
|
6
src/test/java/javFiles/Superclass.jav
Normal file
6
src/test/java/javFiles/Superclass.jav
Normal file
@ -0,0 +1,6 @@
|
||||
public class Superclass {
|
||||
|
||||
public void printMethod() {
|
||||
System.out.println("Printed in Superclass.");
|
||||
}
|
||||
}
|
23
src/test/java/javFiles/Vector.jav
Normal file
23
src/test/java/javFiles/Vector.jav
Normal file
@ -0,0 +1,23 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
import java.lang.Object;
|
||||
|
||||
class MyVector{
|
||||
|
||||
id(x){
|
||||
Object i;
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
x.add(i);
|
||||
return x;
|
||||
}
|
||||
}
|
18
src/test/java/javFiles/fc.jav
Normal file
18
src/test/java/javFiles/fc.jav
Normal file
@ -0,0 +1,18 @@
|
||||
import java.util.List;
|
||||
|
||||
class Test{
|
||||
methode(param1, param2, param3) {
|
||||
param2.add(param3);
|
||||
return param1.meth(param2);
|
||||
}
|
||||
}
|
||||
|
||||
interface Klasse1{
|
||||
Klasse1 meth(List p);
|
||||
Klasse1 meth(Klasse2 p);
|
||||
}
|
||||
|
||||
interface Klasse2{
|
||||
Klasse1 meth(Klasse1 p);
|
||||
Klasse2 meth(Klasse2 p);
|
||||
}
|
13
src/test/java/javFiles/mathStruc.jav
Normal file
13
src/test/java/javFiles/mathStruc.jav
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
class mathStruc<A> {
|
||||
|
||||
mathStruc(A a) { }
|
||||
|
||||
A model(){ A a; return a; }
|
||||
|
||||
methode(){
|
||||
var innerOp = o -> ms ->
|
||||
new mathStruc<A>(o.apply(this.model(),ms.model()));
|
||||
return innerOp;
|
||||
}
|
||||
}
|
15
src/test/java/javFiles/test.jav
Normal file
15
src/test/java/javFiles/test.jav
Normal file
@ -0,0 +1,15 @@
|
||||
class Test{
|
||||
methode(param1, param2, param3) {
|
||||
return param1.meth(param2.meth(param3));
|
||||
}
|
||||
}
|
||||
|
||||
interface Klasse1{
|
||||
Klasse1 meth(Klasse1 p);
|
||||
Klasse1 meth(Klasse2 p);
|
||||
}
|
||||
|
||||
interface Klasse2{
|
||||
Klasse1 meth(Klasse1 p);
|
||||
Klasse2 meth(Klasse2 p);
|
||||
}
|
7
src/test/java/javFiles/test1.jav
Normal file
7
src/test/java/javFiles/test1.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class Faculty {
|
||||
|
||||
int a;
|
||||
m (int x) {
|
||||
return a+x;
|
||||
}
|
||||
}
|
24
src/test/java/log4jTesting.xml
Executable file
24
src/test/java/log4jTesting.xml
Executable file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="CONSOLE" class="de.dhbwstuttgart.logger.ConsoleAppender">
|
||||
<param name="Target" value="System.out"/>
|
||||
|
||||
<layout class="de.dhbwstuttgart.logger.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-15C{1} %-5p [%-9c] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="trtest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="funcTest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
</log4j:configuration>
|
6
src/test/java/parser/AntlrTest.jav
Normal file
6
src/test/java/parser/AntlrTest.jav
Normal file
@ -0,0 +1,6 @@
|
||||
class Test{
|
||||
method(){
|
||||
if(true)i++;
|
||||
if(true)i--;
|
||||
else i++;
|
||||
}}
|
3
src/test/java/parser/BoundedParameter.jav
Normal file
3
src/test/java/parser/BoundedParameter.jav
Normal file
@ -0,0 +1,3 @@
|
||||
class Matrix{
|
||||
<A extends B, C extends B> String op = "String";
|
||||
}
|
8
src/test/java/parser/CastTest.jav
Normal file
8
src/test/java/parser/CastTest.jav
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
class CastTest{
|
||||
void methode(){
|
||||
Object a;
|
||||
String b;
|
||||
a = (Object) b;
|
||||
}
|
||||
}
|
4
src/test/java/parser/ExtendsTest.jav
Normal file
4
src/test/java/parser/ExtendsTest.jav
Normal file
@ -0,0 +1,4 @@
|
||||
class C1 extends Object
|
||||
{
|
||||
m(para) { return para; }
|
||||
}
|
11
src/test/java/parser/FeatherWeightJava.jav
Normal file
11
src/test/java/parser/FeatherWeightJava.jav
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
class FeatherWeightJava {
|
||||
mt4(a,b,c) { return a.add(b).sub(c) ; }
|
||||
|
||||
mt1(a) {return a; }
|
||||
|
||||
mt2(a) {return a.f; }
|
||||
|
||||
mt3(a) {return a.add(); }
|
||||
}
|
||||
|
3
src/test/java/parser/FieldInitializationTest.jav
Normal file
3
src/test/java/parser/FieldInitializationTest.jav
Normal file
@ -0,0 +1,3 @@
|
||||
class FieldInitializationTest{
|
||||
var var = "hallo";
|
||||
}
|
5
src/test/java/parser/FieldVarTest.jav
Normal file
5
src/test/java/parser/FieldVarTest.jav
Normal file
@ -0,0 +1,5 @@
|
||||
package test;
|
||||
|
||||
class Test<Typ>{
|
||||
Typ a;
|
||||
}
|
@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
*
|
||||
*/
|
||||
public class GeneralParserTest{
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/parser/";
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||
|
||||
@Test
|
||||
public void run(){
|
||||
|
3
src/test/java/parser/GenericFieldVarTest.jav
Normal file
3
src/test/java/parser/GenericFieldVarTest.jav
Normal file
@ -0,0 +1,3 @@
|
||||
class Test{
|
||||
<A> A var;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user