Merge branch 'simplifyRes' into bigRefactoring

This commit is contained in:
JanUlrich 2020-09-25 18:48:28 +02:00
commit 5fa1cf11ef
25 changed files with 448 additions and 104 deletions

BIN
PluginBau.docx Normal file

Binary file not shown.

19
pom.xml
View File

@ -7,7 +7,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>JavaTXcompiler</artifactId> <artifactId>JavaTXcompiler</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.2</version> <version>0.1</version>
<name>JavaTXcompiler</name> <name>JavaTXcompiler</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<dependencies> <dependencies>
@ -20,7 +20,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<dependency> <dependency>
<groupId>org.antlr</groupId> <groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId> <artifactId>antlr4</artifactId>
<version>4.7</version> <version>4.8-1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
@ -63,6 +63,19 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<skipTests>true</skipTests> <skipTests>true</skipTests>
</configuration> </configuration>
</plugin> </plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>/home/michael/programs/jdk/jdk8u232-b09/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin -->
<plugin> <plugin>
<groupId>org.antlr</groupId> <groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId> <artifactId>antlr4-maven-plugin</artifactId>
@ -161,6 +174,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
</repository> </repository>
</repositories> </repositories>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<tycho.version>0.23.0</tycho.version> <tycho.version>0.23.0</tycho.version>

View File

@ -43,9 +43,8 @@ public class GenericGenratorResultForSourceFile {
return genericGeneratorResultForAllClasses.stream() return genericGeneratorResultForAllClasses.stream()
.filter(sr -> sr.getClassName().equals(name)) .filter(sr -> sr.getClassName().equals(name))
.findAny() .findAny()
.orElseThrow(() -> new NoSuchElementException( .orElse(new GenericsGeneratorResultForClass(name));
"Simplify results for the class " + pkgName + "." + name + " are not found"));
} }
throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found"); return new GenericsGeneratorResultForClass(name);
} }
} }

View File

@ -5,6 +5,9 @@ package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
/** /**
* @author fayez * @author fayez
@ -56,12 +59,16 @@ public class GenericsGeneratorResultForClass {
.anyMatch(i -> i.equals(id)); .anyMatch(i -> i.equals(id));
} }
public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) { public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) {
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id)) Optional<MethodAndConstraints> methodConstraints = methodsAndTheirConstraints.getMethodsAndConstraints()
.findFirst().get().getConstraints(); .stream()
.filter(mc -> mc.getMethodID().equals(id))
.findFirst();
if (methodConstraints.isPresent()) {
return methodConstraints.get().getConstraints();
} else {
return Collections.emptyList();
}
} }
} }

View File

@ -0,0 +1,50 @@
/**
*
*/
package de.dhbwstuttgart.bytecode.simplifyRes;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
/**
* The simplify results of a source file (package)
*
* @author fayez
*
*/
public class GenericGenratorResultForSourceFile {
private String pkgName;
private final List<GenericsGeneratorResultForClass> genericGeneratorResultForAllClasses = new ArrayList<>();
/**
* @param pkgName
*/
public GenericGenratorResultForSourceFile(String pkgName) {
this.pkgName = pkgName;
}
public List<GenericsGeneratorResultForClass> getGenericGeneratorResultForAllClasses() {
return genericGeneratorResultForAllClasses;
}
/**
* Appends the simplify results of a class to simplifyResForSF
*
* @param sResClass simplify results of a class to added
*/
public void addGenericGeneratorResultClass(GenericsGeneratorResultForClass sResClass) {
genericGeneratorResultForAllClasses.add(sResClass);
}
public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {
for (int i = 0; i < genericGeneratorResultForAllClasses.size(); i++) {
GenericsGeneratorResultForClass genericsGeneratorResult = genericGeneratorResultForAllClasses.get(i);
if (genericsGeneratorResult.getClassName().equals(name)) {
return genericsGeneratorResult;
}
}
return new GenericsGeneratorResultForClass(name);
}
}

View File

