forked from JavaTX/JavaCompilerCore
Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode
This commit is contained in:
commit
034a398515
Binary file not shown.
24
doc/pluginBau.md
Normal file
24
doc/pluginBau.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
## Bau und installation des Eclipse plugins
|
||||||
|
|
||||||
|
1. Zunächst muss der JavaTX Compiler gebaut werden. Dafür wird im Rootverzeichnis des JavaTX Compilers
|
||||||
|
`mvn install` ausgeführt. Falls die Tests nicht laufen kann das mit `-DskipTests` beseitigt werden.
|
||||||
|
|
||||||
|
2. Dann muss das Plugin gebaut werden. Dafür muss ebenfalls `mvn install` ausgeführt werden, im Rootverzeichnis des Plugins.
|
||||||
|
Falls es dabei zu Fehlern mit der Java-Version kommen sollte muss man in ~\.mavenrc oder \~.mavenrc_pre.bat die Zeile
|
||||||
|
`set JAVA_HOME=<JDK-19-Pfad>` (Windows) oder `JAVA_HOME="<JDK-19-Pfad>"` (Linux) einfügen. Damit sollte maven korrekt konfiguriert sein.
|
||||||
|
|
||||||
|
3. Als letzter Schritt muss nun das Plugin in Eclipse geladen werden. Wichtig dabei ist, dass Eclipse selber mit Java 19 startet.
|
||||||
|
Dafür kann die Datei `eclipse.ini` angepasst werden die im Installationsverzeichnis von Eclipse vorhanden ist. Hier müssen zwei Zeilen
|
||||||
|
eingetragen werden:
|
||||||
|
```
|
||||||
|
-vm
|
||||||
|
<JDK-19-Pfad>/javaw.exe
|
||||||
|
```
|
||||||
|
Ganz am Anfang der Datei
|
||||||
|
und unter -vmargs die Option `--enable-preview`
|
||||||
|
|
||||||
|
4. Das gebaute Plugin befindet sich unter `JavaCompilerPlugin\releng\JavaCompilerPlugin.Update\target`
|
||||||
|
Um dieses Plugin in Eclipse laden zu können muss den Dialog `Help > Install new Software` öffnen. Oben rechts steht die Option `Add...`
|
||||||
|
Im sich öffnenden Dialog muss man `Archive` anklicken und dort das Zip Archiv aus dem Oben genannten Pfad einfügen. Nun mit Add den Dialog schließen.
|
||||||
|
Als letztes muss in der Liste oben der Eintrag `JavaCompilerPlugin.Update` ausgewählt werden. Hier sollte nun unten das Plugin angezeigt werden.
|
||||||
|
Einfach auswählen und unten Next drücken. Damit sollte der Vorgang abgeschlossen sein.
|
8
pom.xml
8
pom.xml
@ -54,8 +54,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<version>3.8.0</version>
|
<version>3.8.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<compilerArgs>--enable-preview</compilerArgs>
|
<compilerArgs>--enable-preview</compilerArgs>
|
||||||
<source>20</source>
|
<source>19</source>
|
||||||
<target>20</target>
|
<target>19</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -112,8 +112,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>20</maven.compiler.source>
|
<maven.compiler.source>19</maven.compiler.source>
|
||||||
<maven.compiler.target>20</maven.compiler.target>
|
<maven.compiler.target>19</maven.compiler.target>
|
||||||
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
||||||
</properties>
|
</properties>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package de.dhbwstuttgart.bytecode.constraint;
|
|
||||||
|
|
||||||
public class EqualConstraint extends TPHConstraint {
|
|
||||||
|
|
||||||
public EqualConstraint(String left, String right) {
|
|
||||||
super(left, right, Relation.EQUAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package de.dhbwstuttgart.bytecode.constraint;
|
|
||||||
|
|
||||||
public class ExtendsConstraint extends TPHConstraint {
|
|
||||||
|
|
||||||
public ExtendsConstraint(String left, String right) {
|
|
||||||
super(left, right, Relation.EXTENDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
package de.dhbwstuttgart.bytecode.constraint;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
|
|
||||||
public class TPHConstraint {
|
|
||||||
protected String left;
|
|
||||||
protected String right;
|
|
||||||
protected Relation rel;
|
|
||||||
protected int variance; //noch nicht benutzt
|
|
||||||
public enum Relation{
|
|
||||||
EXTENDS, EQUAL
|
|
||||||
}
|
|
||||||
|
|
||||||
public TPHConstraint(Pair p) {
|
|
||||||
this.left = ((TypePlaceholder)p.TA1).getName();
|
|
||||||
this.right = ((TypePlaceholder)p.TA2).getName();
|
|
||||||
this.rel = p.GetOperator().equals(PairOperator.SMALLERDOT) ? Relation.EXTENDS : Relation.EQUAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TPHConstraint(String left, String right, Relation rel) {
|
|
||||||
this.left = left;
|
|
||||||
this.right = right;
|
|
||||||
this.rel = rel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLeft() {
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getRight() {
|
|
||||||
return right;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Relation getRel() {
|
|
||||||
return rel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLeft(String left) {
|
|
||||||
this.left = left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRight(String right) {
|
|
||||||
this.right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRel(Relation rel) {
|
|
||||||
this.rel = rel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containTPH(String tph) {
|
|
||||||
return left.equals(tph)||right.equals(tph);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equalConstraint(TPHConstraint constraint) {
|
|
||||||
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 (this.left.equals(o_tphcons.getLeft())
|
|
||||||
&& this.right.equals(o_tphcons.getRight())
|
|
||||||
&& this.rel.equals(o_tphcons.rel));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
if(rel == Relation.EXTENDS) {
|
|
||||||
return left + " < " + right;
|
|
||||||
}else {
|
|
||||||
return left + " = " + right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
|
|
||||||
public class ConstraintsWithSameLeftSide {
|
|
||||||
private List<TPHConstraint> constraints;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param constraints
|
|
||||||
*/
|
|
||||||
public ConstraintsWithSameLeftSide(List<TPHConstraint> constraints) {
|
|
||||||
this.constraints = constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the constraints
|
|
||||||
*/
|
|
||||||
public List<TPHConstraint> getConstraints() {
|
|
||||||
return constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param constraints the constraints to set
|
|
||||||
*/
|
|
||||||
public void setConstraints(List<TPHConstraint> constraints) {
|
|
||||||
this.constraints = constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "[" + constraints.toString() + "]";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GenericGeneratorResultsForAllMethods {
|
|
||||||
private final List<MethodAndConstraints> methodsAndConstraints;
|
|
||||||
|
|
||||||
public GenericGeneratorResultsForAllMethods() {
|
|
||||||
this(Collections.emptyList());
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param methodsAndConstraints
|
|
||||||
*/
|
|
||||||
public GenericGeneratorResultsForAllMethods(List<MethodAndConstraints> methodsAndConstraints) {
|
|
||||||
this.methodsAndConstraints = methodsAndConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the methodsAndConstraints
|
|
||||||
*/
|
|
||||||
public List<MethodAndConstraints> getMethodsAndConstraints() {
|
|
||||||
return methodsAndConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String ret = "";
|
|
||||||
ret = ret + methodsAndConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y);
|
|
||||||
//ret = ret + "\n";
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
||||||
|
|
||||||
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(JavaClassName name) {
|
|
||||||
|
|
||||||
if (this.pkgName.equals(name.getPackageName())) {
|
|
||||||
return genericGeneratorResultForAllClasses.stream()
|
|
||||||
.filter(sr -> sr.getClassName().equals(name))
|
|
||||||
.findAny()
|
|
||||||
.orElse(new GenericsGeneratorResultForClass(name));
|
|
||||||
}
|
|
||||||
return new GenericsGeneratorResultForClass(name);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GenericsGeneratorResult {
|
|
||||||
private TPHConstraint constraint;
|
|
||||||
/**
|
|
||||||
* contains the names of all type placeholders which are equals to the left side of
|
|
||||||
* the constraint {@link #constraint}.
|
|
||||||
*/
|
|
||||||
private Set<String> equalsTPHs;
|
|
||||||
/**
|
|
||||||
* @param constraint
|
|
||||||
* @param equalsTPHs
|
|
||||||
*/
|
|
||||||
public GenericsGeneratorResult(TPHConstraint constraint, Set<String> equalsTPHs) {
|
|
||||||
this.constraint = constraint;
|
|
||||||
this.equalsTPHs = equalsTPHs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the constraint
|
|
||||||
*/
|
|
||||||
public TPHConstraint getConstraint() {
|
|
||||||
return constraint;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param constraint the constraint to set
|
|
||||||
*/
|
|
||||||
public void setConstraint(TPHConstraint constraint) {
|
|
||||||
this.constraint = constraint;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return the equalsTPHs
|
|
||||||
*/
|
|
||||||
public Set<String> getEqualsTPHs() {
|
|
||||||
return equalsTPHs;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param equalsTPHs the equalsTPHs to set
|
|
||||||
*/
|
|
||||||
public void setEqualsTPHs(Set<String> equalsTPHs) {
|
|
||||||
this.equalsTPHs = equalsTPHs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GenericsGeneratorResultForClass {
|
|
||||||
private final JavaClassName className;
|
|
||||||
private final List<GenericsGeneratorResult> classConstraints;
|
|
||||||
private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints;
|
|
||||||
|
|
||||||
public GenericsGeneratorResultForClass(JavaClassName className) {
|
|
||||||
this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods());
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param className
|
|
||||||
* @param classConstraints
|
|
||||||
* @param methodsAndTheirConstraints
|
|
||||||
*/
|
|
||||||
public GenericsGeneratorResultForClass(JavaClassName className, List<GenericsGeneratorResult> classConstraints,
|
|
||||||
GenericGeneratorResultsForAllMethods methodsAndTheirConstraints) {
|
|
||||||
this.className = className;
|
|
||||||
this.classConstraints = classConstraints;
|
|
||||||
this.methodsAndTheirConstraints = methodsAndTheirConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the className
|
|
||||||
*/
|
|
||||||
public JavaClassName 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) {
|
|
||||||
Optional<MethodAndConstraints> methodConstraints = methodsAndTheirConstraints.getMethodsAndConstraints()
|
|
||||||
.stream()
|
|
||||||
.filter(mc -> mc.getMethodID().equals(id))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
if (methodConstraints.isPresent()) {
|
|
||||||
return methodConstraints.get().getConstraints();
|
|
||||||
} else {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String ret = "Classconstraints: ";
|
|
||||||
ret = ret + classConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y);
|
|
||||||
ret = ret + "\n" + methodsAndTheirConstraints.toString();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MethodAndConstraints {
|
|
||||||
private final String methodID;
|
|
||||||
private final List<GenericsGeneratorResult> constraints;
|
|
||||||
/**
|
|
||||||
* @param methodID
|
|
||||||
* @param constraints
|
|
||||||
*/
|
|
||||||
public MethodAndConstraints(String methodID, List<GenericsGeneratorResult> constraints) {
|
|
||||||
this.methodID = methodID;
|
|
||||||
this.constraints = constraints;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return the methodID
|
|
||||||
*/
|
|
||||||
public String getMethodID() {
|
|
||||||
// FIXME
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return the constraints
|
|
||||||
*/
|
|
||||||
public List<GenericsGeneratorResult> getConstraints() {
|
|
||||||
return constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String ret = methodID + ": ";
|
|
||||||
ret = ret + constraints.stream().reduce("",
|
|
||||||
(x,y) -> x + y.toString(),
|
|
||||||
(x,y) -> x + y);
|
|
||||||
ret = ret + "\n";
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class NameReplacementResult {
|
|
||||||
private String name;
|
|
||||||
private List<String> oldNames;
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
* @param oldNames
|
|
||||||
*/
|
|
||||||
public NameReplacementResult(String name, List<String> oldNames) {
|
|
||||||
this.name = name;
|
|
||||||
this.oldNames = oldNames;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return the name
|
|
||||||
*/
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param name the name to set
|
|
||||||
*/
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return the oldNames
|
|
||||||
*/
|
|
||||||
public List<String> getOldNames() {
|
|
||||||
return oldNames;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param oldNames the oldNames to set
|
|
||||||
*/
|
|
||||||
public void setOldNames(List<String> oldNames) {
|
|
||||||
this.oldNames = oldNames;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -3,7 +3,6 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import de.dhbwstuttgart.bytecode.Codegen;
|
import de.dhbwstuttgart.bytecode.Codegen;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
@ -857,10 +856,9 @@ public class JavaTXCompiler {
|
|||||||
generateBytecode(path, typeinferenceResult);
|
generateBytecode(path, typeinferenceResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<File, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
private Map<SourceFile, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
||||||
|
|
||||||
// TODO This is a temporary solution, we should integrate with the old API for getting Generics
|
public Map<SourceFile, List<GenericsResult>> getGeneratedGenerics() {
|
||||||
public Map<File, List<GenericsResult>> getGeneratedGenerics() {
|
|
||||||
return generatedGenerics;
|
return generatedGenerics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,22 +878,27 @@ public class JavaTXCompiler {
|
|||||||
path = new File(outputPath ,sf.getPkgName().replace(".","/")); //add package path to root path
|
path = new File(outputPath ,sf.getPkgName().replace(".","/")); //add package path to root path
|
||||||
}
|
}
|
||||||
|
|
||||||
var converter = new ASTToTargetAST(typeinferenceResult, sf, classLoader);
|
var generatedClasses = generateBytecode(sf, typeinferenceResult);
|
||||||
var generatedClasses = new HashMap<JavaClassName, byte[]>();
|
|
||||||
for (var clazz : sf.getClasses()) {
|
|
||||||
var codegen = new Codegen(converter.convert(clazz));
|
|
||||||
var code = codegen.generate();
|
|
||||||
generatedClasses.put(clazz.getClassName(), code);
|
|
||||||
converter.auxiliaries.forEach((name, source) -> {
|
|
||||||
generatedClasses.put(new JavaClassName(name), source);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
generatedGenerics.put(f, converter.javaGenerics());
|
|
||||||
writeClassFile(generatedClasses, path);
|
writeClassFile(generatedClasses, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeClassFile(HashMap<JavaClassName, byte[]> classFiles, File path) throws IOException {
|
public Map<JavaClassName, byte[]> generateBytecode(SourceFile sf, List<ResultSet> typeInferenceResult) {
|
||||||
|
var converter = new ASTToTargetAST(typeInferenceResult, sf, classLoader);
|
||||||
|
var generatedClasses = new HashMap<JavaClassName, byte[]>();
|
||||||
|
for (var clazz : sf.getClasses()) {
|
||||||
|
var codegen = new Codegen(converter.convert(clazz));
|
||||||
|
var code = codegen.generate();
|
||||||
|
generatedClasses.put(clazz.getClassName(), code);
|
||||||
|
converter.auxiliaries.forEach((name, source) -> {
|
||||||
|
generatedClasses.put(new JavaClassName(name), source);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
generatedGenerics.put(sf, converter.javaGenerics());
|
||||||
|
return generatedClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeClassFile(Map<JavaClassName, byte[]> classFiles, File path) throws IOException {
|
||||||
FileOutputStream output;
|
FileOutputStream output;
|
||||||
for (JavaClassName name : classFiles.keySet()) {
|
for (JavaClassName name : classFiles.keySet()) {
|
||||||
byte[] bytecode = classFiles.get(name);
|
byte[] bytecode = classFiles.get(name);
|
||||||
@ -911,11 +914,6 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles(List<ResultSet> results) {
|
|
||||||
// FIXME
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */
|
/* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */
|
||||||
/**
|
/**
|
||||||
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
|
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
|
||||||
|
@ -4,28 +4,27 @@ import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GenericsResult {
|
public class GenericsResult {
|
||||||
final ASTToTargetAST.GenerateGenerics generics;
|
private final ASTToTargetAST.GenerateGenerics generics;
|
||||||
|
|
||||||
GenericsResult(ASTToTargetAST.GenerateGenerics generics) {
|
GenericsResult(ASTToTargetAST.GenerateGenerics generics) {
|
||||||
this.generics = generics;
|
this.generics = generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ResultPair<?, ?>> get(ClassOrInterface clazz) {
|
public GenericsResultSet get(ClassOrInterface clazz) {
|
||||||
var generics = this.generics.computedGenericsOfClasses.get(clazz);
|
var generics = this.generics.computedGenericsOfClasses.get(clazz);
|
||||||
if (generics == null) return Set.of();
|
return new GenericsResultSet(generics, this.generics.equality);
|
||||||
return generics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Compute generics if not present?
|
// TODO Compute generics if not present?
|
||||||
public Set<ResultPair<?, ?>> get(Method method) {
|
public GenericsResultSet get(Method method) {
|
||||||
var generics = this.generics.computedGenericsOfMethods.get(method);
|
var generics = this.generics.computedGenericsOfMethods.get(method);
|
||||||
if (generics == null) return Set.of();
|
return new GenericsResultSet(generics, this.generics.equality);
|
||||||
return generics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {
|
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {
|
||||||
@ -70,4 +69,8 @@ public class GenericsResult {
|
|||||||
return this.generics.getType(tph);
|
return this.generics.getType(tph);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TargetType resolveTarget(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
|
return this.generics.getTargetType(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class GenericsResultSet extends AbstractSet<ResultPair<?, ?>> {
|
||||||
|
|
||||||
|
final Set<ResultPair<?, ?>> backing;
|
||||||
|
final Map<TypePlaceholder, TypePlaceholder> equality;
|
||||||
|
|
||||||
|
public GenericsResultSet(Set<ResultPair<?, ?>> backing, Map<TypePlaceholder, TypePlaceholder> equality) {
|
||||||
|
this.backing = backing == null ? new HashSet<>() : new HashSet<>(backing);
|
||||||
|
this.equality = equality;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<ResultPair<?, ?>> iterator() {
|
||||||
|
return backing.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return backing.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ResultPair<?, ?>> getResultPairFor(TypePlaceholder tph) {
|
||||||
|
var tph2 = equality.getOrDefault(tph, tph);
|
||||||
|
return this.stream().filter(pair -> pair.getLeft().equals(tph2)).findFirst();
|
||||||
|
}
|
||||||
|
}
|
@ -2,15 +2,13 @@ package de.dhbwstuttgart.typedeployment;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.*;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
@ -20,12 +18,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
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:
|
||||||
@ -42,16 +34,12 @@ import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
|||||||
*/
|
*/
|
||||||
public class TypeInsertFactory {
|
public class TypeInsertFactory {
|
||||||
|
|
||||||
private static List<ResultSet> newResults;
|
public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, GenericsResult generics) {
|
||||||
|
return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults, generics);
|
||||||
|
|
||||||
public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, List<ResultSet> newResults, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles){
|
|
||||||
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, List<GenericsGeneratorResult> constraints, List<GenericsGeneratorResult> classConstraints) {
|
ResultSet resultSet, GenericsResultSet constraints, GenericsResultSet classConstraints) {
|
||||||
|
|
||||||
/* PL 2020-04-11 auskommentiert
|
/* PL 2020-04-11 auskommentiert
|
||||||
* try {
|
* try {
|
||||||
@ -79,7 +67,7 @@ public class TypeInsertFactory {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized Set<TypeInsertPoint> createGenericInsert(List<GenericsGeneratorResult> methodConstraints, List<GenericsGeneratorResult> classConstraints,ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
|
private static synchronized Set<TypeInsertPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints,ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
|
||||||
Set<TypeInsertPoint> result = createGenericClassInserts(classConstraints, cl);
|
Set<TypeInsertPoint> result = createGenericClassInserts(classConstraints, cl);
|
||||||
|
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
@ -90,7 +78,7 @@ public class TypeInsertFactory {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<TypeInsertPoint> createMethodConstraints(List<GenericsGeneratorResult> constraints, Token mOffset) {
|
private static Set<TypeInsertPoint> createMethodConstraints(GenericsResultSet constraints, Token mOffset) {
|
||||||
Set<TypeInsertPoint> result = new HashSet<>();
|
Set<TypeInsertPoint> result = new HashSet<>();
|
||||||
Token offset = mOffset;
|
Token offset = mOffset;
|
||||||
|
|
||||||
@ -100,11 +88,11 @@ public class TypeInsertFactory {
|
|||||||
|
|
||||||
String insert = " <";
|
String insert = " <";
|
||||||
|
|
||||||
for (GenericsGeneratorResult genericInsertConstraint : constraints) {
|
for (var genericInsertConstraint : constraints) {
|
||||||
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
|
if (genericInsertConstraint instanceof PairTPHequalRefTypeOrWildcardType peq) {
|
||||||
insert += genericInsertConstraint.getConstraint().getLeft();
|
insert += peq.left.getName();
|
||||||
} else {
|
} else if (genericInsertConstraint instanceof PairTPHsmallerTPH psm) {
|
||||||
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight();
|
insert += psm.left.getName() + " extends " + psm.right.getName();
|
||||||
}
|
}
|
||||||
insert += ", ";
|
insert += ", ";
|
||||||
}
|
}
|
||||||
@ -116,25 +104,23 @@ public class TypeInsertFactory {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<TypeInsertPoint> createGenericClassInserts(List<GenericsGeneratorResult> classConstraints, ClassOrInterface cl) {
|
private static Set<TypeInsertPoint> createGenericClassInserts(GenericsResultSet 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();
|
|
||||||
|
|
||||||
if (classConstraints == null || classConstraints.size() == 0) {
|
if (classConstraints == null || classConstraints.size() == 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String insert = " <";
|
String insert = " <";
|
||||||
|
|
||||||
for (GenericsGeneratorResult genericInsertConstraint : classConstraints) {
|
for (var genericInsertConstraint : classConstraints) {
|
||||||
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
|
if (genericInsertConstraint instanceof PairTPHequalRefTypeOrWildcardType peq) {
|
||||||
insert += genericInsertConstraint.getConstraint().getLeft();
|
insert += peq.left.getName();
|
||||||
} else {
|
} else if (genericInsertConstraint instanceof PairTPHsmallerTPH psm) {
|
||||||
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight();
|
insert += psm.left.getName() + " extends " + psm.right.getName();
|
||||||
}
|
}
|
||||||
insert += ", ";
|
insert += ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
insert = insert.substring(0, insert.length() -2);
|
insert = insert.substring(0, insert.length() -2);
|
||||||
@ -148,11 +134,11 @@ public class TypeInsertFactory {
|
|||||||
|
|
||||||
class TypeToInsertString implements ResultSetVisitor{
|
class TypeToInsertString implements ResultSetVisitor{
|
||||||
String insert = "";
|
String insert = "";
|
||||||
private List<GenericsGeneratorResult> constraints;
|
private GenericsResultSet constraints;
|
||||||
private List<GenericsGeneratorResult> classConstraints;
|
private GenericsResultSet classConstraints;
|
||||||
|
|
||||||
|
|
||||||
TypeToInsertString(RefTypeOrTPHOrWildcardOrGeneric type, List<GenericsGeneratorResult> constraints, List<GenericsGeneratorResult> classConstraints){
|
TypeToInsertString(RefTypeOrTPHOrWildcardOrGeneric type, GenericsResultSet constraints, GenericsResultSet classConstraints){
|
||||||
this.constraints = constraints;
|
this.constraints = constraints;
|
||||||
this.classConstraints = classConstraints;
|
this.classConstraints = classConstraints;
|
||||||
type.accept(this);
|
type.accept(this);
|
||||||
@ -200,32 +186,11 @@ class TypeToInsertString implements ResultSetVisitor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(TypePlaceholder typePlaceholder) {
|
public void visit(TypePlaceholder typePlaceholder) {
|
||||||
String realName = typePlaceholder.getName();
|
insert += ((TypePlaceholder) constraints.getResultPairFor(typePlaceholder).get().getLeft()).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(), constraints, classConstraints).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();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package de.dhbwstuttgart.typedeployment;
|
package de.dhbwstuttgart.typedeployment;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
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.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -17,11 +17,11 @@ public class TypeInsertPlacer extends AbstractASTWalker{
|
|||||||
Set<TypeInsert> inserts = new HashSet<>();
|
Set<TypeInsert> inserts = new HashSet<>();
|
||||||
private ResultSet withResults;
|
private ResultSet withResults;
|
||||||
String pkgName;
|
String pkgName;
|
||||||
private List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
private GenericsResult genericsResult;
|
||||||
|
|
||||||
public Set<TypeInsert> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles){
|
public Set<TypeInsert> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, GenericsResult genericsResult){
|
||||||
this.withResults = withResults;
|
this.withResults = withResults;
|
||||||
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
|
this.genericsResult = genericsResult;
|
||||||
pkgName = forSourceFile.getPkgName();
|
pkgName = forSourceFile.getPkgName();
|
||||||
forSourceFile.accept(this);
|
forSourceFile.accept(this);
|
||||||
return inserts;
|
return inserts;
|
||||||
@ -29,27 +29,22 @@ public class TypeInsertPlacer extends AbstractASTWalker{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
GenericsGeneratorResultForClass generatedGenerics = simplifyResultsForAllSourceFiles
|
TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults, genericsResult);
|
||||||
.stream()
|
|
||||||
.map(sr->sr.getSimplifyResultsByName(classOrInterface.getClassName()))
|
|
||||||
.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;
|
private GenericsResult 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;
|
||||||
|
|
||||||
List<GenericsGeneratorResult> constraints;
|
|
||||||
List<GenericsGeneratorResult> classConstraints;
|
|
||||||
|
|
||||||
TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsGeneratorResultForClass generatedGenerics){
|
GenericsResultSet constraints;
|
||||||
|
GenericsResultSet classConstraints;
|
||||||
|
|
||||||
|
TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsResult generatedGenerics){
|
||||||
this.cl = forClass;
|
this.cl = forClass;
|
||||||
this.method = null;
|
this.method = null;
|
||||||
this.results = withResults;
|
this.results = withResults;
|
||||||
@ -60,8 +55,8 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
//constraints = generatedGenerics.getMethodConstraintsByID(id);
|
constraints = generatedGenerics.get(method);
|
||||||
classConstraints = generatedGenerics.getClassConstraints();
|
classConstraints = generatedGenerics.get(cl);
|
||||||
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, constraints, classConstraints));
|
method.getReturnType(), method.getReturnType().getOffset(), cl, method, results, constraints, classConstraints));
|
||||||
@ -71,9 +66,9 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
|
|||||||
@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();
|
classConstraints = generatedGenerics.get(cl);
|
||||||
inserts.add(TypeInsertFactory.createInsertPoints(
|
inserts.add(TypeInsertFactory.createInsertPoints(
|
||||||
field.getType(), field.getType().getOffset(), cl, method, results, new ArrayList<>(), classConstraints));
|
field.getType(), field.getType().getOffset(), cl, method, results, null, classConstraints));
|
||||||
}
|
}
|
||||||
super.visit(field);
|
super.visit(field);
|
||||||
}
|
}
|
||||||
|
40
src/test/java/TestTypeDeployment.java
Normal file
40
src/test/java/TestTypeDeployment.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
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.nio.file.Path;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class TestTypeDeployment {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeDeployment() throws Exception {
|
||||||
|
var path = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav");
|
||||||
|
var file = path.toFile();
|
||||||
|
var compiler = new JavaTXCompiler(file, false);
|
||||||
|
var parsedSource = compiler.sourceFiles.get(file);
|
||||||
|
var tiResults = compiler.typeInference();
|
||||||
|
Set<TypeInsert> tips = new HashSet<>();
|
||||||
|
|
||||||
|
for (var sf : compiler.sourceFiles.values()) {
|
||||||
|
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(sf, tiResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(compiler.getGeneratedGenerics());
|
||||||
|
|
||||||
|
for (int i = 0; i < tiResults.size(); i++) {
|
||||||
|
ResultSet tiResult = tiResults.get(i);
|
||||||
|
tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
|
||||||
|
for (TypeInsert p : tips) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
@ -14,9 +14,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
public class OLTest {
|
public class OLTest {
|
||||||
private static String path;
|
private static String path;
|
||||||
|
@ -41,8 +41,9 @@ public class TestGenerics {
|
|||||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()));
|
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()));
|
||||||
var inference = compiler.typeInference();
|
var inference = compiler.typeInference();
|
||||||
compiler.generateBytecode(new File(bytecodeDirectory), inference);
|
compiler.generateBytecode(new File(bytecodeDirectory), inference);
|
||||||
var clazz = compiler.sourceFiles.get(file).getClasses().get(0);
|
var sf = compiler.sourceFiles.get(file);
|
||||||
return new Result(compiler.getGeneratedGenerics().get(file), clazz);
|
var clazz = sf.getClasses().get(0);
|
||||||
|
return new Result(compiler.getGeneratedGenerics().get(sf), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -142,7 +141,6 @@ 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);
|
//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);
|
||||||
@ -151,8 +149,9 @@ public class JavaTXCompilerTest {
|
|||||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||||
assert results.size()>0;
|
assert results.size()>0;
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
Set<String> insertedTypes = new HashSet<>();
|
||||||
for(ResultSet resultSet : results){
|
for(var i = 0; i < results.size(); i++) {
|
||||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
var resultSet = results.get(i);
|
||||||
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, compiler.getGeneratedGenerics().get(sf).get(i));
|
||||||
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){
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -106,7 +105,6 @@ 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);
|
||||||
@ -115,8 +113,9 @@ public class Meth_GenTest {
|
|||||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||||
assert results.size()>0;
|
assert results.size()>0;
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
Set<String> insertedTypes = new HashSet<>();
|
||||||
for(ResultSet resultSet : results){
|
for(var i = 0; i < results.size(); i++){
|
||||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
var resultSet = results.get(i);
|
||||||
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, compiler.getGeneratedGenerics().get(sf).get(i));
|
||||||
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){
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -132,7 +131,6 @@ 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);
|
||||||
@ -141,8 +139,9 @@ public class UnifyTest {
|
|||||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||||
assert results.size()>0;
|
assert results.size()>0;
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
Set<String> insertedTypes = new HashSet<>();
|
||||||
for(ResultSet resultSet : results){
|
for(var i = 0; i < results.size(); i++) {
|
||||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
var resultSet = results.get(i);
|
||||||
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, compiler.getGeneratedGenerics().get(sf).get(i));
|
||||||
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){
|
||||||
|
Loading…
Reference in New Issue
Block a user