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:
Michael Uhl 2018-12-25 16:23:44 +01:00
commit d9cda2779f
175 changed files with 3992 additions and 1735 deletions

23
pom.xml
View File

@ -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>

View File

@ -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:)."

View File

@ -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);
}

View File

@ -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

View File

@ -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())+ ";";
}
}

View File

@ -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();

View File

@ -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, Type.getInternalName(Object.class), 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);
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))

View File

@ -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,21 +152,21 @@ 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);
xConsSet = xConsSet.stream().map(x -> {
xConsSet = xConsSet.stream().map(x -> {
//Hier muss ueberlegt werden, ob
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
// mit disableWildcardtable() werden.
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
//PL 2018-04-23
if ((x.getLhsType() instanceof PlaceholderType)) {
if ((x.getLhsType() instanceof PlaceholderType)) {
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
((PlaceholderType)x.getLhsType()).disableWildcardtable();
@ -173,8 +175,8 @@ public class JavaTXCompiler {
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
((PlaceholderType)x.getLhsType()).disableWildcardtable();
}
}
if ((x.getRhsType() instanceof PlaceholderType)) {
}
if ((x.getRhsType() instanceof PlaceholderType)) {
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
((PlaceholderType)x.getRhsType()).disableWildcardtable();
@ -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());
@ -199,12 +202,18 @@ public class JavaTXCompiler {
return y; } )
*/
.collect(Collectors.toCollection(HashSet::new));
varianceInheritance(xConsSet);
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure);
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result);
results.addAll(result);
varianceInheritance(xConsSet);
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());
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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("");
writeLog("nextSetasList: " + nextSetasList.toString());
Set<UnifyPair> a = null;
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
Set<UnifyPair> a = null;
Set<UnifyPair> a_last = a;
if (variance == 1) {
a = oup.max(nextSetasList.iterator());
nextSetasList.remove(a);
@ -485,9 +504,57 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|| result.isEmpty()) {
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
result.addAll(res);
}
}
else {
result.addAll(res);
}
}
//else {
//wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren
// if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) {
@ -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) { }
}
}
}

View File

@ -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<>();

View File

@ -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())

View File

@ -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);
}

View File

@ -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());

View File

@ -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 {

View File

@ -13,37 +13,38 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class BinaryTest {
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;
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/javFiles/bytecode/BinaryInMeth.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("BinaryInMeth");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("BinaryInMeth");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void test() throws Exception {
Method m2 = classToTest.getDeclaredMethod("m2", Integer.class,Integer.class);
Integer res = (Integer) m2.invoke(instanceOfClass, 2,3);
}
@Test
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);
}
@Test
public void testM3() throws Exception {
Method m3 = classToTest.getDeclaredMethod("m3", Integer.class);
Integer res = (Integer) m3.invoke(instanceOfClass, 2);
assertEquals(4, res);
}
}

View File

@ -14,31 +14,31 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class FacTest {
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;
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/javFiles/bytecode/Fac.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("Fac");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Fac");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
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));
}
@Test
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, 6);
}
}

View File

@ -14,41 +14,45 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class FacultyTest {
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;
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/javFiles/Faculty.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("Faculty");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@Test
public void generateBC() throws Exception {
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/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
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 i = 3;
Integer result = (Integer) apply.invoke(instanceOfClass, i);
// Integer result = (Integer) m.invoke(instanceOfClass,i);
assertEquals(Integer.valueOf(6), result);
}
assertEquals(6, result);
}
}

View File

@ -14,30 +14,30 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class FieldTest {
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;
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/javFiles/bytecode/Field.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("Field");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Field");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void test() {
Field[] fields = classToTest.getFields();
assertEquals(1, fields.length);
}
@Test
public void test() {
Field[] fields = classToTest.getFields();
assertEquals(1, fields.length);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View File

@ -13,40 +13,40 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class FunOLTest {
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;
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/javFiles/bytecode/FunOL.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("FunOL");
/*
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@Test
public void generateBC() throws Exception {
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/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("FunOL");
/*
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
Integer i = 77;
Integer i = 77;
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
assertEquals(77, result);
*/
}
assertEquals(77, result);
*/
}
}

