JavaCompilerCore/src/test/java/insertGenerics/TestMutualRecursion.java
pl@gohorb.ba-horb.de 86603ae343 modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java
equals korrigiert

	modified:   src/test/java/insertGenerics/TestGGFinder.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
	modified:   src/test/java/insertGenerics/TestMutualRecursion.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestTwoArgs.java
	modified:   src/test/java/insertGenerics/TestTwoCalls.java
	modified:   src/test/java/insertGenerics/TestVector.java
List -> Set vollendet
2021-03-26 10:51:59 +01:00

120 lines
6.2 KiB
Java

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.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;
@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<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> 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<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> 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<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> 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();
}
}