modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java

new file:   src/test/java/insertGenerics/TestVectorArg.java
	modified:   src/test/resources/bytecode/javFiles/Fac.jav
	new file:   src/test/resources/insertGenericsJav/TestVectorArg.jav
This commit is contained in:
pl@gohorb.ba-horb.de 2021-05-21 09:52:22 +02:00
parent 1b9e824b86
commit 18d9edfeea
4 changed files with 107 additions and 3 deletions

View File

@ -169,7 +169,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
if(ggResult != null) { //Hinzufuegen von Fayez ggResult if(ggResult != null) { //Hinzufuegen von Fayez ggResult
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
} }
// Fayez Ansatz Ende // Fayez Ansatz Ende
//*/ //*/
@ -198,7 +198,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult
generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); //generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
System.out.println(generatedGenericsForSF); System.out.println(generatedGenericsForSF);
} }
System.out.println(ggResultAlternative); System.out.println(ggResultAlternative);

View File

@ -0,0 +1,92 @@
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<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> 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<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();
return new TestResultSet();
}
}

View File

@ -3,7 +3,7 @@ import java.lang.Integer;
public class Fac { public class Fac {
getFac(java.lang.Integer n){ getFac(n){
var res = 1; var res = 1;
var i = 1; var i = 1;
while(i<=n) { while(i<=n) {

View File

@ -0,0 +1,12 @@
import java.util.Vector;
public class TestVectorArg {
add(v, e) {
v.addElement(e);
}
main(v, e) {
add(v, e);
}
}