View File

@ -13,18 +13,18 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class GenTest {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
@Test
public void generateBC() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Gen.jav";
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
compiler.generateBytecode(pathToClassFile);
}
@Test
public void generateBC() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
}
}

View File

@ -15,126 +15,126 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class GreaterEqualTest {
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;
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/javFiles/bytecode/GreaterEqual.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("GreaterEqual");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
classToTest = loader.loadClass("GreaterEqual");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testName() {
assertEquals("GreaterEqual", classToTest.getName());
}
@Test
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 7, 5);
assertTrue(result);
}
@Test
public void testName() {
assertEquals("GreaterEqual", classToTest.getName());
}
@Test
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 7, 5);
assertTrue(result);
}
@Test
public void testIntegers2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5, 7);
assertFalse(result);
}
@Test
public void testIntegers2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5, 7);
assertFalse(result);
}
@Test
public void testEqIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5, 5);
assertTrue(result);
}
@Test
public void testEqIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5, 5);
assertTrue(result);
}
@Test
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Long.class, Long.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 10L,7L);
assertTrue(result);
}
@Test
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Long.class, Long.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 10L,7L);
assertTrue(result);
}
@Test
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5F,7F);
assertFalse(result);
}
@Test
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5F,7F);
assertFalse(result);
}
@Test
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Double.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5.0,7.0);
assertFalse(result);
}
@Test
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Double.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5.0,7.0);
assertFalse(result);
}
@Test
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Long.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 15L,7);
assertTrue(result);
}
@Test
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Long.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 15L,7);
assertTrue(result);
}
@Test
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5F,7);
assertFalse(result);
}
@Test
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5F,7);
assertFalse(result);
}
@Test
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 25.0,17);
assertTrue(result);
}
@Test
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Integer.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 25.0,17);
assertTrue(result);
}
@Test
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Long.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 75F,70L);
assertTrue(result);
}
@Test
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Long.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 75F,70L);
assertTrue(result);
}
@Test
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Long.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5.0,7L);
assertFalse(result);
}
@Test
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Long.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 5.0,7L);
assertFalse(result);
}
@Test
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 7.0,7F);
assertTrue(result);
}
@Test
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 7.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 15.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 15.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 9.0,17F);
assertFalse(result);
}
@Test
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
Boolean result = (Boolean) gE.invoke(instanceOfClass, 9.0,17F);
assertFalse(result);
}
}

View File

@ -15,125 +15,125 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class GreaterThanTest {
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;
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/javFiles/bytecode/GreaterThan.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("GreaterThan");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)});
classToTest = loader.loadClass("GreaterThan");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testName() {
assertEquals("GreaterThan", classToTest.getName());
}
@Test
public void testName() {
assertEquals("GreaterThan", classToTest.getName());
}
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 7, 5);
assertTrue(result);
}
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 7, 5);
assertTrue(result);
}
@Test
public void testIntegers2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5, 7);
assertFalse(result);
}
@Test
public void testIntegers2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5, 7);
assertFalse(result);
}
@Test
public void testEqIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5, 5);
assertFalse(result);
}
@Test
public void testEqIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5, 5);
assertFalse(result);
}
@Test
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Long.class, Long.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 10L,7L);
assertTrue(result);
}@Test
@Test
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Long.class, Long.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 10L,7L);
assertTrue(result);
}@Test
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5F,7F);
assertFalse(result);
}
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5F,7F);
assertFalse(result);
}
@Test
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Double.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5.0,7.0);
assertFalse(result);
}
@Test
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Double.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5.0,7.0);
assertFalse(result);
}
@Test
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Long.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 15L,7);
assertTrue(result);
}
@Test
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Long.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 15L,7);
assertTrue(result);
}
@Test
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5F,7);
assertFalse(result);
}
@Test
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5F,7);
assertFalse(result);
}
@Test
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 25.0,17);
assertTrue(result);
}
@Test
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Integer.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 25.0,17);
assertTrue(result);
}
@Test
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Long.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 75F,70L);
assertTrue(result);
}
@Test
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Long.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 75F,70L);
assertTrue(result);
}
@Test
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Long.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5.0,7L);
assertFalse(result);
}
@Test
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Long.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 5.0,7L);
assertFalse(result);
}
@Test
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 7.0,7F);
assertFalse(result);
}
@Test
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 7.0,7F);
assertFalse(result);
}
@Test
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 15.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 15.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 9.0,17F);
assertFalse(result);
}
@Test
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
Boolean result = (Boolean) gT.invoke(instanceOfClass, 9.0,17F);
assertFalse(result);
}
}

