Merge branch 'generateTestConstraints' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond

This commit is contained in:
pl@gohorb.ba-horb.de 2021-03-25 18:59:34 +01:00
commit 91c075829b
15 changed files with 433 additions and 13 deletions

View File

@ -49,6 +49,23 @@ public class TPHConstraint {
return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight()); 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 (left+right).equals(o_tphcons.getLeft()+o_tphcons.getRight());
}
else {
return false;
}
}
/*
@Override @Override
public String toString() { public String toString() {
if(rel == Relation.EXTENDS) { if(rel == Relation.EXTENDS) {
@ -57,4 +74,13 @@ public class TPHConstraint {
return left + " = " + right; return left + " = " + right;
} }
} }
*/
public String toString() {
if(rel == Relation.EXTENDS) {
return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)";
}
else {
return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)";
}
}
} }

View File

@ -79,6 +79,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
private JavaClassName className; private JavaClassName className;
private Resolver resolver; private Resolver resolver;
/** /**
* @param sf * @param sf
* @param listOfResultSets * @param listOfResultSets
@ -93,6 +94,14 @@ public class GeneratedGenericsFinder implements ASTVisitor {
return generatedGenericsForSF; return generatedGenericsForSF;
} }
/**
* returns the family of Generated Generics
* insbesondere fuer Testzwecke
*/
public FamilyOfGeneratedGenerics getFogg() {
return fogg;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -140,6 +149,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs); System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs);
System.out.println("fogg.classConstraints: "+ fogg.classConstraints); System.out.println("fogg.classConstraints: "+ fogg.classConstraints);
System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition); System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition);
System.out.println(fogg);
///* ///*
//Fayez Ansatz Anfang //Fayez Ansatz Anfang

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.bytecode.insertGenerics; package de.dhbwstuttgart.bytecode.insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
public class ClassConstraint extends TPHConstraint { public class ClassConstraint extends TPHConstraint {
//private TPHConstraint constraint; //private TPHConstraint constraint;
@ -12,4 +13,12 @@ public class ClassConstraint extends TPHConstraint {
/*public ClassConstraint(TPHConstraint constraint) { /*public ClassConstraint(TPHConstraint constraint) {
this.constraint = constraint; this.constraint = constraint;
}*/ }*/
public String toString() {
if(rel == Relation.EXTENDS) {
return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)";
}
else {
return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)";
}
}
} }

View File

@ -833,5 +833,24 @@ public class FamilyOfGeneratedGenerics {
return tempMethodConstraintsWithPosition; return tempMethodConstraintsWithPosition;
} }
public String toString() {
String ret =
"List<ClassConstraint> classConstraintsTest = new ArrayList<>();\n";
for(ClassConstraint cC: classConstraints) {
ret = ret + "classConstraintsTest.add(" + cC.toString() + ");\n";
}
ret = ret + "HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();\n";
ret = ret + "List<MethodConstraint> lmc;\n";
for (String methName : methodConstraintsWithPosition.keySet()) {
String consSet = "";
ret = ret + "lmc = new ArrayList<>();\n";
for (MethodConstraint methConstrs : methodConstraintsWithPosition.get(methName)) {
consSet = consSet + "lmc.add(" + methConstrs + ");\n";
}
ret = ret + consSet + "methodConstraintsWithPositionTest.put(\""+ methName + "\", lmc);\n";
}
return ret;
}
} }

View File

@ -1,9 +1,19 @@
package de.dhbwstuttgart.bytecode.insertGenerics; package de.dhbwstuttgart.bytecode.insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
public class MethodConstraint extends TPHConstraint { public class MethodConstraint extends TPHConstraint {
public MethodConstraint(String left, String right, Relation rel) { public MethodConstraint(String left, String right, Relation rel) {
super(left, right, rel); super(left, right, rel);
} }
public String toString() {
if(rel == Relation.EXTENDS) {
return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)";
}
else {
return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)";
}
}
} }

View File

@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.BytecodeGen;
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError; import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.environment.DirectoryClassLoader; import de.dhbwstuttgart.environment.DirectoryClassLoader;
import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.DebugException;
@ -79,6 +80,11 @@ public class JavaTXCompiler {
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
private final ClassLoader classLoader; private final ClassLoader classLoader;
//nur fuer Testzwecke of Generated Generics
//wieder loeschen PL 2021-03-22
public FamilyOfGeneratedGenerics fogg;
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile), null); this(Arrays.asList(sourceFile), null);
} }
@ -872,6 +878,7 @@ public class JavaTXCompiler {
SourceFile sf = sourceFiles.get(f); SourceFile sf = sourceFiles.get(f);
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult); GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics(); GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
this.fogg = sResFinder.getFogg();
result.add(simplifyResOfSF); result.add(simplifyResOfSF);
} }
return result; return result;

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,12 +14,16 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -40,6 +48,28 @@ public class TestAny {
} }
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> 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<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc);
lmc = new ArrayList<>();
methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); //compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){ for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f); SourceFile sf = compiler.sourceFiles.get(f);

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -45,6 +53,33 @@ public class TestGGFinder {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS));
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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 ArrayList<>();
lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc);
lmc = new ArrayList<>();
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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -45,6 +53,34 @@ public class TestLocalVarLambda {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
FamilyOfGeneratedGenerics fogg = compiler.fogg;
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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));
}
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));
}
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,11 +25,13 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class AllTests { public class TestMutualRecursion {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; 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 String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
@ -33,9 +41,43 @@ public class AllTests {
private static String className; private static String className;
@Test @Test
public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
className = "TestMutualRecursion"; className = "TestMutualRecursion";
execute(new File(rootDirectory+className+".jav")); JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav"));
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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 ArrayList<>();
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 ArrayList<>();
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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
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 @Test
@ -56,12 +98,6 @@ public class AllTests {
execute(new File(rootDirectory+className+".jav")); execute(new File(rootDirectory+className+".jav"));
} }
@Test
public void TestContraVariant() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
className = "TestContraVariant";
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{ private static class TestResultSet{
} }

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ package insertGenerics;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,6 +25,8 @@ package insertGenerics;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -46,6 +54,59 @@ public class TestTPHsAndGenerics {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
FamilyOfGeneratedGenerics fogg = compiler.fogg;
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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("AM", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
}
else {
classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("DZP", "U", 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("AM", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
}
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
/* /*
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});

View File

@ -1,6 +1,13 @@
package insertGenerics; 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.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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -19,6 +26,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -45,6 +54,40 @@ public class TestTwoArgs {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> 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<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc);
lmc = new ArrayList<>();
lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS));
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -45,6 +53,39 @@ public class TestTwoArgs2 {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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 ArrayList<>();
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 ArrayList<>();
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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -45,6 +53,27 @@ public class TestTwoCalls {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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 ArrayList<>();
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));
methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);

View File

@ -1,6 +1,10 @@
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; 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.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -19,6 +25,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -45,6 +53,26 @@ public class TestVector {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
List<MethodConstraint> lmc;
lmc = new ArrayList<>();
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 ArrayList<>();
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);