@ -0,0 +1,75 @@
/**
*
*/
package de.dhbwstuttgart.bytecode.simplifyRes;
import java.util.Collections;
import java.util.List;
import com.google.common.base.Optional;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGeneratorResultsForAllMethods;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
/**
* @author fayez
*
*/
public class GenericsGeneratorResultForClass {
private final String className;
private final List<GenericsGeneratorResult> classConstraints;
private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints;
public GenericsGeneratorResultForClass(String className) {
this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods());
}
/**
* @param className
* @param classConstraints
* @param methodsAndTheirConstraints
*/
public GenericsGeneratorResultForClass(String className, List<GenericsGeneratorResult> classConstraints,
GenericGeneratorResultsForAllMethods methodsAndTheirConstraints) {
this.className = className;
this.classConstraints = classConstraints;
this.methodsAndTheirConstraints = methodsAndTheirConstraints;
}
/**
* @return the className
*/
public String getClassName() {
return className;
}
/**
* @return the classConstraints
*/
public List<GenericsGeneratorResult> getClassConstraints() {
return classConstraints;
}
/**
* @return the methodsAndTheirConstraints
*/
public GenericGeneratorResultsForAllMethods getMethodsAndTheirConstraints() {
return methodsAndTheirConstraints;
}
public boolean contains(String id) {
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().map(mc -> mc.getMethodID())
.anyMatch(i -> i.equals(id));
}
public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) {
java.util.Optional<MethodAndConstraints> methodAndConstraints = methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
.findFirst();
return methodAndConstraints.isPresent() ? methodAndConstraints.get().getConstraints() : Collections.emptyList();
}
}

View File