View 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();
}
}

View File

@ -13,38 +13,38 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class LambdaTest {
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;
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/javFiles/bytecode/Lambda.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("Lambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@Test
public void generateBC() throws Exception {
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/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Lambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
Integer i = 77;
Integer i = 77;
System.out.println(m.invoke(instanceOfClass).toString());
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
assertEquals(Integer.valueOf(77), result);
}
assertEquals(77, result);
}
}

View File

@ -13,35 +13,35 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class LambdaVoidTest {
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;
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/javFiles/Lambda.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("Lambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@Test
public void generateBC() throws Exception {
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/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Lambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
Integer i = 77;
apply.invoke(m.invoke(instanceOfClass), i);
}
Integer i = 77;
apply.invoke(m.invoke(instanceOfClass), i);
}
}

View File

@ -15,119 +15,119 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class LessEqualTest {
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;
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/javFiles/bytecode/LessEqual.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("LessEqual");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("LessEqual");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testName() {
assertEquals("LessEqual", classToTest.getName());
}
@Test
public void testName() {
assertEquals("LessEqual", classToTest.getName());
}
@Test
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5,7);
assertTrue(result);
}
@Test
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5,7);
assertTrue(result);
}
@Test
public void testEqualIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5,5);
assertTrue(result);
}
@Test
public void testEqualIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5,5);
assertTrue(result);
}
@Test
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Long.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5L,7L);
assertTrue(result);
}@Test
@Test
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Long.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5L,7L);
assertTrue(result);
}@Test
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7F);
assertTrue(result);
}
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7F);
assertTrue(result);
}
@Test
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Double.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7.0);
assertTrue(result);
}
@Test
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Double.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7.0);
assertTrue(result);
}
@Test
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5L,7);
assertTrue(result);
}
@Test
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5L,7);
assertTrue(result);
}
@Test
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7);
assertTrue(result);
}
@Test
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7);
assertTrue(result);
}
@Test
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7);
assertTrue(result);
}
@Test
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Integer.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7);
assertTrue(result);
}
@Test
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Long.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7L);
assertTrue(result);
}
@Test
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Long.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7L);
assertTrue(result);
}
@Test
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Long.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7L);
assertTrue(result);
}
@Test
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Long.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7L);
assertTrue(result);
}
@Test
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 7.0,7F);
assertTrue(result);
}
@Test
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 7.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7F);
assertTrue(result);
}
@Test
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 9.0,7F);
assertFalse(result);
}
@Test
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 9.0,7F);
assertFalse(result);
}
}

View File

