toString geaendert, um Tests generieren zu koennen:
modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java geaendert, um GenerateGenerics direkt teste zu koennen, sollte ggf. wieder rueckgaenig gemacht werden modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java angepasset Tests: modified: src/test/java/insertGenerics/TestLocalVarLambda.java modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java modified: src/test/java/insertGenerics/TestTwoArgs.java
This commit is contained in:
parent
539cacef86
commit
e147a8ce85
@ -49,6 +49,23 @@ public class TPHConstraint {
|
||||
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
|
||||
public String toString() {
|
||||
if(rel == Relation.EXTENDS) {
|
||||
@ -57,4 +74,13 @@ public class TPHConstraint {
|
||||
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)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
private JavaClassName className;
|
||||
private Resolver resolver;
|
||||
|
||||
|
||||
/**
|
||||
* @param sf
|
||||
* @param listOfResultSets
|
||||
@ -93,6 +94,14 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
return generatedGenericsForSF;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the family of Generated Generics
|
||||
* insbesondere fuer Testzwecke
|
||||
*/
|
||||
public FamilyOfGeneratedGenerics getFogg() {
|
||||
return fogg;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@ -140,6 +149,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs);
|
||||
System.out.println("fogg.classConstraints: "+ fogg.classConstraints);
|
||||
System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition);
|
||||
System.out.println(fogg);
|
||||
|
||||
///*
|
||||
//Fayez Ansatz Anfang
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
|
||||
public class ClassConstraint extends TPHConstraint {
|
||||
//private TPHConstraint constraint;
|
||||
@ -12,4 +13,12 @@ public class ClassConstraint extends TPHConstraint {
|
||||
/*public ClassConstraint(TPHConstraint 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)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -760,6 +760,25 @@ public class FamilyOfGeneratedGenerics {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
|
||||
public class MethodConstraint extends TPHConstraint {
|
||||
public MethodConstraint(String left, String right, Relation 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)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
@ -78,7 +79,12 @@ public class JavaTXCompiler {
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||
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 {
|
||||
this(Arrays.asList(sourceFile), null);
|
||||
}
|
||||
@ -872,6 +878,7 @@ public class JavaTXCompiler {
|
||||
SourceFile sf = sourceFiles.get(f);
|
||||
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
||||
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
||||
this.fogg = sResFinder.getFogg();
|
||||
result.add(simplifyResOfSF);
|
||||
}
|
||||
return result;
|
||||
|
@ -1,6 +1,10 @@
|
||||
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;
|
||||
@ -10,6 +14,8 @@ 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;
|
||||
@ -19,6 +25,8 @@ 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;
|
||||
@ -45,6 +53,24 @@ public class TestLocalVarLambda {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
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("O", "ALU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(computedClassCons, expectedClassCons);
|
||||
|
||||
assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
|
@ -1,7 +1,11 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
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;
|
||||
@ -10,7 +14,9 @@ package insertGenerics;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
@ -19,7 +25,9 @@ package insertGenerics;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -46,6 +54,35 @@ public class TestTPHsAndGenerics {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
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));
|
||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
List<MethodConstraint> lmc;
|
||||
lmc = new ArrayList<>();
|
||||
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);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(computedClassCons, expectedClassCons);
|
||||
|
||||
assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest);
|
||||
|
||||
/*
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
|
@ -1,6 +1,13 @@
|
||||
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.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;
|
||||
@ -19,6 +26,8 @@ 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;
|
||||
@ -45,6 +54,40 @@ public class TestTwoArgs {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
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(computedClassCons, expectedClassCons);
|
||||
|
||||
assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
|
Loading…
Reference in New Issue
Block a user