@ -48,7 +48,7 @@ import java.util.stream.Collectors;
public class JavaTXCompiler { public class JavaTXCompiler {
public static JavaTXCompiler INSTANCE; //public static JavaTXCompiler INSTANCE;
final CompilationEnvironment environment; final CompilationEnvironment environment;
Boolean resultmodel = true; Boolean resultmodel = true;
public final Map<File, SourceFile> sourceFiles = new HashMap<>(); public final Map<File, SourceFile> sourceFiles = new HashMap<>();
@ -57,13 +57,13 @@ public class JavaTXCompiler {
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile)); this(Arrays.asList(sourceFile));
INSTANCE = this; //INSTANCE = this;
} }
public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException { public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
this(sourceFile); this(sourceFile);
this.log = log; this.log = log;
INSTANCE = this; //INSTANCE = this;
} }
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException { public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
@ -71,7 +71,7 @@ public class JavaTXCompiler {
for (File s : sources) { for (File s : sources) {
sourceFiles.put(s, parse(s)); sourceFiles.put(s, parse(s));
} }
INSTANCE = this; //INSTANCE = this;
} }
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException { public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
@ -714,10 +714,14 @@ public class JavaTXCompiler {
return ret; return ret;
} }
public void generateBytecodForFile(String path, HashMap<String, byte[]> classFiles, SourceFile sf, public synchronized void generateBytecodForFile(String path, /* HashMap<String, byte[]> classFiles,*/ SourceFile sf,
List<ResultSet> typeinferenceResult) throws IOException { List<ResultSet> typeinferenceResult, List<GenericGenratorResultForSourceFile> genericResultsRet) throws IOException {
//genericResultsRet is empty; fuer die Rückgabe
try { try {
HashMap<String, byte[]> classFiles = new HashMap<>();
List<GenericGenratorResultForSourceFile> genericResults = getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); List<GenericGenratorResultForSourceFile> genericResults = getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
genericResultsRet.addAll(genericResults);//fuer Rueckgabe
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult, genericResults, sf,path); BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult, genericResults, sf,path);
bytecodeGen.visit(sf); bytecodeGen.visit(sf);
this.writeClassFile(bytecodeGen.getClassFiles(), path); this.writeClassFile(bytecodeGen.getClassFiles(), path);

View File

@ -359,7 +359,7 @@ public class SyntaxTreeGenerator{
&& fieldDeclarationContext.unannTypeOrAuto().unannType() != null){ && fieldDeclarationContext.unannTypeOrAuto().unannType() != null){
fieldType = TypeGenerator.convert(fieldDeclarationContext.unannTypeOrAuto().unannType(), reg, generics); fieldType = TypeGenerator.convert(fieldDeclarationContext.unannTypeOrAuto().unannType(), reg, generics);
}else{ }else{
fieldType = TypePlaceholder.fresh(fieldDeclarationContext.getStart()); fieldType = TypePlaceholder.fresh(fieldDeclarationContext.variableDeclaratorList().getStart()); //PL 2019-12-06: variableDeclaratorList() eingefuegt, um als Token nicht die Modifier zu bekommen
} }
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){ for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
String fieldName = convert(varCtx.variableDeclaratorId()); String fieldName = convert(varCtx.variableDeclaratorId());

View File

@ -6,7 +6,7 @@ import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/** /**
* Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung * Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung
* Beispiel: 'public Feld FeldVar = FeldWert;' * Beispiel: 'public Feld FeldVar = FeldWert;'
* @author janulrich * @author janulrich
* *
@ -17,7 +17,7 @@ public class FieldDeclaration extends Field{
/** /**
* Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig. * Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig.
* Kein nachträgliches hinzfügen von Informationen oder aufrufen von parserPostProcessing ist notwendig. * Kein nachträgliches hinzfügen von Informationen oder aufrufen von parserPostProcessing ist notwendig.
*/ */
public FieldDeclaration(String name, RefTypeOrTPHOrWildcardOrGeneric typ, int modifier, Expression value, Token offset){ public FieldDeclaration(String name, RefTypeOrTPHOrWildcardOrGeneric typ, int modifier, Expression value, Token offset){
super(name, typ, modifier, offset);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset super(name, typ, modifier, offset);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset

View File

@ -63,7 +63,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
@Override @Override
public Token getOffset() { public Token getOffset() {
return null; return super.getOffset();
} }
public String getName() { public String getName() {

View File

@ -36,7 +36,7 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
/** /**
* @author Andreas Stadelmeier, a10023 * @author Andreas Stadelmeier, a10023
* Ruft die TypePlaceholder.fresh()-Methode auf. * Ruft die TypePlaceholder.fresh()-Methode auf.
* Fügt zusätzlich einen Replacementlistener hinzu. * Fügt zusätzlich einen Replacementlistener hinzu.
* @return * @return
*/ */
public static TypePlaceholder fresh(Token position){ public static TypePlaceholder fresh(Token position){

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.typedeployment;
public enum KindOfTypeInsertPoint {
NORMAL_INSERT,
GENERIC_CLASS_INSERT,
GENERERIC_METHOD_INSERT
}

View File

@ -1,9 +1,15 @@
package de.dhbwstuttgart.typedeployment; package de.dhbwstuttgart.typedeployment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import org.antlr.v4.parse.BlockSetTransformer.setAlt_return;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
public class TypeInsert { public class TypeInsert {
@ -22,10 +28,15 @@ public class TypeInsert {
public String insert(String intoSource){ public String insert(String intoSource){
List<TypeInsertPoint> offsets = new ArrayList<>(); List<TypeInsertPoint> offsets = new ArrayList<>();
String ret = point.insert(intoSource, offsets); String ret = intoSource;
offsets.add(point);
for(TypeInsertPoint insertPoint : inserts){ List<TypeInsertPoint> insertsSorted = new ArrayList<>();
ret = insertPoint.insert(ret, offsets); insertsSorted.add(point);
insertsSorted.addAll(inserts);
Collections.sort(insertsSorted, new TypeInsertPoint.TypeInsertPointPositionComparator().reversed());
for(TypeInsertPoint insertPoint : insertsSorted) {
ret = insertPoint.insert(ret, new ArrayList<>());
offsets.add(insertPoint); offsets.add(insertPoint);
} }
return ret; return ret;
@ -53,6 +64,18 @@ public class TypeInsert {
} }
} }
public Set<TypeInsertPoint> getAdditionalPoints() {
TypeInsertPoint.TypeInsertPointPositionComparator comparator = new TypeInsertPoint.TypeInsertPointPositionComparator();
TreeSet<TypeInsertPoint> result = new TreeSet<>(comparator.reversed());
result.addAll(inserts);
return result;
}
public Set<TypeInsertPoint> getAdditionalPointsUnsorted() {
return inserts;
}
public String toString() { public String toString() {
return point.toString(); return point.toString();
} }

View File

@ -1,20 +1,35 @@
package de.dhbwstuttgart.typedeployment; package de.dhbwstuttgart.typedeployment;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.antlr.v4.runtime.Token;
import org.objectweb.asm.Type;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
import de.dhbwstuttgart.bytecode.utilities.MethodUtility; import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
import de.dhbwstuttgart.bytecode.utilities.Resolver; import de.dhbwstuttgart.bytecode.utilities.Resolver;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.result.*; import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.objectweb.asm.Type; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import java.util.*; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
import de.dhbwstuttgart.typeinference.result.ResolvedType;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
/** /**
* TODO: * TODO:
@ -31,49 +46,60 @@ import java.util.*;
*/ */
public class TypeInsertFactory { public class TypeInsertFactory {
private static List<ResultSet> newResults;
public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults){ public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, List<ResultSet> newResults, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles){
return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults); TypeInsertFactory.newResults = newResults;
return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults, simplifyResultsForAllSourceFiles);
} }
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m, public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
ResultSet resultSet) { ResultSet resultSet, List<GenericsGeneratorResult> constraints, List<GenericsGeneratorResult> classConstraints) {
try { /* PL 2020-04-11 auskommentiert
* try {
*/
ResolvedType resolvedType = resultSet.resolveType(type); ResolvedType resolvedType = resultSet.resolveType(type);
TypeInsertPoint insertPoint = new TypeInsertPoint(offset, TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
new TypeToInsertString(resolvedType.resolvedType).insert); new TypeToInsertString(resolvedType.resolvedType, constraints, classConstraints).insert, KindOfTypeInsertPoint.NORMAL_INSERT);
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(); /* PL 2020-04-11 auskommentiert
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(newResults);
for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) { for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString()); GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString());
return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet), resolvedType.getResultPair()); return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet, offset), resolvedType.getResultPair());
} }
return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair()); return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
*/
//GenericsGeneratorResultForClass genericResultsForClass = genericResult.getSimplifyResultsByName("", cl.getClassName().toString());
return new TypeInsert(insertPoint, createGenericInsert(constraints, classConstraints, cl, m, resultSet, offset), resolvedType.getResultPair());
/* PL 2020-04-11 auskommentiert
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
*/
} }
private static synchronized Set<TypeInsertPoint> createGenericInsert(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl, Method m, ResultSet resultSet){ private static synchronized Set<TypeInsertPoint> createGenericInsert(List<GenericsGeneratorResult> methodConstraints, List<GenericsGeneratorResult> classConstraints,ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
Set<TypeInsertPoint> result = createGenericClassInserts(genericResult, cl); Set<TypeInsertPoint> result = createGenericClassInserts(classConstraints, cl);
for (Method method : cl.getMethods()) { Resolver resolver = new Resolver(resultSet);
Resolver resolver = new Resolver(resultSet);
List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method)); if (m != null) {
createMethodConstraints(method, methodConstraints); //List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, m));
} result.addAll(createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset));
}
return result; return result;
} }
private static Set<TypeInsertPoint> createMethodConstraints(Method method, List<GenericsGeneratorResult> constraints) { private static Set<TypeInsertPoint> createMethodConstraints(List<GenericsGeneratorResult> constraints, Token mOffset) {
Set<TypeInsertPoint> result = new HashSet<>(); Set<TypeInsertPoint> result = new HashSet<>();
Token offset = new GenericDeclarationList(method.getGenerics(), new NullToken()).getOffset(); Token offset = mOffset;
if (constraints.size() == 0) { if (constraints.size() == 0) {
result.add(new TypeInsertPoint(offset, ""));
return result; return result;
} }
@ -83,25 +109,25 @@ public class TypeInsertFactory {
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) { if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
insert += genericInsertConstraint.getConstraint().getLeft(); insert += genericInsertConstraint.getConstraint().getLeft();
} else { } else {
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", "; insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight();
} }
insert += ", ";
} }
insert = insert.substring(0, insert.length() -2); insert = insert.substring(0, insert.length() -2);
insert += ">"; insert += ">";
result.add(new TypeInsertPoint(offset, insert)); result.add(new TypeInsertPoint(offset, insert, KindOfTypeInsertPoint.GENERERIC_METHOD_INSERT));
return result; return result;
} }
private static Set<TypeInsertPoint> createGenericClassInserts(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl) { private static Set<TypeInsertPoint> createGenericClassInserts(List<GenericsGeneratorResult> classConstraints, ClassOrInterface cl) {
Set<TypeInsertPoint> result = new HashSet<>(); Set<TypeInsertPoint> result = new HashSet<>();
Token offset = cl.getGenerics().getOffset(); Token offset = cl.getGenerics().getOffset();
List<GenericsGeneratorResult> classConstraints = genericResult.getClassConstraints(); //List<GenericsGeneratorResult> classConstraints = genericResult.getClassConstraints();
if (classConstraints.size() == 0) { if (classConstraints == null || classConstraints.size() == 0) {
result.add(new TypeInsertPoint(offset, ""));
return result; return result;
} }
@ -111,14 +137,15 @@ public class TypeInsertFactory {
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) { if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
insert += genericInsertConstraint.getConstraint().getLeft(); insert += genericInsertConstraint.getConstraint().getLeft();
} else { } else {
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", "; insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight();
} }
insert += ", ";
} }
insert = insert.substring(0, insert.length() -2); insert = insert.substring(0, insert.length() -2);
insert += ">"; insert += ">";
result.add(new TypeInsertPoint(offset, insert)); result.add(new TypeInsertPoint(offset, insert, KindOfTypeInsertPoint.GENERIC_CLASS_INSERT));
return result; return result;
} }
@ -126,9 +153,14 @@ public class TypeInsertFactory {
class TypeToInsertString implements ResultSetVisitor{ class TypeToInsertString implements ResultSetVisitor{
String insert = ""; String insert = "";
private List<GenericsGeneratorResult> constraints;
private List<GenericsGeneratorResult> classConstraints;
TypeToInsertString(RefTypeOrTPHOrWildcardOrGeneric type){ TypeToInsertString(RefTypeOrTPHOrWildcardOrGeneric type, List<GenericsGeneratorResult> constraints, List<GenericsGeneratorResult> classConstraints){
type.accept(this); this.constraints = constraints;
this.classConstraints = classConstraints;
type.accept(this);
} }
@Override @Override
@ -154,7 +186,7 @@ class TypeToInsertString implements ResultSetVisitor{
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iterator = resolved.getParaList().iterator(); Iterator<RefTypeOrTPHOrWildcardOrGeneric> iterator = resolved.getParaList().iterator();
while(iterator.hasNext()){ while(iterator.hasNext()){
RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next(); RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next();
insert += new TypeToInsertString(typeParam).insert; insert += new TypeToInsertString(typeParam, constraints, classConstraints).insert;
if(iterator.hasNext())insert += ", "; if(iterator.hasNext())insert += ", ";
} }
insert += ">"; insert += ">";
@ -168,16 +200,37 @@ class TypeToInsertString implements ResultSetVisitor{
@Override @Override
public void visit(SuperWildcardType superWildcardType) { public void visit(SuperWildcardType superWildcardType) {
insert += "? super " + new TypeToInsertString(superWildcardType.getInnerType()).insert; insert += "? super " + new TypeToInsertString(superWildcardType.getInnerType(), constraints, classConstraints).insert;
} }
@Override @Override
public void visit(TypePlaceholder typePlaceholder) { public void visit(TypePlaceholder typePlaceholder) {
insert += typePlaceholder.getName(); String realName = typePlaceholder.getName();
//String realName = sig2.substring(1, sig2.length() - 1);
//String toVisit = realName+SPECIAL_CHAR;
//if(!genericsAndBounds.containsKey(toVisit)) {//PL 202-04-1 vielleicht braucht man das, vgl. Signature.java
Optional<GenericsGeneratorResult> equalTPH = getEqualTPHFromClassConstraints(classConstraints, realName);
if(equalTPH.isPresent()){
insert += equalTPH.get().getConstraint().getLeft();// + SPECIAL_CHAR;
} else {
insert += getEqualTPH(constraints, realName);// + SPECIAL_CHAR;
}
} }
@Override @Override
public void visit(ExtendsWildcardType extendsWildcardType) { public void visit(ExtendsWildcardType extendsWildcardType) {
insert += "? extends " + new TypeToInsertString(extendsWildcardType.getInnerType()).insert; insert += "? extends " + new TypeToInsertString(extendsWildcardType.getInnerType(), constraints, classConstraints).insert;
} }
private Optional<GenericsGeneratorResult> getEqualTPHFromClassConstraints(List<GenericsGeneratorResult> listOfConstraints, String tph) {
return listOfConstraints.stream()
.filter(c -> c.getConstraint().getLeft().equals(tph) || c.getEqualsTPHs().contains(tph))
.findFirst();
}
private String getEqualTPH(List<GenericsGeneratorResult> constraints2, String tph) {
return constraints2.stream()
.filter(c -> c.getConstraint().getLeft().equals(tph) || c.getEqualsTPHs().contains(tph))
.findFirst().get().getConstraint().getLeft();
}
} }

View File

@ -1,59 +1,85 @@
package de.dhbwstuttgart.typedeployment; package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
import de.dhbwstuttgart.bytecode.utilities.Resolver;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
public class TypeInsertPlacer extends AbstractASTWalker{ public class TypeInsertPlacer extends AbstractASTWalker{
Set<TypeInsert> inserts = new HashSet<>(); Set<TypeInsert> inserts = new HashSet<>();
private ResultSet withResults; private ResultSet withResults;
String pkgName;
private List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
public Set<TypeInsert> getTypeInserts(SourceFile forSourceFile, ResultSet withResults){ public Set<TypeInsert> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles){
this.withResults = withResults; this.withResults = withResults;
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
pkgName = forSourceFile.getPkgName();
forSourceFile.accept(this); forSourceFile.accept(this);
return inserts; return inserts;
} }
@Override @Override
public void visit(ClassOrInterface classOrInterface) { public void visit(ClassOrInterface classOrInterface) {
TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults); GenericsGeneratorResultForClass generatedGenerics = simplifyResultsForAllSourceFiles
.stream()
.map(sr->sr.getSimplifyResultsByName(pkgName, classOrInterface.getClassName().toString()))
.findFirst()
.get();
TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults, generatedGenerics);
this.inserts.addAll(cl.inserts); this.inserts.addAll(cl.inserts);
} }
} }
class TypeInsertPlacerClass extends AbstractASTWalker{ class TypeInsertPlacerClass extends AbstractASTWalker{
protected final ResultSet results; protected final ResultSet results;
private GenericsGeneratorResultForClass generatedGenerics;
protected final ClassOrInterface cl; protected final ClassOrInterface cl;
public final Set<TypeInsert> inserts = new HashSet<>(); public final Set<TypeInsert> inserts = new HashSet<>();
private Method method; private Method method;
private Resolver resolver;
List<GenericsGeneratorResult> constraints;
List<GenericsGeneratorResult> classConstraints;
TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults){ TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsGeneratorResultForClass generatedGenerics){
this.cl = forClass; this.cl = forClass;
this.method = null; this.method = null;
this.results = withResults; this.results = withResults;
this.generatedGenerics = generatedGenerics;
resolver = new Resolver(withResults); //PL 2020-04-12 Ob das stimmt weiss ich nicht
forClass.accept(this); forClass.accept(this);
} }
@Override @Override
public void visit(Method method) { public void visit(Method method) {
this.method = method; this.method = method;
String id = MethodUtility.createID(resolver, method);
constraints = generatedGenerics.getMethodConstraintsByID(id);
classConstraints = generatedGenerics.getClassConstraints();
if(method.getReturnType() instanceof TypePlaceholder) if(method.getReturnType() instanceof TypePlaceholder)
inserts.add(TypeInsertFactory.createInsertPoints( inserts.add(TypeInsertFactory.createInsertPoints(
method.getReturnType(), method.getReturnType().getOffset(), cl, method, results)); method.getReturnType(), method.getReturnType().getOffset(), cl, method, results, constraints, classConstraints));
super.visit(method); super.visit(method);
} }
@Override @Override
public void visit(Field field) { public void visit(Field field) {
if(field.getType() instanceof TypePlaceholder){ if(field.getType() instanceof TypePlaceholder){
classConstraints = generatedGenerics.getClassConstraints();
inserts.add(TypeInsertFactory.createInsertPoints( inserts.add(TypeInsertFactory.createInsertPoints(
field.getType(), field.getType().getOffset(), cl, method, results)); field.getType(), field.getType().getOffset(), cl, method, results, new ArrayList<>(), classConstraints));
} }
super.visit(field); super.visit(field);
} }
@ -62,7 +88,7 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
public void visit(FormalParameter param) { public void visit(FormalParameter param) {
if(param.getType() instanceof TypePlaceholder) if(param.getType() instanceof TypePlaceholder)
inserts.add(TypeInsertFactory.createInsertPoints( inserts.add(TypeInsertFactory.createInsertPoints(
param.getType(), param.getType().getOffset(), cl, method, results)); param.getType(), param.getType().getOffset(), cl, method, results, constraints, classConstraints));
super.visit(param); super.visit(param);
} }