@ -15,127 +15,127 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class LessThanTest {
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;
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/javFiles/bytecode/LessThan.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("LessThan");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("LessThan");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testClassName() {
assertEquals("LessThan", classToTest.getName());
}
@Test
public void testClassName() {
assertEquals("LessThan", classToTest.getName());
}
@Test
public void testLessThanInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class,Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5, 7);
assertTrue(result);
}
@Test
public void testLessThanInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class,Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5, 7);
assertTrue(result);
}
@Test
public void testLessThanInt2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7, 5);
assertFalse(result);
}
@Test
public void testLessThanInt2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7, 5);
assertFalse(result);
}
@Test
public void testLessThanInt3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5, 5);
assertFalse(result);
}
@Test
public void testLessThanInt3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5, 5);
assertFalse(result);
}
@Test
public void testLessThanLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class,Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5L, 7L);
assertTrue(result);
}
@Test
public void testLessThanLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class,Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5L, 7L);
assertTrue(result);
}
@Test
public void testLessThanLong2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7L, 5L);
assertFalse(result);
}
@Test
public void testLessThanLong2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7L, 5L);
assertFalse(result);
}
@Test
public void testLessThanLong3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5L, 5L);
assertFalse(result);
}
@Test
public void testLessThanLong3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5L, 5L);
assertFalse(result);
}
@Test
public void testLessThanFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Float.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5F);
assertFalse(result);
}
@Test
public void testLessThanFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Float.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5F);
assertFalse(result);
}
@Test
public void testLessThanDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Double.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5.0);
assertFalse(result);
}
@Test
public void testLessThanDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Double.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5.0);
assertFalse(result);
}
@Test
public void testLessThanLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7L, 5);
assertFalse(result);
}
@Test
public void testLessThanLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7L, 5);
assertFalse(result);
}
@Test
public void testLessThanFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5);
assertFalse(result);
}
@Test
public void testLessThanFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5);
assertFalse(result);
}
@Test
public void testLessThanDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5);
assertFalse(result);
}
@Test
public void testLessThanDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Integer.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5);
assertFalse(result);
}
@Test
public void testLessThanFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5L);
assertFalse(result);
}
@Test
public void testLessThanFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5L);
assertFalse(result);
}
@Test
public void testLessThanDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5L);
assertFalse(result);
}
@Test
public void testLessThanDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Long.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5L);
assertFalse(result);
}
@Test
public void testLessThanDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Float.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5F);
assertFalse(result);
}
@Test
public void testLessThanDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Float.class);
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5F);
assertFalse(result);
}
}

View File

@ -16,76 +16,76 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class MatrixOpTest {
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_m1;
private static Object instanceOfClass_m2;
private static Object instanceOfClass_m3;
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_m1;
private static Object instanceOfClass_m2;
private static Object instanceOfClass_m3;
@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";
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");
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
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");
/*
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
Vector<Integer> v1 = new Vector<Integer> ();
v1.addElement(2);
v1.addElement(2);
Vector<Integer> v2 = new Vector<Integer> ();
v2.addElement(3);
v2.addElement(3);
//Matrix m1 = new Matrix();
//m1.addElement(v1);
//m1.addElement(v2);
vv.addElement(v1);
vv.addElement(v2);
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
Vector<Integer> v1 = new Vector<Integer> ();
v1.addElement(2);
v1.addElement(2);
Vector<Integer> v2 = new Vector<Integer> ();
v2.addElement(3);
v2.addElement(3);
//Matrix m1 = new Matrix();
//m1.addElement(v1);
//m1.addElement(v2);
vv.addElement(v1);
vv.addElement(v2);
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
Vector<Integer> v3 = new Vector<Integer> ();
v3.addElement(2);
v3.addElement(2);
Vector<Integer> v4 = new Vector<Integer> ();
v4.addElement(3);
v4.addElement(3);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
vv1.addElement(v3);
vv1.addElement(v4);
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
Vector<Integer> v3 = new Vector<Integer> ();
v3.addElement(2);
v3.addElement(2);
Vector<Integer> v4 = new Vector<Integer> ();
v4.addElement(3);
v4.addElement(3);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
vv1.addElement(v3);
vv1.addElement(v4);
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
//Matrix m3 = m1.mul(vv1);
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
//Matrix m3 = m1.mul(vv1);
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
Vector<Integer> v5 = new Vector<Integer> ();
v5.addElement(10);
v5.addElement(10);
Vector<Integer> v6 = new Vector<Integer> ();
v6.addElement(15);
v6.addElement(15);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
res.addElement(v5);
res.addElement(v6);
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
assertEquals(result, instanceOfClass_m3);
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
Vector<Integer> v5 = new Vector<Integer> ();
v5.addElement(10);
v5.addElement(10);
Vector<Integer> v6 = new Vector<Integer> ();
v6.addElement(15);
v6.addElement(15);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
res.addElement(v5);
res.addElement(v6);
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
assertEquals(result, instanceOfClass_m3);
*/
}
}
}

View File

@ -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/";

View File

