diff --git a/pom.xml b/pom.xml index b743985f..b47e1deb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,4 @@ + &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:)." diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java index dcf98357..f67b9c4d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -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 tphsClass; + // stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,... HashMap 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 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: * 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 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 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> constraints = Simplify.simplifyConstraints(field.name, tphExtractor); + HashMap> 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> constraints = Simplify.simplifyConstraints(method.name, tphExtractor); + HashMap> constraints = Simplify.simplifyConstraints(method.name, tphExtractor, tphsClass); // ArrayList 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); } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 1e1048ff..6fc80347 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -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 diff --git a/src/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java similarity index 100% rename from src/de/dhbwstuttgart/bytecode/TPHExtractor.java rename to src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java index d92efe5a..07471ae1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java @@ -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())+ ";"; } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java index f74d2eef..995cdf17 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -41,11 +41,16 @@ public class Signature { private ResultSet resultSet; private ArrayList commonPairs; private HashMap> methodConstraints; + private ArrayList tphsClass; + private ArrayList consClass; - public Signature(ClassOrInterface classOrInterface, HashMap genericsAndBounds,ArrayList commonPairs) { + public Signature(ClassOrInterface classOrInterface, HashMap genericsAndBounds, + ArrayList commonPairs, ArrayList tphsClass, ArrayList 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 types = new ArrayList<>(); + ArrayList 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 types = new ArrayList<>(); ArrayList 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(); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java index 2ec212f7..49b1b4f4 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java @@ -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> simplifyConstraints(String name, TPHExtractor tphExtractor) { + public static HashMap> simplifyConstraints(String name, TPHExtractor tphExtractor, ArrayList tphsClass) { // 1. check if there are any simple cycles like L 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 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 subAndSuper = new HashMap<>(); + ArrayList eqCons = new ArrayList<>(); for(TPHConstraint c : allCons) { if(subAndSuper.containsKey(c.getLeft())) { LinkedList 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 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 equals = getEqualsTphsFromEqualCons(eqCons,subTphRes); + result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals); + if(!isTPHInConstraint(result, superTphRes) && !isTphInEqualSet(result,superTphRes)) { + HashSet 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 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 tphsClass, String superTphRes) { + for(TypePlaceholder tph : tphsClass) { + if(tph.getName().equals(superTphRes)) + return true; + } + return false; + } + + private static boolean isTphInEqualSet(HashMap> result, String tph) { + for(HashSet hs: result.values()) { + if(hs.contains(tph)) + return true; + } + return false; + } + + private static HashSet getEqualsTphsFromEqualCons(ArrayList eqCons, String tph) { + HashSet 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 subAndSuper, ArrayList allCons,ArrayList 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 allCons) { for(TPHConstraint c : allCons) { if(c.getLeft().equals(oldRight) && c.getRight().equals(right)) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index ad909f11..a860adf9 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -120,12 +120,14 @@ public class JavaTXCompiler { TypeUnify unify = new TypeUnify(); Set> 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>> cardProd = unifyCons.cartesianProduct(); for (List> xCons : cardProd ){ Set xConsSet = new HashSet<>(); @@ -150,21 +152,21 @@ public class JavaTXCompiler { paraTypeVarNames.addAll(constructorParaTypeVarNames); Set 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 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> result = unify.unifySequential(xConsSet, finiteClosure); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - results.addAll(result); - } + varianceInheritance(xConsSet); + + + + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> 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> 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()); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 609600cd..2f705c67 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -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 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); } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index e2edbb97..d4e6b551 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -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 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); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 5f0126aa..fa190cb7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -8,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set eq, IFiniteClosure fc) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true); + public Set> unify(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } - public Set> unifySequential(Set eq, IFiniteClosure fc) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false); + public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); Set> res = unifyTask.compute(); return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 106f0688..801cae50 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -51,7 +51,10 @@ public class TypeUnifyTask extends RecursiveTask>> { 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>> { rules = new RuleSet(); } - public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel) { + public TypeUnifyTask(Set 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>> { * 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>> { // 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> 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>> { 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>> { //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>> { * 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>> { return result; } Set> nextSet = remainingSets.remove(0); - + writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); try { //List> @@ -433,9 +451,10 @@ public class TypeUnifyTask extends RecursiveTask>> { 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 a = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { - Set a = null; + Set a_last = a; if (variance == 1) { a = oup.max(nextSetasList.iterator()); nextSetasList.remove(a); @@ -485,9 +504,57 @@ public class TypeUnifyTask extends RecursiveTask>> { 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 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 fstElemRes = res.iterator().next(); + Set 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 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 fstElemResult = result.iterator().next(); + Set 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)) { @@ -505,7 +572,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); - Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); + Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { System.out.println(""); while (nextSetasListIt.hasNext()) { @@ -570,11 +637,25 @@ public class TypeUnifyTask extends RecursiveTask>> { // 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>> { // 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 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>> { permuteParams(candidates, idx+1, result, current); } } + + void writeLog(String str) { + if (log) { + try { + logFile.write(str+"\n"); + logFile.flush(); + + } + catch (IOException e) { } + } + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 5eef0308..4aa769e5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -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 implements IFiniteClosure { +public class FiniteClosure //extends Ordering //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 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 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 al = new ArrayList<>(); + PlaceholderType xx =new PlaceholderType("xx"); + al.add(xx); + left = new ExtendsType(xx); + right = xx; + */ + /* + List 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 hs = new HashSet<>(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 8cebdd8a..c655e6fd 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -151,7 +151,7 @@ public class OrderingUnifyPair extends Ordering> { System.out.print(""); //Set varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); //Set 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()) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index ef41de65..01209998 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -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 EXISTING_PLACEHOLDERS = new HashSet(); + public static final ArrayList EXISTING_PLACEHOLDERS = new ArrayList(); /** * 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); } diff --git a/src/test/java/asp/ClingoTest.java b/src/test/java/asp/ClingoTest.java index b5d8c035..90635bde 100644 --- a/src/test/java/asp/ClingoTest.java +++ b/src/test/java/asp/ClingoTest.java @@ -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,13 +22,11 @@ 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()); - + PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); writer.println(content); writer.close(); diff --git a/src/test/java/asp/gencay/GeneratorTest.java b/src/test/java/asp/gencay/GeneratorTest.java index 54da7c0f..bd268a4b 100644 --- a/src/test/java/asp/gencay/GeneratorTest.java +++ b/src/test/java/asp/gencay/GeneratorTest.java @@ -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 { diff --git a/src/test/java/bytecode/BinaryTest.java b/src/test/java/bytecode/BinaryTest.java index dafa7a18..b47841ed 100644 --- a/src/test/java/bytecode/BinaryTest.java +++ b/src/test/java/bytecode/BinaryTest.java @@ -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/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(); + } - @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(); - } - - @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 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 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(4, res); + } } diff --git a/src/test/java/bytecode/FacTest.java b/src/test/java/bytecode/FacTest.java index 9f9f90cd..8152452d 100644 --- a/src/test/java/bytecode/FacTest.java +++ b/src/test/java/bytecode/FacTest.java @@ -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; - - @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(); - } - - @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)); - } + 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/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, 6); + } } diff --git a/src/test/java/bytecode/FacultyTest.java b/src/test/java/bytecode/FacultyTest.java index 7ba08e58..07b099e5 100644 --- a/src/test/java/bytecode/FacultyTest.java +++ b/src/test/java/bytecode/FacultyTest.java @@ -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; - - @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(); - -// Method m = classToTest.getDeclaredMethod("m", Integer.class); - Field fact = classToTest.getDeclaredField("fact"); + 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/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 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); + } } diff --git a/src/test/java/bytecode/FieldTest.java b/src/test/java/bytecode/FieldTest.java index e7ec2582..2d710fac 100644 --- a/src/test/java/bytecode/FieldTest.java +++ b/src/test/java/bytecode/FieldTest.java @@ -13,31 +13,31 @@ import java.net.URLClassLoader; 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; + + @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(); + } - 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(); - } - - @Test - public void test() { - Field[] fields = classToTest.getFields(); - assertEquals(1, fields.length); - } + @Test + public void test() { + Field[] fields = classToTest.getFields(); + assertEquals(1, fields.length); + } } diff --git a/src/test/java/bytecode/FieldTph.java b/src/test/java/bytecode/FieldTph.java new file mode 100644 index 00000000..abc1a3fc --- /dev/null +++ b/src/test/java/bytecode/FieldTph.java @@ -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); + } + +} diff --git a/src/test/java/bytecode/FieldTph2Test.java b/src/test/java/bytecode/FieldTph2Test.java new file mode 100644 index 00000000..6da35b7b --- /dev/null +++ b/src/test/java/bytecode/FieldTph2Test.java @@ -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); + } + +} diff --git a/src/test/java/bytecode/FieldTphConsMethTest.java b/src/test/java/bytecode/FieldTphConsMethTest.java new file mode 100644 index 00000000..8748d535 --- /dev/null +++ b/src/test/java/bytecode/FieldTphConsMethTest.java @@ -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); + } + +} diff --git a/src/test/java/bytecode/FunOLTest.java b/src/test/java/bytecode/FunOLTest.java index c7686e8a..863b3118 100644 --- a/src/test/java/bytecode/FunOLTest.java +++ b/src/test/java/bytecode/FunOLTest.java @@ -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/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(); - @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(); + 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 result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - Integer i = 77; - - Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - - assertEquals(77, result); - */ - } + assertEquals(77, result); + */ + } } diff --git a/src/test/java/bytecode/GenTest.java b/src/test/java/bytecode/GenTest.java index 97d02372..0dfcba7f 100644 --- a/src/test/java/bytecode/GenTest.java +++ b/src/test/java/bytecode/GenTest.java @@ -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; - - @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); - } + 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/bytecodeJavFiles/Gen.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + compiler.generateBytecode(pathToClassFile); + } } diff --git a/src/test/java/bytecode/GreaterEqualTest.java b/src/test/java/bytecode/GreaterEqualTest.java index 920f6e3b..33f716c4 100644 --- a/src/test/java/bytecode/GreaterEqualTest.java +++ b/src/test/java/bytecode/GreaterEqualTest.java @@ -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/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(); + } - @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(); - } + @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 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 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 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 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 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 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 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 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 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 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 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 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 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); + } } diff --git a/src/test/java/bytecode/GreaterThanTest.java b/src/test/java/bytecode/GreaterThanTest.java index 524dc43a..595c67ae 100644 --- a/src/test/java/bytecode/GreaterThanTest.java +++ b/src/test/java/bytecode/GreaterThanTest.java @@ -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/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(); + } - @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(); - } - - @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); - } - - @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 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); - } - - @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 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 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 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 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 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); + } + + @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 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); + } + + @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 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 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 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 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); + } } diff --git a/src/test/java/bytecode/LambdaCapturetest.java b/src/test/java/bytecode/LambdaCapturetest.java new file mode 100644 index 00000000..c957e64e --- /dev/null +++ b/src/test/java/bytecode/LambdaCapturetest.java @@ -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(); + } + +} diff --git a/src/test/java/bytecode/LambdaTest.java b/src/test/java/bytecode/LambdaTest.java index 6a66bd04..c7553c2d 100644 --- a/src/test/java/bytecode/LambdaTest.java +++ b/src/test/java/bytecode/LambdaTest.java @@ -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/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(); - @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(); + 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; + System.out.println(m.invoke(instanceOfClass).toString()); + Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - Integer i = 77; - - Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - - assertEquals(Integer.valueOf(77), result); - } + assertEquals(77, result); + } } diff --git a/src/test/java/bytecode/LambdaVoidTest.java b/src/test/java/bytecode/LambdaVoidTest.java index 13c66d2c..6d0a9024 100644 --- a/src/test/java/bytecode/LambdaVoidTest.java +++ b/src/test/java/bytecode/LambdaVoidTest.java @@ -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/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(); - @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(); + 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); + } } diff --git a/src/test/java/bytecode/LessEqualTest.java b/src/test/java/bytecode/LessEqualTest.java index c1a2da11..217ec4b1 100644 --- a/src/test/java/bytecode/LessEqualTest.java +++ b/src/test/java/bytecode/LessEqualTest.java @@ -14,120 +14,120 @@ import org.junit.Test; 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; + + @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(); + } - 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(); - } - - @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 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 - - 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 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 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 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 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 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 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 + + 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 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 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 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 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); + } } diff --git a/src/test/java/bytecode/LessThanTest.java b/src/test/java/bytecode/LessThanTest.java index 17233ebb..192291a1 100644 --- a/src/test/java/bytecode/LessThanTest.java +++ b/src/test/java/bytecode/LessThanTest.java @@ -14,128 +14,128 @@ import org.junit.Test; 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; + + @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(); + } - 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(); - } - - @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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); + } } diff --git a/src/test/java/bytecode/MatrixOpTest.java b/src/test/java/bytecode/MatrixOpTest.java index e1c368a3..8e876467 100644 --- a/src/test/java/bytecode/MatrixOpTest.java +++ b/src/test/java/bytecode/MatrixOpTest.java @@ -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"); -/* - Vector> vv = new Vector>(); - Vector v1 = new Vector (); - v1.addElement(2); - v1.addElement(2); - Vector v2 = new Vector (); - 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); + @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> vv = new Vector>(); + Vector v1 = new Vector (); + v1.addElement(2); + v1.addElement(2); + Vector v2 = new Vector (); + 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> vv1 = new Vector>(); - Vector v3 = new Vector (); - v3.addElement(2); - v3.addElement(2); - Vector v4 = new Vector (); - 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> vv1 = new Vector>(); + Vector v3 = new Vector (); + v3.addElement(2); + v3.addElement(2); + Vector v4 = new Vector (); + 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()); - - Vector> res = new Vector>(); - Vector v5 = new Vector (); - v5.addElement(10); - v5.addElement(10); - Vector v6 = new Vector (); - 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); -*/ - } + //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> res = new Vector>(); + Vector v5 = new Vector (); + v5.addElement(10); + v5.addElement(10); + Vector v6 = new Vector (); + 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); +*/ + } } diff --git a/src/test/java/bytecode/MatrixTest.java b/src/test/java/bytecode/MatrixTest.java index 20e42df7..146e771a 100644 --- a/src/test/java/bytecode/MatrixTest.java +++ b/src/test/java/bytecode/MatrixTest.java @@ -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/"; diff --git a/src/test/java/bytecode/MergeTest.java b/src/test/java/bytecode/MergeTest.java index d0f2cc71..1edac3e4 100644 --- a/src/test/java/bytecode/MergeTest.java +++ b/src/test/java/bytecode/MergeTest.java @@ -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); - - //assertEquals(result.getClass(), loader.loadClass("Apply")); - } + //Method m = classToTest.getDeclaredMethod("m"); + //Object result = m.invoke(instanceOfClass); + + //assertEquals(result.getClass(), loader.loadClass("Apply")); + } } diff --git a/src/test/java/bytecode/OLTest.java b/src/test/java/bytecode/OLTest.java index 3e5b076d..0eac154c 100644 --- a/src/test/java/bytecode/OLTest.java +++ b/src/test/java/bytecode/OLTest.java @@ -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; - - @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(); - } - - @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 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 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 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 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 testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Method main = classToTest1.getDeclaredMethod("main", String.class); - String result = (String) main.invoke(instanceOfClass1, "xxx"); - assertEquals("xxxxxx", result); - } + 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/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 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(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 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(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(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); + } } diff --git a/src/test/java/bytecode/OpTest.java b/src/test/java/bytecode/OpTest.java index c2aed4f6..138701d1 100644 --- a/src/test/java/bytecode/OpTest.java +++ b/src/test/java/bytecode/OpTest.java @@ -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; - - @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(); - } - - @Test - public void testAddString() throws NoSuchMethodException, SecurityException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException, InstantiationException { - - Method m = classToTest.getDeclaredMethod("m", String.class,String.class); - - String result = (String) m.invoke(instanceOfClass, "Byte","Code"); - - assertEquals("ByteCode", result); - } - - @Test - public void testAddInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException, InstantiationException { - - Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class); - - Integer result = (Integer) m.invoke(instanceOfClass, 7,3); - - assertEquals(Integer.valueOf(10), result); - } + 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/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 { + + Method m = classToTest.getDeclaredMethod("m", String.class,String.class); + + String result = (String) m.invoke(instanceOfClass, "Byte","Code"); + + assertEquals("ByteCode", result); + } + + @Test + public void testAddInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException, InstantiationException { + + Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class); + + Integer result = (Integer) m.invoke(instanceOfClass, 7,3); + + assertEquals(10, result); + } + } diff --git a/src/test/java/bytecode/OverloadingSortingTest.java b/src/test/java/bytecode/OverloadingSortingTest.java index bec86b4a..e9751062 100644 --- a/src/test/java/bytecode/OverloadingSortingTest.java +++ b/src/test/java/bytecode/OverloadingSortingTest.java @@ -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/"; diff --git a/src/test/java/bytecode/OverloadingTest.java b/src/test/java/bytecode/OverloadingTest.java index be5a5a4d..d1f0187d 100644 --- a/src/test/java/bytecode/OverloadingTest.java +++ b/src/test/java/bytecode/OverloadingTest.java @@ -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; + + @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(); + } - 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(); - - 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 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 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); + } } diff --git a/src/test/java/bytecode/PlusTest.java b/src/test/java/bytecode/PlusTest.java index eeaa8d18..b7c1298a 100644 --- a/src/test/java/bytecode/PlusTest.java +++ b/src/test/java/bytecode/PlusTest.java @@ -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/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(); + } - @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(); - } - - @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 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); + } } diff --git a/src/test/java/bytecode/PostIncTest.java b/src/test/java/bytecode/PostIncTest.java index 10535d46..96af2177 100644 --- a/src/test/java/bytecode/PostIncTest.java +++ b/src/test/java/bytecode/PostIncTest.java @@ -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/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(); + } - @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(); - } - - @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 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 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 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 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(0, 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(0, res); + } } diff --git a/src/test/java/bytecode/PreIncTest.java b/src/test/java/bytecode/PreIncTest.java index e6e3502d..9eb9acc2 100644 --- a/src/test/java/bytecode/PreIncTest.java +++ b/src/test/java/bytecode/PreIncTest.java @@ -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/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(); + } - @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(); - } - - @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 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 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 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 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(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(-1, res); + } } diff --git a/src/test/java/bytecode/RelOpsTest.java b/src/test/java/bytecode/RelOpsTest.java index a2cfbba0..ef5b7579 100644 --- a/src/test/java/bytecode/RelOpsTest.java +++ b/src/test/java/bytecode/RelOpsTest.java @@ -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/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(); + } - @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(); - } - - @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); + } } diff --git a/src/test/java/bytecode/SortingTest.java b/src/test/java/bytecode/SortingTest.java index 16fbde55..47c7c949 100644 --- a/src/test/java/bytecode/SortingTest.java +++ b/src/test/java/bytecode/SortingTest.java @@ -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/"); diff --git a/src/test/java/bytecode/SubMatTest.java b/src/test/java/bytecode/SubMatTest.java index c7018e7c..876c3f7c 100644 --- a/src/test/java/bytecode/SubMatTest.java +++ b/src/test/java/bytecode/SubMatTest.java @@ -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; - - @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); - } + 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/bytecodeJavFiles/SubMatrix.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + compiler.generateBytecode(pathToClassFile); + } } diff --git a/src/test/java/bytecode/Tph2Test.java b/src/test/java/bytecode/Tph2Test.java index 8ecb31b1..ca587e0d 100644 --- a/src/test/java/bytecode/Tph2Test.java +++ b/src/test/java/bytecode/Tph2Test.java @@ -13,57 +13,57 @@ import org.junit.Test; 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; + + @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(); + } - 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(); - } - - @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); - } - - @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); - } - - @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); - } - - @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); - } + @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); + } + + @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); + } + + @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); + } + + @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); + } } diff --git a/src/test/java/bytecode/Tph3Test.java b/src/test/java/bytecode/Tph3Test.java index dc856935..8aba473d 100644 --- a/src/test/java/bytecode/Tph3Test.java +++ b/src/test/java/bytecode/Tph3Test.java @@ -13,19 +13,19 @@ import org.junit.Test; import de.dhbwstuttgart.core.JavaTXCompiler; public class Tph3Test { - - 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); - } + + 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/bytecodeJavFiles/Tph3.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + compiler.generateBytecode(pathToClassFile); + } } diff --git a/src/test/java/bytecode/Tph5Test.java b/src/test/java/bytecode/Tph5Test.java index 0bee721d..9a07a7a5 100644 --- a/src/test/java/bytecode/Tph5Test.java +++ b/src/test/java/bytecode/Tph5Test.java @@ -13,33 +13,33 @@ import org.junit.Test; 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; + + @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(); + } - 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(); - } - - @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); + } } diff --git a/src/test/java/bytecode/TphTest.java b/src/test/java/bytecode/TphTest.java index 9b8144a5..2a7e395e 100644 --- a/src/test/java/bytecode/TphTest.java +++ b/src/test/java/bytecode/TphTest.java @@ -13,57 +13,57 @@ import org.junit.Test; 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; + + @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(); + } - 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(); - } - - @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); - } - - @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); - } - - @Test - public void test3() throws Exception { - Method m = classToTest.getDeclaredMethod("m2", Object.class); - Object result = m.invoke(instanceOfClass, 2); - - assertEquals(2,result); - } - - @Test - public void test4() throws Exception { - Method m = classToTest.getDeclaredMethod("m2", Object.class); - Object result = m.invoke(instanceOfClass,"xxx"); - - assertEquals("xxx",result); - } + @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); + } + + @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); + } + + @Test + public void test3() throws Exception { + Method m = classToTest.getDeclaredMethod("m2", Object.class); + Object result = m.invoke(instanceOfClass, 2); + + assertEquals(2,result); + } + + @Test + public void test4() throws Exception { + Method m = classToTest.getDeclaredMethod("m2", Object.class); + Object result = m.invoke(instanceOfClass,"xxx"); + + assertEquals("xxx",result); + } } diff --git a/src/test/java/bytecode/WhileTest.java b/src/test/java/bytecode/WhileTest.java index 6cc96d58..5cebf8a3 100644 --- a/src/test/java/bytecode/WhileTest.java +++ b/src/test/java/bytecode/WhileTest.java @@ -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/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(); + } - @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(); - } - - @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 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 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 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(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(2l, result); + } } diff --git a/src/test/java/bytecode/YTest.java b/src/test/java/bytecode/YTest.java index 160a0b07..396b1584 100644 --- a/src/test/java/bytecode/YTest.java +++ b/src/test/java/bytecode/YTest.java @@ -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 + 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(); - @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(); + 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 result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - Integer i = 77; - - Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - - assertEquals(77, result); - */ - } + assertEquals(77, result); + */ + } } diff --git a/src/test/java/bytecode/applyLambdaTest.java b/src/test/java/bytecode/applyLambdaTest.java index ec0b6f57..26b004f5 100644 --- a/src/test/java/bytecode/applyLambdaTest.java +++ b/src/test/java/bytecode/applyLambdaTest.java @@ -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/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(); - @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(); - - Method m = classToTest.getDeclaredMethod("m"); - Object result = m.invoke(instanceOfClass); - - assertEquals(result.getClass(), loader.loadClass("Apply")); - } + Method m = classToTest.getDeclaredMethod("m"); + Object result = m.invoke(instanceOfClass); + + assertEquals(result.getClass(), loader.loadClass("Apply")); + } } diff --git a/src/test/java/bytecode/simplifyalgo/CycleTest.java b/src/test/java/bytecode/simplifyalgo/CycleTest.java new file mode 100644 index 00000000..f847eff4 --- /dev/null +++ b/src/test/java/bytecode/simplifyalgo/CycleTest.java @@ -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> result = new HashMap<>(); + HashSet 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> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>()); + boolean areEquals = SimpleCycle.areMapsEqual(result, sim); + assertTrue(areEquals); + } + +} diff --git a/src/test/java/bytecode/simplifyalgo/SameLeftSide.java b/src/test/java/bytecode/simplifyalgo/SameLeftSide.java new file mode 100644 index 00000000..69d50c63 --- /dev/null +++ b/src/test/java/bytecode/simplifyalgo/SameLeftSide.java @@ -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> 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 hs = new HashSet<>(); + + result.put(b, hs); + + HashMap> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>()); + boolean areEquals = SimpleCycle.areMapsEqual(result, sim); + assertTrue(areEquals); + } + + @Test + public void testM2() { + HashMap> 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 hs = new HashSet<>(); + hs.add("B"); + result.put(c, hs); + + HashMap> sim = Simplify.simplifyConstraints(methName2, tphExtractor,new ArrayList<>()); + boolean areEquals = SimpleCycle.areMapsEqual(result, sim); + assertTrue(areEquals); + } + +} diff --git a/src/test/java/bytecode/simplifyalgo/SimpleCycle.java b/src/test/java/bytecode/simplifyalgo/SimpleCycle.java new file mode 100644 index 00000000..545b0514 --- /dev/null +++ b/src/test/java/bytecode/simplifyalgo/SimpleCycle.java @@ -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> result = new HashMap<>(); + HashSet 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> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>()); + boolean areEquals = areMapsEqual(result, sim); + assertTrue(areEquals); + } + + public static boolean areMapsEqual(HashMap> m1, HashMap> 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 eq1 = m1.get(c); + HashSet 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; + } + +} diff --git a/src/test/java/javFiles/AddLong.jav b/src/test/java/javFiles/AddLong.jav new file mode 100644 index 00000000..d6d47e9f --- /dev/null +++ b/src/test/java/javFiles/AddLong.jav @@ -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; + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/EmptyClass.jav b/src/test/java/javFiles/EmptyClass.jav new file mode 100644 index 00000000..8160d7da --- /dev/null +++ b/src/test/java/javFiles/EmptyClass.jav @@ -0,0 +1,3 @@ +public class EmptyClass{ + +} \ No newline at end of file diff --git a/src/test/java/javFiles/EmptyMethod.jav b/src/test/java/javFiles/EmptyMethod.jav new file mode 100644 index 00000000..dd28fc69 --- /dev/null +++ b/src/test/java/javFiles/EmptyMethod.jav @@ -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; + } +}*/ \ No newline at end of file diff --git a/src/test/java/javFiles/Expressions.jav b/src/test/java/javFiles/Expressions.jav new file mode 100644 index 00000000..e2e992a1 --- /dev/null +++ b/src/test/java/javFiles/Expressions.jav @@ -0,0 +1,8 @@ +class Expressions{ + +void test(){ + var x = 2; + x = x + 2; +} + +} \ No newline at end of file diff --git a/src/test/java/javFiles/FC_Matrix.jav b/src/test/java/javFiles/FC_Matrix.jav new file mode 100644 index 00000000..75ead472 --- /dev/null +++ b/src/test/java/javFiles/FC_Matrix.jav @@ -0,0 +1,10 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + methode(m) { + m.add(1); + Matrix i; + methode(i); + } + } diff --git a/src/test/java/javFiles/Faculty.jav b/src/test/java/javFiles/Faculty.jav new file mode 100644 index 00000000..ca539add --- /dev/null +++ b/src/test/java/javFiles/Faculty.jav @@ -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; + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/FacultyIf.jav b/src/test/java/javFiles/FacultyIf.jav new file mode 100644 index 00000000..3c368923 --- /dev/null +++ b/src/test/java/javFiles/FacultyIf.jav @@ -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; + } +} diff --git a/src/test/java/javFiles/FacultyTyped.jav b/src/test/java/javFiles/FacultyTyped.jav new file mode 100644 index 00000000..089d2f33 --- /dev/null +++ b/src/test/java/javFiles/FacultyTyped.jav @@ -0,0 +1,19 @@ +import java.lang.Integer; + +class Faculty { + + Integer mul(Integer x, Integer y) { + return x; + } + + Fun1 m () { + var fact = (Integer x) -> { + return mul(x, fact.apply(x)); + }; + return fact; + } +} + +interface Fun1{ + B apply(A a); +} \ No newline at end of file diff --git a/src/test/java/javFiles/Fields.jav b/src/test/java/javFiles/Fields.jav new file mode 100644 index 00000000..cd2add71 --- /dev/null +++ b/src/test/java/javFiles/Fields.jav @@ -0,0 +1,11 @@ +import java.lang.String; + +class Fields{ +test2 = "test"; +test; +m(){ + var test3; + return test; +} + +} \ No newline at end of file diff --git a/src/test/java/javFiles/Generics.jav b/src/test/java/javFiles/Generics.jav new file mode 100644 index 00000000..dd7b4eba --- /dev/null +++ b/src/test/java/javFiles/Generics.jav @@ -0,0 +1,22 @@ +import java.lang.String; + +class Generics { + // A mt1(A a, B b){ + B mt1(B a, B b){ + return mt1(a, a); + } +} + +class Test { + methode(String s){ + return new Generics().mt1(s,s); + } +} + +/* +Problem: +auto test = new List(); +auto test2 = new List(); +... //code, welcher möglicherweise test und test2 vertauscht +test.add("hallo"); +*/ \ No newline at end of file diff --git a/src/test/java/javFiles/IfTest.jav b/src/test/java/javFiles/IfTest.jav new file mode 100644 index 00000000..1e1141df --- /dev/null +++ b/src/test/java/javFiles/IfTest.jav @@ -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; + } + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/Import.jav b/src/test/java/javFiles/Import.jav new file mode 100644 index 00000000..c48082ba --- /dev/null +++ b/src/test/java/javFiles/Import.jav @@ -0,0 +1,8 @@ +import java.util.Vector; + +class Import { + void methode(){ + Vector v; + v.add(v); + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/Lambda.jav b/src/test/java/javFiles/Lambda.jav new file mode 100644 index 00000000..5bd67a0b --- /dev/null +++ b/src/test/java/javFiles/Lambda.jav @@ -0,0 +1,13 @@ + +class Apply { } + +public class Lambda { + + m () { + var lam1 = (x) -> { + return x; + }; + return lam1.apply(new Apply()); + } +} + diff --git a/src/test/java/javFiles/Lambda2.jav b/src/test/java/javFiles/Lambda2.jav new file mode 100644 index 00000000..cf1e910b --- /dev/null +++ b/src/test/java/javFiles/Lambda2.jav @@ -0,0 +1,33 @@ +import java.lang.String; + +public class Lambda2 +{ + public static void main(List args){ + var listOfStrings = new List(); + var listOfObjects; + listOfObjects = map(listOfStrings, (a) -> a); +} + +public map(a , b){ + b.apply(a); + return a; +} + +/* +public static List map(List input, Function func) { + List output; + output = new List(); + output.add(func.apply(input.get())); + return output; +} +*/ +} + +class List{ + A get(); + void add(A); +} + +class Function{ + B apply(A a); +} \ No newline at end of file diff --git a/src/test/java/javFiles/Lambda3.jav b/src/test/java/javFiles/Lambda3.jav new file mode 100644 index 00000000..9e22f302 --- /dev/null +++ b/src/test/java/javFiles/Lambda3.jav @@ -0,0 +1,24 @@ +import java.lang.String; + +public class Lambda2 +{ + /* + public static List map(List input, + Function func){ + input.add(func.apply(input.get())); + } + */ + public map(input,func){ + input.add(func.apply(input.get())); + return map(new List(), func); + } +} + +class List{ + A get(); + void add(A); +} + +class Function{ + B apply(A a); +} \ No newline at end of file diff --git a/src/test/java/javFiles/LambdaField.jav b/src/test/java/javFiles/LambdaField.jav new file mode 100644 index 00000000..4eb53738 --- /dev/null +++ b/src/test/java/javFiles/LambdaField.jav @@ -0,0 +1,6 @@ +public class LambdaField { + + f = x -> x; + +} + diff --git a/src/test/java/javFiles/LambdaRunnable.jav b/src/test/java/javFiles/LambdaRunnable.jav new file mode 100644 index 00000000..37924ea2 --- /dev/null +++ b/src/test/java/javFiles/LambdaRunnable.jav @@ -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(); + } +} + diff --git a/src/test/java/javFiles/ListenerOverload.jav b/src/test/java/javFiles/ListenerOverload.jav new file mode 100644 index 00000000..e1a8d65d --- /dev/null +++ b/src/test/java/javFiles/ListenerOverload.jav @@ -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 left; + B right; +} \ No newline at end of file diff --git a/src/test/java/javFiles/Matrix.jav b/src/test/java/javFiles/Matrix.jav new file mode 100644 index 00000000..5e1eac08 --- /dev/null +++ b/src/test/java/javFiles/Matrix.jav @@ -0,0 +1,28 @@ +import java.util.Vector; +import java.lang.Integer; + +class Matrix extends Vector> { + 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(); + 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; + } +} diff --git a/src/test/java/javFiles/Meth_Gen.jav b/src/test/java/javFiles/Meth_Gen.jav new file mode 100644 index 00000000..056dd82f --- /dev/null +++ b/src/test/java/javFiles/Meth_Gen.jav @@ -0,0 +1,11 @@ +class Meth_Gen { + + m1(x, y) { + m2(x); + x = y; + } + + m2(y) { + m1(y, y); + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/MethodCallGenerics.jav b/src/test/java/javFiles/MethodCallGenerics.jav new file mode 100644 index 00000000..0d02509b --- /dev/null +++ b/src/test/java/javFiles/MethodCallGenerics.jav @@ -0,0 +1,14 @@ +import java.lang.String; + +class Generics { + // A mt1(A a, B b){ + B mt1(B a, B b){ + return mt1(a, a); + } +} + +class Test { + methode(String s){ + return new Generics().mt1(s,s); + } +} diff --git a/src/test/java/javFiles/Methods.jav b/src/test/java/javFiles/Methods.jav new file mode 100644 index 00000000..e45d9830 --- /dev/null +++ b/src/test/java/javFiles/Methods.jav @@ -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){} +} \ No newline at end of file diff --git a/src/test/java/javFiles/MethodsEasy.jav b/src/test/java/javFiles/MethodsEasy.jav new file mode 100644 index 00000000..ee6f9daf --- /dev/null +++ b/src/test/java/javFiles/MethodsEasy.jav @@ -0,0 +1,7 @@ + +class Methods { + mt4(a,b,c) { return a.mt3(b).mt3(c) ; } + + mt3(a) {return a.mt3(a); } +} + diff --git a/src/test/java/javFiles/Op1.jav b/src/test/java/javFiles/Op1.jav new file mode 100644 index 00000000..800f58b8 --- /dev/null +++ b/src/test/java/javFiles/Op1.jav @@ -0,0 +1,11 @@ +public class Op1{ + public Op1() { + + Runnable lam = () -> { + String test = ""; + String b = "b"; + test = b; + System.out.println(test);}; + //lam.run(); + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/Package.jav b/src/test/java/javFiles/Package.jav new file mode 100644 index 00000000..bbc1e51d --- /dev/null +++ b/src/test/java/javFiles/Package.jav @@ -0,0 +1,5 @@ +package strucType.input; + +class Neu +{ +} \ No newline at end of file diff --git a/src/test/java/javFiles/Sorting.jav b/src/test/java/javFiles/Sorting.jav new file mode 100644 index 00000000..04ef23e5 --- /dev/null +++ b/src/test/java/javFiles/Sorting.jav @@ -0,0 +1,8 @@ +import java.util.List; +import java.util.Collection; + +class Sorting{ + void merge(a, b){ + a.addAll(b); + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/Subclass.jav b/src/test/java/javFiles/Subclass.jav new file mode 100644 index 00000000..fe6e9208 --- /dev/null +++ b/src/test/java/javFiles/Subclass.jav @@ -0,0 +1,6 @@ +public class Subclass extends Superclass { + + public void printMethod() { + super.printMethod(); + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/Superclass.jav b/src/test/java/javFiles/Superclass.jav new file mode 100644 index 00000000..d58089de --- /dev/null +++ b/src/test/java/javFiles/Superclass.jav @@ -0,0 +1,6 @@ +public class Superclass { + + public void printMethod() { + System.out.println("Printed in Superclass."); + } +} diff --git a/src/test/java/javFiles/Vector.jav b/src/test/java/javFiles/Vector.jav new file mode 100644 index 00000000..5c21cfff --- /dev/null +++ b/src/test/java/javFiles/Vector.jav @@ -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; +} +} \ No newline at end of file diff --git a/src/test/java/javFiles/fc.jav b/src/test/java/javFiles/fc.jav new file mode 100644 index 00000000..a3278cbc --- /dev/null +++ b/src/test/java/javFiles/fc.jav @@ -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); +} \ No newline at end of file diff --git a/src/test/java/javFiles/mathStruc.jav b/src/test/java/javFiles/mathStruc.jav new file mode 100644 index 00000000..93f901ce --- /dev/null +++ b/src/test/java/javFiles/mathStruc.jav @@ -0,0 +1,13 @@ + +class mathStruc { + +mathStruc(A a) { } + +A model(){ A a; return a; } + +methode(){ +var innerOp = o -> ms -> + new mathStruc(o.apply(this.model(),ms.model())); + return innerOp; + } +} \ No newline at end of file diff --git a/src/test/java/javFiles/test.jav b/src/test/java/javFiles/test.jav new file mode 100644 index 00000000..303d167a --- /dev/null +++ b/src/test/java/javFiles/test.jav @@ -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); +} \ No newline at end of file diff --git a/src/test/java/javFiles/test1.jav b/src/test/java/javFiles/test1.jav new file mode 100644 index 00000000..4b34948e --- /dev/null +++ b/src/test/java/javFiles/test1.jav @@ -0,0 +1,7 @@ +class Faculty { + + int a; + m (int x) { + return a+x; + } +} diff --git a/src/test/java/log4jTesting.xml b/src/test/java/log4jTesting.xml new file mode 100755 index 00000000..dc30c245 --- /dev/null +++ b/src/test/java/log4jTesting.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/parser/AntlrTest.jav b/src/test/java/parser/AntlrTest.jav new file mode 100644 index 00000000..31ab067d --- /dev/null +++ b/src/test/java/parser/AntlrTest.jav @@ -0,0 +1,6 @@ +class Test{ +method(){ + if(true)i++; + if(true)i--; + else i++; +}} \ No newline at end of file diff --git a/src/test/java/parser/BoundedParameter.jav b/src/test/java/parser/BoundedParameter.jav new file mode 100644 index 00000000..6d7518a9 --- /dev/null +++ b/src/test/java/parser/BoundedParameter.jav @@ -0,0 +1,3 @@ +class Matrix{ + String op = "String"; +} diff --git a/src/test/java/parser/CastTest.jav b/src/test/java/parser/CastTest.jav new file mode 100644 index 00000000..86ca7519 --- /dev/null +++ b/src/test/java/parser/CastTest.jav @@ -0,0 +1,8 @@ + +class CastTest{ +void methode(){ + Object a; + String b; + a = (Object) b; +} +} \ No newline at end of file diff --git a/src/test/java/parser/ExtendsTest.jav b/src/test/java/parser/ExtendsTest.jav new file mode 100644 index 00000000..9103f463 --- /dev/null +++ b/src/test/java/parser/ExtendsTest.jav @@ -0,0 +1,4 @@ +class C1 extends Object +{ + m(para) { return para; } +} \ No newline at end of file diff --git a/src/test/java/parser/FeatherWeightJava.jav b/src/test/java/parser/FeatherWeightJava.jav new file mode 100644 index 00000000..e607b12a --- /dev/null +++ b/src/test/java/parser/FeatherWeightJava.jav @@ -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(); } +} + diff --git a/src/test/java/parser/FieldInitializationTest.jav b/src/test/java/parser/FieldInitializationTest.jav new file mode 100644 index 00000000..f7818cc3 --- /dev/null +++ b/src/test/java/parser/FieldInitializationTest.jav @@ -0,0 +1,3 @@ +class FieldInitializationTest{ + var var = "hallo"; +} \ No newline at end of file diff --git a/src/test/java/parser/FieldVarTest.jav b/src/test/java/parser/FieldVarTest.jav new file mode 100644 index 00000000..6e897824 --- /dev/null +++ b/src/test/java/parser/FieldVarTest.jav @@ -0,0 +1,5 @@ +package test; + +class Test{ +Typ a; +} \ No newline at end of file diff --git a/src/test/java/parser/GeneralParserTest.java b/src/test/java/parser/GeneralParserTest.java index f7180a74..4e7d9868 100644 --- a/src/test/java/parser/GeneralParserTest.java +++ b/src/test/java/parser/GeneralParserTest.java @@ -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 filenames = new ArrayList(); - /* - 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 filenames = new ArrayList(); + /* + 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); + } + } diff --git a/src/test/java/parser/GenericFieldVarTest.jav b/src/test/java/parser/GenericFieldVarTest.jav new file mode 100644 index 00000000..a47b41eb --- /dev/null +++ b/src/test/java/parser/GenericFieldVarTest.jav @@ -0,0 +1,3 @@ +class Test{ + A var; +} diff --git a/src/test/java/parser/ImportTest.jav b/src/test/java/parser/ImportTest.jav new file mode 100644 index 00000000..2de55cee --- /dev/null +++ b/src/test/java/parser/ImportTest.jav @@ -0,0 +1,4 @@ +import java.util.*; + +class ImportTest{ +} \ No newline at end of file diff --git a/src/test/java/parser/ImportTest2.jav b/src/test/java/parser/ImportTest2.jav new file mode 100644 index 00000000..3492e31c --- /dev/null +++ b/src/test/java/parser/ImportTest2.jav @@ -0,0 +1,4 @@ +import java.util.ArrayList; + +class ImportTest{ +} \ No newline at end of file diff --git a/src/test/java/parser/ImportTestGeneric.jav b/src/test/java/parser/ImportTestGeneric.jav new file mode 100644 index 00000000..094f4c5e --- /dev/null +++ b/src/test/java/parser/ImportTestGeneric.jav @@ -0,0 +1,5 @@ +import java.util.List; + +class ImportTest{ + List test; +} \ No newline at end of file diff --git a/src/test/java/parser/NewTest.jav b/src/test/java/parser/NewTest.jav new file mode 100644 index 00000000..992a2e8d --- /dev/null +++ b/src/test/java/parser/NewTest.jav @@ -0,0 +1,5 @@ + +class NewTest { +main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new +NewTest(3)); } +} \ No newline at end of file diff --git a/src/test/java/parser/OpratorTest.jav b/src/test/java/parser/OpratorTest.jav new file mode 100644 index 00000000..2764adf4 --- /dev/null +++ b/src/test/java/parser/OpratorTest.jav @@ -0,0 +1,12 @@ +import java.lang.Integer; + +class OpratorTest { + m(Integer a, Integer b) { + c = a+b; +// d = a-b; +// e = a*b; +// f = a/b; + + return c; + } +} \ No newline at end of file diff --git a/src/test/java/parser/PackageNameTest.jav b/src/test/java/parser/PackageNameTest.jav new file mode 100644 index 00000000..53c889b7 --- /dev/null +++ b/src/test/java/parser/PackageNameTest.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; +import java.lang.Comparable; + +class PackageNameTest{ +java.lang.Integer test(a){return a;} + +Comparable test2(a){return a;} + +} \ No newline at end of file diff --git a/src/test/java/parser/StatementsTest.jav b/src/test/java/parser/StatementsTest.jav new file mode 100644 index 00000000..891dff12 --- /dev/null +++ b/src/test/java/parser/StatementsTest.jav @@ -0,0 +1,8 @@ +class Statements{ + +public void methodeTest(){ + methodeTest(); + return null; +} + +} diff --git a/src/test/java/parser/StructuralTypes.jav b/src/test/java/parser/StructuralTypes.jav new file mode 100644 index 00000000..b3c210c8 --- /dev/null +++ b/src/test/java/parser/StructuralTypes.jav @@ -0,0 +1,5 @@ + +class A { + mt(x, y, z) { return x.sub(y).add(z); } +} + diff --git a/src/test/java/parser/WhileTest.jav b/src/test/java/parser/WhileTest.jav new file mode 100644 index 00000000..2ce192bd --- /dev/null +++ b/src/test/java/parser/WhileTest.jav @@ -0,0 +1,14 @@ +class WhileTest{ + void methode(){ + Boolean test; + do{ + test=test; + }while(test); + + + while(test){ + test = test; + } + return; + } +} \ No newline at end of file diff --git a/src/test/java/typeinference/UnifyTest.java b/src/test/java/typeinference/UnifyTest.java index dd352f85..38af248e 100644 --- a/src/test/java/typeinference/UnifyTest.java +++ b/src/test/java/typeinference/UnifyTest.java @@ -53,12 +53,12 @@ public class UnifyTest { public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); } - + @Test public void lambdafield() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"LambdaField.jav")); } - + @Test public void mathStruc() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"mathStruc.jav")); @@ -80,16 +80,16 @@ public class UnifyTest { execute(new File(rootDirectory+"FacultyTyped.jav")); } */ - + @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); - //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); - //compiler.generateBytecode(); + //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); + //compiler.generateBytecode(); } + - -/* +/* @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); diff --git a/src/test/resources/bytecodeJavFiles/AssignToLit.jav b/src/test/resources/bytecodeJavFiles/AssignToLit.jav new file mode 100644 index 00000000..873828ed --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/AssignToLit.jav @@ -0,0 +1,30 @@ +import java.lang.Integer; +import java.lang.Boolean; +import java.lang.String; +import java.lang.Byte; +import java.lang.Short; +import java.lang.Long; +import java.lang.Float; +import java.lang.Double; +import java.lang.Character; + +class AssignToLit { + void m(){ +// String s = "Test"; +// Boolean b = false; +// Byte byte1 = 5; +// Byte byte2 = 55; +// Short short1 = 5; +// Short short2 = 55; +// Integer int1 = 5; +// Integer int2 = 8888888; +// Long long1 = 1; +// Long long2 = 5; +// Long long3 = 89989898; +// Float float1 = 1; +// Float float2 = 55; +// Double d1 = 1; +// Double d2 = 55; + Character c = 'A'; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/BinaryInMeth.jav b/src/test/resources/bytecodeJavFiles/BinaryInMeth.jav new file mode 100644 index 00000000..3b5fa77b --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/BinaryInMeth.jav @@ -0,0 +1,17 @@ +import java.lang.Integer; +import java.lang.Double; + +public class BinaryInMeth { + + m(a){ + return ++a; + } + + m2(a,b){ + return m(a+b); + } + + m3(a) { + return m(++a); + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/DuMethod.jav b/src/test/resources/bytecodeJavFiles/DuMethod.jav new file mode 100644 index 00000000..3898a7ba --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/DuMethod.jav @@ -0,0 +1,11 @@ +public class DuMethod{ + + method(a){ + return a+a; + } + + method(a){ + return a; + } + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/EmptyMethod.jav b/src/test/resources/bytecodeJavFiles/EmptyMethod.jav new file mode 100644 index 00000000..961989df --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/EmptyMethod.jav @@ -0,0 +1,8 @@ +public class EmptyMethod{ + + public void m1(){ + System.out.println("test"); + } + + public void m2(){} +} diff --git a/src/test/resources/bytecodeJavFiles/Example.jav b/src/test/resources/bytecodeJavFiles/Example.jav new file mode 100644 index 00000000..b7455a3f --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Example.jav @@ -0,0 +1,9 @@ +import java.lang.String; + +public class Example { + + public m() { + String x = "X"; + return x; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Exceptions.jav b/src/test/resources/bytecodeJavFiles/Exceptions.jav new file mode 100644 index 00000000..9903511c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Exceptions.jav @@ -0,0 +1,3 @@ +public class Exceptions { +// m(Integer i) throws +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Fac.jav b/src/test/resources/bytecodeJavFiles/Fac.jav new file mode 100644 index 00000000..28650b45 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Fac.jav @@ -0,0 +1,15 @@ +import java.lang.Integer; +//import java.lang.Double; + +public class Fac { + + getFac(n){ + var res = 1; + var i = 1; + while(i<=n) { + res = res * i; + i++; + } + return res; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Faculty.jav b/src/test/resources/bytecodeJavFiles/Faculty.jav new file mode 100644 index 00000000..2754b7f8 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Faculty.jav @@ -0,0 +1,48 @@ +import java.lang.Integer; + +public class Faculty { + public fact; + Faculty() { + fact = (x) -> { + if (x == 1) { + return 1; + } + else { + return x * (fact.apply(x-1)); + } + }; + } + + + public getFact(x) { + return fact.apply(x); + } +// m (x) { +// +//// var fact = (x) -> { +//// if (x == 1) { +//// return x; +//// } +//// else { +//// return x * (fact.apply(x-1)); +//// } +//// }; +//// return fact; +//// var x = 13; +//// if(x>22) { +//// return 0; +//// }else if(x <1){ +//// return x; +//// }else { +//// return 1; +//// } +// +// if (x < 0) { +// return 0; +// }else if(x<2) { +// return x; +// } else { +// return x * m(x-1); +// } +// } +} diff --git a/src/test/resources/bytecodeJavFiles/Faculty2.jav b/src/test/resources/bytecodeJavFiles/Faculty2.jav new file mode 100644 index 00000000..828f06f5 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Faculty2.jav @@ -0,0 +1,10 @@ +class Faculty2 { + + m () { + + var fact = (Integer x) -> { + return x; + }; + return fact; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Field.jav b/src/test/resources/bytecodeJavFiles/Field.jav new file mode 100644 index 00000000..b19b2308 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Field.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; + +public class Field { + public Integer x = 5; + + m(){ + return x; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/FieldTph.jav b/src/test/resources/bytecodeJavFiles/FieldTph.jav new file mode 100644 index 00000000..fc74e539 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/FieldTph.jav @@ -0,0 +1,4 @@ +public class FieldTph { + a; + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/FieldTph2.jav b/src/test/resources/bytecodeJavFiles/FieldTph2.jav new file mode 100644 index 00000000..7d60b683 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/FieldTph2.jav @@ -0,0 +1,12 @@ +public class FieldTph2 { + a; + + m(b){ + b = a; + return b; + } + + m2(c){ + a = c; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/FieldTphConsMeth.jav b/src/test/resources/bytecodeJavFiles/FieldTphConsMeth.jav new file mode 100644 index 00000000..e749bb4f --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/FieldTphConsMeth.jav @@ -0,0 +1,11 @@ +public class FieldTphConsMeth { + + a; + public FieldTphConsMeth(c) { + a = m(c); + } + + m(b) { + return b; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/For.jav b/src/test/resources/bytecodeJavFiles/For.jav new file mode 100644 index 00000000..c4bd6677 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/For.jav @@ -0,0 +1,30 @@ +import java.lang.Integer; +import java.lang.Boolean; + +class For{ + Integer m(Integer x){ + var c = x + 2; +// Boolean b = true; +// c = 5; +// c++; +// ++c; +// c--; +// --c; +// while(x<2){ +// x = x +1; +// b = false; +// } + return c; +// for(int i = 0;i<10;i++) { +// x = x + 5; +// } + } + +// m2(Integer x){ +// if(x<2) { +// return 1; +// }else { +// return 2; +// } +// } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/FunOL.jav b/src/test/resources/bytecodeJavFiles/FunOL.jav new file mode 100644 index 00000000..60736e1f --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/FunOL.jav @@ -0,0 +1,12 @@ +import java.util.Vector; +import java.lang.Integer; +import java.lang.String; +//import java.lang.Byte; +//import java.lang.Boolean; + +public class FunOL { + + add(f, y) { + return f.apply() + y; + } +} diff --git a/src/test/resources/bytecodeJavFiles/Gen.jav b/src/test/resources/bytecodeJavFiles/Gen.jav new file mode 100644 index 00000000..3b58b188 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Gen.jav @@ -0,0 +1,8 @@ +import java.lang.Integer; +import java.util.Vector; + +public class Gen{ + Vector m(Vector v){ + return v; + } +} diff --git a/src/test/resources/bytecodeJavFiles/Generics.jav b/src/test/resources/bytecodeJavFiles/Generics.jav new file mode 100644 index 00000000..bb7b2af5 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Generics.jav @@ -0,0 +1,17 @@ + +class Generics { + Generics(B b){ + } + B mt1(B b){ + return mt1(b); + } +} + + +/* +Problem: +auto test = new List(); +auto test2 = new List(); +... //code, welcher möglicherweise test und test2 vertauscht +test.add("hallo"); +*/ \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Generics2.jav b/src/test/resources/bytecodeJavFiles/Generics2.jav new file mode 100644 index 00000000..52d5caa2 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Generics2.jav @@ -0,0 +1,6 @@ +class Generics2{ + B m1(B b){ + return b; + } + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/GreaterEqual.jav b/src/test/resources/bytecodeJavFiles/GreaterEqual.jav new file mode 100644 index 00000000..3ec69e8a --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/GreaterEqual.jav @@ -0,0 +1,57 @@ +import java.lang.Integer; +import java.lang.Long; +import java.lang.Float; +import java.lang.Double; + +public class GreaterEqual { + + gE(Integer a, Integer b){ + var c = a>=b; + return c; + } + + gE(Long a, Long b){ + var c = a>=b; + return c; + } + + gE(Float a, Float b){ + var c = a>=b; + return c; + } + + gE(Double a, Double b){ + var c = a>=b; + return c; + } + + gE(Long a, Integer b){ + var c = a>=b; + return c; + } + + gE(Float a, Integer b){ + var c = a>=b; + return c; + } + + gE(Double a, Integer b){ + var c = a>=b; + return c; + } + + gE(Float a, Long b){ + var c = a>=b; + return c; + } + + gE(Double a, Long b){ + var c = a>=b; + return c; + } + + gE(Double a, Float b){ + var c = a>=b; + return c; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/GreaterThan.jav b/src/test/resources/bytecodeJavFiles/GreaterThan.jav new file mode 100644 index 00000000..9077f5b1 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/GreaterThan.jav @@ -0,0 +1,56 @@ +import java.lang.Integer; +import java.lang.Long; +import java.lang.Float; +import java.lang.Double; + +public class GreaterThan { + gT(Integer a, Integer b){ + var c = a>b; + return c; + } + + gT(Long a, Long b){ + var c = a>b; + return c; + } + + gT(Float a, Float b){ + var c = a>b; + return c; + } + + gT(Double a, Double b){ + var c = a>b; + return c; + } + + gT(Long a, Integer b){ + var c = a>b; + return c; + } + + gT(Float a, Integer b){ + var c = a>b; + return c; + } + + gT(Double a, Integer b){ + var c = a>b; + return c; + } + + gT(Float a, Long b){ + var c = a>b; + return c; + } + + gT(Double a, Long b){ + var c = a>b; + return c; + } + + gT(Double a, Float b){ + var c = a>b; + return c; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/IfTest.jav b/src/test/resources/bytecodeJavFiles/IfTest.jav new file mode 100644 index 00000000..bbcda96c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/IfTest.jav @@ -0,0 +1,15 @@ +import java.lang.Integer; +import java.lang.Boolean; +import java.lang.String; + +public class IfTest{ + Integer m1(Boolean b) { + Integer i; + String b; + if(b) { + return i; + }else{ + return b; + } + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Import.jav b/src/test/resources/bytecodeJavFiles/Import.jav new file mode 100644 index 00000000..c658568f --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Import.jav @@ -0,0 +1,8 @@ +import java.util.Vector; + +class Import { + void methode(){ + Vector v = new Vector<>(); + v.add("X"); + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Interface1.jav b/src/test/resources/bytecodeJavFiles/Interface1.jav new file mode 100644 index 00000000..b741819c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Interface1.jav @@ -0,0 +1,3 @@ +public interface Interface1{ + public void test(); +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/LamRunnable.jav b/src/test/resources/bytecodeJavFiles/LamRunnable.jav new file mode 100644 index 00000000..451858f2 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/LamRunnable.jav @@ -0,0 +1,9 @@ +public class LamRunnable{ + + public LamRunnable(){ + + Runnable lam = () -> {System.out.println("lambda");}; + lam.run(); + } +} + \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Lambda.jav b/src/test/resources/bytecodeJavFiles/Lambda.jav new file mode 100644 index 00000000..b0321fc2 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Lambda.jav @@ -0,0 +1,10 @@ +import java.lang.Integer; + +public class Lambda { + + m () { + var lam1 = (x) -> { + return x; + }; + return lam1; +} diff --git a/src/test/resources/bytecodeJavFiles/Lambda2.jav b/src/test/resources/bytecodeJavFiles/Lambda2.jav new file mode 100644 index 00000000..92f32b71 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Lambda2.jav @@ -0,0 +1,35 @@ +import java.lang.String; + +public class Lambda2 +{ + public static void main(List args){ + var listOfStrings = new List(); + var listOfObjects; + listOfObjects = map(listOfStrings, (a) -> a); +} + +public map(a , b){ + b.apply(a); + return a; +} + +/* +public static List map(List input, Function func) { + List output; + output = new List(); + output.add(func.apply(input.get())); + return output; +} +*/ +} + +class List{ + /* A get(); + void add(A); + */ +} +/* +class Function{ + B apply(A a); +} +*/ \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Lambda3.jav b/src/test/resources/bytecodeJavFiles/Lambda3.jav new file mode 100644 index 00000000..9c4e960c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Lambda3.jav @@ -0,0 +1,23 @@ + +public class Lambda2 +{ + /* + public static List map(List input, + Function func){ + input.add(func.apply(input.get())); + } + */ + public map(input,func){ + input.add(func.apply(input.get())); + return map(new List(), func); + } +} + +class List{ + A get(); + void add(A); +} + +class Function{ + B apply(A a); +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Lambda4.jav b/src/test/resources/bytecodeJavFiles/Lambda4.jav new file mode 100644 index 00000000..378eb4d3 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Lambda4.jav @@ -0,0 +1,18 @@ +class Lambda{ + +methode(){ + return ((f) -> f); +} +} +/* +interface Fun0{ + A apply(); +} + +interface Fun1{ + A apply(B b); +} +*/ +interface Fun2{ + A apply(B b, C c); +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/LambdaCapture.jav b/src/test/resources/bytecodeJavFiles/LambdaCapture.jav new file mode 100644 index 00000000..ab1751f4 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/LambdaCapture.jav @@ -0,0 +1,12 @@ +import java.lang.Integer; +public class LambdaCapture { + Integer i = 8; + f; + public LambdaCapture(){ + Integer w = 7; + f = j ->{ + return w+i;}; + + } + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/LambdaVoid.jav b/src/test/resources/bytecodeJavFiles/LambdaVoid.jav new file mode 100644 index 00000000..dc16fcbf --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/LambdaVoid.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; + +public class Lambda { + + m () { + var lam1 = (x) -> { }; + return lam1; + } +} diff --git a/src/test/resources/bytecodeJavFiles/LessEqual.jav b/src/test/resources/bytecodeJavFiles/LessEqual.jav new file mode 100644 index 00000000..2e3b7024 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/LessEqual.jav @@ -0,0 +1,56 @@ +import java.lang.Integer; +import java.lang.Long; +import java.lang.Float; +import java.lang.Double; + +public class LessEqual { + lessEqual(Integer a, Integer b){ + var c = a<=b; + return c; + } + + lessEqual(Long a, Long b){ + var c = a<=b; + return c; + } + + lessEqual(Float a, Float b){ + var c = a<=b; + return c; + } + + lessEqual(Double a, Double b){ + var c = a<=b; + return c; + } + + lessEqual(Long a, Integer b){ + var c = a<=b; + return c; + } + + lessEqual(Float a, Integer b){ + var c = a<=b; + return c; + } + + lessEqual(Double a, Integer b){ + var c = a<=b; + return c; + } + + lessEqual(Float a, Long b){ + var c = a<=b; + return c; + } + + lessEqual(Double a, Long b){ + var c = a<=b; + return c; + } + + lessEqual(Double a, Float b){ + var c = a<=b; + return c; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/LessThan.jav b/src/test/resources/bytecodeJavFiles/LessThan.jav new file mode 100644 index 00000000..04e1e83e --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/LessThan.jav @@ -0,0 +1,57 @@ +import java.lang.Integer; +import java.lang.Long; +import java.lang.Float; +import java.lang.Double; + +public class LessThan { + + lessThan(Integer a, Integer b){ + var c = a> { + + Matrix () { + } + + Matrix(vv) { + Integer i; + i = 0; + while(i < vv.size()) { +// Boolean a = this.add(vv.elementAt(i)); + this.add(vv.elementAt(i)); + i=i+1; + } + } + + mul(m) { + var ret = new Matrix(); + var i = 0; + while(i < size()) { + var v1 = this.elementAt(i); + var v2 = new Vector(); + 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); + k++; } +// v2.addElement(new Integer(erg)); + v2.addElement(erg); + j++; } + ret.addElement(v2); + i++; + } + return ret; + } +} diff --git a/src/test/resources/bytecodeJavFiles/MatrixOP.jav b/src/test/resources/bytecodeJavFiles/MatrixOP.jav new file mode 100644 index 00000000..828a270b --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/MatrixOP.jav @@ -0,0 +1,43 @@ +import java.util.Vector; +import java.lang.Integer; +//import java.lang.Byte; +import java.lang.Boolean; + +public class MatrixOP extends Vector> { + + MatrixOP () { + } + + MatrixOP(vv) { + Integer i; + i = 0; + while(i < vv.size()) { +// Boolean a = this.add(vv.elementAt(i)); + this.add(vv.elementAt(i)); + i=i+1; + } + } + + mul = (m1, m2) -> { + var ret = new MatrixOP(); + var i = 0; + while(i < size()) { + var v1 = m1.elementAt(i); + var v2 = new Vector(); + var j = 0; + while(j < v1.size()) { + var erg = 0; + var k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k) + * m2.elementAt(k).elementAt(j); + k++; } +// v2.addElement(new Integer(erg)); + v2.addElement(erg); + j++; } + ret.addElement(v2); + i++; + } + return ret; + }; +} diff --git a/src/test/resources/bytecodeJavFiles/Merge.jav b/src/test/resources/bytecodeJavFiles/Merge.jav new file mode 100644 index 00000000..9240146e --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Merge.jav @@ -0,0 +1,20 @@ +import java.util.List; +import java.lang.Integer; +import java.util.Collection; + +class Merge { + + merge(a, b) { + a.addAll(b); + return a; + } + + + + sort(in){ + var firstHalf = in.subList(1,2); + var secondHalf = in.subList(1,2); + return merge(sort(firstHalf), sort(secondHalf)); + } + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Methods.jav b/src/test/resources/bytecodeJavFiles/Methods.jav new file mode 100644 index 00000000..3c46739d --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Methods.jav @@ -0,0 +1,14 @@ +import java.lang.Integer; + +class Methods { + + m(a,b){ + var c=a+b; + return c; + } + + method2(x){ + Integer i = this.m(x,2); + return i; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/OL.jav b/src/test/resources/bytecodeJavFiles/OL.jav new file mode 100644 index 00000000..700e50f0 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/OL.jav @@ -0,0 +1,22 @@ +import java.lang.String; +import java.lang.Integer; +import java.lang.Double; + + + +public class OL { + + m(x) { return x + x; } + +} + + + +public class OLMain { + + main(x) { + var ol; + ol = new OL(); + return ol.m(x); + } +} diff --git a/src/test/resources/bytecodeJavFiles/Op.jav b/src/test/resources/bytecodeJavFiles/Op.jav new file mode 100644 index 00000000..082f48d8 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Op.jav @@ -0,0 +1,16 @@ +import java.lang.Integer; +import java.lang.String; +import java.lang.Long; +import java.lang.Float; +import java.lang.Double; +import java.lang.Boolean; +import java.lang.Short; +import java.lang.Byte; + +public class Op { + + m(a, b) { + //var c = a+b; + return a+b; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Op2.jav b/src/test/resources/bytecodeJavFiles/Op2.jav new file mode 100644 index 00000000..9d446eb2 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Op2.jav @@ -0,0 +1,11 @@ +import java.lang.Integer; +import java.lang.String; + +public class Op2 { + m(){ + var x = ""; + var a = 5+x; + + return a; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/OverlaodGen.jav b/src/test/resources/bytecodeJavFiles/OverlaodGen.jav new file mode 100644 index 00000000..d5946496 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/OverlaodGen.jav @@ -0,0 +1,11 @@ +import java.util.Vector; + +class OverlaodGen { + void method(Vector v) { +// Integer i = v.get(0); + } + + void method(Vector v) { +// String s = v.get(0); + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Overloading.jav b/src/test/resources/bytecodeJavFiles/Overloading.jav new file mode 100644 index 00000000..fb48fe0f --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Overloading.jav @@ -0,0 +1,18 @@ +import java.lang.String; + +public class Overloading{ + + test(x){ + return x.methode(); + } + + methode(){ + return "Overloading"; + } +} + +public class Overloading2{ + methode(){ + return "Overloading2"; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Plus.jav b/src/test/resources/bytecodeJavFiles/Plus.jav new file mode 100644 index 00000000..1cdecc8c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Plus.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; +import java.lang.String; + +public class Plus { + + m(a,b) { + return a+b; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/PostIncDec.jav b/src/test/resources/bytecodeJavFiles/PostIncDec.jav new file mode 100644 index 00000000..29c2ef17 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/PostIncDec.jav @@ -0,0 +1,27 @@ +import java.lang.Integer; + +public class PostIncDec { + m() { + var i = 0; + i++; + return i; + } + + m2() { + var i = 0; + var j = i++; + return j; + } + + d() { + var i = 0; + i--; + return i; + } + + d2() { + var i = 0; + var j = i--; + return j; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/PreInc.jav b/src/test/resources/bytecodeJavFiles/PreInc.jav new file mode 100644 index 00000000..011501f1 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/PreInc.jav @@ -0,0 +1,28 @@ +import java.lang.Integer; + +public class PreInc { + m() { + var i = 0; + ++i; + return i; + } + + m2() { + var i = 0; + var j = ++i; + return j; + } + + d() { + var i = 0; + --i; + return i; + } + + d2() { + var i = 0; + var j = --i; + return j; + } + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/RecursiveMeth.jav b/src/test/resources/bytecodeJavFiles/RecursiveMeth.jav new file mode 100644 index 00000000..be35a43c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/RecursiveMeth.jav @@ -0,0 +1,5 @@ +public class RecursiveMeth{ + public Integer test(){ + return this.test(); + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/RelOps.jav b/src/test/resources/bytecodeJavFiles/RelOps.jav new file mode 100644 index 00000000..0fdd2cff --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/RelOps.jav @@ -0,0 +1,8 @@ +import java.lang.Integer; +import java.lang.Boolean; + +public class RelOps { + m(a,b){ + return a a){ + a = merge(a,a); + } +*/ +} diff --git a/src/test/resources/bytecodeJavFiles/StaticM.jav b/src/test/resources/bytecodeJavFiles/StaticM.jav new file mode 100644 index 00000000..66890033 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/StaticM.jav @@ -0,0 +1,10 @@ +public class StaticM { + + public static void m() { + System.out.println("Test"); + } + + public static void m2() { + m(); + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/SubMatrix.jav b/src/test/resources/bytecodeJavFiles/SubMatrix.jav new file mode 100644 index 00000000..f761321c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/SubMatrix.jav @@ -0,0 +1,13 @@ +import java.util.Vector; +import java.lang.Integer; + +public class Matrix2 extends Vector { + +} + +public class SubMatrix extends Matrix2 { + m(){ + Vector v = new Vector(); + v.add(1); + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Tph.jav b/src/test/resources/bytecodeJavFiles/Tph.jav new file mode 100644 index 00000000..4a49ac46 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Tph.jav @@ -0,0 +1,12 @@ +public class Tph { + + m(a,b){ + var c = m2(b); +// return a; + return m2(b); + } + + m2(b){ + return b; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Tph2.jav b/src/test/resources/bytecodeJavFiles/Tph2.jav new file mode 100644 index 00000000..c957eae6 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Tph2.jav @@ -0,0 +1,10 @@ +public class Tph2 { + m(a,b){ + var c = m2(a,b); + return a; + } + + m2(a,b){ + return b; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Tph3.jav b/src/test/resources/bytecodeJavFiles/Tph3.jav new file mode 100644 index 00000000..f2bcd2ef --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Tph3.jav @@ -0,0 +1,13 @@ +public class Tph3 { +// m(a,b){ +// var c = m2(a,b); +// return c; +// } +// +// m2(a,b){ +// return m(a,b); +// } + m1(x, y) { m2(x); x = y; } + + m2(y) { m1(y, y); } +} diff --git a/src/test/resources/bytecodeJavFiles/Tph4.jav b/src/test/resources/bytecodeJavFiles/Tph4.jav new file mode 100644 index 00000000..1eb529de --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Tph4.jav @@ -0,0 +1,12 @@ +public class Tph4{ + m(a,b){ + var c = m2(b); + var d = m2(c); + return a; + } + + m2(b){ + return b + } + +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Tph5.jav b/src/test/resources/bytecodeJavFiles/Tph5.jav new file mode 100644 index 00000000..e73cfa2c --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Tph5.jav @@ -0,0 +1,13 @@ +public class Tph5 { +// m(a,b,c){ +// a = c; +// b = c; +// return a; +// } + + m(x,y){ + x = m2(y); + } + + m2(y) { return y; } +} diff --git a/src/test/resources/bytecodeJavFiles/VectorAdd.jav b/src/test/resources/bytecodeJavFiles/VectorAdd.jav new file mode 100644 index 00000000..814f46c2 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/VectorAdd.jav @@ -0,0 +1,19 @@ +import java.util.Vector; +import java.lang.Integer; +import java.lang.String; +//import java.lang.Byte; +//import java.lang.Boolean; + +public class VectorAdd { + + add(v1, v2) { + var ret = new Vector(); + var i = 0; + var erg; + while(i < v1.size()) { + erg = v1.elementAt(i) + v2.elementAt(i); + ret.addElement(erg); + } + return ret; + } +} diff --git a/src/test/resources/bytecodeJavFiles/VoidMeth.jav b/src/test/resources/bytecodeJavFiles/VoidMeth.jav new file mode 100644 index 00000000..6b3ab212 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/VoidMeth.jav @@ -0,0 +1,4 @@ +public class VoidMeth{ + public void test(){ + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/WC.jav b/src/test/resources/bytecodeJavFiles/WC.jav new file mode 100644 index 00000000..389a4fcd --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/WC.jav @@ -0,0 +1,8 @@ +import java.lang.Integer; +import java.util.List; +public class WC { + + void m (List a, List b) { + + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/While.jav b/src/test/resources/bytecodeJavFiles/While.jav new file mode 100644 index 00000000..cd2139a6 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/While.jav @@ -0,0 +1,12 @@ +import java.lang.Integer; +import java.lang.Long; +import java.lang.Double; + +public class While { + m(x) { + while(x < 2) { + x = x+1; + } + return x; + } +} \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/Y.jav b/src/test/resources/bytecodeJavFiles/Y.jav new file mode 100644 index 00000000..3c3e204d --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Y.jav @@ -0,0 +1,28 @@ +import java.lang.Integer; + +class Y { + y; + //factorial; + + Y() { + y = f -> t -> f.apply(y.apply(f)).apply(t); + //factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); }); + } +} + +/* +ergibt Parse-Error +class fac1 { + factorial; + + fac1() { + var y; + y = new Y<>().y; + factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); }); + } + public static void main(String args[]) { + System.out.println(new fac1().factorial.apply(3)); + } + +} +*/ \ No newline at end of file diff --git a/src/test/resources/bytecodeJavFiles/applyLambda.jav b/src/test/resources/bytecodeJavFiles/applyLambda.jav new file mode 100644 index 00000000..331bfbfe --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/applyLambda.jav @@ -0,0 +1,16 @@ +import java.util.Vector; +class Apply { } + +public class applyLambda { + + m () { + var lam1 = (x) -> { + return x; + }; + + return lam1.apply(new Apply()); + //return lam1; + //return new Vector(); + } +} + diff --git a/test/bytecode/FacultyTest.java b/test/bytecode/FacultyTest.java deleted file mode 100644 index c347456a..00000000 --- a/test/bytecode/FacultyTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package bytecode; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; - -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; - - @Test - public void generateBC() throws Exception { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Faculty.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("Faculty"); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - - Method getFact = classToTest.getDeclaredMethod("getFact", Integer.class); -// Field fact = classToTest.getDeclaredField("fact"); -// Class lambda = m.invoke(instanceOfClass).getClass(); -// 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); - // 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); - - assertEquals(6, result); - } - - -} diff --git a/test/bytecode/LambdaTest.java b/test/bytecode/LambdaTest.java deleted file mode 100644 index d2e69249..00000000 --- a/test/bytecode/LambdaTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package bytecode; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; - -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; - - @Test - public void generateBC() throws Exception { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Lambda.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("Lambda"); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - - 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); - - Integer i = 77; - System.out.println(m.invoke(instanceOfClass).toString()); - Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - - assertEquals(77, result); - } - - -} diff --git a/test/bytecode/MatrixOpTest.java b/test/bytecode/MatrixOpTest.java deleted file mode 100644 index 178aa43e..00000000 --- a/test/bytecode/MatrixOpTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package bytecode; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Vector; - -import org.junit.BeforeClass; -import org.junit.Test; - -import de.dhbwstuttgart.core.JavaTXCompiler; - -public class 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; - - @Test - public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/MatrixOP.jav"; - fileToTest = new File(path); - compiler = new JavaTXCompiler(fileToTest); - pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; - compiler.generateBytecode(pathToClassFile); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass("MatrixOP"); -/* - Vector> vv = new Vector>(); - Vector v1 = new Vector (); - v1.addElement(2); - v1.addElement(2); - Vector v2 = new Vector (); - 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> vv1 = new Vector>(); - Vector v3 = new Vector (); - v3.addElement(2); - v3.addElement(2); - Vector v4 = new Vector (); - 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()); - - Vector> res = new Vector>(); - Vector v5 = new Vector (); - v5.addElement(10); - v5.addElement(10); - Vector v6 = new Vector (); - 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); -*/ - } - -} diff --git a/test/bytecode/YTest.java b/test/bytecode/YTest.java deleted file mode 100644 index 1c4f13a6..00000000 --- a/test/bytecode/YTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package bytecode; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; - -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; - - @Test - public void generateBC() throws Exception { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/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); - - // Damit man auf die Methode zugreifen kann - apply.setAccessible(true); - - Integer i = 77; - - Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); - - assertEquals(77, result); - */ - } - - -}