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

This commit is contained in:
AluAli 2021-01-31 20:34:18 +01:00
commit a0c92c2d9d
3 changed files with 24 additions and 40 deletions

View File

@ -156,11 +156,13 @@ public class GeneratedGenericsFinder implements ASTVisitor {
} }
if(ggResult != null)
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
*/ */
if(ggResult != null) { //Hinzufuegen von Fayez ggResult
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
}
List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>(); List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>();
for(TPHConstraint clCons: fogg.classConstraints) { for(TPHConstraint clCons: fogg.classConstraints) {
// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight()); // ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight());
@ -183,7 +185,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons); ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons);
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM); ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
if(ggResultAlternative != null) { if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult
generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative); generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
System.out.println(generatedGenericsForSF); System.out.println(generatedGenericsForSF);
} }

View File

@ -12,6 +12,9 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; 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.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -22,51 +25,30 @@ import java.util.Set;
public class TestGGFinder { public class TestGGFinder {
public 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 static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestGGFinder";
@Test @Test
public void ggFinder() throws IOException, ClassNotFoundException { public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+"TestGGFinder.jav")); execute(new File(rootDirectory+className+".jav"));
} }
private static class TestResultSet{ private static class TestResultSet{
} }
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){ loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
SourceFile sf = compiler.sourceFiles.get(f); classToTest = loader.loadClass(className);
System.out.println(ASTTypePrinter.print(sf)); instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> 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(); return new TestResultSet();
} }
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
} }

View File

@ -1,4 +1,4 @@
class TestGGFinder { public class TestGGFinder {
a; a;
id(b) { id(b) {