@ -13,29 +13,29 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class MergeTest {
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;
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/javFiles/bytecode/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/";
@Test
public void generateBC() throws Exception {
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")+"/testBytecode/generatedBC/";
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
// classToTest = loader.loadClass("Merge");
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
//Method m = classToTest.getDeclaredMethod("m");
//Object result = m.invoke(instanceOfClass);
//Method m = classToTest.getDeclaredMethod("m");
//Object result = m.invoke(instanceOfClass);
//assertEquals(result.getClass(), loader.loadClass("Apply"));
}
//assertEquals(result.getClass(), loader.loadClass("Apply"));
}
}

View File

@ -14,79 +14,79 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class OLTest {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static ClassLoader loader;
private static Class<?> classToTest;
private static Class<?> classToTest1;
private static String pathToClassFile;
private static Object instanceOfClass;
private static Object instanceOfClass1;
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static ClassLoader loader;
private static Class<?> classToTest;
private static Class<?> classToTest1;
private static String pathToClassFile;
private static Object instanceOfClass;
private static Object instanceOfClass1;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/OL.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("OL");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
classToTest1 = loader.loadClass("OLMain");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("OL");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
classToTest1 = loader.loadClass("OLMain");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
}
@Test
public void testOLClassName() {
assertEquals("OL", classToTest.getName());
}
@Test
public void testOLClassName() {
assertEquals("OL", classToTest.getName());
}
@Test
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);
}
@Test
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", Integer.class);
Integer result = (Integer) m.invoke(instanceOfClass, 5);
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);
}
@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(10.0, result);
}
@Test
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", String.class);
String result = (String) m.invoke(instanceOfClass, "xxx");
assertEquals("xxxxxx", result);
}
@Test
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", String.class);
String result = (String) m.invoke(instanceOfClass, "xxx");
assertEquals("xxxxxx", result);
}
@Test
public void testOLMainClassName() {
assertEquals("OLMain", classToTest1.getName());
}
@Test
public void testOLMainClassName() {
assertEquals("OLMain", classToTest1.getName());
}
@Test
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);
}
@Test
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
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);
}
@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(10.0, result);
}
@Test
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", String.class);
String result = (String) main.invoke(instanceOfClass1, "xxx");
assertEquals("xxxxxx", result);
}
@Test
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method main = classToTest1.getDeclaredMethod("main", String.class);
String result = (String) main.invoke(instanceOfClass1, "xxx");
assertEquals("xxxxxx", result);
}
}

View File

@ -15,47 +15,47 @@ import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class OpTest {
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;
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/javFiles/bytecode/Op.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("Op");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Op");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testAddString() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
@Test
public void testAddString() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
Method m = classToTest.getDeclaredMethod("m", String.class,String.class);
Method m = classToTest.getDeclaredMethod("m", String.class,String.class);
String result = (String) m.invoke(instanceOfClass, "Byte","Code");
String result = (String) m.invoke(instanceOfClass, "Byte","Code");
assertEquals("ByteCode", result);
}
assertEquals("ByteCode", result);
}
@Test
public void testAddInt() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
@Test
public void testAddInt() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class);
Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class);
Integer result = (Integer) m.invoke(instanceOfClass, 7,3);
Integer result = (Integer) m.invoke(instanceOfClass, 7,3);
assertEquals(Integer.valueOf(10), result);
}
assertEquals(10, result);
}
}

View File

@ -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/";

View File

@ -14,44 +14,44 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class OverloadingTest {
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;
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;
private static Class<?> classOL2;
private static Object instanceOfClassOL2;
private static Class<?> classOL2;
private static Object instanceOfClassOL2;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Overloading.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("Overloading");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Overloading");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
classOL2 = loader.loadClass("Overloading2");
instanceOfClassOL2 = classOL2.getDeclaredConstructor().newInstance();
}
classOL2 = loader.loadClass("Overloading2");
instanceOfClassOL2 = classOL2.getDeclaredConstructor().newInstance();
}
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method meth = classToTest.getDeclaredMethod("test", classToTest);
String res = (String) meth.invoke(instanceOfClass, instanceOfClass);
assertEquals("Overloading", res);
}
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method meth = classToTest.getDeclaredMethod("test", classToTest);
String res = (String) meth.invoke(instanceOfClass, instanceOfClass);
assertEquals("Overloading", res);
}
@Test
public void test2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method meth = classToTest.getDeclaredMethod("test", classOL2);
String res = (String) meth.invoke(instanceOfClass, instanceOfClassOL2);
assertEquals("Overloading2", res);
}
@Test
public void test2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method meth = classToTest.getDeclaredMethod("test", classOL2);
String res = (String) meth.invoke(instanceOfClass, instanceOfClassOL2);
assertEquals("Overloading2", res);
}
}