View File

@ -1,29 +1,29 @@
package de.dhbwstuttgart.typedeployment; package de.dhbwstuttgart.typedeployment;
import org.antlr.v4.runtime.Token; import java.util.Comparator;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import java.time.OffsetDateTime;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.Set;
import org.antlr.v4.runtime.Token;
public class TypeInsertPoint { public class TypeInsertPoint {
public Token point; public Token point;
private String insertString; private String insertString;
private int extraOffset = 0; private int extraOffset = 0;
private KindOfTypeInsertPoint kind;
public TypeInsertPoint(Token point, String toInsert){ public TypeInsertPoint(Token point, String toInsert, KindOfTypeInsertPoint kind){
this.point = point; this.point = point;
this.kind = kind;
this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ; this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ;
} }
public boolean isGenericClassInsertPoint() {
return kind == KindOfTypeInsertPoint.GENERIC_CLASS_INSERT;
}
public String insert(String intoSource, List<TypeInsertPoint> additionalOffset){ public String insert(String intoSource, List<TypeInsertPoint> additionalOffset){
int offset = additionalOffset.stream().filter((token -> return new StringBuilder(intoSource).insert(point.getStartIndex()+extraOffset, insertString).toString();
//token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
token.point.getStartIndex() <= point.getStartIndex()))
.mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString();
} }
public String getInsertString() { public String getInsertString() {
@ -44,16 +44,50 @@ public class TypeInsertPoint {
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
public boolean equals(Object obj) { public boolean equals(Object obj) {
return this == obj;
/*
if(!(obj instanceof TypeInsertPoint)) { if(!(obj instanceof TypeInsertPoint)) {
return false; return false;
} }
else { else {
return ((TypeInsertPoint)obj).point.equals(this.point) && return
((TypeInsertPoint)obj).insertString.equals(this.insertString); ((TypeInsertPoint)obj).getPositionInCode() == this.getPositionInCode() &&
} ((TypeInsertPoint)obj).insertString.equals(this.insertString);
}
*/
}
public int hashCode() {
return getPositionInCode() * 11 * insertString.hashCode();
}
public Set<TypeInsertPoint> getAdditionalPoints() {
return this.getAdditionalPoints();
} }
public String toString() { public String toString() {
return point.toString() + " " + insertString.toString(); return point.getLine() + ":" + point.getCharPositionInLine() + ":" + insertString;
}
public static final class TypeInsertPointPositionComparator implements Comparator<TypeInsertPoint> {
@Override
public int compare(TypeInsertPoint o1, TypeInsertPoint o2) {
if (o1.point == null && o2.point == null) {
return 0;
} else if (o2.point == null) {
return 1;
} else if (o1.point == null) {
return -1;
}
if (o1.getPositionInCode() > o2.getPositionInCode()) {
return 1;
} else if (o1.getPositionInCode() < o2.getPositionInCode()) {
return -1;
}
return 0;
}
} }
} }

View File

@ -186,6 +186,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
usedTasks.cancel(); usedTasks.cancel();
writeLog(nOfUnify.toString() + "cancel"); writeLog(nOfUnify.toString() + "cancel");
System.out.println("cancel"); System.out.println("cancel");
try {
logFile.write("Abbruch");
}
catch (IOException e) {
System.err.println("log-File nicht vorhanden");
}
} }
*/ */
rules = new RuleSet(logFile); rules = new RuleSet(logFile);
@ -303,6 +309,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* /*
* Step 1: Repeated application of reduce, adapt, erase, swap * Step 1: Repeated application of reduce, adapt, erase, swap
*/ */
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
rekTiefe++; rekTiefe++;
nOfUnify++; nOfUnify++;
@ -463,7 +474,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// .collect(Collectors.toCollection(HashSet::new)); // .collect(Collectors.toCollection(HashSet::new));
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>(); Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
@ -907,6 +922,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("wait "+ forkOrig.thNo); writeLog("wait "+ forkOrig.thNo);
noOfThread--; noOfThread--;
res = forkOrig.join(); res = forkOrig.join();
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
//noOfThread++; //noOfThread++;
forkOrig.writeLog("final Orig 1"); forkOrig.writeLog("final Orig 1");
forkOrig.closeLogFile(); forkOrig.closeLogFile();
@ -922,6 +942,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
synchronized (this) { synchronized (this) {
noOfThread--; noOfThread--;
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
//noOfThread++; //noOfThread++;
writeLog("Join " + new Integer(fork.thNo).toString()); writeLog("Join " + new Integer(fork.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
@ -1013,6 +1038,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("wait "+ forkOrig.thNo); writeLog("wait "+ forkOrig.thNo);
noOfThread--; noOfThread--;
res = forkOrig.join(); res = forkOrig.join();
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
//noOfThread++; //noOfThread++;
forkOrig.writeLog("final Orig -1"); forkOrig.writeLog("final Orig -1");
forkOrig.closeLogFile(); forkOrig.closeLogFile();
@ -1028,6 +1058,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
synchronized (this) { synchronized (this) {
noOfThread--; noOfThread--;
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
//noOfThread++; //noOfThread++;
writeLog("Join " + new Integer(fork.thNo).toString()); writeLog("Join " + new Integer(fork.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
@ -1089,6 +1124,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("wait "+ forkOrig.thNo); writeLog("wait "+ forkOrig.thNo);
noOfThread--; noOfThread--;
res = forkOrig.join(); res = forkOrig.join();
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
//noOfThread++; //noOfThread++;
forkOrig.writeLog("final Orig 2"); forkOrig.writeLog("final Orig 2");
forkOrig.closeLogFile(); forkOrig.closeLogFile();
@ -1103,6 +1143,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
synchronized (this) { synchronized (this) {
noOfThread--; noOfThread--;
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
synchronized (usedTasks) {
if (this.myIsCancelled()) {
return new HashSet<>();
}
}
//noOfThread++; //noOfThread++;
writeLog("Join " + new Integer(fork.thNo).toString()); writeLog("Join " + new Integer(fork.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
@ -1224,7 +1269,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
result = par_res; result = par_res;
if (par_res.iterator().next() instanceof WildcardType) { if (!par_res.isEmpty() && par_res.iterator().next() instanceof WildcardType) {
System.out.println(""); System.out.println("");
} }
} }

View File

@ -1,5 +1,6 @@
package typeinference; package typeinference;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -133,7 +134,8 @@ public class JavaTXCompilerTest {
System.out.println(ASTPrinter.print(sf)); System.out.println(ASTPrinter.print(sf));
} }
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){ for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f); SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf)); System.out.println(ASTTypePrinter.print(sf));
@ -142,7 +144,7 @@ public class JavaTXCompilerTest {
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){ for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0; assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8); String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){ for(TypeInsert tip : result){

View File

@ -1,5 +1,6 @@
package typeinference; package typeinference;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -105,6 +106,7 @@ public class Meth_GenTest {
System.out.println(ASTPrinter.print(sf)); System.out.println(ASTPrinter.print(sf));
} }
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
for(File f : compiler.sourceFiles.keySet()){ for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f); SourceFile sf = compiler.sourceFiles.get(f);
@ -114,7 +116,7 @@ public class Meth_GenTest {
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){ for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0; assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8); String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){ for(TypeInsert tip : result){

View File

@ -1,5 +1,6 @@
package typeinference; package typeinference;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@ -131,6 +132,7 @@ public class UnifyTest {
System.out.println(ASTPrinter.print(sf)); System.out.println(ASTPrinter.print(sf));
} }
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
for(File f : compiler.sourceFiles.keySet()){ for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f); SourceFile sf = compiler.sourceFiles.get(f);
@ -140,7 +142,7 @@ public class UnifyTest {
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){ for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0; assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8); String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){ for(TypeInsert tip : result){

View File

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

View File

@ -1,7 +1,7 @@
import java.lang.Integer; import java.lang.Integer;
public class Field { public class Field {
public Integer x = 5; public x = 5;
m(){ m(){
return x; return x;

View File

@ -2,7 +2,7 @@ import java.lang.Integer;
import java.lang.Boolean; import java.lang.Boolean;
import java.lang.Object; import java.lang.Object;
public class IfTest{ public class IfTest {
Object m1(b) { Object m1(b) {
Integer i; Integer i;
if(b) { if(b) {

View File

@ -14,7 +14,7 @@ call(String s){}
} }
class Pair<A,B>{ class Pair{
A left; left;
B right; right;
} }

View File

@ -8,7 +8,7 @@ class Test{
} }
interface Klasse1{ interface Klasse1{
Klasse1 meth(List p); Klasse1 meth(p);
Klasse1 meth(Klasse2 p); Klasse1 meth(Klasse2 p);
} }