modified: src/main/java/de/dhbwstuttgart/bytecode/gGenericsAli/ClassConstraint.java

modified:   src/main/java/de/dhbwstuttgart/bytecode/gGenericsAli/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/gGenericsAli/MethodConstraint.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
	new file:   src/test/java/insertGenerics/MethodsTest.java
	new file:   src/test/java/insertGenerics/TryTest.java
	new file:   src/test/resources/insertGenericsJav/TestGGFinder.jav
This commit is contained in:
AluAli 2020-10-23 10:42:24 +02:00
parent 7900449897
commit 5060cca6db
7 changed files with 174 additions and 13 deletions

View File

@ -1,4 +1,9 @@
package de.dhbwstuttgart.bytecode.gGenericsAli;
public class ClassConstraint {
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
public class ClassConstraint extends TPHConstraint {
public ClassConstraint(String left, String right, Relation rel) {
super(left, right, rel);
}
}

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.bytecode.gGenericsAli;
import de.dhbwstuttgart.bytecode.TPHExtractor;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGenerator.ConstraintsSimplierResult;
@ -10,14 +11,14 @@ import de.dhbwstuttgart.syntaxtree.Method;
import java.util.List;
public class FamilyOfGeneratedGenerics { // extends TPHConstraint?
// private final TPHExtractor tphExtractor = new TPHExtractor();
private final List<TPHConstraint> cs;
private final TPHExtractor tphExtractor = new TPHExtractor();
private final List<TPHConstraint> cs = tphExtractor.allCons; //alle Constraints bekommen wie?
public FamilyOfGeneratedGenerics(List<TPHConstraint> cs) {
this.cs = cs;
}
List<ClassConstraint> cs_cl;
List<MethodConstraint> cs_m;
List<ClassConstraint> cs_cl = null;
List<MethodConstraint> cs_m = null;
/*public Type getLeftSideOfConstraint(TPHConstraint constraint) {
Type leftSideType = null;
@ -85,6 +86,12 @@ public class FamilyOfGeneratedGenerics { // extends TPHConstraint?
*/
public List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> cs) {
//TODO:
for(TPHConstraint cons: cs){
if(cons.getRight()!=null && cons.getRel()==Relation.EXTENDS) {
cs_cl.add(new ClassConstraint(cons.getLeft(), cons.getRight(),cons.getRel()));
}
}
return cs_cl;
}
/**
@ -93,6 +100,12 @@ public class FamilyOfGeneratedGenerics { // extends TPHConstraint?
*/
public List<ClassConstraint> transitiveSubtypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> classConstraints) {
//TODO:
for(ClassConstraint cCons: classConstraints) {
// if(tphExtractor.containsConstraint(allConstraints, cCons)) {
// }
if(cCons.getRight() == )
}
}
/**
@ -148,12 +161,7 @@ public class FamilyOfGeneratedGenerics { // extends TPHConstraint?
GeneratedGenericsFinder genGenFinder;
/* GeneratedGenericsFinder genGenFinder;
ConstraintsSimplierResult simplifiedConstraints = null;
GenericsGeneratorResultForClass ggResult = null;
Method m;
@ -162,7 +170,7 @@ public class FamilyOfGeneratedGenerics { // extends TPHConstraint?
genGenFinder.addMethodConstraints(simplifiedConstraints, ggResult, m);
cs_m.add();
}
*/
}

View File

@ -1,4 +1,9 @@
package de.dhbwstuttgart.bytecode.gGenericsAli;
public class MethodConstraint {
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
public class MethodConstraint extends TPHConstraint {
public MethodConstraint(String left, String right, Relation rel) {
super(left, right, rel);
}
}

View File

@ -9,6 +9,7 @@ import java.util.List;
import java.util.Optional;
import de.dhbwstuttgart.bytecode.TPHExtractor;
import de.dhbwstuttgart.bytecode.gGenericsAli.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
@ -74,6 +75,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
private GenericGenratorResultForSourceFile generatedGenericsForSF;//Ergebnis des GGenerics
private ResultSet resultSet;
private final List<String> methodNameAndParamsT = new ArrayList<>();
private FamilyOfGeneratedGenerics fogg;
private String pkgName;
private JavaClassName className;
@ -133,6 +135,8 @@ public class GeneratedGenericsFinder implements ASTVisitor {
classOrInterface.accept(tphExtractor);
//PL 2020-10-16: Ab hier GGenerics implementieren durch Ali
//Rueckgabe an generatedGenericsForSF
fogg = new FamilyOfGeneratedGenerics(tphExtractor);
tphsClass = tphExtractor.tphsClass;
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);

View File

@ -0,0 +1,30 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import junit.framework.TestResult;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class MethodsTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
public static final String fileDirectory = rootDirectory + "TestGGFinder.jav";
@Test
public void testVisit(ClassOrInterface coi) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(new File(fileDirectory));
SourceFile sf = compiler.sourceFiles.get(compiler.sourceFiles.keySet());
List<ResultSet> results = compiler.typeInference();
GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results);
ClassOrInterface coiHere = coi;
ggf.visit(coiHere);
//assert results.size()>0;
}
}

View File

@ -0,0 +1,92 @@
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.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 TryTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestGGFinder.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
//filesToTest.add(new File(rootDirectory+"fc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav"));
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
// System.out.println(ASTTypePrinter.print(sf));
// System.out.println("---------------------------1");
// System.out.println(ASTPrinter.print(sf));
// System.out.println("---------------------------2");
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> 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("---------------------------3");
System.out.println(ASTPrinter.print(sf));
// System.out.println("---------------------------4");
//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("---------------------------51");
System.out.println(s);
System.out.println("---------------------------52");
}
}
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

@ -0,0 +1,17 @@
class Generics{
a;
id(b) {
var c = b;
return c;
}
setA(x) {
a = x;
return a;
}
m(x,y) {
x = id(y);
}
}