View File

@ -14,40 +14,40 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class PlusTest {
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;
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/javFiles/bytecode/Plus.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("Plus");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Plus");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testAddInt() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
Method addInt = classToTest.getDeclaredMethod("m", Integer.class,Integer.class);
Number result = (Number) addInt.invoke(instanceOfClass, 7,3);
assertEquals(10, result);
}
@Test
public void testAddInt() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
Method addInt = classToTest.getDeclaredMethod("m", Integer.class,Integer.class);
Number result = (Number) addInt.invoke(instanceOfClass, 7,3);
assertEquals(10, result);
}
@Test
public void testAddString() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
Method addString = classToTest.getDeclaredMethod("m", String.class,String.class);
String result = (String) addString.invoke(instanceOfClass, "Byte","Code");
assertEquals("ByteCode", result);
}
@Test
public void testAddString() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InstantiationException {
Method addString = classToTest.getDeclaredMethod("m", String.class,String.class);
String result = (String) addString.invoke(instanceOfClass, "Byte","Code");
assertEquals("ByteCode", result);
}
}

View File

@ -14,52 +14,52 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class PostIncTest {
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;
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/javFiles/bytecode/PostIncDec.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("PostIncDec");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("PostIncDec");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
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);
}
@Test
public void testM1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m");
Integer res = (Integer) m.invoke(instanceOfClass);
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);
}
@Test
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m2");
Integer res = (Integer) m.invoke(instanceOfClass);
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);
}
@Test
public void testD1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("d");
Integer res = (Integer) m.invoke(instanceOfClass);
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);
}
@Test
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("d2");
Integer res = (Integer) m.invoke(instanceOfClass);
assertEquals(0, res);
}
}

View File

@ -14,52 +14,52 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class PreIncTest {
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;
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/javFiles/bytecode/PreInc.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("PreInc");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)});
classToTest = loader.loadClass("PreInc");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
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);
}
@Test
public void testM() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m");
Integer res = (Integer) m.invoke(instanceOfClass);
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);
}
@Test
public void testM2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m2");
Integer res = (Integer) m.invoke(instanceOfClass);
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);
}
@Test
public void testD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("d");
Integer res = (Integer) m.invoke(instanceOfClass);
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);
}
@Test
public void testD2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("d2");
Integer res = (Integer) m.invoke(instanceOfClass);
assertEquals(-1, res);
}
}

View File

@ -14,31 +14,31 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class RelOpsTest {
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;
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/javFiles/bytecode/RelOps.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("RelOps");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("RelOps");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class);
Boolean result = (Boolean) m.invoke(instanceOfClass, 7,3);
assertFalse(result);
}
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class);
Boolean result = (Boolean) m.invoke(instanceOfClass, 7,3);
assertFalse(result);
}
}

View File

@ -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/");

View File

@ -10,18 +10,18 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class SubMatTest {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
@Test
public void test() throws ClassNotFoundException, IOException {
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/SubMatrix.jav";
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
compiler.generateBytecode(pathToClassFile);
}
@Test
public void test() throws ClassNotFoundException, IOException {
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/";
compiler.generateBytecode(pathToClassFile);
}
}

View File

