From dbd5311d93268fbb37a7da56f3f1cb2845629233 Mon Sep 17 00:00:00 2001 From: Vic Nightfall Date: Wed, 23 Nov 2022 21:35:33 +0100 Subject: [PATCH] Fix the build by reinstating old classes --- .../bytecode/constraint/EqualConstraint.java | 9 + .../constraint/ExtendsConstraint.java | 9 + .../bytecode/constraint/TPHConstraint.java | 90 +++++++ .../ConstraintsWithSameLeftSide.java | 35 +++ .../GenericGeneratorResultsForAllMethods.java | 41 ++++ .../GenericGenratorResultForSourceFile.java | 52 ++++ .../GenericsGeneratorResult.java | 59 +++++ .../GenericsGeneratorResultForClass.java | 84 +++++++ .../MethodAndConstraints.java | 47 ++++ .../NameReplacementResult.java | 49 ++++ .../de/dhbwstuttgart/core/JavaTXCompiler.java | 10 +- .../typedeployment/TypeInsertFactory.java | 9 +- .../typedeployment/TypeInsertPlacer.java | 10 +- .../constraintSimplify/FamilyOfGenerics.java | 8 +- .../FamilyOfGeneratedGenericsTest.java | 228 ------------------ src/test/java/insertGenerics/TestAny.java | 112 --------- .../java/insertGenerics/TestClassField.java | 79 ------ .../insertGenerics/TestContraVariant.java | 112 --------- .../java/insertGenerics/TestExample42.java | 62 ----- .../TestExample42_allInOneMethod.java | 61 ----- .../java/insertGenerics/TestGGFinder.java | 99 -------- .../insertGenerics/TestLocalVarLambda.java | 112 --------- .../insertGenerics/TestMutualRecursion.java | 126 ---------- .../java/insertGenerics/TestReturnVar.java | 79 ------ .../TestSecondLineOfClassConstraints.java | 79 ------ .../insertGenerics/TestTPHsAndGenerics.java | 154 ------------ .../insertGenerics/TestTPHsAndGenerics2.java | 79 ------ .../java/insertGenerics/TestThreeArgs.java | 99 -------- .../insertGenerics/TestTransitiveClosure.java | 28 --- src/test/java/insertGenerics/TestTwoArgs.java | 111 --------- .../java/insertGenerics/TestTwoArgs2.java | 105 -------- .../java/insertGenerics/TestTwoCalls.java | 95 -------- src/test/java/insertGenerics/TestVector.java | 92 ------- .../java/insertGenerics/TestVectorArg.java | 92 ------- .../java/insertGenerics/TestVoidMeth.java | 79 ------ src/test/java/packages/OLOneFileTest.java | 4 +- src/test/java/targetast/GreaterEqualTest.java | 1 + src/test/java/targetast/GreaterThanTest.java | 1 + src/test/java/targetast/InheritTest.java | 1 + src/test/java/targetast/InheritTest2.java | 1 + src/test/java/targetast/LessEqualTest.java | 1 + src/test/java/targetast/LessThanTest.java | 1 + src/test/java/targetast/OLTest.java | 1 + src/test/java/targetast/PostIncTest.java | 1 + src/test/java/targetast/PreIncTest.java | 1 + src/test/java/targetast/PutTest.java | 1 + src/test/java/targetast/TestComplete.java | 1 + src/test/java/targetast/TphTest.java | 1 + src/test/java/targetast/WhileTest.java | 1 + 49 files changed, 507 insertions(+), 2105 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/ConstraintsWithSameLeftSide.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGenratorResultForSourceFile.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/NameReplacementResult.java delete mode 100644 src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java delete mode 100644 src/test/java/insertGenerics/TestAny.java delete mode 100644 src/test/java/insertGenerics/TestClassField.java delete mode 100644 src/test/java/insertGenerics/TestContraVariant.java delete mode 100644 src/test/java/insertGenerics/TestExample42.java delete mode 100644 src/test/java/insertGenerics/TestExample42_allInOneMethod.java delete mode 100644 src/test/java/insertGenerics/TestGGFinder.java delete mode 100644 src/test/java/insertGenerics/TestLocalVarLambda.java delete mode 100644 src/test/java/insertGenerics/TestMutualRecursion.java delete mode 100644 src/test/java/insertGenerics/TestReturnVar.java delete mode 100644 src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java delete mode 100644 src/test/java/insertGenerics/TestTPHsAndGenerics.java delete mode 100644 src/test/java/insertGenerics/TestTPHsAndGenerics2.java delete mode 100644 src/test/java/insertGenerics/TestThreeArgs.java delete mode 100644 src/test/java/insertGenerics/TestTransitiveClosure.java delete mode 100644 src/test/java/insertGenerics/TestTwoArgs.java delete mode 100644 src/test/java/insertGenerics/TestTwoArgs2.java delete mode 100644 src/test/java/insertGenerics/TestTwoCalls.java delete mode 100644 src/test/java/insertGenerics/TestVector.java delete mode 100644 src/test/java/insertGenerics/TestVectorArg.java delete mode 100644 src/test/java/insertGenerics/TestVoidMeth.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java new file mode 100644 index 00000000..69fb0b02 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/EqualConstraint.java @@ -0,0 +1,9 @@ +package de.dhbwstuttgart.bytecode.constraint; + +public class EqualConstraint extends TPHConstraint { + + public EqualConstraint(String left, String right) { + super(left, right, Relation.EQUAL); + } + +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java new file mode 100644 index 00000000..77007a3b --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/ExtendsConstraint.java @@ -0,0 +1,9 @@ +package de.dhbwstuttgart.bytecode.constraint; + +public class ExtendsConstraint extends TPHConstraint { + + public ExtendsConstraint(String left, String right) { + super(left, right, Relation.EXTENDS); + } + +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java new file mode 100644 index 00000000..0533a028 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java @@ -0,0 +1,90 @@ +package de.dhbwstuttgart.bytecode.constraint; + +import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; + +public class TPHConstraint { + protected String left; + protected String right; + protected Relation rel; + protected int variance; //noch nicht benutzt + public enum Relation{ + EXTENDS, EQUAL + } + + public TPHConstraint(Pair p) { + this.left = ((TypePlaceholder)p.TA1).getName(); + this.right = ((TypePlaceholder)p.TA2).getName(); + this.rel = p.GetOperator().equals(PairOperator.SMALLERDOT) ? Relation.EXTENDS : Relation.EQUAL; + } + + public TPHConstraint(String left, String right, Relation rel) { + this.left = left; + this.right = right; + this.rel = rel; + } + + public String getLeft() { + return left; + } + + + public String getRight() { + return right; + } + + + public Relation getRel() { + return rel; + } + + public void setLeft(String left) { + this.left = left; + } + + public void setRight(String right) { + this.right = right; + } + + public void setRel(Relation rel) { + this.rel = rel; + } + + public boolean containTPH(String tph) { + return left.equals(tph)||right.equals(tph); + } + + public boolean equalConstraint(TPHConstraint constraint) { + return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight()); + } + + @Override + public int hashCode() { + return (left+right).hashCode(); + } + + @Override + public boolean equals (Object o) { + if (o instanceof TPHConstraint) { + TPHConstraint o_tphcons = (TPHConstraint)o; + return (this.left.equals(o_tphcons.getLeft()) + && this.right.equals(o_tphcons.getRight()) + && this.rel.equals(o_tphcons.rel)); + } + else { + return false; + } + } + + + @Override + public String toString() { + if(rel == Relation.EXTENDS) { + return left + " < " + right; + }else { + return left + " = " + right; + } + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/ConstraintsWithSameLeftSide.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/ConstraintsWithSameLeftSide.java new file mode 100644 index 00000000..1b184048 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/ConstraintsWithSameLeftSide.java @@ -0,0 +1,35 @@ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import java.util.List; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; + +public class ConstraintsWithSameLeftSide { + private List constraints; + + /** + * @param constraints + */ + public ConstraintsWithSameLeftSide(List constraints) { + this.constraints = constraints; + } + + /** + * @return the constraints + */ + public List getConstraints() { + return constraints; + } + + /** + * @param constraints the constraints to set + */ + public void setConstraints(List constraints) { + this.constraints = constraints; + } + + @Override + public String toString() { + return "[" + constraints.toString() + "]"; + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java new file mode 100644 index 00000000..091587ff --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGeneratorResultsForAllMethods.java @@ -0,0 +1,41 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import java.util.Collections; +import java.util.List; + +/** + * @author fayez + * + */ +public class GenericGeneratorResultsForAllMethods { + private final List methodsAndConstraints; + + public GenericGeneratorResultsForAllMethods() { + this(Collections.emptyList()); + } + /** + * @param methodsAndConstraints + */ + public GenericGeneratorResultsForAllMethods(List methodsAndConstraints) { + this.methodsAndConstraints = methodsAndConstraints; + } + + /** + * @return the methodsAndConstraints + */ + public List getMethodsAndConstraints() { + return methodsAndConstraints; + } + + @Override + public String toString() { + String ret = ""; + ret = ret + methodsAndConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y); + //ret = ret + "\n"; + return ret; + } + +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGenratorResultForSourceFile.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGenratorResultForSourceFile.java new file mode 100644 index 00000000..3bcf1939 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericGenratorResultForSourceFile.java @@ -0,0 +1,52 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import de.dhbwstuttgart.parser.scope.JavaClassName; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; + +/** + * The simplify results of a source file (package) + * + * @author fayez + * + */ +public class GenericGenratorResultForSourceFile { + private String pkgName; + private final List genericGeneratorResultForAllClasses = new ArrayList<>(); + + /** + * @param pkgName + */ + public GenericGenratorResultForSourceFile(String pkgName) { + this.pkgName = pkgName; + } + + public List getGenericGeneratorResultForAllClasses() { + return genericGeneratorResultForAllClasses; + } + + /** + * Appends the simplify results of a class to simplifyResForSF + * + * @param sResClass simplify results of a class to added + */ + public void addGenericGeneratorResultClass(GenericsGeneratorResultForClass sResClass) { + genericGeneratorResultForAllClasses.add(sResClass); + } + + public GenericsGeneratorResultForClass getSimplifyResultsByName(JavaClassName name) { + + if (this.pkgName.equals(name.getPackageName())) { + return genericGeneratorResultForAllClasses.stream() + .filter(sr -> sr.getClassName().equals(name)) + .findAny() + .orElse(new GenericsGeneratorResultForClass(name)); + } + return new GenericsGeneratorResultForClass(name); + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java new file mode 100644 index 00000000..fe23f239 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResult.java @@ -0,0 +1,59 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import java.util.Set; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; + +/** + * @author fayez + * + */ +public class GenericsGeneratorResult { + private TPHConstraint constraint; + /** + * contains the names of all type placeholders which are equals to the left side of + * the constraint {@link #constraint}. + */ + private Set equalsTPHs; + /** + * @param constraint + * @param equalsTPHs + */ + public GenericsGeneratorResult(TPHConstraint constraint, Set equalsTPHs) { + this.constraint = constraint; + this.equalsTPHs = equalsTPHs; + } + + /** + * @return the constraint + */ + public TPHConstraint getConstraint() { + return constraint; + } + /** + * @param constraint the constraint to set + */ + public void setConstraint(TPHConstraint constraint) { + this.constraint = constraint; + } + /** + * @return the equalsTPHs + */ + public Set getEqualsTPHs() { + return equalsTPHs; + } + /** + * @param equalsTPHs the equalsTPHs to set + */ + public void setEqualsTPHs(Set equalsTPHs) { + this.equalsTPHs = equalsTPHs; + } + + @Override + public String toString() { + return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString(); + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java new file mode 100644 index 00000000..0a3626d2 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java @@ -0,0 +1,84 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import de.dhbwstuttgart.parser.scope.JavaClassName; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import com.google.common.collect.Lists; + +/** + * @author fayez + * + */ +public class GenericsGeneratorResultForClass { + private final JavaClassName className; + private final List classConstraints; + private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints; + + public GenericsGeneratorResultForClass(JavaClassName className) { + this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods()); + } + /** + * @param className + * @param classConstraints + * @param methodsAndTheirConstraints + */ + public GenericsGeneratorResultForClass(JavaClassName className, List classConstraints, + GenericGeneratorResultsForAllMethods methodsAndTheirConstraints) { + this.className = className; + this.classConstraints = classConstraints; + this.methodsAndTheirConstraints = methodsAndTheirConstraints; + } + + /** + * @return the className + */ + public JavaClassName getClassName() { + return className; + } + + /** + * @return the classConstraints + */ + public List getClassConstraints() { + return classConstraints; + } + + /** + * @return the methodsAndTheirConstraints + */ + public GenericGeneratorResultsForAllMethods getMethodsAndTheirConstraints() { + return methodsAndTheirConstraints; + } + + public boolean contains(String id) { + return methodsAndTheirConstraints.getMethodsAndConstraints().stream().map(mc -> mc.getMethodID()) + .anyMatch(i -> i.equals(id)); + } + + public List getMethodConstraintsByID(String id) { + Optional methodConstraints = methodsAndTheirConstraints.getMethodsAndConstraints() + .stream() + .filter(mc -> mc.getMethodID().equals(id)) + .findFirst(); + + if (methodConstraints.isPresent()) { + return methodConstraints.get().getConstraints(); + } else { + return Collections.emptyList(); + } + } + + @Override + public String toString() { + String ret = "Classconstraints: "; + ret = ret + classConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y); + ret = ret + "\n" + methodsAndTheirConstraints.toString(); + return ret; + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java new file mode 100644 index 00000000..b9437c3a --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java @@ -0,0 +1,47 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import java.util.List; + +/** + * @author fayez + * + */ +public class MethodAndConstraints { + private final String methodID; + private final List constraints; + /** + * @param methodID + * @param constraints + */ + public MethodAndConstraints(String methodID, List constraints) { + this.methodID = methodID; + this.constraints = constraints; + } + /** + * @return the methodID + */ + public String getMethodID() { + // FIXME + return null; + } + /** + * @return the constraints + */ + public List getConstraints() { + return constraints; + } + + + @Override + public String toString() { + String ret = methodID + ": "; + ret = ret + constraints.stream().reduce("", + (x,y) -> x + y.toString(), + (x,y) -> x + y); + ret = ret + "\n"; + return ret; + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/NameReplacementResult.java b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/NameReplacementResult.java new file mode 100644 index 00000000..4a91655e --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/NameReplacementResult.java @@ -0,0 +1,49 @@ +/** + * + */ +package de.dhbwstuttgart.bytecode.genericsGeneratorTypes; + +import java.util.List; + +/** + * @author fayez + * + */ +public class NameReplacementResult { + private String name; + private List oldNames; + /** + * @param name + * @param oldNames + */ + public NameReplacementResult(String name, List oldNames) { + this.name = name; + this.oldNames = oldNames; + } + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the oldNames + */ + public List getOldNames() { + return oldNames; + } + /** + * @param oldNames the oldNames to set + */ + public void setOldNames(List oldNames) { + this.oldNames = oldNames; + }; + + +} diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 3db897a8..7c4a6b45 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.core; import com.google.common.collect.Lists; import de.dhbwstuttgart.bytecode.Codegen; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.environment.DirectoryClassLoader; import de.dhbwstuttgart.exceptions.DebugException; @@ -896,8 +897,13 @@ public class JavaTXCompiler { System.out.println(name + ".class file generated"); } } - - /* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */ + + public List getGeneratedGenericResultsForAllSourceFiles(List results) { + // FIXME + return null; + } + + /* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */ /** * Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus. */ diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index 54a988c6..c185018f 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -6,15 +6,11 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import org.antlr.v4.runtime.Token; import org.objectweb.asm.Type; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass; -import de.dhbwstuttgart.bytecode.utilities.MethodUtility; -import de.dhbwstuttgart.bytecode.utilities.Resolver; -import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.SourceFile; @@ -48,6 +44,7 @@ public class TypeInsertFactory { private static List newResults; + public static Set createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, List newResults, List simplifyResultsForAllSourceFiles){ TypeInsertFactory.newResults = newResults; return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults, simplifyResultsForAllSourceFiles); @@ -84,8 +81,6 @@ public class TypeInsertFactory { private static synchronized Set createGenericInsert(List methodConstraints, List classConstraints,ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){ Set result = createGenericClassInserts(classConstraints, cl); - - Resolver resolver = new Resolver(resultSet); if (m != null) { //List methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, m)); diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index a26263cf..aba0e72e 100644 --- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -1,5 +1,8 @@ package de.dhbwstuttgart.typedeployment; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -14,6 +17,7 @@ public class TypeInsertPlacer extends AbstractASTWalker{ Set inserts = new HashSet<>(); private ResultSet withResults; String pkgName; + private List simplifyResultsForAllSourceFiles; public Set getTypeInserts(SourceFile forSourceFile, ResultSet withResults, List simplifyResultsForAllSourceFiles){ this.withResults = withResults; @@ -42,8 +46,6 @@ class TypeInsertPlacerClass extends AbstractASTWalker{ public final Set inserts = new HashSet<>(); private Method method; - private Resolver resolver; - List constraints; List classConstraints; @@ -52,15 +54,13 @@ class TypeInsertPlacerClass extends AbstractASTWalker{ this.method = null; this.results = withResults; this.generatedGenerics = generatedGenerics; - resolver = new Resolver(withResults); //PL 2020-04-12 Ob das stimmt weiss ich nicht forClass.accept(this); } @Override public void visit(Method method) { this.method = method; - String id = MethodUtility.createID(resolver, method); - constraints = generatedGenerics.getMethodConstraintsByID(id); + //constraints = generatedGenerics.getMethodConstraintsByID(id); classConstraints = generatedGenerics.getClassConstraints(); if(method.getReturnType() instanceof TypePlaceholder) inserts.add(TypeInsertFactory.createInsertPoints( diff --git a/src/test/java/constraintSimplify/FamilyOfGenerics.java b/src/test/java/constraintSimplify/FamilyOfGenerics.java index 2708d220..c7b97773 100644 --- a/src/test/java/constraintSimplify/FamilyOfGenerics.java +++ b/src/test/java/constraintSimplify/FamilyOfGenerics.java @@ -1,31 +1,27 @@ package constraintSimplify; -import de.dhbwstuttgart.bytecode.insertGenerics.PositionFinder; -import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Optional; public class FamilyOfGenerics { @Test public void generateBC() throws Exception { - SourceFile sf = generateAST(); + /*SourceFile sf = generateAST(); PositionFinder.getPositionOfTPH(sf, null); TPHExtractor tphExtractor = new TPHExtractor(); List results = new ArrayList(); - GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results); + GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results);*/ } public static SourceFile generateAST(){ diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java deleted file mode 100644 index 53122862..00000000 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.*; -import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class FamilyOfGeneratedGenericsTest extends TestCase { - - public void testIdentityMethod(){ - */ -/* - Example method: - A id(B i) return i; - gives constraint: B <. A and A <. Object, which are method constraints - *//* - - - List inputConstraints = new ArrayList<>(); - inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS)); - - HashMap> tphPositions = new HashMap<>(); - PairTphMethod meth1 = new PairTphMethod(PositionFinder.Position.METHOD, "m1"); - tphPositions.put("A", meth1); - tphPositions.put("B", meth1); - - List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); - assertTrue(classConstraints.isEmpty()); - - */ -/* - MethodConstraints should be the same as the input constraint - *//* - -// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); -// assertTrue(methodConstraints.size() == 2); -// assertTrue(methodConstraints.get(0).getLeft().equals("B")); -// assertTrue(methodConstraints.get(0).getRight().equals("A")); - } - - public void testClassField(){ - */ -/* - class Example{ - A f; - B fReturn(){ - return f; - } - } - gives constraint: A <. B and B <. Object which are class constraints - *//* - - - List inputConstraints = new ArrayList<>(); - inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); - - HashMap> tphPositions = new HashMap<>(); - PairTphMethod posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null); - tphPositions.put("A", posOfA); - PairTphMethod posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn"); - tphPositions.put("B", posOfB); - - */ -/* - ClassConstraints should not be the same as the input constraint - *//* - - List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); - System.out.println(classConstraints); - assertTrue(classConstraints.size() == 2); - //assertTrue(classConstraints.get(0).getLeft().equals("A")); - //assertTrue(classConstraints.get(0).getRight().equals("B")); -// HashMap> methodConstraintsWithPosition = FamilyOfGeneratedGenerics.getMethodConstraintsWithPosition(inputConstraints,classConstraints,tphPositions,) - } - - public void testSecondLineOfClassConstraints() { - */ -/* - class Example() { - A a; - B b = a; - C anyMethod() { - F f; - return f; - } - D otherMethod(E e) { - this.b = e; - e = this.a; - return e; - } - } - *//* - - - List inputConstraints = new ArrayList<>(); - inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("F", "C", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("E", "B", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("A", "E", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("E", "D", TPHConstraint.Relation.EXTENDS)); - - HashMap> tphPositions = new HashMap<>(); - PairTphMethod posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null); - PairTphMethod posOfB = new PairTphMethod<>(PositionFinder.Position.FIELD, null); - PairTphMethod posOfC = new PairTphMethod<>(PositionFinder.Position.METHOD, "anyMethod"); - PairTphMethod posOfD = new PairTphMethod<>(PositionFinder.Position.METHOD, "otherMethod"); - PairTphMethod posOfE = new PairTphMethod<>(PositionFinder.Position.METHOD, "otherMethod"); - PairTphMethod posOfF = new PairTphMethod<>(PositionFinder.Position.METHOD, "anyMethod"); - - tphPositions.put("A", posOfA); - tphPositions.put("B", posOfB); - tphPositions.put("C", posOfC); - tphPositions.put("F", posOfF); - tphPositions.put("D", posOfD); - tphPositions.put("E", posOfE); - - List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); - System.out.println(classConstraints); -// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); -// System.out.println(methodConstraints); - assertFalse(classConstraints.isEmpty()); - assertTrue(classConstraints.size() == 6); -// assertFalse(methodConstraints.isEmpty()); -// assertTrue(methodConstraints.size() == 2); - - } - - public void testTPHsAndGenerics() { - */ -/* - class TPHsAndGenerics { - Fun1 id = x -> x; - C id2 (D x) { - return id.apply(x); - } - E m(F a, G b){ - var c = m2(a,b); - return a; - } - H m2(I a, J b){ - return b; - } - } - *//* - - - List inputConstraints = new ArrayList<>(); - inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("B","C", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("D","A", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("F","E", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("F","I", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("G","J", TPHConstraint.Relation.EXTENDS)); - inputConstraints.add(new TPHConstraint("J","H", TPHConstraint.Relation.EXTENDS)); - - HashMap> tphPositions = new HashMap<>(); - PairTphMethod posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null); - PairTphMethod posOfB = new PairTphMethod<>(PositionFinder.Position.FIELD, null); - PairTphMethod posOfC = new PairTphMethod<>(PositionFinder.Position.METHOD, "id2"); - PairTphMethod posOfD = new PairTphMethod<>(PositionFinder.Position.METHOD, "id2"); - PairTphMethod posOfE = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfF = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfG = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfH = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2"); - PairTphMethod posOfI = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2"); - PairTphMethod posOfJ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2"); - - tphPositions.put("A", posOfA); - tphPositions.put("B", posOfB); - tphPositions.put("C", posOfC); - tphPositions.put("D", posOfD); - tphPositions.put("E", posOfE); - tphPositions.put("F", posOfF); - tphPositions.put("G", posOfG); - tphPositions.put("H", posOfH); - tphPositions.put("I", posOfI); - tphPositions.put("J", posOfJ); - - List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); - System.out.println(classConstraints); -// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); -// System.out.println(methodConstraints); - - assertFalse(classConstraints.isEmpty()); - assertTrue(classConstraints.size() == 3); -// assertFalse(methodConstraints.isEmpty()); -// assertTrue(methodConstraints.size()==9); - } - - - public void testPositionConverter() { - HashMap allTphsOld = new HashMap<>(); - List listOfMethodsAndTphs = new ArrayList<>(); - allTphsOld.put("A", true); - allTphsOld.put("B", false); - MethodAndTPH m1 = new MethodAndTPH("m1"); - m1.getTphs().add("A"); - MethodAndTPH bla = new MethodAndTPH("bla"); - MethodAndTPH blubb = new MethodAndTPH("blubb"); -// blubb.getTphs().add("A"); - listOfMethodsAndTphs.add(bla); - listOfMethodsAndTphs.add(blubb); - listOfMethodsAndTphs.add(m1); - - - - HashMap>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs); - System.out.println(allTphsNew); - //was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten? - //ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt? - //überarbeiten oder lassen? - - - assertTrue(allTphsNew.get("A").fst.equals(PositionFinder.Position.METHOD)); - assertTrue(allTphsNew.get("B").fst.equals(PositionFinder.Position.FIELD)); - } - - - public void testFirstTransitiveSubtypeForMethodTypes(){ - - } - -}*/ diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java deleted file mode 100644 index e5614515..00000000 --- a/src/test/java/insertGenerics/TestAny.java +++ /dev/null @@ -1,112 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestAny { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestAny.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("N", "O", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc); - lmc = new HashSet<>(); - methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/insertGenerics/TestClassField.java b/src/test/java/insertGenerics/TestClassField.java deleted file mode 100644 index a8070976..00000000 --- a/src/test/java/insertGenerics/TestClassField.java +++ /dev/null @@ -1,79 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestClassField { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestClassField.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/insertGenerics/TestContraVariant.java b/src/test/java/insertGenerics/TestContraVariant.java deleted file mode 100644 index 744f18f5..00000000 --- a/src/test/java/insertGenerics/TestContraVariant.java +++ /dev/null @@ -1,112 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestContraVariant { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestContraVariant.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("R", "O", Relation.EXTENDS)); - lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc); - lmc = new HashSet<>(); - //lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS)); - lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java deleted file mode 100644 index a052bacf..00000000 --- a/src/test/java/insertGenerics/TestExample42.java +++ /dev/null @@ -1,62 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.insertGenerics.*; -import org.junit.Test; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class TestExample42 { - public List fillConstraintsList() { - List cs = new ArrayList<>(); - cs.add(new TPHConstraint("M", "N", Relation.EXTENDS)); - cs.add(new TPHConstraint("N", "Z", Relation.EXTENDS)); - cs.add(new TPHConstraint("Q", "K", Relation.EXTENDS)); - cs.add(new TPHConstraint("K", "P", Relation.EXTENDS)); - cs.add(new TPHConstraint("W", "M", Relation.EXTENDS)); - cs.add(new TPHConstraint("Z", "V", Relation.EXTENDS)); - return cs; - } - - public HashMap> fillPosOfTphs() { - HashMap> posOfTphs = new HashMap<>(); - - // TPHs "U" und "L" auskommentiert, da nach Vorgaben L zu Z umbenannt und U als void interpretiert wird - PairTphMethod posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); -// PairTphMethod posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); - PairTphMethod posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); - PairTphMethod posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); - PairTphMethod posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); - PairTphMethod posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); -// PairTphMethod posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - - posOfTphs.put("K", posOfK); -// posOfTphs.put("L", posOfL); - posOfTphs.put("M", posOfM); - posOfTphs.put("N", posOfN); - posOfTphs.put("P", posOfP); - posOfTphs.put("Q", posOfQ); -// posOfTphs.put("U", posOfU); - posOfTphs.put("V", posOfV); - posOfTphs.put("W", posOfW); - posOfTphs.put("Z", posOfZ); - return posOfTphs; - } - - @Test - public void genericTest() { -// List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); -// System.out.println("ClassConstraints: " + classConstraints); -// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); -// System.out.println("MethodConstraints: " + methodConstraints); - - List testCons; - } -} diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java deleted file mode 100644 index f3fe7213..00000000 --- a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java +++ /dev/null @@ -1,61 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.insertGenerics.*; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class TestExample42_allInOneMethod { - public List fillConstraintsList() { - List cs = new ArrayList<>(); - cs.add(new TPHConstraint("M", "N", Relation.EXTENDS)); - cs.add(new TPHConstraint("N", "Z", Relation.EXTENDS)); - cs.add(new TPHConstraint("Q", "K", Relation.EXTENDS)); - cs.add(new TPHConstraint("K", "P", Relation.EXTENDS)); - cs.add(new TPHConstraint("W", "M", Relation.EXTENDS)); - cs.add(new TPHConstraint("Z", "V", Relation.EXTENDS)); - return cs; - } - - public HashMap> fillPosOfTphs() { - HashMap> posOfTphs = new HashMap<>(); - - // TPHs "U" und "L" auskommentiert, da nach Vorgaben L zu Z umbenannt und U als void interpretiert wird - PairTphMethod posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); -// PairTphMethod posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); -// PairTphMethod posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - PairTphMethod posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); - - posOfTphs.put("K", posOfK); -// posOfTphs.put("L", posOfL); - posOfTphs.put("M", posOfM); - posOfTphs.put("N", posOfN); - posOfTphs.put("P", posOfP); - posOfTphs.put("Q", posOfQ); -// posOfTphs.put("U", posOfU); - posOfTphs.put("V", posOfV); - posOfTphs.put("W", posOfW); - posOfTphs.put("Z", posOfZ); - return posOfTphs; - } - - @Test - public void genericTest() { -// List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); -// System.out.println("ClassConstraints: " + classConstraints); -// List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),); -// System.out.println("MethodConstraints: " + methodConstraints); - - List testCons; - } -} diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java deleted file mode 100644 index 49ca4297..00000000 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ /dev/null @@ -1,99 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestGGFinder { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestGGFinder"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS)); - lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); - lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); - lmc.add(new MethodConstraint("Y", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("voidm(TPH YTPH Z)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java deleted file mode 100644 index a3592a24..00000000 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ /dev/null @@ -1,112 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestLocalVarLambda { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestLocalVarLambda"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - - Set lmc; - lmc = new HashSet<>(); - - if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) { - lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS)); - lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS)); - lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); - } - else if (fogg.allConstraints.contains((new MethodConstraint("O", "DIV", Relation.EXTENDS)))) { - lmc.add(new MethodConstraint("O", "DIV", Relation.EXTENDS)); - lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("DIV", "N", Relation.EXTENDS)); - lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc); - } - else - { - lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS)); - lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS)); - lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc); - } - - - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestMutualRecursion.java b/src/test/java/insertGenerics/TestMutualRecursion.java deleted file mode 100644 index 82385060..00000000 --- a/src/test/java/insertGenerics/TestMutualRecursion.java +++ /dev/null @@ -1,126 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestMutualRecursion { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - className = "TestMutualRecursion"; - JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav")); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - - List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS)); - lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ALmain(TPH AGTPH AH)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - } - - @Test - public void TestMutualRecursionWithField() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - className = "TestMutualRecursionWithField"; - execute(new File(rootDirectory+className+".jav")); - } - - @Test - public void TestMutualRecursionWithField2() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - className = "TestMutualRecursionWithField2"; - execute(new File(rootDirectory+className+".jav")); - } - - @Test - public void TestMutualRecursionWithField3() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - className = "TestMutualRecursionWithField3"; - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestReturnVar.java b/src/test/java/insertGenerics/TestReturnVar.java deleted file mode 100644 index d4b98474..00000000 --- a/src/test/java/insertGenerics/TestReturnVar.java +++ /dev/null @@ -1,79 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestReturnVar { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestReturnVar.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java b/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java deleted file mode 100644 index 97cd468f..00000000 --- a/src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java +++ /dev/null @@ -1,79 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestSecondLineOfClassConstraints { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java deleted file mode 100644 index d065151b..00000000 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ /dev/null @@ -1,154 +0,0 @@ -package insertGenerics; - - import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; - import de.dhbwstuttgart.syntaxtree.SourceFile; - import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; - import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; - import de.dhbwstuttgart.typedeployment.TypeInsert; - import de.dhbwstuttgart.typedeployment.TypeInsertFactory; - import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; - import java.io.IOException; - import java.lang.reflect.InvocationTargetException; - import java.net.URL; - import java.net.URLClassLoader; - import java.nio.charset.Charset; - import java.nio.charset.StandardCharsets; - import java.nio.file.Files; - import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; - import java.util.List; - import java.util.Set; - - -public class TestTPHsAndGenerics { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestTPHsAndGenerics"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - - Set lmc; - lmc = new HashSet<>(); - - if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) { - classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS)); - - lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); - } else { - if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) { - classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS)); - - lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Uid2(TPH V)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); - } else { - if (fogg.allConstraints.contains((new MethodConstraint("EIM", "FEA", Relation.EXTENDS)))) { - classConstraintsTest.add(new ClassConstraint("VK", "EIM", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("EIM", "FEA", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("FEA", "java/lang/Object", Relation.EXTENDS)); - - lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); - //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH FEAid2(TPH V)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc); - } - } - - } - - - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - /* - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - */ - return new TestResultSet(); - - } - } diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics2.java b/src/test/java/insertGenerics/TestTPHsAndGenerics2.java deleted file mode 100644 index ebf0d9df..00000000 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics2.java +++ /dev/null @@ -1,79 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestTPHsAndGenerics2 { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/insertGenerics/TestThreeArgs.java b/src/test/java/insertGenerics/TestThreeArgs.java deleted file mode 100644 index ff7951f6..00000000 --- a/src/test/java/insertGenerics/TestThreeArgs.java +++ /dev/null @@ -1,99 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestThreeArgs { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestThreeArgs"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS)); - lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); - lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Wm(TPH WTPH ABTPH AC)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - //liefert Fehler, da Variable "a" nicht initialisiert ist. - //instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestTransitiveClosure.java b/src/test/java/insertGenerics/TestTransitiveClosure.java deleted file mode 100644 index 4eaf0527..00000000 --- a/src/test/java/insertGenerics/TestTransitiveClosure.java +++ /dev/null @@ -1,28 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import org.junit.Test; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -public class TestTransitiveClosure { - public List fillList() { - List list = new ArrayList<>(); - list.add(new TPHConstraint("A", "B", Relation.EXTENDS)); - list.add(new TPHConstraint("B", "C", Relation.EXTENDS)); - list.add(new TPHConstraint("C", "D", Relation.EXTENDS)); - - return list; - } - - @Test - public void genericTest() { - //List testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList()); - //System.out.println(testCons); - - } -} diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java deleted file mode 100644 index 16fbd062..00000000 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ /dev/null @@ -1,111 +0,0 @@ -package insertGenerics; - -import static org.junit.Assert.*; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestTwoArgs { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestTwoArgs"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("AP", "Z", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("Z", "P", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS)); - classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); - lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); - lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS)); - lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS)); - lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java deleted file mode 100644 index 467cac40..00000000 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ /dev/null @@ -1,105 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestTwoArgs2 { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestTwoArgs2"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); - lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS)); - lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AA", "U", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); - lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS)); - lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); - lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java deleted file mode 100644 index adc3bbac..00000000 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ /dev/null @@ -1,95 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestTwoCalls { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestTwoCalls"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); - lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS)); - lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); - lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); - lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java deleted file mode 100644 index 6a30a456..00000000 --- a/src/test/java/insertGenerics/TestVector.java +++ /dev/null @@ -1,92 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestVector { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestVector"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); - lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); - lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestVectorArg.java b/src/test/java/insertGenerics/TestVectorArg.java deleted file mode 100644 index 45509288..00000000 --- a/src/test/java/insertGenerics/TestVectorArg.java +++ /dev/null @@ -1,92 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; -import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; -import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestVectorArg { - - private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; - private static ClassLoader loader; - private static Class classToTest; - private static Object instanceOfClass; - private static String className = "TestVectorArg"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - execute(new File(rootDirectory+className+".jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - - List classConstraintsTest = new ArrayList<>(); - HashMap> methodConstraintsWithPositionTest = new HashMap<>(); - Set lmc; - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); - lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); - lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); - lmc = new HashSet<>(); - lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS)); - methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); - - FamilyOfGeneratedGenerics fogg = compiler.fogg; - Set computedClassCons = new HashSet<>(fogg.classConstraints); - Set expectedClassCons = new HashSet<>(classConstraintsTest); - - //assertEquals(expectedClassCons, computedClassCons); - - HashMap> methodConstraintsWithPositionComputed = new HashMap<>(); - fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l))); - - //assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed); - compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass(className); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - return new TestResultSet(); - } -} diff --git a/src/test/java/insertGenerics/TestVoidMeth.java b/src/test/java/insertGenerics/TestVoidMeth.java deleted file mode 100644 index 9dc8f99b..00000000 --- a/src/test/java/insertGenerics/TestVoidMeth.java +++ /dev/null @@ -1,79 +0,0 @@ -package insertGenerics; - -import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class TestVoidMeth { - - public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; - - @BeforeClass - public static void resetNamesOfTypePlaceholder() { - de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset(); - } - - @Test - public void ggFinder() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"TestVoidMeth.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - } - List results = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); - //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } -} diff --git a/src/test/java/packages/OLOneFileTest.java b/src/test/java/packages/OLOneFileTest.java index 64b1a2b1..c46dcb75 100644 --- a/src/test/java/packages/OLOneFileTest.java +++ b/src/test/java/packages/OLOneFileTest.java @@ -42,8 +42,8 @@ public class OLOneFileTest { Lists.newArrayList(new File(rootDirectory+"de/test/output/"))); pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/"; List typeinferenceResult = compiler.typeInference(); - List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); - compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); + //List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + //compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("OLOneFile"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); diff --git a/src/test/java/targetast/GreaterEqualTest.java b/src/test/java/targetast/GreaterEqualTest.java index ac9216c9..c104433f 100644 --- a/src/test/java/targetast/GreaterEqualTest.java +++ b/src/test/java/targetast/GreaterEqualTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/GreaterThanTest.java b/src/test/java/targetast/GreaterThanTest.java index c5684c5a..fd1d654a 100644 --- a/src/test/java/targetast/GreaterThanTest.java +++ b/src/test/java/targetast/GreaterThanTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/InheritTest.java b/src/test/java/targetast/InheritTest.java index 35527ed0..9e9fff71 100644 --- a/src/test/java/targetast/InheritTest.java +++ b/src/test/java/targetast/InheritTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/InheritTest2.java b/src/test/java/targetast/InheritTest2.java index 80fa66fa..87e052f1 100644 --- a/src/test/java/targetast/InheritTest2.java +++ b/src/test/java/targetast/InheritTest2.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/LessEqualTest.java b/src/test/java/targetast/LessEqualTest.java index d0eea8b2..af5237cc 100644 --- a/src/test/java/targetast/LessEqualTest.java +++ b/src/test/java/targetast/LessEqualTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/LessThanTest.java b/src/test/java/targetast/LessThanTest.java index 4de4b1d3..7b0d45c8 100644 --- a/src/test/java/targetast/LessThanTest.java +++ b/src/test/java/targetast/LessThanTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/OLTest.java b/src/test/java/targetast/OLTest.java index a4972320..8afcc669 100644 --- a/src/test/java/targetast/OLTest.java +++ b/src/test/java/targetast/OLTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/PostIncTest.java b/src/test/java/targetast/PostIncTest.java index 28a4b4e3..d0d0a02d 100644 --- a/src/test/java/targetast/PostIncTest.java +++ b/src/test/java/targetast/PostIncTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/PreIncTest.java b/src/test/java/targetast/PreIncTest.java index 24fc5cfb..d946b0e3 100644 --- a/src/test/java/targetast/PreIncTest.java +++ b/src/test/java/targetast/PreIncTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/PutTest.java b/src/test/java/targetast/PutTest.java index a14771b4..66600337 100644 --- a/src/test/java/targetast/PutTest.java +++ b/src/test/java/targetast/PutTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index f1e4edd5..53747024 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.Test; import java.lang.reflect.Method; diff --git a/src/test/java/targetast/TphTest.java b/src/test/java/targetast/TphTest.java index 5d578596..b902b155 100644 --- a/src/test/java/targetast/TphTest.java +++ b/src/test/java/targetast/TphTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/targetast/WhileTest.java b/src/test/java/targetast/WhileTest.java index 7643c705..7b496f15 100644 --- a/src/test/java/targetast/WhileTest.java +++ b/src/test/java/targetast/WhileTest.java @@ -1,5 +1,6 @@ package targetast; +import de.dhbwstuttgart.environment.ByteArrayClassLoader; import org.junit.BeforeClass; import org.junit.Test;