@ -14,56 +14,56 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class Tph2Test {
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;
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/javFiles/bytecode/Tph2.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("Tph2");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Tph2");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void test1() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,2);
@Test
public void test1() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,2);
assertEquals(1,result);
}
assertEquals(1,result);
}
@Test
public void test2() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, "sss",2);
@Test
public void test2() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, "sss",2);
assertEquals("sss",result);
}
assertEquals("sss",result);
}
@Test
public void test3() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,2);
@Test
public void test3() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,2);
assertEquals(2,result);
}
assertEquals(2,result);
}
@Test
public void test4() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,"xxx");
@Test
public void test4() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,"xxx");
assertEquals("xxx",result);
}
assertEquals("xxx",result);
}
}

View File

@ -14,18 +14,18 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class Tph3Test {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
@Test
public void generateBC() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/Tph3.jav";
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
compiler.generateBytecode(pathToClassFile);
}
@Test
public void generateBC() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
}
}

View File

@ -14,32 +14,32 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class Tph5Test {
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;
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/javFiles/bytecode/Tph5.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("Tph5");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Tph5");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void test() throws Exception {
@Test
public void test() throws Exception {
// Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class, Object.class);
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
// Object result = m.invoke(instanceOfClass, "xx",2,3);
//assertEquals(2,result);
}
//assertEquals(2,result);
}
}

View File

@ -14,56 +14,56 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
public class TphTest {
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;
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/javFiles/bytecode/Tph.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("Tph");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Tph");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void test1() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,2);
@Test
public void test1() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1,2);
assertEquals(2,result);
}
assertEquals(2,result);
}
@Test
public void test2() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1, "sss");
@Test
public void test2() throws Exception {
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
Object result = m.invoke(instanceOfClass, 1, "sss");
assertEquals("sss",result);
}
assertEquals("sss",result);
}
@Test
public void test3() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class);
Object result = m.invoke(instanceOfClass, 2);
@Test
public void test3() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class);
Object result = m.invoke(instanceOfClass, 2);
assertEquals(2,result);
}
assertEquals(2,result);
}
@Test
public void test4() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class);
Object result = m.invoke(instanceOfClass,"xxx");
@Test
public void test4() throws Exception {
Method m = classToTest.getDeclaredMethod("m2", Object.class);
Object result = m.invoke(instanceOfClass,"xxx");
assertEquals("xxx",result);
}
assertEquals("xxx",result);
}
}

View File

@ -14,45 +14,45 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class WhileTest {
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;
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/javFiles/bytecode/While.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("While");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
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/";
compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("While");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
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);
}
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method m = classToTest.getDeclaredMethod("m", Integer.class);
Integer result = (Integer) m.invoke(instanceOfClass, 0);
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);
}
@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(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);
}
@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(2l, result);
}
}

View File

@ -8,47 +8,45 @@ 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;
public class YTest {
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;
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
@Ignore
public void generateBC() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/bytecode/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");
/*
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@Test
public void generateBC() throws Exception {
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")+"/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();
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
// Damit man auf die Methode zugreifen kann
apply.setAccessible(true);
Integer i = 77;
Integer i = 77;
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
assertEquals(77, result);
*/
}
assertEquals(77, result);
*/
}
}

View File

@ -12,28 +12,28 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class applyLambdaTest {
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;
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/javFiles/bytecode/applyLambda.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("applyLambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@Test
public void generateBC() throws Exception {
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/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("applyLambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
Method m = classToTest.getDeclaredMethod("m");
Object result = m.invoke(instanceOfClass);
Method m = classToTest.getDeclaredMethod("m");
Object result = m.invoke(instanceOfClass);
assertEquals(result.getClass(), loader.loadClass("Apply"));
}
assertEquals(result.getClass(), loader.loadClass("Apply"));
}
}

View 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);
}
}

View 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);
}
}

View 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;
}
}

View 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;
}
}

View File

@ -0,0 +1,3 @@
public class EmptyClass{
}

View 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;
}
}*/

View File

@ -0,0 +1,8 @@
class Expressions{
void test(){
var x = 2;
x = x + 2;
}
}

View File

@ -0,0 +1,10 @@
import java.util.Vector;
class Matrix extends Vector<Vector<Integer>> {
methode(m) {
m.add(1);
Matrix i;
methode(i);
}
}

View 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;
}
}

View 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;
}
}

View 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);
}

View File

@ -0,0 +1,11 @@
import java.lang.String;
class Fields{
test2 = "test";
test;
m(){
var test3;
return test;
}
}

View 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");
*/

View 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;
}
}
}

View File

@ -0,0 +1,8 @@
import java.util.Vector;
class Import {
void methode(){
Vector v;
v.add(v);
}
}

View File

@ -0,0 +1,13 @@
class Apply { }
public class Lambda {
m () {
var lam1 = (x) -> {
return x;
};
return lam1.apply(new Apply());
}
}

View 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);
}

View 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);
}

View File

@ -0,0 +1,6 @@
public class LambdaField {
f = x -> x;
}

View 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();
}
}

View 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;
}

View 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;
}
}

View File

@ -0,0 +1,11 @@
class Meth_Gen {
m1(x, y) {
m2(x);
x = y;
}
m2(y) {
m1(y, y);
}
}

View 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);
}
}

View 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){}
}

View File

@ -0,0 +1,7 @@
class Methods {
mt4(a,b,c) { return a.mt3(b).mt3(c) ; }
mt3(a) {return a.mt3(a); }
}

View 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();
}
}

View File

@ -0,0 +1,5 @@
package strucType.input;
class Neu
{
}

View File

@ -0,0 +1,8 @@
import java.util.List;
import java.util.Collection;
class Sorting{
void merge(a, b){
a.addAll(b);
}
}

View File

@ -0,0 +1,6 @@
public class Subclass extends Superclass {
public void printMethod() {
super.printMethod();
}
}

View File

@ -0,0 +1,6 @@
public class Superclass {
public void printMethod() {
System.out.println("Printed in Superclass.");
}
}

View 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;
}
}

View 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);
}

View 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;
}
}

View 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);
}

View File

@ -0,0 +1,7 @@
class Faculty {
int a;
m (int x) {
return a+x;
}
}

24
src/test/java/log4jTesting.xml Executable file
View 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>

View File

@ -0,0 +1,6 @@
class Test{
method(){
if(true)i++;
if(true)i--;
else i++;
}}

View File

@ -0,0 +1,3 @@
class Matrix{
<A extends B, C extends B> String op = "String";
}

View File

@ -0,0 +1,8 @@
class CastTest{
void methode(){
Object a;
String b;
a = (Object) b;
}
}

View File

@ -0,0 +1,4 @@
class C1 extends Object
{
m(para) { return para; }
}

View 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(); }
}

View File

@ -0,0 +1,3 @@
class FieldInitializationTest{
var var = "hallo";
}

View File

@ -0,0 +1,5 @@
package test;
class Test<Typ>{
Typ a;
}

View File

@ -20,36 +20,36 @@ 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(){
@Test
public void run(){
List<String> filenames = new ArrayList<String>();
/*
filenames.add("NewTest.jav");
filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav");
filenames.add("CastTest.jav");
filenames.add("StatementsTest.jav");
//filenames.add("Methods.jav");
filenames.add("ImportTestGeneric.jav");
filenames.add("CastTest.jav");
//filenames.add("BoundedParameter.jav");
//filenames.add("GenericFieldVarTest.jav");
filenames.add("FieldVarTest.jav");
filenames.add("StructuralTypes.jav");
*/
List<String> filenames = new ArrayList<String>();
/*
filenames.add("NewTest.jav");
filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav");
filenames.add("CastTest.jav");
filenames.add("StatementsTest.jav");
//filenames.add("Methods.jav");
filenames.add("ImportTestGeneric.jav");
filenames.add("CastTest.jav");
//filenames.add("BoundedParameter.jav");
//filenames.add("GenericFieldVarTest.jav");
filenames.add("FieldVarTest.jav");
filenames.add("StructuralTypes.jav");
*/
// filenames.add("ExtendsTest.jav");
filenames.add("PackageNameTest.jav");
try{
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
}catch(Exception exc){
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen",filenames.size()>0);
}
filenames.add("PackageNameTest.jav");
try{
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
}catch(Exception exc){
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen",filenames.size()>0);
}
}

View 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