Compare commits
68 Commits
LSP-Interf
...
133ca1fe41
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
133ca1fe41 | ||
|
|
f9cf6fe722 | ||
|
|
c0d8dc4692 | ||
|
|
84f5f05672 | ||
|
|
588036ea46 | ||
|
|
70b28bbfb0 | ||
|
|
701962b0e7 | ||
|
|
e91a9370df | ||
|
|
d71e67cfdd | ||
|
|
c2c2d6f445 | ||
|
|
7296e3de44 | ||
|
|
c1aebaf1f5 | ||
|
|
2871586c71 | ||
|
|
fa1f3a0507 | ||
|
|
f66edd4c4b | ||
|
|
598fe8ebe9 | ||
|
|
41d97dfa80 | ||
|
|
0f18cedf90 | ||
| f43d1f4f4f | |||
| 2a44773403 | |||
|
|
a6ca31d509 | ||
|
|
b13f2b357b | ||
|
|
45fa0ff0b9 | ||
|
|
c292ff2d9e | ||
|
|
c14dd6e97c | ||
|
|
8f8ee9a385 | ||
|
|
3863968a6e | ||
|
|
03c432455d | ||
|
|
441e50a70d | ||
|
|
0807885465 | ||
|
|
8abe7f6c28 | ||
|
|
2a92a0e48e | ||
|
|
b3639a3d08 | ||
|
|
28969e7931 | ||
|
|
b806fa88ff | ||
|
|
301e9143ec | ||
|
|
bb4eaaccc5 | ||
|
|
4dbae46765 | ||
|
|
c64071f235 | ||
|
|
94dbf1f7ad | ||
|
|
890f64c813 | ||
|
|
5aadb7545e | ||
|
|
0c0ac61a02 | ||
|
|
46192e3fd3 | ||
|
|
61653c5d88 | ||
|
|
3cd608a4ac | ||
|
|
deec0ae706 | ||
|
|
d6a79ea3a1 | ||
|
|
1f909f13ee | ||
|
|
be6f4bd578 | ||
|
|
478efd5649 | ||
|
|
c73e57cf2b | ||
|
|
ce29f4bcf1 | ||
|
|
42821f3215 | ||
|
|
f68afc88a6 | ||
|
|
82061474b2 | ||
|
|
d849bc127f | ||
|
|
6815d8fc0a | ||
|
|
317f8b1aad | ||
|
|
79335449d0 | ||
|
|
14606a846e | ||
| 2b67230a15 | |||
|
|
29b05b56cc | ||
|
|
08b9fc0ea3 | ||
|
|
070dd16999 | ||
|
|
9d7e46925d | ||
|
|
d780d322f0 | ||
|
|
867f3d39e8 |
@@ -1,8 +1,5 @@
|
|||||||
name: Build and Test with Maven
|
name: Build and Test with Maven
|
||||||
on:
|
on: [push]
|
||||||
push:
|
|
||||||
branches-ignore:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build-and-test-with-Maven:
|
Build-and-test-with-Maven:
|
||||||
@@ -18,11 +15,11 @@ jobs:
|
|||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '24'
|
java-version: '22'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
- name: Compile project
|
- name: Compile project
|
||||||
run: |
|
run: |
|
||||||
mvn compile
|
mvn compile
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
mvn test
|
mvn test
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize, reopened]
|
|
||||||
|
|
||||||
name: SonarQube Scan
|
|
||||||
jobs:
|
|
||||||
sonarqube:
|
|
||||||
name: SonarQube Trigger
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checking out
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
# Disabling shallow clone is recommended for improving relevancy of reporting
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Install maven
|
|
||||||
run: |
|
|
||||||
apt update
|
|
||||||
apt install -y maven
|
|
||||||
- name: Install java
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '24'
|
|
||||||
cache: 'maven'
|
|
||||||
- name: Compile project
|
|
||||||
run: |
|
|
||||||
mvn clean dependency:copy-dependencies verify
|
|
||||||
- name: SonarQube Scan
|
|
||||||
uses: SonarSource/sonarqube-scan-action@v5.3.0
|
|
||||||
env:
|
|
||||||
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
|
|
||||||
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
|
|
||||||
with:
|
|
||||||
args: >
|
|
||||||
-Dsonar.projectKey=Java-TX
|
|
||||||
-Dsonar.sources=src/main/java
|
|
||||||
-Dsonar.tests=src/test/java
|
|
||||||
-Dsonar.junit.reportPaths=target/test-reports
|
|
||||||
-Dsonar.java.binaries=target/classes
|
|
||||||
-Dsonar.java.libraries=target/dependency/*.jar
|
|
||||||
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
|
|
||||||
3
Makefile
Normal file
3
Makefile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
NoOptParallel:
|
||||||
|
mvn -DskipTests package
|
||||||
|
cp target/JavaTXcompiler-0.1-jar-with-dependencies.jar target/JavaTXcompiler-0.1-jar-with-dependencies_NoOptParallel.jar
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
## Java-TX Compiler
|
|
||||||
|
|
||||||
[](https://gitea.hb.dhbw-stuttgart.de/sonarqube/dashboard?id=Java-TX)
|
|
||||||
[](https://gitea.hb.dhbw-stuttgart.de/sonarqube/dashboard?id=Java-TX)
|
|
||||||
[](https://gitea.hb.dhbw-stuttgart.de/sonarqube/dashboard?id=Java-TX)
|
|
||||||
|
|
||||||
Work in Progress Java-TX Compiler repository!
|
|
||||||
68
pom.xml
68
pom.xml
@@ -12,79 +12,77 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>5.13.2</version>
|
<version>4.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
|
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.antlr</groupId>
|
<groupId>org.antlr</groupId>
|
||||||
<artifactId>antlr4</artifactId>
|
<artifactId>antlr4</artifactId>
|
||||||
<version>4.13.2</version>
|
<version>4.11.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.19.0</version>
|
<version>2.16.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.classgraph</groupId>
|
<groupId>io.github.classgraph</groupId>
|
||||||
<artifactId>classgraph</artifactId>
|
<artifactId>classgraph</artifactId>
|
||||||
<version>4.8.180</version>
|
<version>4.8.172</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>33.4.8-jre</version>
|
<version>33.2.0-jre</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ow2.asm</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
<version>9.8</version>
|
<version>9.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.java-websocket</groupId>
|
||||||
|
<artifactId>Java-WebSocket</artifactId>
|
||||||
|
<version>1.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.17.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.13</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>prepare-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>report</id>
|
|
||||||
<phase>prepare-package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.14.0</version>
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<compilerArgs>--enable-preview</compilerArgs>
|
<compilerArgs>--enable-preview</compilerArgs>
|
||||||
<source>24</source>
|
<source>23</source>
|
||||||
<target>24</target>
|
<target>23</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.5.3</version>
|
<version>3.1.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
||||||
<reportsDirectory>${project.build.directory}/test-reports</reportsDirectory>
|
<reportsDirectory>${project.build.directory}/test-reports</reportsDirectory>
|
||||||
<argLine>${argLine} --enable-preview</argLine>
|
<argLine>--enable-preview</argLine>
|
||||||
<trimStackTrace>false</trimStackTrace>
|
<trimStackTrace>false</trimStackTrace>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/JavaTXCompilerTest.java</exclude>
|
<exclude>**/JavaTXCompilerTest.java</exclude>
|
||||||
@@ -96,7 +94,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.antlr</groupId>
|
<groupId>org.antlr</groupId>
|
||||||
<artifactId>antlr4-maven-plugin</artifactId>
|
<artifactId>antlr4-maven-plugin</artifactId>
|
||||||
<version>4.13.2</version>
|
<version>4.11.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>antlr</id>
|
<id>antlr</id>
|
||||||
@@ -109,7 +107,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
@@ -157,4 +155,4 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<url>file:///${project.basedir}/maven-repository/</url>
|
<url>file:///${project.basedir}/maven-repository/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class Bug325 {
|
public class Bug325 {
|
||||||
public main() {
|
public main() {
|
||||||
var list = new ArrayList<>(List.of(1,2,3,4,5));
|
List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5));
|
||||||
var func = x -> x*2;
|
var func = x -> x*2;
|
||||||
return list.stream().map(func).toList();
|
return list.stream().map(func).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import java.lang.String;
|
|
||||||
|
|
||||||
|
|
||||||
public class Bug363 {
|
|
||||||
uncurry (f){
|
|
||||||
return x -> f.apply(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
uncurry (f){
|
|
||||||
return (x, y) -> f.apply(x).apply(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
uncurry (f){
|
|
||||||
return (x, y, z) -> f.apply(x).apply(y).apply(z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public test(){
|
|
||||||
var f = x -> y -> z -> x + y + z;
|
|
||||||
var g = uncurry(f);
|
|
||||||
return g.apply("A", "B", "C"); // Outputs: 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import java.lang.String;
|
|
||||||
|
|
||||||
public class Bug364{
|
|
||||||
public main(){
|
|
||||||
var f = x -> y -> z -> x + y + z;
|
|
||||||
return f.apply("A").apply("B").apply("C");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import java.lang.String;
|
|
||||||
import java.lang.Object;
|
|
||||||
|
|
||||||
public class Bug365{
|
|
||||||
swap(f){
|
|
||||||
return x -> y -> f.apply(y).apply(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
swap(Fun1$$<String, Fun1$$<String, Fun1$$<String, Object>>> f){
|
|
||||||
return x -> y -> z -> f.apply(z).apply(y).apply(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ex1() {
|
|
||||||
var func = x -> y -> z -> x + y + z;
|
|
||||||
return func.apply("A").apply("B").apply("C");
|
|
||||||
}
|
|
||||||
public ex2() {
|
|
||||||
var func = x -> y -> z -> x + y + z;
|
|
||||||
return swap(func).apply("A").apply("B").apply("C");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
public class Bug366 {
|
|
||||||
public static lambda() {
|
|
||||||
return (a, b) -> a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static test() {
|
|
||||||
var l = lambda();
|
|
||||||
return l.apply(10, 20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import java.lang.Boolean;
|
|
||||||
|
|
||||||
public class Bug371 {
|
|
||||||
static m1(x, y) { return x || y; }
|
|
||||||
static m2(x, y) { return x && y; }
|
|
||||||
|
|
||||||
public static test() {
|
|
||||||
return m2(m1(true, false), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import java.lang.Boolean;
|
|
||||||
import java.lang.Integer;
|
|
||||||
import java.lang.System;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.lang.Character;
|
|
||||||
|
|
||||||
public class Bug373 {
|
|
||||||
public static main() {
|
|
||||||
System.out.println(true);
|
|
||||||
System.out.println(false);
|
|
||||||
System.out.println(1);
|
|
||||||
System.out.println(1l);
|
|
||||||
System.out.println(1.0);
|
|
||||||
System.out.println(1.0f);
|
|
||||||
System.out.println('a');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
16
resources/bytecode/javFiles/BugXXX.jav
Normal file
16
resources/bytecode/javFiles/BugXXX.jav
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class BugXXX {
|
||||||
|
public main() {
|
||||||
|
List<Integer> i = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10));
|
||||||
|
Optional<Integer> tmp = i.stream().filter(x -> x == 5).map(x -> x*2).findFirst();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import java.lang.Object;
|
|
||||||
import java.lang.System;
|
|
||||||
import java.lang.Iterable;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.lang.String;
|
|
||||||
|
|
||||||
class Main {
|
|
||||||
static main(args) {
|
|
||||||
for (var arg : args) {
|
|
||||||
System.out.println(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ import java.lang.Integer;
|
|||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class MatrixOP extends Vector<Vector<Integer>> {
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
MatrixOP () {
|
MatrixOP () {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ public class MatrixOP extends Vector<Vector<Integer>> {
|
|||||||
v2.addElement(erg);
|
v2.addElement(erg);
|
||||||
j++; }
|
j++; }
|
||||||
ret.addElement(v2);
|
ret.addElement(v2);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import java.util.Vector;
|
//import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Float;
|
import java.lang.Float;
|
||||||
//import java.lang.Byte;
|
//import java.lang.Byte;
|
||||||
@@ -12,15 +12,14 @@ public class Scalar extends Vector<Integer> {
|
|||||||
while(i < v.size()) {
|
while(i < v.size()) {
|
||||||
this.add(v.elementAt(i));
|
this.add(v.elementAt(i));
|
||||||
i=i+1;
|
i=i+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public mul(v) {
|
public mul(v) {
|
||||||
var ret = 0;
|
var ret = 0;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
ret = ret + this.elementAt(i) * v.elementAt(i);
|
ret = ret + this.elementAt(i) * v.elementAt(i);
|
||||||
i = i+1;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
2
server-tests/.gitignore
vendored
Normal file
2
server-tests/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
out
|
||||||
|
outputs
|
||||||
13
server-tests/Lambda.jav
Normal file
13
server-tests/Lambda.jav
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
class Apply { }
|
||||||
|
|
||||||
|
public class Lambda {
|
||||||
|
|
||||||
|
m () {
|
||||||
|
var lam1 = (x) -> {
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
return lam1.apply(new Apply());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
28
server-tests/Matrix.jav
Normal file
28
server-tests/Matrix.jav
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class Matrix extends Vector<Vector<Integer>> {
|
||||||
|
Integer mul1(Integer x, Integer y) { return x;}
|
||||||
|
Integer add1(Integer x, Integer y) { return x;}
|
||||||
|
mul(m) {
|
||||||
|
var ret = new Matrix();
|
||||||
|
var i = 0;
|
||||||
|
while(i < size()) {
|
||||||
|
var v1 = this.elementAt(i);
|
||||||
|
var v2 = new Vector<Integer>();
|
||||||
|
var j = 0;
|
||||||
|
while(j < v1.size()) {
|
||||||
|
var erg = 0;
|
||||||
|
var k = 0;
|
||||||
|
while(k < v1.size()) {
|
||||||
|
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
|
||||||
|
//erg = add1(erg, mul1(v1.elementAt(k),
|
||||||
|
// m.elementAt(k).elementAt(j)));
|
||||||
|
k++; }
|
||||||
|
v2.addElement(new Integer(erg));
|
||||||
|
j++; }
|
||||||
|
ret.addElement(v2);
|
||||||
|
i++; }
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
server-tests/SomeList.jav
Normal file
25
server-tests/SomeList.jav
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class SomeEvenMoreAbstractList<A, B> extends Vector<A> {
|
||||||
|
}
|
||||||
|
|
||||||
|
class SomeAbstractList<A, B> extends SomeEvenMoreAbstractList<A, B> {
|
||||||
|
}
|
||||||
|
|
||||||
|
class SomeList extends SomeAbstractList<Integer, Integer> {
|
||||||
|
|
||||||
|
mul(otherList) {
|
||||||
|
var result = new SomeList();
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
while (i < 4) {
|
||||||
|
i++;
|
||||||
|
var a = this.elementAt(i);
|
||||||
|
var b = otherList.elementAt(i);
|
||||||
|
result.addElement(a * b);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
server-tests/_runClient.sh
Executable file
21
server-tests/_runClient.sh
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# build the compiler if -c is set
|
||||||
|
if [[ "${@,,}" == *"-c"* ]]; then
|
||||||
|
(cd .. && make || exit)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# a very small and short running example
|
||||||
|
# JAV_FILE="Lambda.jav"
|
||||||
|
|
||||||
|
# a medium and average running example
|
||||||
|
JAV_FILE="SomeList.jav"
|
||||||
|
|
||||||
|
# a very large and long running example
|
||||||
|
# JAV_FILE="Matrix.jav"
|
||||||
|
|
||||||
|
|
||||||
|
# remove old generated files and run the compiler
|
||||||
|
rm -rf ./out/client
|
||||||
|
mkdir -p ./out/client \
|
||||||
|
&& java -jar ../target/JavaTXcompiler-0.1-jar-with-dependencies.jar -d ./out/client $JAV_FILE
|
||||||
12
server-tests/_runServer.sh
Executable file
12
server-tests/_runServer.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# build the compiler if -c is set
|
||||||
|
if [[ "${@,,}" == *"-c"* ]]; then
|
||||||
|
(cd .. && make || exit)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# remove old generated files
|
||||||
|
rm -rf ./out/server
|
||||||
|
|
||||||
|
# run the server
|
||||||
|
mkdir -p ./out/server && java -jar ../target/JavaTXcompiler-0.1-jar-with-dependencies.jar -d ./out/server -server 5000
|
||||||
@@ -13,11 +13,10 @@ import org.objectweb.asm.*;
|
|||||||
import java.lang.invoke.*;
|
import java.lang.invoke.*;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
|
||||||
import static de.dhbwstuttgart.target.tree.expression.TargetBinaryOp.*;
|
import static de.dhbwstuttgart.target.tree.expression.TargetBinaryOp.*;
|
||||||
import static de.dhbwstuttgart.target.tree.expression.TargetLiteral.*;
|
import static de.dhbwstuttgart.target.tree.expression.TargetLiteral.*;
|
||||||
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
public class Codegen {
|
public class Codegen {
|
||||||
private final TargetStructure clazz;
|
private final TargetStructure clazz;
|
||||||
@@ -85,16 +84,14 @@ public class Codegen {
|
|||||||
int localCounter;
|
int localCounter;
|
||||||
MethodVisitor mv;
|
MethodVisitor mv;
|
||||||
TargetType returnType;
|
TargetType returnType;
|
||||||
boolean isStatic = false;
|
|
||||||
|
|
||||||
Stack<BreakEnv> breakStack = new Stack<>();
|
Stack<BreakEnv> breakStack = new Stack<>();
|
||||||
Stack<Integer> switchResultValue = new Stack<>();
|
Stack<Integer> switchResultValue = new Stack<>();
|
||||||
|
|
||||||
State(TargetType returnType, MethodVisitor mv, int localCounter, boolean isStatic) {
|
State(TargetType returnType, MethodVisitor mv, int localCounter) {
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.localCounter = localCounter;
|
this.localCounter = localCounter;
|
||||||
this.isStatic = isStatic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void enterScope() {
|
void enterScope() {
|
||||||
@@ -132,7 +129,6 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void boxPrimitive(State state, TargetType type) {
|
private void boxPrimitive(State state, TargetType type) {
|
||||||
if (type instanceof TargetExtendsWildcard ew) type = ew.innerType();
|
|
||||||
var mv = state.mv;
|
var mv = state.mv;
|
||||||
if (type.equals(TargetType.Boolean) || type.equals(TargetType.boolean_)) {
|
if (type.equals(TargetType.Boolean) || type.equals(TargetType.boolean_)) {
|
||||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
||||||
@@ -154,7 +150,6 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void unboxPrimitive(State state, TargetType type) {
|
private void unboxPrimitive(State state, TargetType type) {
|
||||||
if (type instanceof TargetExtendsWildcard ew) type = ew.innerType();
|
|
||||||
var mv = state.mv;
|
var mv = state.mv;
|
||||||
if (type.equals(TargetType.Boolean)) {
|
if (type.equals(TargetType.Boolean)) {
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
|
||||||
@@ -230,16 +225,13 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void convertTo(State state, TargetType source, TargetType dest) {
|
private void convertTo(State state, TargetType source, TargetType dest) {
|
||||||
if (source instanceof TargetExtendsWildcard ew) source = ew.innerType();
|
|
||||||
if (dest instanceof TargetExtendsWildcard ew) dest = ew.innerType();
|
|
||||||
|
|
||||||
var mv = state.mv;
|
var mv = state.mv;
|
||||||
if (source.equals(dest))
|
if (source.equals(dest))
|
||||||
return;
|
return;
|
||||||
if (source.equals(TargetType.Long)) {
|
if (source.equals(TargetType.Long)) {
|
||||||
if (dest.equals(TargetType.Integer))
|
if (dest.equals(TargetType.Integer)) {
|
||||||
mv.visitInsn(L2I);
|
mv.visitInsn(L2I);
|
||||||
else if (dest.equals(TargetType.Float))
|
} else if (dest.equals(TargetType.Float))
|
||||||
mv.visitInsn(L2F);
|
mv.visitInsn(L2F);
|
||||||
else if (dest.equals(TargetType.Double))
|
else if (dest.equals(TargetType.Double))
|
||||||
mv.visitInsn(L2D);
|
mv.visitInsn(L2D);
|
||||||
@@ -282,8 +274,6 @@ public class Codegen {
|
|||||||
mv.visitInsn(I2F);
|
mv.visitInsn(I2F);
|
||||||
else if (dest.equals(TargetType.Double))
|
else if (dest.equals(TargetType.Double))
|
||||||
mv.visitInsn(I2D);
|
mv.visitInsn(I2D);
|
||||||
} else if (source.equals(TargetType.Boolean)) {
|
|
||||||
unboxPrimitive(state, dest);
|
|
||||||
} else if (isFunctionalInterface(source) && isFunctionalInterface(dest) &&
|
} else if (isFunctionalInterface(source) && isFunctionalInterface(dest) &&
|
||||||
!(source instanceof TargetFunNType && dest instanceof TargetFunNType)) {
|
!(source instanceof TargetFunNType && dest instanceof TargetFunNType)) {
|
||||||
boxFunctionalInterface(state, source, dest);
|
boxFunctionalInterface(state, source, dest);
|
||||||
@@ -645,7 +635,7 @@ public class Codegen {
|
|||||||
} else if (op.expr() instanceof TargetFieldVar fieldVar) {
|
} else if (op.expr() instanceof TargetFieldVar fieldVar) {
|
||||||
generate(state, fieldVar.left());
|
generate(state, fieldVar.left());
|
||||||
mv.visitInsn(SWAP);
|
mv.visitInsn(SWAP);
|
||||||
mv.visitFieldInsn(PUTFIELD, fieldVar.owner().getInternalName(), fieldVar.right(), fieldVar.type().toDescriptor());
|
mv.visitFieldInsn(PUTFIELD, fieldVar.owner().getInternalName(), fieldVar.right(), fieldVar.type().toSignature());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,16 +757,6 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TargetType removeGenerics(TargetType param) {
|
|
||||||
return switch (param) {
|
|
||||||
case null -> null;
|
|
||||||
case TargetFunNType funNType -> new TargetFunNType(funNType.name(), funNType.funNParams(), List.of(), funNType.returnArguments());
|
|
||||||
case TargetRefType refType -> new TargetRefType(refType.name());
|
|
||||||
case TargetGenericType targetGenericType -> TargetType.Object;
|
|
||||||
default -> param;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateLambdaExpression(State state, TargetLambdaExpression lambda) {
|
private void generateLambdaExpression(State state, TargetLambdaExpression lambda) {
|
||||||
var mv = state.mv;
|
var mv = state.mv;
|
||||||
|
|
||||||
@@ -788,8 +768,7 @@ public class Codegen {
|
|||||||
|
|
||||||
var parameters = new ArrayList<>(lambda.captures());
|
var parameters = new ArrayList<>(lambda.captures());
|
||||||
parameters.addAll(signature.parameters());
|
parameters.addAll(signature.parameters());
|
||||||
parameters = parameters.stream().map(param -> param.withType(removeGenerics(param.pattern().type()))).collect(Collectors.toCollection(ArrayList::new));
|
var implSignature = new TargetMethod.Signature(Set.of(), parameters, lambda.signature().returnType());
|
||||||
var implSignature = new TargetMethod.Signature(Set.of(), parameters, removeGenerics(lambda.signature().returnType()));
|
|
||||||
|
|
||||||
TargetMethod impl;
|
TargetMethod impl;
|
||||||
if (lambdas.containsKey(lambda)) {
|
if (lambdas.containsKey(lambda)) {
|
||||||
@@ -797,22 +776,21 @@ public class Codegen {
|
|||||||
} else {
|
} else {
|
||||||
var name = "lambda$" + lambdaCounter++;
|
var name = "lambda$" + lambdaCounter++;
|
||||||
|
|
||||||
impl = new TargetMethod(state.isStatic ? ACC_STATIC : 0, name, lambda.block(), implSignature, null);
|
impl = new TargetMethod(0, name, lambda.block(), implSignature, null);
|
||||||
generateMethod(impl, state);
|
generateMethod(impl);
|
||||||
lambdas.put(lambda, impl);
|
lambdas.put(lambda, impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
|
var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
|
||||||
|
|
||||||
var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", mt.toMethodDescriptorString(), false);
|
var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", mt.toMethodDescriptorString(), false);
|
||||||
var handle = new Handle(state.isStatic ? H_INVOKESTATIC : H_INVOKEVIRTUAL, clazz.getName(), impl.name(), implSignature.getDescriptor(), false);
|
var handle = new Handle(H_INVOKEVIRTUAL, clazz.getName(), impl.name(), implSignature.getDescriptor(), false);
|
||||||
|
|
||||||
var params = new ArrayList<TargetType>();
|
var params = new ArrayList<TargetType>();
|
||||||
if(!state.isStatic) params.add(new TargetRefType(clazz.qualifiedName().toString()));
|
params.add(new TargetRefType(clazz.qualifiedName().getClassName()));
|
||||||
params.addAll(lambda.captures().stream().map(mp -> mp.pattern().type()).toList());
|
params.addAll(lambda.captures().stream().map(mp -> mp.pattern().type()).toList());
|
||||||
|
|
||||||
if (!state.isStatic)
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
|
||||||
for (var index = 0; index < lambda.captures().size(); index++) {
|
for (var index = 0; index < lambda.captures().size(); index++) {
|
||||||
var capture = lambda.captures().get(index);
|
var capture = lambda.captures().get(index);
|
||||||
var pattern = (TargetTypePattern) capture.pattern();
|
var pattern = (TargetTypePattern) capture.pattern();
|
||||||
@@ -947,7 +925,7 @@ public class Codegen {
|
|||||||
mv.visitInsn(DUP);
|
mv.visitInsn(DUP);
|
||||||
else
|
else
|
||||||
mv.visitInsn(DUP_X1);
|
mv.visitInsn(DUP_X1);
|
||||||
mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toDescriptor());
|
mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toSignature());
|
||||||
}
|
}
|
||||||
default -> throw new CodeGenException("Invalid assignment");
|
default -> throw new CodeGenException("Invalid assignment");
|
||||||
}
|
}
|
||||||
@@ -964,7 +942,7 @@ public class Codegen {
|
|||||||
case TargetFieldVar dot: {
|
case TargetFieldVar dot: {
|
||||||
if (!dot.isStatic())
|
if (!dot.isStatic())
|
||||||
generate(state, dot.left());
|
generate(state, dot.left());
|
||||||
mv.visitFieldInsn(dot.isStatic() ? GETSTATIC : GETFIELD, dot.left().type().getInternalName(), dot.right(), dot.type().toDescriptor());
|
mv.visitFieldInsn(dot.isStatic() ? GETSTATIC : GETFIELD, dot.left().type().getInternalName(), dot.right(), dot.type().toSignature());
|
||||||
unboxPrimitive(state, dot.type());
|
unboxPrimitive(state, dot.type());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1428,7 +1406,7 @@ public class Codegen {
|
|||||||
throw new CodeGenException("Couldn't find suitable field accessor for '" + type.name() + "'");
|
throw new CodeGenException("Couldn't find suitable field accessor for '" + type.name() + "'");
|
||||||
var field = clazz.getFieldDecl().get(i);
|
var field = clazz.getFieldDecl().get(i);
|
||||||
var fieldType = converter.convert(field.getType());
|
var fieldType = converter.convert(field.getType());
|
||||||
state.mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), field.getName(), "()" + fieldType.toDescriptor(), false);
|
state.mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), field.getName(), "()" + fieldType.toSignature(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindPattern(State state, TargetType type, TargetPattern pat, Label start, int index, int depth) {
|
private void bindPattern(State state, TargetType type, TargetPattern pat, Label start, int index, int depth) {
|
||||||
@@ -1533,14 +1511,14 @@ public class Codegen {
|
|||||||
//if ((access & ACC_PRIVATE) == 0 && (access & ACC_PROTECTED) == 0) // TODO Implement access modifiers properly
|
//if ((access & ACC_PRIVATE) == 0 && (access & ACC_PROTECTED) == 0) // TODO Implement access modifiers properly
|
||||||
// access |= ACC_PUBLIC;
|
// access |= ACC_PUBLIC;
|
||||||
|
|
||||||
cw.visitField(access, field.name(), field.type().toDescriptor(), field.type().toSignature(), null);
|
cw.visitField(access, field.name(), field.type().toSignature(), field.type().toDescriptor(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateStaticConstructor(TargetMethod constructor) {
|
private void generateStaticConstructor(TargetMethod constructor) {
|
||||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
|
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|
||||||
var state = new State(null, mv, 0, true);
|
var state = new State(null, mv, 0);
|
||||||
generate(state, constructor.block());
|
generate(state, constructor.block());
|
||||||
|
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
@@ -1552,9 +1530,9 @@ public class Codegen {
|
|||||||
MethodVisitor mv = cw.visitMethod(constructor.access(), "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(constructor.access(), "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
||||||
if (constructor.txGenerics() != null)
|
if (constructor.txGenerics() != null)
|
||||||
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(null, mv, 1, false);
|
var state = new State(null, mv, 1);
|
||||||
for (var param : constructor.parameters()) {
|
for (var param : constructor.parameters()) {
|
||||||
var pattern = param.pattern();
|
var pattern = param.pattern();
|
||||||
if (pattern instanceof TargetTypePattern tp)
|
if (pattern instanceof TargetTypePattern tp)
|
||||||
@@ -1600,31 +1578,9 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateMethod(TargetMethod method) {
|
private void generateMethod(TargetMethod method) {
|
||||||
generateMethod(method, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateMainMethod() {
|
|
||||||
var mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
|
|
||||||
mv.visitCode();
|
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
|
||||||
mv.visitMethodInsn(INVOKESTATIC, "java/util/List", "of", "([Ljava/lang/Object;)Ljava/util/List;", true);
|
|
||||||
mv.visitMethodInsn(INVOKESTATIC, new TargetRefType(clazz.qualifiedName().toString()).getInternalName(), "main", "(Ljava/util/List;)V", false);
|
|
||||||
mv.visitInsn(RETURN);
|
|
||||||
mv.visitMaxs(0, 0);
|
|
||||||
mv.visitEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateMethod(TargetMethod method, State parent) {
|
|
||||||
var access = method.access();
|
var access = method.access();
|
||||||
|
|
||||||
var params = method.signature().parameters();
|
|
||||||
if (method.name().equals("main") && method.isStatic() && params.size() == 1 &&
|
|
||||||
params.getFirst().pattern().type().equals(new TargetRefType("java.util.List", List.of(new TargetRefType("java.lang.String"))))) {
|
|
||||||
|
|
||||||
generateMainMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method.block() == null)
|
if (method.block() == null)
|
||||||
access |= ACC_ABSTRACT;
|
access |= ACC_ABSTRACT;
|
||||||
if (clazz instanceof TargetInterface)
|
if (clazz instanceof TargetInterface)
|
||||||
@@ -1638,10 +1594,7 @@ public class Codegen {
|
|||||||
|
|
||||||
if (method.block() != null) {
|
if (method.block() != null) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(method.signature().returnType(), mv, method.isStatic() ? 0 : 1, method.isStatic());
|
var state = new State(method.signature().returnType(), mv, method.isStatic() ? 0 : 1);
|
||||||
if (parent != null) {
|
|
||||||
state.scope.parent = parent.scope;
|
|
||||||
}
|
|
||||||
var offset = 1;
|
var offset = 1;
|
||||||
for (var param : method.signature().parameters()) {
|
for (var param : method.signature().parameters()) {
|
||||||
state.createVariable(param.pattern().name(), param.pattern().type());
|
state.createVariable(param.pattern().name(), param.pattern().type());
|
||||||
@@ -1651,8 +1604,6 @@ public class Codegen {
|
|||||||
bindLocalVariables(state, cp, offset);
|
bindLocalVariables(state, cp, offset);
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
//if (parent != null) System.out.println("parent: " + parent.scope.locals.keySet());
|
|
||||||
//System.out.println(state.scope.locals.keySet());
|
|
||||||
generate(state, method.block());
|
generate(state, method.block());
|
||||||
if (method.signature().returnType() == null)
|
if (method.signature().returnType() == null)
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
@@ -1666,12 +1617,12 @@ public class Codegen {
|
|||||||
if (!generics.isEmpty()) {
|
if (!generics.isEmpty()) {
|
||||||
ret += "<";
|
ret += "<";
|
||||||
for (var generic : generics) {
|
for (var generic : generics) {
|
||||||
ret += generic.name() + ":" + generic.bound().toSignature();
|
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
||||||
}
|
}
|
||||||
ret += ">";
|
ret += ">";
|
||||||
}
|
}
|
||||||
if (clazz.superType() != null)
|
if (clazz.superType() != null)
|
||||||
ret += clazz.superType().toSignature();
|
ret += clazz.superType().toDescriptor();
|
||||||
for (var intf : clazz.implementingInterfaces()) {
|
for (var intf : clazz.implementingInterfaces()) {
|
||||||
ret += intf.toSignature();
|
ret += intf.toSignature();
|
||||||
}
|
}
|
||||||
@@ -1759,7 +1710,7 @@ public class Codegen {
|
|||||||
|
|
||||||
// Generate wrapper method
|
// Generate wrapper method
|
||||||
var mv = cw2.visitMethod(ACC_PUBLIC, toMethod.name, toDescriptor, null, null);
|
var mv = cw2.visitMethod(ACC_PUBLIC, toMethod.name, toDescriptor, null, null);
|
||||||
var state = new State(null, mv, 0, false);
|
var state = new State(null, mv, 0);
|
||||||
|
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
mv.visitFieldInsn(GETFIELD, className, "wrapped", pair.from.toDescriptor());
|
mv.visitFieldInsn(GETFIELD, className, "wrapped", pair.from.toDescriptor());
|
||||||
@@ -1783,7 +1734,7 @@ public class Codegen {
|
|||||||
|
|
||||||
cw2.visitEnd();
|
cw2.visitEnd();
|
||||||
var bytes = cw2.toByteArray();
|
var bytes = cw2.toByteArray();
|
||||||
compiler.auxiliaries.put(className, bytes);
|
converter.auxiliaries.put(className, bytes);
|
||||||
|
|
||||||
// TODO These class loading shenanigans happen in a few places, the tests load the classes individually.
|
// TODO These class loading shenanigans happen in a few places, the tests load the classes individually.
|
||||||
// Instead we should just look at the folder.
|
// Instead we should just look at the folder.
|
||||||
@@ -1791,7 +1742,7 @@ public class Codegen {
|
|||||||
converter.classLoader.findClass(className);
|
converter.classLoader.findClass(className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
try {
|
try {
|
||||||
converter.classLoader.loadClass(className, bytes);
|
converter.classLoader.loadClass(bytes);
|
||||||
} catch (LinkageError ignored) {}
|
} catch (LinkageError ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1826,7 +1777,7 @@ public class Codegen {
|
|||||||
bootstrapArgs[1] = String.join(";", clazz.fields().stream().map(TargetField::name).toArray(String[]::new));
|
bootstrapArgs[1] = String.join(";", clazz.fields().stream().map(TargetField::name).toArray(String[]::new));
|
||||||
for (var i = 0; i < clazz.fields().size(); i++) {
|
for (var i = 0; i < clazz.fields().size(); i++) {
|
||||||
var field = clazz.fields().get(i);
|
var field = clazz.fields().get(i);
|
||||||
var fieldRef = new Handle(H_GETFIELD, clazz.getName(), field.name(), field.type().toDescriptor(), false);
|
var fieldRef = new Handle(H_GETFIELD, clazz.getName(), field.name(), field.type().toSignature(), false);
|
||||||
bootstrapArgs[i + 2] = fieldRef;
|
bootstrapArgs[i + 2] = fieldRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,10 +39,6 @@ public class FunNGenerator {
|
|||||||
public final List<TargetType> inParams;
|
public final List<TargetType> inParams;
|
||||||
public final List<TargetType> realParams;
|
public final List<TargetType> realParams;
|
||||||
|
|
||||||
public GenericParameters(TargetFunNType funNType) {
|
|
||||||
this(funNType.funNParams(), funNType.returnArguments());
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericParameters(List<TargetType> params, int numReturns) {
|
public GenericParameters(List<TargetType> params, int numReturns) {
|
||||||
this.realParams = params;
|
this.realParams = params;
|
||||||
this.inParams = flattenTypeParams(params);
|
this.inParams = flattenTypeParams(params);
|
||||||
@@ -98,7 +94,7 @@ public class FunNGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String applySignature(TargetType a) { return a.toSignature(); }
|
private static String applySignature(TargetType a) { return a.toSignature(); }
|
||||||
private static String applyNameDescriptor(TargetType a){ return a instanceof TargetGenericType ? "LTPH;" : String.format("%s", a.toDescriptor()); }
|
private static String applyNameDescriptor(TargetType a){ return a instanceof TargetGenericType ? "LTPH;" : String.format("%s", applySignature(a)); }
|
||||||
|
|
||||||
public static String encodeType(TargetType type) {
|
public static String encodeType(TargetType type) {
|
||||||
if (type == null) return VOID;
|
if (type == null) return VOID;
|
||||||
|
|||||||
@@ -5,41 +5,72 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
public class ConsoleInterface {
|
import java.util.ArrayList;
|
||||||
private static final String directory = System.getProperty("user.dir");
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
public class ConsoleInterface {
|
||||||
List<File> input = new ArrayList<>();
|
private static final String directory = System.getProperty("user.dir");
|
||||||
List<File> classpath = new ArrayList<>();
|
|
||||||
|
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||||
|
List<File> input = new ArrayList<>();
|
||||||
|
List<File> classpath = new ArrayList<>();
|
||||||
String outputPath = null;
|
String outputPath = null;
|
||||||
Iterator<String> it = Arrays.asList(args).iterator();
|
int runAsServerWithPort = -1;
|
||||||
if(args.length == 0){
|
String unificationServer = null;
|
||||||
|
|
||||||
|
Iterator<String> it = Arrays.asList(args).iterator();
|
||||||
|
if (args.length == 0) {
|
||||||
System.out.println("No input files given. Get help with --help");
|
System.out.println("No input files given. Get help with --help");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}else if(args.length == 1 && args[0].equals("--help")){
|
} else if (args.length == 1 && args[0].equals("--help")) {
|
||||||
System.out.println("Usage: javatx [OPTION]... [FILE]...\n" +
|
System.out.println("Usage: javatx [OPTION]... [FILE]...\n" +
|
||||||
"\t-cp\tSet Classpath\n" +
|
"\t-cp\tSet Classpath\n" +
|
||||||
"\t-d\tSet destination directory");
|
"\t-d\tSet destination directory\n" +
|
||||||
|
"\t-s\tRun the compiler in server mode and listen for incoming requests on the given port\n" +
|
||||||
|
"\t-us\tSet the address of a remote server for the unification process"
|
||||||
|
);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
while(it.hasNext()){
|
while (it.hasNext()) {
|
||||||
String arg = it.next();
|
String arg = it.next();
|
||||||
if(arg.equals("-d")){
|
if (arg.equals("-d")) {
|
||||||
outputPath = it.next();
|
outputPath = it.next();
|
||||||
}else if(arg.startsWith("-d")) {
|
}
|
||||||
|
else if (arg.startsWith("-d")) {
|
||||||
outputPath = arg.substring(2);
|
outputPath = arg.substring(2);
|
||||||
}else if(arg.equals("-cp") || arg.equals("-classpath")){
|
}
|
||||||
|
else if (arg.equals("-cp") || arg.equals("-classpath")) {
|
||||||
String[] cps = it.next().split(":");
|
String[] cps = it.next().split(":");
|
||||||
for(String cp : cps){
|
for (String cp : cps) {
|
||||||
classpath.add(new File(cp));
|
classpath.add(new File(cp));
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else if (arg.equals("-s") || arg.equals("-server")) {
|
||||||
|
if (unificationServer != null) {
|
||||||
|
throw new IllegalArgumentException("Cannot run in server-Mode and use unification server at the same time");
|
||||||
|
}
|
||||||
|
runAsServerWithPort = Integer.parseInt(it.next());
|
||||||
|
}
|
||||||
|
else if (arg.equals("-us") || arg.equals("-unification-server")) {
|
||||||
|
if (runAsServerWithPort != -1) {
|
||||||
|
throw new IllegalArgumentException("Cannot run in server-Mode and use unification server at the same time");
|
||||||
|
}
|
||||||
|
unificationServer = it.next();
|
||||||
|
} else {
|
||||||
input.add(new File(arg));
|
input.add(new File(arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath, outputPath != null ? new File(outputPath) : null);
|
|
||||||
//compiler.typeInference();
|
if (runAsServerWithPort != -1) {
|
||||||
compiler.generateBytecode();
|
JavaTXServer server = new JavaTXServer(runAsServerWithPort);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath, outputPath != null ? new File(outputPath) : null);
|
||||||
|
//compiler.typeInference();
|
||||||
|
compiler.generateBytecode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Codegen;
|
import de.dhbwstuttgart.bytecode.Codegen;
|
||||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
|
||||||
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;
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
@@ -14,6 +12,7 @@ import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
|||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SourceFileContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SourceFileContext;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
|
import de.dhbwstuttgart.server.SocketClient;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
@@ -32,24 +31,19 @@ import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
|||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.typeinference.TypeInference;
|
||||||
|
import de.dhbwstuttgart.typeinference.TypeInferenceHelper;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
import de.dhbwstuttgart.typeinference.unify.*;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -59,6 +53,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.util.Logger;
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
@@ -66,20 +61,16 @@ public class JavaTXCompiler {
|
|||||||
// public static JavaTXCompiler INSTANCE;
|
// public static JavaTXCompiler INSTANCE;
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
Boolean resultmodel = true;
|
Boolean resultmodel = true;
|
||||||
|
Optional<String> unificationServer = Optional.empty();
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
|
|
||||||
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
public UnifyTaskModelParallel usedTasks = new UnifyTaskModelParallel();
|
||||||
public final DirectoryClassLoader classLoader;
|
public final DirectoryClassLoader classLoader;
|
||||||
|
|
||||||
public final List<File> classPath;
|
public final List<File> classPath;
|
||||||
private final File outputPath;
|
private final File outputPath;
|
||||||
|
|
||||||
public final Map<String, FunNGenerator.GenericParameters> usedFunN = new HashMap<>();
|
|
||||||
public final Set<Integer> usedFunNSuperTypes = new HashSet<>();
|
|
||||||
|
|
||||||
public Map<String, byte[]> auxiliaries = new HashMap<>();
|
|
||||||
|
|
||||||
public DirectoryClassLoader getClassLoader() {
|
public DirectoryClassLoader getClassLoader() {
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
@@ -289,7 +280,7 @@ public class JavaTXCompiler {
|
|||||||
* x.getRhsType().accept(new distributeVariance(), a.getVariance());}); eq1 = new HashSet<>(eq); eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); phSetVariance = new ArrayList<>(phSet); phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } }
|
* x.getRhsType().accept(new distributeVariance(), a.getVariance());}); eq1 = new HashSet<>(eq); eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); phSetVariance = new ArrayList<>(phSet); phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile) throws ClassNotFoundException, IOException {
|
public UnifyResultModelParallel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile) throws ClassNotFoundException, IOException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for (Entry<File, SourceFile> source : this.sourceFiles.entrySet()) {
|
for (Entry<File, SourceFile> source : this.sourceFiles.entrySet()) {
|
||||||
@@ -305,13 +296,17 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
UnifyResultModel urm = null;
|
UnifyResultModelParallel urm = null;
|
||||||
// urm.addUnifyResultListener(resultListener);
|
// urm.addUnifyResultListener(resultListener);
|
||||||
try {
|
try {
|
||||||
logFile = logFile == null ? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName())) : logFile;
|
Logger logger = new Logger(true, "log_" + sourceFiles.keySet().iterator().next().getName());
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, getClassLoader(), this);
|
if (logFile == null) {
|
||||||
|
logFile = logger.getLogFileWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logger, getClassLoader(), this);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
urm = new UnifyResultModel(cons, finiteClosure);
|
urm = new UnifyResultModelParallel(cons, finiteClosure);
|
||||||
urm.addUnifyResultListener(resultListener);
|
urm.addUnifyResultListener(resultListener);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
||||||
|
|
||||||
@@ -357,6 +352,12 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference(File file) throws ClassNotFoundException, IOException {
|
public List<ResultSet> typeInference(File file) throws ClassNotFoundException, IOException {
|
||||||
|
|
||||||
|
// START create logger
|
||||||
|
Logger logger = new Logger(log, "log_" + sourceFiles.keySet().iterator().next().getName());
|
||||||
|
// END create logger
|
||||||
|
|
||||||
|
// START gather classes and interfaces
|
||||||
var sf = sourceFiles.get(file);
|
var sf = sourceFiles.get(file);
|
||||||
Set<ClassOrInterface> allClasses = new HashSet<>();// environment.getAllAvailableClasses();
|
Set<ClassOrInterface> allClasses = new HashSet<>();// environment.getAllAvailableClasses();
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
@@ -369,195 +370,56 @@ public class JavaTXCompiler {
|
|||||||
if (allClasses.stream().noneMatch(old -> old.getClassName().equals(clazz.getClassName())))
|
if (allClasses.stream().noneMatch(old -> old.getClassName().equals(clazz.getClassName())))
|
||||||
allClasses.add(clazz);
|
allClasses.add(clazz);
|
||||||
}
|
}
|
||||||
|
logger.write(ASTTypePrinter.print(sf));
|
||||||
|
// END gather classes and interfaces
|
||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints(file);
|
// START create finite closure
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses.stream().toList(), logger, classLoader, this);
|
||||||
try {
|
logger.write("FC:\\" + finiteClosure.toString() + "\n");
|
||||||
var logFolder = new File(System.getProperty("user.dir") + "/logFiles/");
|
// END create finite closure
|
||||||
if (log) logFolder.mkdirs();
|
|
||||||
Writer logFile = log ? new FileWriter(new File(logFolder, "log_" + sourceFiles.keySet().iterator().next().getName())) : new OutputStreamWriter(new NullOutputStream());
|
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses.stream().toList(), logFile, classLoader, this);
|
|
||||||
System.out.println(finiteClosure);
|
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
|
||||||
System.out.println("xxx1");
|
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
|
||||||
UnifyType lhs, rhs;
|
|
||||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType) && ((rhs = x.getRhsType()) instanceof PlaceholderType) && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
|
|
||||||
((PlaceholderType) lhs).setInnerType(true);
|
|
||||||
((PlaceholderType) rhs).setInnerType(true);
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
|
|
||||||
};
|
// START create unify constraints
|
||||||
|
ConstraintSet<Pair> cons = getConstraints(file);
|
||||||
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
||||||
|
logger.write("Unify:" + unifyCons.toString());
|
||||||
|
unifyCons = unifyCons.map(TypeInferenceHelper::distributeInnerVars);
|
||||||
|
logger.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
||||||
|
System.out.println("xxx1");
|
||||||
|
// END create unify constraints
|
||||||
|
|
||||||
logFile.write("Unify:" + unifyCons.toString());
|
// START unused variance calculation
|
||||||
System.out.println("Unify:" + unifyCons.toString());
|
Set<PlaceholderType> varianceTPHold;
|
||||||
unifyCons = unifyCons.map(distributeInnerVars);
|
Set<PlaceholderType> varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
/*
|
||||||
TypeUnify unify = new TypeUnify();
|
* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH); varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { if (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
||||||
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) { ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType( )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType( )).getVariance()); } } return y; } ); } while (!varianceTPHold.equals(varianceTPH));
|
||||||
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
*/
|
||||||
logFile.write(ASTTypePrinter.print(sf));
|
// END unused variance calculation
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
|
||||||
logFile.flush();
|
|
||||||
List<UnifyPair> andConstraintsSorted = unifyCons.getUndConstraints().stream()
|
|
||||||
.sorted(Comparator.comparing(UnifyPair::getPairOp).thenComparing(UnifyPair::getLhsType, Comparator.comparing(UnifyType::getName)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
System.out.println(andConstraintsSorted);
|
TypeInference typeInference = new TypeInference(
|
||||||
|
logger,
|
||||||
Set<PlaceholderType> varianceTPHold;
|
classLoader,
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
usedTasks,
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
file,
|
||||||
|
cons,
|
||||||
/*
|
allClasses,
|
||||||
* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH); varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { if (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
finiteClosure,
|
||||||
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) { ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType( )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType( )).getVariance()); } } return y; } ); } while (!varianceTPHold.equals(varianceTPH));
|
unifyCons
|
||||||
*/
|
);
|
||||||
|
if (unificationServer.isPresent()) {
|
||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
return typeInference.executeOnRemoteServer(unificationServer.get());
|
||||||
// logFile, log);
|
}
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
else if (resultmodel) {
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()// .stream().map(x -> {
|
return typeInference.executeResultModel();
|
||||||
/*
|
}
|
||||||
* Set<Set<UnifyPair>> ret = new HashSet<>(); for (Constraint<UnifyPair> y : x) { ret.add(new HashSet<>(y)); } return ret; }).collect(Collectors.toCollection(ArrayList::new))
|
else {
|
||||||
*/;
|
return typeInference.executeNoResultModel();
|
||||||
if (resultmodel) {
|
|
||||||
/* UnifyResultModel Anfang */
|
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
|
||||||
urm.addUnifyResultListener(li);
|
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
|
||||||
//System.out.println("RESULT Final: " + li.getResults());
|
|
||||||
var finalResults = li.getResults().stream().sorted().toList();
|
|
||||||
int i = 0;
|
|
||||||
System.out.println("RESULT Final: ");
|
|
||||||
for (var result : finalResults){
|
|
||||||
System.out.println("Result: " + i++);
|
|
||||||
System.out.println(result.getSortedResults());
|
|
||||||
}
|
|
||||||
System.out.println("Constraints for Generated Generics: " + " ???");
|
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
|
||||||
logFile.flush();
|
|
||||||
return li.getResults();
|
|
||||||
}
|
|
||||||
/* UnifyResultModel End */
|
|
||||||
else {
|
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(),
|
|
||||||
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
|
|
||||||
// finiteClosure));
|
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
|
||||||
System.out.println("RESULT: " + result);
|
|
||||||
logFile.write("RES: " + result.toString() + "\n");
|
|
||||||
logFile.flush();
|
|
||||||
results.addAll(result);
|
|
||||||
|
|
||||||
results = results.stream().map(x -> {
|
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC)
|
|
||||||
y.setPairOp(PairOperator.EQUALSDOT);
|
|
||||||
return y; // alle Paare a <.? b erden durch a =. b ersetzt
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
|
||||||
if (res.isPresent()) {// wenn subst ein Erg liefert wurde was veraendert
|
|
||||||
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
|
||||||
} else
|
|
||||||
return x; // wenn nichts veraendert wurde wird x zurueckgegeben
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
System.out.println("RESULT Final: " + results);
|
|
||||||
System.out.println("Constraints for Generated Generics: " + " ???");
|
|
||||||
logFile.write("RES_FINAL: " + results.toString() + "\n");
|
|
||||||
logFile.flush();
|
|
||||||
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);
|
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("kein LogFile");
|
|
||||||
}
|
}
|
||||||
return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TEMPORARY - Only for Language Server Usage
|
|
||||||
*/
|
|
||||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(File file) throws IOException, ClassNotFoundException {
|
|
||||||
var sf = sourceFiles.get(file);
|
|
||||||
if(sf == null){
|
|
||||||
sf = sourceFiles.values().stream().findFirst().get();
|
|
||||||
}
|
|
||||||
Set<ClassOrInterface> allClasses = new HashSet<>();
|
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
var newClasses = CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), file, this).stream().map(ASTFactory::createClass).collect(Collectors.toSet());
|
|
||||||
for (var clazz : newClasses) {
|
|
||||||
// Don't load classes that get recompiled
|
|
||||||
if (sf.getClasses().stream().anyMatch(nf -> nf.getClassName().equals(clazz.getClassName())))
|
|
||||||
continue;
|
|
||||||
if (allClasses.stream().noneMatch(old -> old.getClassName().equals(clazz.getClassName())))
|
|
||||||
allClasses.add(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints(file);
|
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
|
||||||
try {
|
|
||||||
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses.stream().toList(), logFile, classLoader, this);
|
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
|
||||||
UnifyType lhs, rhs;
|
|
||||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType) && ((rhs = x.getRhsType()) instanceof PlaceholderType) && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
|
|
||||||
((PlaceholderType) lhs).setInnerType(true);
|
|
||||||
((PlaceholderType) rhs).setInnerType(true);
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
unifyCons = unifyCons.map(distributeInnerVars);
|
|
||||||
TypeUnify unify = new TypeUnify();
|
|
||||||
Set<PlaceholderType> varianceTPHold;
|
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
|
||||||
|
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints();
|
|
||||||
|
|
||||||
if (resultmodel) {
|
|
||||||
/* UnifyResultModel Anfang */
|
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
|
||||||
urm.addUnifyResultListener(li);
|
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
|
||||||
generateBytecode(sf, li.getResults());
|
|
||||||
return new LanguageServerTransferObject(li.getResults(), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
|
||||||
}
|
|
||||||
/* UnifyResultModel End */
|
|
||||||
else {
|
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
|
||||||
results.addAll(result);
|
|
||||||
|
|
||||||
results = results.stream().map(x -> {
|
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC)
|
|
||||||
y.setPairOp(PairOperator.EQUALSDOT);
|
|
||||||
return y; // alle Paare a <.? b erden durch a =. b ersetzt
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
|
||||||
if (res.isPresent()) {// wenn subst ein Erg liefert wurde was veraendert
|
|
||||||
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
|
||||||
} else
|
|
||||||
return x; // wenn nichts veraendert wurde wird x zurueckgegeben
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
}
|
|
||||||
generateBytecode(sf, results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()));
|
|
||||||
return new LanguageServerTransferObject(results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private Set<PlaceholderType> varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
|
private Set<PlaceholderType> varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
|
||||||
@@ -729,12 +591,12 @@ public class JavaTXCompiler {
|
|||||||
var codegen = new Codegen(converter.convert(clazz), this, converter);
|
var codegen = new Codegen(converter.convert(clazz), this, converter);
|
||||||
var code = codegen.generate();
|
var code = codegen.generate();
|
||||||
generatedClasses.put(clazz.getClassName(), code);
|
generatedClasses.put(clazz.getClassName(), code);
|
||||||
|
converter.auxiliaries.forEach((name, source) -> {
|
||||||
|
generatedClasses.put(new JavaClassName(name), source);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
generatedGenerics.put(sf, converter.javaGenerics());
|
generatedGenerics.put(sf, converter.javaGenerics());
|
||||||
converter.generateFunNTypes();
|
converter.generateFunNTypes();
|
||||||
auxiliaries.forEach((name, source) -> {
|
|
||||||
generatedClasses.put(new JavaClassName(name), source);
|
|
||||||
});
|
|
||||||
return generatedClasses;
|
return generatedClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
src/main/java/de/dhbwstuttgart/core/JavaTXServer.java
Normal file
15
src/main/java/de/dhbwstuttgart/core/JavaTXServer.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.SocketServer;
|
||||||
|
|
||||||
|
public class JavaTXServer {
|
||||||
|
|
||||||
|
JavaTXServer(int port) {
|
||||||
|
try {
|
||||||
|
SocketServer socketServer = new SocketServer(port);
|
||||||
|
socketServer.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package de.dhbwstuttgart.environment;
|
||||||
|
|
||||||
|
public class ByteArrayClassLoader extends ClassLoader implements IByteArrayClassLoader {
|
||||||
|
@Override
|
||||||
|
public Class _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError {
|
||||||
|
return defineClass(name, code, i, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
|
return super.findClass(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
package de.dhbwstuttgart.environment;
|
package de.dhbwstuttgart.environment;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
@@ -18,6 +12,17 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser.SourceFileContext;
|
|||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext;
|
||||||
import de.dhbwstuttgart.parser.scope.GatherNames;
|
import de.dhbwstuttgart.parser.scope.GatherNames;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
||||||
@@ -30,8 +35,8 @@ public class CompilationEnvironment {
|
|||||||
public final PackageCrawler packageCrawler;
|
public final PackageCrawler packageCrawler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien Die Environment enthält automatisch die Java Standard Library
|
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien Die Environment enth<EFBFBD>lt automatisch die Java Standard Library
|
||||||
*
|
*
|
||||||
* @param sourceFiles die zu kompilierenden Dateien
|
* @param sourceFiles die zu kompilierenden Dateien
|
||||||
*/
|
*/
|
||||||
public CompilationEnvironment(List<File> sourceFiles, DirectoryClassLoader classLoader) {
|
public CompilationEnvironment(List<File> sourceFiles, DirectoryClassLoader classLoader) {
|
||||||
|
|||||||
@@ -6,22 +6,18 @@ import java.nio.file.Path;
|
|||||||
|
|
||||||
public interface IByteArrayClassLoader {
|
public interface IByteArrayClassLoader {
|
||||||
|
|
||||||
Class<?> loadClass(String path) throws ClassNotFoundException;
|
Class loadClass(String path) throws ClassNotFoundException;
|
||||||
|
|
||||||
default Class<?> loadClass(byte[] code) {
|
default Class loadClass(byte[] code) {
|
||||||
return this.loadClass(null, code);
|
return this._defineClass(null, code, 0, code.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
default Class<?> loadClass(String name, byte[] code) {
|
default Class loadClass(Path path) throws IOException {
|
||||||
return this._defineClass(name, code, 0, code.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
default Class<?> loadClass(Path path) throws IOException {
|
|
||||||
var code = Files.readAllBytes(path);
|
var code = Files.readAllBytes(path);
|
||||||
return this._defineClass(null, code, 0, code.length);
|
return this._defineClass(null, code, 0, code.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException;
|
public Class<?> findClass(String name) throws ClassNotFoundException;
|
||||||
|
|
||||||
Class<?> _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError;
|
Class _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,120 +0,0 @@
|
|||||||
package de.dhbwstuttgart.languageServerInterface;
|
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Codegen;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.target.tree.TargetStructure;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of an Interface for the Language-Server to get the Resultset and abstract Syntax.
|
|
||||||
*/
|
|
||||||
public class LanguageServerInterface {
|
|
||||||
|
|
||||||
|
|
||||||
public LanguageServerTransferObject getResultSetAndAbastractSyntax(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
|
||||||
NameGenerator.resetTo(resetNamesTo);
|
|
||||||
return getResultSetAndAbstractSyntax(path);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public SourceFile getAst(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
|
||||||
NameGenerator.resetTo(resetNamesTo);
|
|
||||||
return getAST(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the ResultSets, GenericResultSet and the AST
|
|
||||||
* You have to give the input as well as the path because of potential locks when the File is currently opened in an IDE.
|
|
||||||
* Example: file:///c:/test/main.jav -> file:///c:/test/out/main.class
|
|
||||||
*
|
|
||||||
* @param pathAsString the URI of the File. See Example.
|
|
||||||
*/
|
|
||||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(String pathAsString){
|
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
|
||||||
try {
|
|
||||||
var uri = new URI(pathAsString);
|
|
||||||
var path = Path.of(uri);
|
|
||||||
var file = path.toFile();
|
|
||||||
Files.createDirectories(path.getParent().resolve("out"));
|
|
||||||
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile());
|
|
||||||
|
|
||||||
var parsedSource = compiler.sourceFiles.get(file);
|
|
||||||
var tiResults = compiler.typeInference(file);
|
|
||||||
|
|
||||||
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(parsedSource, tiResults);
|
|
||||||
Files.createDirectories(path.getParent().resolve("out"));
|
|
||||||
compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
|
|
||||||
|
|
||||||
return new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
|
||||||
}catch (Exception e){
|
|
||||||
throw new RuntimeException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the AST without calculating the result
|
|
||||||
* You have to give the input as well as the path because of potential locks when the File is currently opened in an IDE.
|
|
||||||
* Example: file:///c:/test/main.jav -> file:///c:/test/out/main.class
|
|
||||||
*
|
|
||||||
* @param path the URI of the File. See Example.
|
|
||||||
* @throws IOException
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
* @throws URISyntaxException
|
|
||||||
*/
|
|
||||||
public SourceFile getAST(String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
|
||||||
|
|
||||||
|
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
|
||||||
|
|
||||||
|
|
||||||
URI uri = new URI(path);
|
|
||||||
ArrayList<String> pathWithoutName = new ArrayList<>(List.of(uri.getPath().split("/")));
|
|
||||||
pathWithoutName.remove(List.of(uri.getPath().split("/")).size() - 1);
|
|
||||||
String stringPathWithoutName = "";
|
|
||||||
|
|
||||||
for (String i : pathWithoutName) {
|
|
||||||
stringPathWithoutName += "/" + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
FileUtils.cleanDirectory(new File(stringPathWithoutName + "/out"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
(new File(stringPathWithoutName + "/out")).mkdirs();
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
var test = getAST(uri.getPath().split("/")[uri.getPath().split("/").length - 1], new File(stringPathWithoutName).getPath());
|
|
||||||
System.setOut(System.out);
|
|
||||||
return test;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SourceFile getAST(String filename, String filePath) throws IOException, ClassNotFoundException {
|
|
||||||
var file = Path.of(filePath, filename).toFile();
|
|
||||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()), Path.of(filePath + "/out").toFile());
|
|
||||||
return compiler.sourceFiles.get(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package de.dhbwstuttgart.languageServerInterface;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.CustomParserErrorHandler;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Lexer;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17ParserBaseListener;
|
|
||||||
import org.antlr.v4.runtime.CharStream;
|
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ParserInterface {
|
|
||||||
|
|
||||||
public List<ParserError> getParseErrors(String input){
|
|
||||||
|
|
||||||
CustomParserErrorHandler errorListener = new CustomParserErrorHandler();
|
|
||||||
CharStream charStream = CharStreams.fromString(input);
|
|
||||||
|
|
||||||
Java17Lexer lexer = new Java17Lexer(charStream);
|
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
||||||
|
|
||||||
Java17Parser parser = new Java17Parser(tokens);
|
|
||||||
parser.removeErrorListeners();
|
|
||||||
parser.addErrorListener(errorListener);
|
|
||||||
|
|
||||||
|
|
||||||
ParseTree tree = parser.sourceFile();
|
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
|
||||||
Java17ParserBaseListener listener = new Java17ParserBaseListener();
|
|
||||||
walker.walk(listener, tree);
|
|
||||||
|
|
||||||
return errorListener.getErrorMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package de.dhbwstuttgart.languageServerInterface.model;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.*;
|
|
||||||
import org.antlr.v4.runtime.atn.ATNConfigSet;
|
|
||||||
import org.antlr.v4.runtime.dfa.DFA;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.BitSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CustomParserErrorHandler implements ANTLRErrorListener {
|
|
||||||
private final List<ParserError> errorMessages = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
|
|
||||||
int endCharPosition = charPositionInLine;
|
|
||||||
if (offendingSymbol instanceof Token) {
|
|
||||||
Token offendingToken = (Token) offendingSymbol;
|
|
||||||
endCharPosition = charPositionInLine + offendingToken.getText().length();
|
|
||||||
}
|
|
||||||
|
|
||||||
ParserError parserError = new ParserError(line, charPositionInLine, endCharPosition, msg);
|
|
||||||
errorMessages.add(parserError);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reportAmbiguity(Parser parser, DFA dfa, int i, int i1, boolean b, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reportAttemptingFullContext(Parser parser, DFA dfa, int i, int i1, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reportContextSensitivity(Parser parser, DFA dfa, int i, int i1, int i2, ATNConfigSet atnConfigSet) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ParserError> getErrorMessages() {
|
|
||||||
return errorMessages;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package de.dhbwstuttgart.languageServerInterface.model;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class LanguageServerTransferObject {
|
|
||||||
List<ResultSet> resultSets;
|
|
||||||
SourceFile Ast;
|
|
||||||
String printedAst;
|
|
||||||
Map<SourceFile, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
public LanguageServerTransferObject(List<ResultSet> resultSets, SourceFile Ast, String printedAst, Map<SourceFile, List<GenericsResult>> generatedGenerics) {
|
|
||||||
this.resultSets = resultSets;
|
|
||||||
this.Ast = Ast;
|
|
||||||
this.printedAst = printedAst;
|
|
||||||
this.generatedGenerics = generatedGenerics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ResultSet> getResultSets() {return resultSets;}
|
|
||||||
public SourceFile getAst() {return Ast;}
|
|
||||||
public String getPrintedAst() {return printedAst;}
|
|
||||||
public Map<SourceFile, List<GenericsResult>> getGeneratedGenerics() {return generatedGenerics;}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package de.dhbwstuttgart.languageServerInterface.model;
|
|
||||||
|
|
||||||
public class ParserError {
|
|
||||||
|
|
||||||
private int line;
|
|
||||||
private int charPositionInLine;
|
|
||||||
private int endCharPosition;
|
|
||||||
String msg;
|
|
||||||
|
|
||||||
public ParserError(int line, int charPositionInLine, int endCharPosition, String msg) {
|
|
||||||
this.line = line;
|
|
||||||
this.charPositionInLine = charPositionInLine;
|
|
||||||
this. endCharPosition = endCharPosition;
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEndCharPosition() {
|
|
||||||
return endCharPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndCharPosition(int endCharPosition) {
|
|
||||||
this.endCharPosition = endCharPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCharPositionInLine(int charPositionInLine) {
|
|
||||||
this.charPositionInLine = charPositionInLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLine(int line) {
|
|
||||||
this.line = line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMsg(String msg) {
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCharPositionInLine() {
|
|
||||||
return charPositionInLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsg() {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package de.dhbwstuttgart.languageServerInterface.model;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.reflect.TypeResolver;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultEvent;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
|
||||||
|
|
||||||
public class ResultSetListener implements UnifyResultListener {
|
|
||||||
|
|
||||||
TypeResolver typeResolver;
|
|
||||||
|
|
||||||
public ResultSetListener(TypeResolver typeResolver){
|
|
||||||
this.typeResolver = typeResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNewTypeResultFound(UnifyResultEvent evt) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,10 +11,10 @@ import org.antlr.v4.runtime.CharStream;
|
|||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.io.FileInputStream;
|
||||||
import java.util.ArrayList;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class JavaTXParser {
|
public class JavaTXParser {
|
||||||
public static Java17Parser.SourceFileContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
|
public static Java17Parser.SourceFileContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
|
|
||||||
public class AssignToLocal extends AssignLeftSide {
|
public class AssignToLocal extends AssignLeftSide {
|
||||||
@@ -17,4 +16,4 @@ public class AssignToLocal extends AssignLeftSide {
|
|||||||
public void accept(StatementVisitor visitor) {
|
public void accept(StatementVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,13 +12,12 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
|||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
|
|
||||||
public class FCGenerator {
|
public class FCGenerator {
|
||||||
/**
|
/**
|
||||||
* Baut die FiniteClosure aus availableClasses.
|
* Baut die FiniteClosure aus availableClasses.
|
||||||
@@ -37,8 +36,8 @@ public class FCGenerator {
|
|||||||
for(ClassOrInterface cly : availableClasses){
|
for(ClassOrInterface cly : availableClasses){
|
||||||
List<Pair> newPairs = getSuperTypes(cly, availableClasses, gtvs, classLoader);
|
List<Pair> newPairs = getSuperTypes(cly, availableClasses, gtvs, classLoader);
|
||||||
pairs.addAll(newPairs);
|
pairs.addAll(newPairs);
|
||||||
|
|
||||||
//For all Functional Interfaces FI: FunN$$<... args auf dem Functional Interface ...> <. FI is added to FC
|
//For all Functional Interfaces FI: FunN$$<... args auf dem Functional Interface ...> <. FI is added to FC
|
||||||
if (isFunctionalInterface(cly)) {
|
if (isFunctionalInterface(cly)) {
|
||||||
pairs.add(genImplFunType(cly, newPairs.get(0).TA1, gtvs));
|
pairs.add(genImplFunType(cly, newPairs.get(0).TA1, gtvs));
|
||||||
}
|
}
|
||||||
@@ -48,19 +47,19 @@ public class FCGenerator {
|
|||||||
|
|
||||||
|
|
||||||
private static Boolean isFunctionalInterface(ClassOrInterface cly) {
|
private static Boolean isFunctionalInterface(ClassOrInterface cly) {
|
||||||
return (cly.isInterface() && (cly.isFunctionalInterface() || cly.getMethods().size() == 1));
|
return (cly.isInterface() && (cly.isFunctionalInterface() || cly.getMethods().size() == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Pair genImplFunType(ClassOrInterface cly, RefTypeOrTPHOrWildcardOrGeneric fIType, HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) {
|
private static Pair genImplFunType(ClassOrInterface cly, RefTypeOrTPHOrWildcardOrGeneric fIType, HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) {
|
||||||
for(Method m : cly.getMethods()) {
|
for(Method m : cly.getMethods()) {
|
||||||
if (!java.lang.reflect.Modifier.isAbstract(m.modifier))
|
if (!java.lang.reflect.Modifier.isAbstract(m.modifier))
|
||||||
continue;
|
continue;
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> tl =
|
List<RefTypeOrTPHOrWildcardOrGeneric> tl =
|
||||||
(m.getParameterList().getFormalparalist()
|
(m.getParameterList().getFormalparalist()
|
||||||
.stream().map(p -> p.getType().acceptTV(new TypeExchanger(gtvs)))
|
.stream().map(p -> p.getType().acceptTV(new TypeExchanger(gtvs)))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
tl.add(m.getReturnType().acceptTV(new TypeExchanger(gtvs)));
|
tl.add(m.getReturnType().acceptTV(new TypeExchanger(gtvs)));
|
||||||
return new Pair(new RefType(new JavaClassName("Fun" + (tl.size()-1) + "$$"), tl, new NullToken()),
|
return new Pair(new RefType(new JavaClassName("Fun" + (tl.size()-1) + "$$"), tl, new NullToken()),
|
||||||
fIType, PairOperator.SMALLER);
|
fIType, PairOperator.SMALLER);
|
||||||
}
|
}
|
||||||
return null; //kann nicht passieren, da die Methode nur aufgerufen wird wenn cl Functional Interface ist
|
return null; //kann nicht passieren, da die Methode nur aufgerufen wird wenn cl Functional Interface ist
|
||||||
@@ -202,7 +201,7 @@ public class FCGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus auf den Argumenten der Argumente.
|
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus auf den Argumenten der Argumente.
|
||||||
* Hier sind Wildcards zulässig
|
* Hier sind Wildcards zulässig
|
||||||
@@ -248,5 +247,5 @@ public class FCGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,11 +149,11 @@ public class StatementGenerator {
|
|||||||
type = TypeGenerator.convert(fp.typeType(), reg, generics);
|
type = TypeGenerator.convert(fp.typeType(), reg, generics);
|
||||||
} else {
|
} else {
|
||||||
type = methodparameters?
|
type = methodparameters?
|
||||||
TypePlaceholder.fresh(fp.getStart(), 1, false)
|
TypePlaceholder.fresh(fp.getStart(), 1, false)
|
||||||
: TypePlaceholder.fresh(fp.getStart(), 1, false);
|
: TypePlaceholder.fresh(fp.getStart());
|
||||||
}
|
}
|
||||||
ret.add(new FormalParameter(paramName, type, fp.getStart()));
|
ret.add(new FormalParameter(paramName, type, fp.getStart()));
|
||||||
localVars.put(paramName, type);
|
localVars.put(paramName, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ParameterList(ret, ret.get(0).getOffset());
|
return new ParameterList(ret, ret.get(0).getOffset());
|
||||||
@@ -1065,7 +1065,7 @@ public class StatementGenerator {
|
|||||||
List<Pattern> parameterList = new ArrayList<>();
|
List<Pattern> parameterList = new ArrayList<>();
|
||||||
for (IdentifierContext identifier : lambdaParams.identifier()) {
|
for (IdentifierContext identifier : lambdaParams.identifier()) {
|
||||||
Token offset = identifier.getStart();
|
Token offset = identifier.getStart();
|
||||||
parameterList.add(new FormalParameter(identifier.getText(), TypePlaceholder.fresh(offset, 1, false), offset));
|
parameterList.add(new FormalParameter(identifier.getText(), TypePlaceholder.fresh(offset), offset));
|
||||||
}
|
}
|
||||||
params = new ParameterList(parameterList, lambdaParams.getStart());
|
params = new ParameterList(parameterList, lambdaParams.getStart());
|
||||||
} else if (lambdaParams.formalParameterList() != null) {
|
} else if (lambdaParams.formalParameterList() != null) {
|
||||||
@@ -1075,7 +1075,7 @@ public class StatementGenerator {
|
|||||||
List<Pattern> parameterList = new ArrayList<>();
|
List<Pattern> parameterList = new ArrayList<>();
|
||||||
for (LambdaLVTIParameterContext param : lambdaParams.lambdaLVTIList().lambdaLVTIParameter()) {
|
for (LambdaLVTIParameterContext param : lambdaParams.lambdaLVTIList().lambdaLVTIParameter()) {
|
||||||
Token offset = param.getStart();
|
Token offset = param.getStart();
|
||||||
parameterList.add(new FormalParameter(param.identifier().getText(), TypePlaceholder.fresh(offset, 1, false), offset));
|
parameterList.add(new FormalParameter(param.identifier().getText(), TypePlaceholder.fresh(offset), offset));
|
||||||
}
|
}
|
||||||
params = new ParameterList(parameterList, lambdaParams.getStart());
|
params = new ParameterList(parameterList, lambdaParams.getStart());
|
||||||
} else {
|
} else {
|
||||||
@@ -1099,9 +1099,9 @@ public class StatementGenerator {
|
|||||||
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
||||||
}
|
}
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||||
funNParams.add(TypePlaceholder.fresh(expression.getStart(), -1, false));// ret-Type
|
funNParams.add(TypePlaceholder.fresh(expression.getStart()));// ret-Type
|
||||||
params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen:
|
params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen:
|
||||||
funNParams.add(TypePlaceholder.fresh(expression.getStart(), 1, false)));
|
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
|
||||||
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
||||||
// RefType lambdaType = new
|
// RefType lambdaType = new
|
||||||
// RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
// RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -14,12 +14,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
|||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -164,4 +164,4 @@ public class GatherNames {
|
|||||||
}
|
}
|
||||||
return pkgName;
|
return pkgName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class JavaClassName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt von einem Klassennamen nur den Namen der Klasse zurück
|
* Gibt von einem Klassennamen nur den Namen der Klasse zur<EFBFBD>ck
|
||||||
* Beispiel:
|
* Beispiel:
|
||||||
* java.lang.Object wird zu: Object
|
* java.lang.Object wird zu: Object
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ package de.dhbwstuttgart.parser.scope;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Speichert die Klassen für einen bestimmten Projektscope
|
* Speichert die Klassen f<EFBFBD>r einen bestimmten Projektscope
|
||||||
*/
|
*/
|
||||||
public class JavaClassRegistry{
|
public class JavaClassRegistry {
|
||||||
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
||||||
|
|
||||||
public JavaClassRegistry(Map<String, Integer> initialNames) {
|
public JavaClassRegistry(Map<String, Integer> initialNames) {
|
||||||
@@ -22,10 +25,6 @@ public class JavaClassRegistry{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<JavaClassName> getAllClassNames(){
|
|
||||||
return existingClasses.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addName(String className, int numberOfGenerics) {
|
public void addName(String className, int numberOfGenerics) {
|
||||||
existingClasses.put(new JavaClassName(className), numberOfGenerics);
|
existingClasses.put(new JavaClassName(className), numberOfGenerics);
|
||||||
}
|
}
|
||||||
@@ -66,4 +65,4 @@ public class JavaClassRegistry{
|
|||||||
public int getNumberOfGenerics(String name) {
|
public int getNumberOfGenerics(String name) {
|
||||||
return existingClasses.get(new JavaClassName(name));
|
return existingClasses.get(new JavaClassName(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
143
src/main/java/de/dhbwstuttgart/server/SocketClient.java
Normal file
143
src/main/java/de/dhbwstuttgart/server/SocketClient.java
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
package de.dhbwstuttgart.server;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import de.dhbwstuttgart.server.packet.ErrorPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.InvalidPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.MessagePacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.PacketContainer;
|
||||||
|
import de.dhbwstuttgart.server.packet.UnifyRequestPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.UnifyResultPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import org.java_websocket.client.WebSocketClient;
|
||||||
|
import org.java_websocket.enums.ReadyState;
|
||||||
|
import org.java_websocket.handshake.ServerHandshake;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Client-side of the websocket
|
||||||
|
*/
|
||||||
|
public class SocketClient extends WebSocketClient {
|
||||||
|
|
||||||
|
// use a latch to wait until the connection is closed by the remote host
|
||||||
|
private final CountDownLatch closeLatch = new CountDownLatch(1);
|
||||||
|
// temporarily: The received unify result packet
|
||||||
|
private UnifyResultPacket unifyResultPacket = null;
|
||||||
|
|
||||||
|
public SocketClient(String url) {
|
||||||
|
super(URI.create(url));
|
||||||
|
// make sure, the url is in a valid format
|
||||||
|
final String regex = "^wss?://(\\w+(\\.\\w+)?)*:(\\d+)$";
|
||||||
|
final Matcher matcher = Pattern.compile(regex).matcher(url);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
throw new RuntimeException("Provided string \"" + url + "\" is not a valid server URL! Use pattern ws(s?)://<host.name>:<port>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SocketClient(String host, int port, boolean secure) {
|
||||||
|
super(URI.create(String.format("%s://%s:%d/", secure ? "wss" : "ws", host, port)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main method for connecting, requesting and waiting for the server to unify.
|
||||||
|
* This is synchronized to prevent multiple webSockets connections at the moment, but it is not called from any
|
||||||
|
* thread except the main thread right now and is not necessary at all, probably. Maybe remove it later
|
||||||
|
*/
|
||||||
|
synchronized public List<ResultSet> execute(
|
||||||
|
IFiniteClosure finiteClosure,
|
||||||
|
ConstraintSet<Pair> constraints,
|
||||||
|
ConstraintSet<UnifyPair> unifyConstraints
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
// wait for the connection to be set up
|
||||||
|
this.connectBlocking();
|
||||||
|
// make sure the connection has been established successfully
|
||||||
|
if (this.getReadyState() != ReadyState.OPEN) {
|
||||||
|
throw new RuntimeException("WebSocket Client could not connect to remote host at " + this.uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
// send the unify task request
|
||||||
|
UnifyRequestPacket packet = UnifyRequestPacket.create(finiteClosure, constraints, unifyConstraints);
|
||||||
|
String json = PacketContainer.serialize(packet);
|
||||||
|
this.send(json);
|
||||||
|
|
||||||
|
// block the thread, until the connection is closed by the remote host (usually after sending the results)
|
||||||
|
this.waitUntilClosed();
|
||||||
|
// wait for the connection to fully close
|
||||||
|
this.closeBlocking();
|
||||||
|
} catch (InterruptedException exception) {
|
||||||
|
System.err.println("Interrupted: " + exception);
|
||||||
|
this.notifyAll();
|
||||||
|
throw new RuntimeException("Remote unification failed: " + exception);
|
||||||
|
} catch (JsonProcessingException exception) {
|
||||||
|
System.err.println("JSON processing exception: " + exception);
|
||||||
|
this.notifyAll();
|
||||||
|
throw new RuntimeException("Remote unification failed: " + exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// detect error cases, in which no error was thrown, but also no result was sent back from the server
|
||||||
|
if (this.unifyResultPacket == null) {
|
||||||
|
throw new RuntimeException("Did not receive server response but closed connection already");
|
||||||
|
}
|
||||||
|
|
||||||
|
return unifyResultPacket.getResultSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific client-side implementations to handle incomming packets
|
||||||
|
*/
|
||||||
|
protected void handleReceivedPacket(IPacket packet) {
|
||||||
|
if (packet instanceof InvalidPacket) {
|
||||||
|
System.err.println("[socket] " + ((InvalidPacket) packet).error);
|
||||||
|
} else if (packet instanceof MessagePacket) {
|
||||||
|
System.out.println("[socket] " + ((MessagePacket) packet).message);
|
||||||
|
} else if (packet instanceof ErrorPacket) {
|
||||||
|
System.err.println("[socket] " + ((ErrorPacket) packet).error);
|
||||||
|
} else if (packet instanceof UnifyResultPacket) {
|
||||||
|
System.out.println("[socket] Received unify result");
|
||||||
|
unifyResultPacket = (UnifyResultPacket) packet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(ServerHandshake handshakedata) {
|
||||||
|
System.out.println("Connected to server with status " + handshakedata.getHttpStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(String message) {
|
||||||
|
// System.out.println("received: " + message);
|
||||||
|
IPacket packet = PacketContainer.deserialize(message);
|
||||||
|
this.handleReceivedPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose(int code, String reason, boolean remote) {
|
||||||
|
System.out.println(
|
||||||
|
"Disconnected from server " +
|
||||||
|
"with code " + code + " " +
|
||||||
|
(reason.isEmpty() ? "" : "and reason " + reason + " ") +
|
||||||
|
"(closed by remote: " + remote + ")"
|
||||||
|
);
|
||||||
|
this.closeLatch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Exception e) {
|
||||||
|
System.out.println("Error: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitUntilClosed() throws InterruptedException {
|
||||||
|
closeLatch.await();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/main/java/de/dhbwstuttgart/server/SocketData.java
Normal file
17
src/main/java/de/dhbwstuttgart/server/SocketData.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package de.dhbwstuttgart.server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The data that is associated server-side with any connected client.
|
||||||
|
* This makes it possible to store information that can be mapped to any existing connection.
|
||||||
|
*/
|
||||||
|
public class SocketData {
|
||||||
|
|
||||||
|
public final String id;
|
||||||
|
// used for the timeout of 10 seconds, until an unused open connection is automatically closed
|
||||||
|
public boolean hasSentTask = false;
|
||||||
|
|
||||||
|
public SocketData(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
138
src/main/java/de/dhbwstuttgart/server/SocketServer.java
Normal file
138
src/main/java/de/dhbwstuttgart/server/SocketServer.java
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
package de.dhbwstuttgart.server;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.MessagePacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.PacketContainer;
|
||||||
|
import de.dhbwstuttgart.server.packet.UnifyRequestPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.UnifyResultPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.TypeInference;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.java_websocket.WebSocket;
|
||||||
|
import org.java_websocket.handshake.ClientHandshake;
|
||||||
|
import org.java_websocket.server.WebSocketServer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class SocketServer extends WebSocketServer {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(SocketServer.class);
|
||||||
|
|
||||||
|
public SocketServer(int port) {
|
||||||
|
super(new InetSocketAddress(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
|
||||||
|
System.out.println("New connection: " + webSocket.getResourceDescriptor());
|
||||||
|
webSocket.setAttachment(new SocketData(UUID.randomUUID().toString()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendMessage(webSocket, "Welcome to the server!");
|
||||||
|
|
||||||
|
// wait 10 seconds for the client to send a task and close the connection, if nothing has been received until then
|
||||||
|
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
Runnable task = () -> {
|
||||||
|
if (webSocket.<SocketData>getAttachment().hasSentTask || !webSocket.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendMessage(webSocket, "No task received after 10 seconds. Closing connection...");
|
||||||
|
webSocket.close();
|
||||||
|
};
|
||||||
|
executor.schedule(task, 10, TimeUnit.SECONDS);
|
||||||
|
executor.shutdown();
|
||||||
|
|
||||||
|
// and finally, when your program wants to exit
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("e: ", e);
|
||||||
|
webSocket.close(1, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose(WebSocket webSocket, int code, String reason, boolean remote) {
|
||||||
|
System.out.println("Connection closed: " + webSocket.getResourceDescriptor());
|
||||||
|
System.out.println(
|
||||||
|
"Disconnected client " + webSocket.getResourceDescriptor() + " " +
|
||||||
|
"with code " + code + " " +
|
||||||
|
(reason.isEmpty() ? "" : "and reason " + reason + " ") +
|
||||||
|
"(closed by client: " + remote + ")"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(WebSocket webSocket, String s) {
|
||||||
|
// System.out.println("Received: " + s.substring(0, 50));
|
||||||
|
IPacket reconstructedPacket = PacketContainer.deserialize(s);
|
||||||
|
this.onPacketReceived(webSocket, reconstructedPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(WebSocket webSocket, Exception e) {
|
||||||
|
webSocket.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
System.out.println("Websocket server started");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A shorthand method for sending informational messages to the client
|
||||||
|
*/
|
||||||
|
public void sendMessage(WebSocket webSocket, String text) {
|
||||||
|
try {
|
||||||
|
MessagePacket message = new MessagePacket();
|
||||||
|
message.message = text;
|
||||||
|
webSocket.send(PacketContainer.serialize(message));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Failed to send message: " + text);
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server-side implementation on how to handle certain packets when received
|
||||||
|
*/
|
||||||
|
private void onPacketReceived(WebSocket webSocket, IPacket packet) {
|
||||||
|
if (packet instanceof UnifyRequestPacket unifyRequestPacket) {
|
||||||
|
|
||||||
|
// TODO: this static property will be a problem once we send more than one request per server and
|
||||||
|
// should be replaced by a dynamic object property
|
||||||
|
PlaceholderType.EXISTING_PLACEHOLDERS.clear();
|
||||||
|
sendMessage(webSocket, "You requested a unify! Please wait until I calculated everything...");
|
||||||
|
System.out.println("Client " + webSocket.<SocketData>getAttachment().id + " requested a unification. Starting now...");
|
||||||
|
webSocket.<SocketData>getAttachment().hasSentTask = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// start the unification algorithm from the received data
|
||||||
|
List<ResultSet> result = TypeInference.executeWithoutContext(
|
||||||
|
unifyRequestPacket.retrieveFiniteClosure(),
|
||||||
|
unifyRequestPacket.retrieveConstraints(),
|
||||||
|
unifyRequestPacket.retrieveUnifyConstraints()
|
||||||
|
);
|
||||||
|
System.out.println("Finished unification for client " + webSocket.<SocketData>getAttachment().id);
|
||||||
|
sendMessage(webSocket, "Unification finished. Found " + result.size() + " result sets");
|
||||||
|
|
||||||
|
if (webSocket.isOpen()) {
|
||||||
|
UnifyResultPacket resultPacket = UnifyResultPacket.create(result);
|
||||||
|
webSocket.send(PacketContainer.serialize(resultPacket));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println(e);
|
||||||
|
log.error("e: ", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
webSocket.close();
|
||||||
|
} else {
|
||||||
|
sendMessage(webSocket, "The package of type " + packet.getClass().getName() + " is not handled by the server!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A packet to send simple error messages between the client and the server
|
||||||
|
*/
|
||||||
|
public class ErrorPacket implements IPacket {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error endpoint for messages from the server, that should be logged out outputted
|
||||||
|
*/
|
||||||
|
public String error;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
18
src/main/java/de/dhbwstuttgart/server/packet/IPacket.java
Normal file
18
src/main/java/de/dhbwstuttgart/server/packet/IPacket.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The shared interface for all packet of the server connection.
|
||||||
|
* A packet must always:
|
||||||
|
* - Have a default / no-parameter constructor
|
||||||
|
* - Have only serializable public properties (or disable them via jackson annotations)
|
||||||
|
* A packet should have, for easy usage and consisteny:
|
||||||
|
* - a static create() method
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IPacket {
|
||||||
|
|
||||||
|
interface IDataContainer<T> {
|
||||||
|
T toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fallback packet that is generated, if the received json could not be mapped to an existing package
|
||||||
|
*/
|
||||||
|
public class InvalidPacket implements IPacket {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If available, the error that caused this package to appear
|
||||||
|
*/
|
||||||
|
public String error = "<unknown error>";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A packet to send simple informational messages between the client and the server
|
||||||
|
*/
|
||||||
|
public class MessagePacket implements IPacket {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The informational message from the server, that should be logged out outputted
|
||||||
|
*/
|
||||||
|
public String message;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper for the packet to ensure correct serialization/deserialization and make it possible to detect the matching
|
||||||
|
* packet type for deserialization.
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class PacketContainer {
|
||||||
|
|
||||||
|
// The jackson serializer / deserializer tool
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The available packet types. The one type that is represented in the JSON should always be the ONLY non-null value.
|
||||||
|
* They have to be private (for the moment) to let jackson fill them in while deserializing
|
||||||
|
*/
|
||||||
|
public ErrorPacket errorPacket = null;
|
||||||
|
public MessagePacket messagePacket = null;
|
||||||
|
public InvalidPacket invalidPacket = null;
|
||||||
|
public UnifyRequestPacket unifyRequestPacket = null;
|
||||||
|
public UnifyResultPacket unifyResultPacket = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the JSON string for the given packet
|
||||||
|
*
|
||||||
|
* @param packet The packet to serialize
|
||||||
|
* @return The json representation of the packet
|
||||||
|
*/
|
||||||
|
public static String serialize(IPacket packet) throws JsonProcessingException {
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
PacketContainer container = new PacketContainer();
|
||||||
|
|
||||||
|
if (packet instanceof ErrorPacket)
|
||||||
|
container.errorPacket = (ErrorPacket) packet;
|
||||||
|
else if (packet instanceof MessagePacket)
|
||||||
|
container.messagePacket = (MessagePacket) packet;
|
||||||
|
else if (packet instanceof UnifyRequestPacket)
|
||||||
|
container.unifyRequestPacket = (UnifyRequestPacket) packet;
|
||||||
|
else if (packet instanceof UnifyResultPacket)
|
||||||
|
container.unifyResultPacket = (UnifyResultPacket) packet;
|
||||||
|
// Add new packets here and in the deserialize method
|
||||||
|
|
||||||
|
return objectMapper.writeValueAsString(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the JSON string to generate the matching packet object
|
||||||
|
*
|
||||||
|
* @param json The serialized representation of a packet container
|
||||||
|
* @return The deserialized Packet object
|
||||||
|
*/
|
||||||
|
public static IPacket deserialize(String json) {
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
|
||||||
|
try {
|
||||||
|
PacketContainer container = objectMapper.readValue(json, PacketContainer.class);
|
||||||
|
|
||||||
|
if (container.errorPacket != null)
|
||||||
|
return container.errorPacket;
|
||||||
|
if (container.messagePacket != null)
|
||||||
|
return container.messagePacket;
|
||||||
|
if (container.invalidPacket != null)
|
||||||
|
return container.invalidPacket;
|
||||||
|
if (container.unifyRequestPacket != null)
|
||||||
|
return container.unifyRequestPacket;
|
||||||
|
if (container.unifyResultPacket != null)
|
||||||
|
return container.unifyResultPacket;
|
||||||
|
// Add new packets here and in the serialize method
|
||||||
|
|
||||||
|
throw new RuntimeException("Cannot map received json to any known packet class");
|
||||||
|
} catch (Exception e) {
|
||||||
|
InvalidPacket packet = new InvalidPacket();
|
||||||
|
packet.error = e.getMessage();
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedPairConstraintSet;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A packet to send all required data for the unification algorithm to the server and request the unification
|
||||||
|
*/
|
||||||
|
public class UnifyRequestPacket implements IPacket {
|
||||||
|
|
||||||
|
public SerializedFiniteClosure finiteClosure;
|
||||||
|
public SerializedPairConstraintSet constraints;
|
||||||
|
public SerializedUnifyConstraintSet unifyConstraints;
|
||||||
|
|
||||||
|
public static UnifyRequestPacket create(
|
||||||
|
IFiniteClosure finiteClosure,
|
||||||
|
ConstraintSet<Pair> constraints,
|
||||||
|
ConstraintSet<UnifyPair> unifyConstraints
|
||||||
|
) {
|
||||||
|
UnifyRequestPacket packet = new UnifyRequestPacket();
|
||||||
|
packet.finiteClosure = SerializedFiniteClosure.create(finiteClosure);
|
||||||
|
packet.constraints = SerializedPairConstraintSet.create(constraints);
|
||||||
|
packet.unifyConstraints = SerializedUnifyConstraintSet.create(unifyConstraints);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public IFiniteClosure retrieveFiniteClosure() {
|
||||||
|
return this.finiteClosure.toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public ConstraintSet<Pair> retrieveConstraints() {
|
||||||
|
return this.constraints.toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public ConstraintSet<UnifyPair> retrieveUnifyConstraints() {
|
||||||
|
return this.unifyConstraints.toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A packet to send all calculated data from the unification algorithm back to the client
|
||||||
|
*/
|
||||||
|
public class UnifyResultPacket implements IPacket {
|
||||||
|
|
||||||
|
public SerializedResultSet[] results;
|
||||||
|
|
||||||
|
public static UnifyResultPacket create(List<ResultSet> resultSets) {
|
||||||
|
UnifyResultPacket serialized = new UnifyResultPacket();
|
||||||
|
serialized.results = resultSets.stream().map(SerializedResultSet::create).toArray(SerializedResultSet[]::new);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public List<ResultSet> getResultSet() {
|
||||||
|
return Arrays.stream(this.results).map(SerializedResultSet::toObject).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see IFiniteClosure
|
||||||
|
*/
|
||||||
|
public class SerializedFiniteClosure implements IPacket.IDataContainer<IFiniteClosure> {
|
||||||
|
public SerializedUnifyPair[] pairs;
|
||||||
|
|
||||||
|
public static SerializedFiniteClosure create(IFiniteClosure finiteClosure) {
|
||||||
|
SerializedFiniteClosure fc = new SerializedFiniteClosure();
|
||||||
|
fc.pairs = finiteClosure.getPairs().stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IFiniteClosure toObject() {
|
||||||
|
return new FiniteClosure(
|
||||||
|
new HashSet<>(Arrays.stream(pairs).map(SerializedUnifyPair::toObject).toList()),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see Pair
|
||||||
|
*/
|
||||||
|
public class SerializedPair implements IPacket.IDataContainer<Pair> {
|
||||||
|
|
||||||
|
@JsonProperty("o")
|
||||||
|
public PairOperator operator;
|
||||||
|
public SerializedTokenWrapper ta1;
|
||||||
|
public SerializedTokenWrapper ta2;
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedPair create(Pair pair) {
|
||||||
|
SerializedPair sPair = new SerializedPair();
|
||||||
|
sPair.operator = pair.GetOperator();
|
||||||
|
sPair.ta1 = SerializedTokenWrapper.create(pair.TA1);
|
||||||
|
sPair.ta2 = SerializedTokenWrapper.create(pair.TA2);
|
||||||
|
return sPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pair toObject() {
|
||||||
|
return new Pair(
|
||||||
|
ta1.toObject(),
|
||||||
|
ta2.toObject(),
|
||||||
|
operator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see Constraint<Pair>
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class SerializedPairConstraint implements IPacket.IDataContainer<Constraint<Pair>> {
|
||||||
|
|
||||||
|
// serialize recursive structure
|
||||||
|
public static final HashMap<Constraint<Pair>, String> UNIQUE_CONSTRAINT_KEY_MAP = new HashMap<>();
|
||||||
|
public static final HashMap<String, SerializedPairConstraint> UNIQUE_CONSTRAINT_MAP = new HashMap<>();
|
||||||
|
// deserialize recursive structure
|
||||||
|
private static final HashMap<String, Constraint<Pair>> UNIQUE_OBJECT_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
@JsonProperty("i")
|
||||||
|
public boolean isInherited;
|
||||||
|
@JsonProperty("u")
|
||||||
|
public String uniqueKey;
|
||||||
|
@JsonProperty("e")
|
||||||
|
public String extendedConstraint = null;
|
||||||
|
@JsonProperty("m")
|
||||||
|
public SerializedPair[] methodSignatureConstraint;
|
||||||
|
@JsonProperty("c")
|
||||||
|
public SerializedPair[] constraintElements;
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedPairConstraint create(Constraint<Pair> constraint) {
|
||||||
|
final String uniqueKey = UNIQUE_CONSTRAINT_KEY_MAP.getOrDefault(constraint, "_" + UNIQUE_CONSTRAINT_MAP.size());
|
||||||
|
|
||||||
|
if (UNIQUE_CONSTRAINT_MAP.containsKey(uniqueKey)) {
|
||||||
|
return UNIQUE_CONSTRAINT_MAP.get(uniqueKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
SerializedPairConstraint pairConstraint = new SerializedPairConstraint();
|
||||||
|
pairConstraint.uniqueKey = uniqueKey;
|
||||||
|
UNIQUE_CONSTRAINT_KEY_MAP.put(constraint, uniqueKey);
|
||||||
|
UNIQUE_CONSTRAINT_MAP.put(uniqueKey, pairConstraint);
|
||||||
|
|
||||||
|
pairConstraint.constraintElements = constraint.stream().map(SerializedPair::create).toArray(SerializedPair[]::new);
|
||||||
|
pairConstraint.isInherited = constraint.isInherited();
|
||||||
|
pairConstraint.methodSignatureConstraint = constraint.getmethodSignatureConstraint().stream().map(SerializedPair::create).toArray(SerializedPair[]::new);
|
||||||
|
if (constraint.getExtendConstraint() != null) {
|
||||||
|
pairConstraint.extendedConstraint = SerializedPairConstraint.create(constraint.getExtendConstraint()).uniqueKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pairConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Constraint<Pair> toObject() {
|
||||||
|
if (UNIQUE_OBJECT_MAP.containsKey(uniqueKey)) {
|
||||||
|
return UNIQUE_OBJECT_MAP.get(uniqueKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
Constraint<Pair> constraint = new Constraint<>();
|
||||||
|
UNIQUE_OBJECT_MAP.put(uniqueKey, constraint);
|
||||||
|
|
||||||
|
constraint.addAll(Arrays.stream(constraintElements).map(SerializedPair::toObject).toList());
|
||||||
|
constraint.setIsInherited(isInherited);
|
||||||
|
constraint.setmethodSignatureConstraint(new HashSet<>(
|
||||||
|
Arrays.stream(methodSignatureConstraint).map(SerializedPair::toObject).toList()
|
||||||
|
));
|
||||||
|
SerializedPairConstraint extendedConstraint = this.extendedConstraint == null ? null :
|
||||||
|
SerializedPairConstraint.UNIQUE_CONSTRAINT_MAP.get(this.extendedConstraint);
|
||||||
|
if (extendedConstraint != null) {
|
||||||
|
constraint.setExtendConstraint(extendedConstraint.toObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
return constraint;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ConstraintSet<Pair>
|
||||||
|
*/
|
||||||
|
public class SerializedPairConstraintSet implements IPacket.IDataContainer<ConstraintSet<Pair>> {
|
||||||
|
|
||||||
|
public SerializedPair[] undConstraints;
|
||||||
|
public SerializedPairConstraint[][] oderConstraints;
|
||||||
|
public Map<String, SerializedPairConstraint> uniqueConstraintMap = new HashMap<>();
|
||||||
|
|
||||||
|
public static SerializedPairConstraintSet create(ConstraintSet<Pair> constraints) {
|
||||||
|
SerializedPairConstraintSet constraintSet = new SerializedPairConstraintSet();
|
||||||
|
|
||||||
|
constraintSet.undConstraints = constraints.getUndConstraints().stream().map(SerializedPair::create).toArray(SerializedPair[]::new);
|
||||||
|
constraintSet.oderConstraints = constraints.getOderConstraints().stream().map(consSet ->
|
||||||
|
consSet.stream().map(SerializedPairConstraint::create).toArray(SerializedPairConstraint[]::new)
|
||||||
|
).toArray(SerializedPairConstraint[][]::new);
|
||||||
|
|
||||||
|
// add all the gathered constraints to a serializable property
|
||||||
|
constraintSet.uniqueConstraintMap.putAll(SerializedPairConstraint.UNIQUE_CONSTRAINT_MAP);
|
||||||
|
|
||||||
|
return constraintSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstraintSet<Pair> toObject() {
|
||||||
|
ConstraintSet<Pair> consSet = new ConstraintSet<>();
|
||||||
|
|
||||||
|
// read all the constraints from the serializable property
|
||||||
|
SerializedPairConstraint.UNIQUE_CONSTRAINT_MAP.putAll(this.uniqueConstraintMap);
|
||||||
|
|
||||||
|
Constraint<Pair> undCons = new Constraint<>();
|
||||||
|
undCons.addAll(Arrays.stream(undConstraints).map(SerializedPair::toObject).toList());
|
||||||
|
consSet.addAllUndConstraint(undCons);
|
||||||
|
|
||||||
|
List<Set<Constraint<Pair>>> oderCons = new ArrayList<>(Arrays.stream(oderConstraints).map(cons ->
|
||||||
|
new HashSet<>(
|
||||||
|
Arrays.stream(cons).map(SerializedPairConstraint::toObject).toList()
|
||||||
|
)
|
||||||
|
).toList());
|
||||||
|
consSet.addAllOderConstraint(oderCons);
|
||||||
|
|
||||||
|
return consSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairNoResult;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairTPHEqualTPH;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairTPHequalRefTypeOrWildcardType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairTPHsmallerTPH;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairNoResult;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ResultPair
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class SerializedResultPairWrapper implements IPacket.IDataContainer<ResultPair<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric>> {
|
||||||
|
|
||||||
|
@JsonProperty("nr")
|
||||||
|
public SerializedPairNoResult noResult = null;
|
||||||
|
@JsonProperty("teo")
|
||||||
|
public SerializedPairTPHequalRefTypeOrWildcardType tphEqualOther = null;
|
||||||
|
@JsonProperty("tet")
|
||||||
|
public SerializedPairTPHEqualTPH tphEqualTph = null;
|
||||||
|
@JsonProperty("tst")
|
||||||
|
public SerializedPairTPHsmallerTPH tphSmallerTPH = null;
|
||||||
|
|
||||||
|
|
||||||
|
public static <A extends RefTypeOrTPHOrWildcardOrGeneric, B extends RefTypeOrTPHOrWildcardOrGeneric> SerializedResultPairWrapper create(ResultPair<A, B> pair) {
|
||||||
|
SerializedResultPairWrapper serialized = new SerializedResultPairWrapper();
|
||||||
|
|
||||||
|
if (pair instanceof PairNoResult noResult)
|
||||||
|
serialized.noResult = SerializedPairNoResult.create(noResult);
|
||||||
|
else if (pair instanceof PairTPHequalRefTypeOrWildcardType tphEqualOther)
|
||||||
|
serialized.tphEqualOther = SerializedPairTPHequalRefTypeOrWildcardType.create(tphEqualOther);
|
||||||
|
else if (pair instanceof PairTPHEqualTPH tphEqualTph)
|
||||||
|
serialized.tphEqualTph = SerializedPairTPHEqualTPH.create(tphEqualTph);
|
||||||
|
else if (pair instanceof PairTPHsmallerTPH tphSmallerTPH)
|
||||||
|
serialized.tphSmallerTPH = SerializedPairTPHsmallerTPH.create(tphSmallerTPH);
|
||||||
|
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes") // this is not optimal, but we have to conform to interface specifications
|
||||||
|
public ResultPair toObject() {
|
||||||
|
if (noResult != null)
|
||||||
|
return noResult.toObject();
|
||||||
|
else if (tphEqualOther != null)
|
||||||
|
return tphEqualOther.toObject();
|
||||||
|
else if (tphEqualTph != null)
|
||||||
|
return tphEqualTph.toObject();
|
||||||
|
else if (tphSmallerTPH != null)
|
||||||
|
return tphSmallerTPH.toObject();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ResultSet
|
||||||
|
*/
|
||||||
|
public class SerializedResultSet implements IPacket.IDataContainer<ResultSet> {
|
||||||
|
|
||||||
|
public SerializedResultPairWrapper[] results;
|
||||||
|
|
||||||
|
public static SerializedResultSet create(ResultSet resultSet) {
|
||||||
|
SerializedResultSet serialized = new SerializedResultSet();
|
||||||
|
serialized.results = resultSet.results.stream().map(SerializedResultPairWrapper::create).toArray(SerializedResultPairWrapper[]::new);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet toObject() {
|
||||||
|
return new ResultSet(
|
||||||
|
new HashSet<>(
|
||||||
|
Arrays.stream(this.results).map(SerializedResultPairWrapper::toObject).toList()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedExtendsWildcardType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedGenericRefType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedRefType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedSuperWildcardType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedVoidType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see RefTypeOrTPHOrWildcardOrGeneric
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class SerializedTokenWrapper implements IPacket.IDataContainer<RefTypeOrTPHOrWildcardOrGeneric> {
|
||||||
|
|
||||||
|
@JsonProperty("ew")
|
||||||
|
public SerializedExtendsWildcardType extendsWildcardType = null;
|
||||||
|
@JsonProperty("gr")
|
||||||
|
public SerializedGenericRefType genericRefType = null;
|
||||||
|
@JsonProperty("p")
|
||||||
|
public SerializedPlaceholderType placeholderType = null;
|
||||||
|
@JsonProperty("r")
|
||||||
|
public SerializedRefType refType = null;
|
||||||
|
@JsonProperty("sw")
|
||||||
|
public SerializedSuperWildcardType superWildcardType = null;
|
||||||
|
@JsonProperty("v")
|
||||||
|
public SerializedVoidType voidType = null;
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedTokenWrapper create(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
|
SerializedTokenWrapper wrapper = new SerializedTokenWrapper();
|
||||||
|
|
||||||
|
if (type instanceof ExtendsWildcardType)
|
||||||
|
wrapper.extendsWildcardType = SerializedExtendsWildcardType.create((ExtendsWildcardType) type);
|
||||||
|
else if (type instanceof GenericRefType)
|
||||||
|
wrapper.genericRefType = SerializedGenericRefType.create((GenericRefType) type);
|
||||||
|
else if (type instanceof TypePlaceholder)
|
||||||
|
wrapper.placeholderType = SerializedPlaceholderType.create((TypePlaceholder) type);
|
||||||
|
else if (type instanceof Void)
|
||||||
|
wrapper.voidType = SerializedVoidType.create((Void) type);
|
||||||
|
else if (type instanceof RefType)
|
||||||
|
wrapper.refType = SerializedRefType.create((RefType) type);
|
||||||
|
else if (type instanceof SuperWildcardType)
|
||||||
|
wrapper.superWildcardType = SerializedSuperWildcardType.create((SuperWildcardType) type);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric toObject() {
|
||||||
|
if (extendsWildcardType != null) return extendsWildcardType.toObject();
|
||||||
|
if (genericRefType != null) return genericRefType.toObject();
|
||||||
|
if (placeholderType != null) return placeholderType.toObject();
|
||||||
|
if (refType != null) return refType.toObject();
|
||||||
|
if (superWildcardType != null) return superWildcardType.toObject();
|
||||||
|
if (voidType != null) return voidType.toObject();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ConstraintSet<UnifyPair>
|
||||||
|
*/
|
||||||
|
public class SerializedUnifyConstraintSet implements IPacket.IDataContainer<ConstraintSet<UnifyPair>> {
|
||||||
|
|
||||||
|
public SerializedUnifyPair[] undConstraints;
|
||||||
|
public SerializedUnifyPairConstraint[][] oderConstraints;
|
||||||
|
|
||||||
|
public static SerializedUnifyConstraintSet create(ConstraintSet<UnifyPair> unifyCons) {
|
||||||
|
SerializedUnifyConstraintSet constraintSet = new SerializedUnifyConstraintSet();
|
||||||
|
constraintSet.undConstraints = unifyCons.getUndConstraints().stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||||
|
constraintSet.oderConstraints = unifyCons.getOderConstraints().stream().map(constraints ->
|
||||||
|
constraints.stream().map(SerializedUnifyPairConstraint::create).toArray(SerializedUnifyPairConstraint[]::new)
|
||||||
|
).toArray(SerializedUnifyPairConstraint[][]::new);
|
||||||
|
return constraintSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstraintSet<UnifyPair> toObject() {
|
||||||
|
ConstraintSet<UnifyPair> consSet = new ConstraintSet<>();
|
||||||
|
|
||||||
|
Constraint<UnifyPair> undCons = new Constraint<>();
|
||||||
|
undCons.addAll(Arrays.stream(undConstraints).map(SerializedUnifyPair::toObject).toList());
|
||||||
|
consSet.addAllUndConstraint(undCons);
|
||||||
|
|
||||||
|
List<Set<Constraint<UnifyPair>>> oderCons = new ArrayList<>(Arrays.stream(oderConstraints).map(oderConsSet ->
|
||||||
|
new HashSet<>(
|
||||||
|
Arrays.stream(oderConsSet).map(SerializedUnifyPairConstraint::toObject).toList()
|
||||||
|
)
|
||||||
|
).toList());
|
||||||
|
consSet.addAllOderConstraint(oderCons);
|
||||||
|
|
||||||
|
return consSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see UnifyPair
|
||||||
|
*/
|
||||||
|
public class SerializedUnifyPair implements IPacket.IDataContainer<UnifyPair> {
|
||||||
|
|
||||||
|
public SerializedUnifyTypeWrapper lhs;
|
||||||
|
public SerializedUnifyTypeWrapper rhs;
|
||||||
|
@JsonProperty("o")
|
||||||
|
public PairOperator operator;
|
||||||
|
|
||||||
|
public static SerializedUnifyPair create(UnifyPair unifyPair) {
|
||||||
|
SerializedUnifyPair pair = new SerializedUnifyPair();
|
||||||
|
pair.lhs = SerializedUnifyTypeWrapper.create(unifyPair.getLhsType());
|
||||||
|
pair.rhs = SerializedUnifyTypeWrapper.create(unifyPair.getRhsType());
|
||||||
|
pair.operator = unifyPair.getPairOp();
|
||||||
|
return pair;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnifyPair toObject() {
|
||||||
|
return new UnifyPair(lhs.toObject(), rhs.toObject(), operator);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see Constraint<UnifyPair>
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class SerializedUnifyPairConstraint implements IPacket.IDataContainer<Constraint<UnifyPair>> {
|
||||||
|
|
||||||
|
@JsonProperty("i")
|
||||||
|
public boolean isInherited;
|
||||||
|
@JsonProperty("ec")
|
||||||
|
public SerializedUnifyPairConstraint extendedConstraint = null;
|
||||||
|
@JsonProperty("p")
|
||||||
|
public SerializedUnifyPair[] methodSignatureConstraints;
|
||||||
|
@JsonProperty("c")
|
||||||
|
public SerializedUnifyPair[] constraintElements;
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedUnifyPairConstraint create(Constraint<UnifyPair> constraint) {
|
||||||
|
SerializedUnifyPairConstraint cons = new SerializedUnifyPairConstraint();
|
||||||
|
cons.constraintElements = constraint.stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||||
|
cons.isInherited = constraint.isInherited();
|
||||||
|
if (constraint.getExtendConstraint() != null) {
|
||||||
|
cons.extendedConstraint = SerializedUnifyPairConstraint.create(constraint.getExtendConstraint());
|
||||||
|
}
|
||||||
|
cons.methodSignatureConstraints = constraint.getmethodSignatureConstraint().stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||||
|
return cons;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Constraint<UnifyPair> toObject() {
|
||||||
|
Constraint<UnifyPair> cons = new Constraint<>();
|
||||||
|
|
||||||
|
cons.addAll(Arrays.stream(constraintElements).map(SerializedUnifyPair::toObject).toList());
|
||||||
|
cons.setIsInherited(isInherited);
|
||||||
|
if (extendedConstraint != null) {
|
||||||
|
cons.setExtendConstraint(extendedConstraint.toObject());
|
||||||
|
}
|
||||||
|
cons.setmethodSignatureConstraint(new HashSet<>(Arrays.stream(methodSignatureConstraints).map(SerializedUnifyPair::toObject).toList()));
|
||||||
|
return cons;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.unifyType.SerializedExtendsType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.unifyType.SerializedFunNType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.unifyType.SerializedPlaceholderType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.unifyType.SerializedReferenceType;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.unifyType.SerializedSuperType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see UnifyType
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class SerializedUnifyTypeWrapper implements IPacket.IDataContainer<UnifyType> {
|
||||||
|
|
||||||
|
@JsonProperty("e")
|
||||||
|
public SerializedExtendsType extendsType = null;
|
||||||
|
@JsonProperty("s")
|
||||||
|
public SerializedSuperType superType = null;
|
||||||
|
@JsonProperty("r")
|
||||||
|
public SerializedReferenceType referenceType = null;
|
||||||
|
@JsonProperty("f")
|
||||||
|
public SerializedFunNType funNType = null;
|
||||||
|
@JsonProperty("p")
|
||||||
|
public SerializedPlaceholderType placeholderType = null;
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedUnifyTypeWrapper create(UnifyType unifyType) {
|
||||||
|
SerializedUnifyTypeWrapper wrapper = new SerializedUnifyTypeWrapper();
|
||||||
|
|
||||||
|
if (unifyType instanceof ExtendsType)
|
||||||
|
wrapper.extendsType = SerializedExtendsType.create((ExtendsType) unifyType);
|
||||||
|
else if (unifyType instanceof SuperType)
|
||||||
|
wrapper.superType = SerializedSuperType.create((SuperType) unifyType);
|
||||||
|
else if (unifyType instanceof ReferenceType)
|
||||||
|
wrapper.referenceType = SerializedReferenceType.create((ReferenceType) unifyType);
|
||||||
|
else if (unifyType instanceof FunNType)
|
||||||
|
wrapper.funNType = SerializedFunNType.create((FunNType) unifyType);
|
||||||
|
else if (unifyType instanceof PlaceholderType)
|
||||||
|
wrapper.placeholderType = SerializedPlaceholderType.create((PlaceholderType) unifyType);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnifyType toObject() {
|
||||||
|
if (extendsType != null) return extendsType.toObject();
|
||||||
|
if (superType != null) return superType.toObject();
|
||||||
|
if (referenceType != null) return referenceType.toObject();
|
||||||
|
if (funNType != null) return funNType.toObject();
|
||||||
|
if (placeholderType != null) return placeholderType.toObject();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairNoResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see PairNoResult
|
||||||
|
*/
|
||||||
|
public class SerializedPairNoResult implements IPacket.IDataContainer<PairNoResult> {
|
||||||
|
|
||||||
|
@JsonProperty("l")
|
||||||
|
public SerializedTokenWrapper left;
|
||||||
|
@JsonProperty("r")
|
||||||
|
public SerializedTokenWrapper right;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a static create method to leave the default constructor and simplify list conversions
|
||||||
|
*/
|
||||||
|
public static SerializedPairNoResult create(PairNoResult pair) {
|
||||||
|
SerializedPairNoResult serialized = new SerializedPairNoResult();
|
||||||
|
serialized.left = SerializedTokenWrapper.create(pair.getLeft());
|
||||||
|
serialized.right = SerializedTokenWrapper.create(pair.getRight());
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PairNoResult toObject() {
|
||||||
|
return new PairNoResult(
|
||||||
|
left.toObject(),
|
||||||
|
right.toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see PairTPHEqualTPH
|
||||||
|
*/
|
||||||
|
public class SerializedPairTPHEqualTPH implements IPacket.IDataContainer<PairTPHEqualTPH> {
|
||||||
|
|
||||||
|
@JsonProperty("l")
|
||||||
|
public SerializedPlaceholderType left;
|
||||||
|
@JsonProperty("r")
|
||||||
|
public SerializedPlaceholderType right;
|
||||||
|
|
||||||
|
public static SerializedPairTPHEqualTPH create(PairTPHEqualTPH pair) {
|
||||||
|
SerializedPairTPHEqualTPH serialized = new SerializedPairTPHEqualTPH();
|
||||||
|
serialized.left = SerializedPlaceholderType.create(pair.getLeft());
|
||||||
|
serialized.right = SerializedPlaceholderType.create(pair.getRight());
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PairTPHEqualTPH toObject() {
|
||||||
|
return new PairTPHEqualTPH(
|
||||||
|
left.toObject(),
|
||||||
|
right.toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see PairTPHequalRefTypeOrWildcardType
|
||||||
|
*/
|
||||||
|
public class SerializedPairTPHequalRefTypeOrWildcardType implements IPacket.IDataContainer<PairTPHequalRefTypeOrWildcardType> {
|
||||||
|
|
||||||
|
@JsonProperty("l")
|
||||||
|
public SerializedPlaceholderType left;
|
||||||
|
@JsonProperty("r")
|
||||||
|
public SerializedTokenWrapper right;
|
||||||
|
|
||||||
|
public static SerializedPairTPHequalRefTypeOrWildcardType create(PairTPHequalRefTypeOrWildcardType pair) {
|
||||||
|
SerializedPairTPHequalRefTypeOrWildcardType serialized = new SerializedPairTPHequalRefTypeOrWildcardType();
|
||||||
|
serialized.left = SerializedPlaceholderType.create(pair.left);
|
||||||
|
serialized.right = SerializedTokenWrapper.create(pair.right);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PairTPHequalRefTypeOrWildcardType toObject() {
|
||||||
|
return new PairTPHequalRefTypeOrWildcardType(
|
||||||
|
left.toObject(),
|
||||||
|
right.toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see PairTPHsmallerTPH
|
||||||
|
*/
|
||||||
|
public class SerializedPairTPHsmallerTPH implements IPacket.IDataContainer<PairTPHsmallerTPH> {
|
||||||
|
|
||||||
|
@JsonProperty("l")
|
||||||
|
public SerializedPlaceholderType left;
|
||||||
|
@JsonProperty("r")
|
||||||
|
public SerializedPlaceholderType right;
|
||||||
|
|
||||||
|
public static SerializedPairTPHsmallerTPH create(PairTPHsmallerTPH pair) {
|
||||||
|
SerializedPairTPHsmallerTPH serialized = new SerializedPairTPHsmallerTPH();
|
||||||
|
serialized.left = SerializedPlaceholderType.create(pair.left);
|
||||||
|
serialized.right = SerializedPlaceholderType.create(pair.right);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PairTPHsmallerTPH toObject() {
|
||||||
|
return new PairTPHsmallerTPH(
|
||||||
|
left.toObject(),
|
||||||
|
right.toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ExtendsWildcardType
|
||||||
|
*/
|
||||||
|
public class SerializedExtendsWildcardType implements IPacket.IDataContainer<ExtendsWildcardType> {
|
||||||
|
|
||||||
|
@JsonProperty("e")
|
||||||
|
public SerializedTokenWrapper extendsType;
|
||||||
|
|
||||||
|
public static SerializedExtendsWildcardType create(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
SerializedExtendsWildcardType type = new SerializedExtendsWildcardType();
|
||||||
|
type.extendsType = SerializedTokenWrapper.create(extendsWildcardType.getInnerType());
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendsWildcardType toObject() {
|
||||||
|
return new ExtendsWildcardType(extendsType.toObject(), new NullToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see GenericRefType
|
||||||
|
*/
|
||||||
|
public class SerializedGenericRefType implements IPacket.IDataContainer<GenericRefType> {
|
||||||
|
|
||||||
|
@JsonProperty("n")
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
public static SerializedGenericRefType create(GenericRefType genericRefType) {
|
||||||
|
SerializedGenericRefType serialized = new SerializedGenericRefType();
|
||||||
|
serialized.name = genericRefType.getParsedName();
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GenericRefType toObject() {
|
||||||
|
return new GenericRefType(name, new NullToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see TypePlaceholder
|
||||||
|
*/
|
||||||
|
public class SerializedPlaceholderType implements IPacket.IDataContainer<TypePlaceholder> {
|
||||||
|
|
||||||
|
@JsonProperty("n")
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
public static SerializedPlaceholderType create(TypePlaceholder typePlaceholder) {
|
||||||
|
SerializedPlaceholderType serialized = new SerializedPlaceholderType();
|
||||||
|
serialized.name = typePlaceholder.getName();
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypePlaceholder toObject() {
|
||||||
|
return (TypePlaceholder) TypePlaceholder.of(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see RefType
|
||||||
|
*/
|
||||||
|
public class SerializedRefType implements IPacket.IDataContainer<RefType> {
|
||||||
|
|
||||||
|
@JsonProperty("n")
|
||||||
|
public String name;
|
||||||
|
@JsonProperty("p")
|
||||||
|
public SerializedTokenWrapper[] parameters;
|
||||||
|
|
||||||
|
public static SerializedRefType create(RefType refType) {
|
||||||
|
SerializedRefType serialized = new SerializedRefType();
|
||||||
|
|
||||||
|
serialized.name = refType.getName().toString();
|
||||||
|
serialized.parameters = refType.getParaList().stream().map(SerializedTokenWrapper::create).toArray(SerializedTokenWrapper[]::new);
|
||||||
|
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefType toObject() {
|
||||||
|
return new RefType(
|
||||||
|
new JavaClassName(name),
|
||||||
|
Arrays.stream(parameters).map(SerializedTokenWrapper::toObject).toList(),
|
||||||
|
new NullToken()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see SuperWildcardType
|
||||||
|
*/
|
||||||
|
public class SerializedSuperWildcardType implements IPacket.IDataContainer<SuperWildcardType> {
|
||||||
|
|
||||||
|
@JsonProperty("s")
|
||||||
|
public SerializedTokenWrapper superType;
|
||||||
|
|
||||||
|
public static SerializedSuperWildcardType create(SuperWildcardType superWildcardType) {
|
||||||
|
SerializedSuperWildcardType type = new SerializedSuperWildcardType();
|
||||||
|
type.superType = SerializedTokenWrapper.create(superWildcardType.getInnerType());
|
||||||
|
type.superType = SerializedTokenWrapper.create(superWildcardType.getInnerType());
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SuperWildcardType toObject() {
|
||||||
|
return new SuperWildcardType(superType.toObject(), new NullToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see Void
|
||||||
|
*/
|
||||||
|
public class SerializedVoidType implements IPacket.IDataContainer<Void> {
|
||||||
|
|
||||||
|
public int i = 0;
|
||||||
|
|
||||||
|
public static SerializedVoidType create(Void voidType) {
|
||||||
|
return new SerializedVoidType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void toObject() {
|
||||||
|
return new Void(new NullToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ExtendsType
|
||||||
|
*/
|
||||||
|
public class SerializedExtendsType extends SerializedWildcardType implements IPacket.IDataContainer<ExtendsType> {
|
||||||
|
|
||||||
|
public static SerializedExtendsType create(ExtendsType extendsType) {
|
||||||
|
SerializedExtendsType type = new SerializedExtendsType();
|
||||||
|
type.readWildcardTypeValues(extendsType);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendsType toObject() {
|
||||||
|
return new ExtendsType(
|
||||||
|
this.wildcardedType.toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see FunNType
|
||||||
|
*/
|
||||||
|
public class SerializedFunNType extends SerializedUnifyType implements IPacket.IDataContainer<FunNType> {
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedFunNType create(FunNType funN) {
|
||||||
|
SerializedFunNType type = new SerializedFunNType();
|
||||||
|
type.readUnifyTypeValues(funN);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunNType toObject() {
|
||||||
|
return FunNType.getFunNType(
|
||||||
|
new TypeParams(
|
||||||
|
Arrays.stream(this.params).map(SerializedUnifyTypeWrapper::toObject).toList()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see PlaceholderType
|
||||||
|
*/
|
||||||
|
public class SerializedPlaceholderType extends SerializedUnifyType implements IPacket.IDataContainer<PlaceholderType> {
|
||||||
|
|
||||||
|
public boolean isGenerated;
|
||||||
|
public boolean isInnerType;
|
||||||
|
public int variance;
|
||||||
|
public byte orCons;
|
||||||
|
|
||||||
|
|
||||||
|
public static SerializedPlaceholderType create(PlaceholderType placeholder) {
|
||||||
|
SerializedPlaceholderType type = new SerializedPlaceholderType();
|
||||||
|
type.readUnifyTypeValues(placeholder);
|
||||||
|
type.isGenerated = placeholder.isGenerated();
|
||||||
|
type.isInnerType = placeholder.isInnerType();
|
||||||
|
type.variance = placeholder.getVariance();
|
||||||
|
type.orCons = placeholder.getOrCons();
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlaceholderType toObject() {
|
||||||
|
PlaceholderType placeholderType = new PlaceholderType(this.name, this.isGenerated);
|
||||||
|
placeholderType.setInnerType(this.isInnerType);
|
||||||
|
placeholderType.setVariance(this.variance);
|
||||||
|
placeholderType.setOrCons(this.orCons);
|
||||||
|
return placeholderType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see ReferenceType
|
||||||
|
*/
|
||||||
|
public class SerializedReferenceType extends SerializedUnifyType implements IPacket.IDataContainer<ReferenceType> {
|
||||||
|
|
||||||
|
@JsonProperty("gt")
|
||||||
|
public boolean genericTypeVar;
|
||||||
|
|
||||||
|
public static SerializedReferenceType create(ReferenceType referenceType) {
|
||||||
|
SerializedReferenceType type = new SerializedReferenceType();
|
||||||
|
type.readUnifyTypeValues(referenceType);
|
||||||
|
type.genericTypeVar = referenceType.isGenTypeVar();
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReferenceType toObject() {
|
||||||
|
ReferenceType referenceType = new ReferenceType(this.name, this.genericTypeVar);
|
||||||
|
return (ReferenceType) referenceType.setTypeParams(
|
||||||
|
new TypeParams(
|
||||||
|
Arrays.stream(this.params).map(SerializedUnifyTypeWrapper::toObject).toList()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable container of
|
||||||
|
*
|
||||||
|
* @see SuperType
|
||||||
|
*/
|
||||||
|
public class SerializedSuperType extends SerializedWildcardType implements IPacket.IDataContainer<SuperType> {
|
||||||
|
|
||||||
|
public static SerializedSuperType create(SuperType superType) {
|
||||||
|
SerializedSuperType type = new SerializedSuperType();
|
||||||
|
type.readWildcardTypeValues(superType);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SuperType toObject() {
|
||||||
|
return new SuperType(
|
||||||
|
this.wildcardedType.toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable abstract container of
|
||||||
|
*
|
||||||
|
* @see UnifyType
|
||||||
|
*/
|
||||||
|
abstract class SerializedUnifyType {
|
||||||
|
|
||||||
|
@JsonProperty("n")
|
||||||
|
public String name;
|
||||||
|
@JsonProperty("p")
|
||||||
|
public SerializedUnifyTypeWrapper[] params = new SerializedUnifyTypeWrapper[]{};
|
||||||
|
|
||||||
|
public void readUnifyTypeValues(UnifyType unifyType) {
|
||||||
|
name = unifyType.getName();
|
||||||
|
params = Arrays.stream(unifyType.getTypeParams().get()).map(SerializedUnifyTypeWrapper::create).toArray(SerializedUnifyTypeWrapper[]::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable abstract container of
|
||||||
|
*
|
||||||
|
* @see WildcardType
|
||||||
|
*/
|
||||||
|
abstract class SerializedWildcardType extends SerializedUnifyType {
|
||||||
|
|
||||||
|
public SerializedUnifyTypeWrapper wildcardedType;
|
||||||
|
|
||||||
|
public void readWildcardTypeValues(WildcardType wildcardType) {
|
||||||
|
this.readUnifyTypeValues(wildcardType);
|
||||||
|
wildcardedType = SerializedUnifyTypeWrapper.create(wildcardType.getWildcardedType());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -349,4 +349,4 @@ public abstract class AbstractASTWalker implements ASTVisitor {
|
|||||||
ternary.iftrue.accept(this);
|
ternary.iftrue.accept(this);
|
||||||
ternary.iffalse.accept(this);
|
ternary.iffalse.accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,12 +6,10 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.target.tree.TargetGeneric;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
@@ -33,7 +31,6 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
private List<RefType> implementedInterfaces;
|
private List<RefType> implementedInterfaces;
|
||||||
private List<RefType> permittedSubtypes;
|
private List<RefType> permittedSubtypes;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
private Set<GenericTypeVar> userDefinedGenerics;
|
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
||||||
super(offset);
|
super(offset);
|
||||||
@@ -202,22 +199,4 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(name);
|
return Objects.hash(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<GenericTypeVar> getUserDefinedGenerics() {
|
|
||||||
if (this.userDefinedGenerics != null) return this.userDefinedGenerics;
|
|
||||||
|
|
||||||
var genericsIter = getGenerics().iterator();
|
|
||||||
if (genericsIter.hasNext()) {
|
|
||||||
// Add empty set of generics to cache so that it doesn't try to calculate it later
|
|
||||||
this.userDefinedGenerics = new HashSet<>();
|
|
||||||
while (genericsIter.hasNext()) {
|
|
||||||
var next = genericsIter.next();
|
|
||||||
userDefinedGenerics.add(next);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.userDefinedGenerics = new HashSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.userDefinedGenerics;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import de.dhbwstuttgart.parser.NullToken;
|
|||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung
|
* Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung
|
||||||
@@ -25,4 +24,4 @@ public class FieldDeclaration extends Field{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -3,17 +3,14 @@ package de.dhbwstuttgart.syntaxtree;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
|
||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
|
||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPEStmt;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
import java.util.ArrayList;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt eine Methode dar. Problem: Parser kann nicht zwischen Methode und
|
* Stellt eine Methode dar. Problem: Parser kann nicht zwischen Methode und
|
||||||
@@ -34,7 +31,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
public final Boolean isInherited;
|
public final Boolean isInherited;
|
||||||
public final Boolean isImplemented;
|
public final Boolean isImplemented;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* its Constraints
|
* its Constraints
|
||||||
* eingefuegt PL 2021-02-15
|
* eingefuegt PL 2021-02-15
|
||||||
@@ -110,10 +107,10 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(name, parameterlist, returnType);
|
return Objects.hash(name, parameterlist, returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import java.util.*;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import java.util.ArrayList;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import java.util.HashSet;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
//import sun.security.x509.X509CertInfo;
|
//import sun.security.x509.X509CertInfo;
|
||||||
|
|
||||||
public class SourceFile extends SyntaxTreeNode {
|
public class SourceFile extends SyntaxTreeNode {
|
||||||
@@ -20,7 +21,6 @@ public class SourceFile extends SyntaxTreeNode {
|
|||||||
private boolean isGenerated;
|
private boolean isGenerated;
|
||||||
|
|
||||||
public List<ClassOrInterface> availableClasses = new ArrayList<>();
|
public List<ClassOrInterface> availableClasses = new ArrayList<>();
|
||||||
public List<ASTToTargetAST.Generics> generics = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
||||||
@@ -43,10 +43,6 @@ public class SourceFile extends SyntaxTreeNode {
|
|||||||
this.imports = new HashSet<>(sf.imports);
|
this.imports = new HashSet<>(sf.imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addResultSet(ResultSet rs) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPackageName(String packageName) {
|
public void setPackageName(String packageName) {
|
||||||
this.pkgName = packageName;
|
this.pkgName = packageName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
//import org.antlr.v4.runtime.misc.Pair;
|
//import org.antlr.v4.runtime.misc.Pair;
|
||||||
|
|
||||||
@@ -20,4 +16,4 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void accept(ASTVisitor visitor);
|
public abstract void accept(ASTVisitor visitor);
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,9 @@ package de.dhbwstuttgart.syntaxtree;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
|
|
||||||
public interface TypeScope {
|
public interface TypeScope {
|
||||||
Iterable<? extends GenericTypeVar> getGenerics();
|
Iterable<? extends GenericTypeVar> getGenerics();
|
||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric getReturnType();
|
RefTypeOrTPHOrWildcardOrGeneric getReturnType();
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,10 @@ import org.objectweb.asm.*;
|
|||||||
import org.objectweb.asm.signature.SignatureReader;
|
import org.objectweb.asm.signature.SignatureReader;
|
||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anmerkung: Die ASTFactory Methoden, welche ASTBäume aus java.lang.Class Objekten generieren, können davon ausgehen, dass alle Imports und Typnamen korrekt sind und müssen diese nicht überprüfen.
|
* Anmerkung: Die ASTFactory Methoden, welche ASTBäume aus java.lang.Class Objekten generieren, können davon ausgehen, dass alle Imports und Typnamen korrekt sind und müssen diese nicht überprüfen.
|
||||||
*/
|
*/
|
||||||
@@ -111,9 +115,9 @@ public class ASTFactory {
|
|||||||
else {
|
else {
|
||||||
Boolean isImplemented = false;
|
Boolean isImplemented = false;
|
||||||
isImplemented = Arrays.stream(jreClass.getInterfaces()).
|
isImplemented = Arrays.stream(jreClass.getInterfaces()).
|
||||||
reduce(false,
|
reduce(false,
|
||||||
(x,y) -> {
|
(x,y) -> {
|
||||||
try {
|
try {
|
||||||
y.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
y.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -122,24 +126,24 @@ public class ASTFactory {
|
|||||||
}},
|
}},
|
||||||
(x,y) -> (x || y)
|
(x,y) -> (x || y)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isImplemented) {
|
if (isImplemented) {
|
||||||
methoden.add(createMethod(method, signature, jreClass, false, true));
|
methoden.add(createMethod(method, signature, jreClass, false, true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (Modifier.isAbstract(jreClass.getSuperclass().getModifiers())) {
|
if (Modifier.isAbstract(jreClass.getSuperclass().getModifiers())) {
|
||||||
try {
|
try {
|
||||||
jreClass.getSuperclass().getDeclaredMethod(method.getName(), method.getParameterTypes());
|
jreClass.getSuperclass().getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||||
methoden.add(createMethod(method, signature, jreClass, false, true));
|
methoden.add(createMethod(method, signature, jreClass, false, true));
|
||||||
}
|
}
|
||||||
catch (java.lang.NoSuchMethodException e) {
|
catch (java.lang.NoSuchMethodException e) {
|
||||||
methoden.add(createMethod(method, signature, jreClass, false, false));
|
methoden.add(createMethod(method, signature, jreClass, false, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
methoden.add(createMethod(method, signature, jreClass, false, false));
|
methoden.add(createMethod(method, signature, jreClass, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
for (java.lang.reflect.Method method : allInheritedMethods) {
|
for (java.lang.reflect.Method method : allInheritedMethods) {
|
||||||
@@ -153,11 +157,11 @@ public class ASTFactory {
|
|||||||
int modifier = jreClass.getModifiers();
|
int modifier = jreClass.getModifiers();
|
||||||
boolean isInterface = jreClass.isInterface();
|
boolean isInterface = jreClass.isInterface();
|
||||||
List<Annotation> aLA;
|
List<Annotation> aLA;
|
||||||
boolean isFunctionalInterface =
|
boolean isFunctionalInterface =
|
||||||
(aLA = Arrays.asList(jreClass.getAnnotations())).size() > 0 &&
|
(aLA = Arrays.asList(jreClass.getAnnotations())).size() > 0 &&
|
||||||
aLA.get(0) instanceof FunctionalInterface ?
|
aLA.get(0) instanceof FunctionalInterface ?
|
||||||
true :
|
true :
|
||||||
false;
|
false;
|
||||||
// see: https://stackoverflow.com/questions/9934774/getting-generic-parameter-from-supertype-class
|
// see: https://stackoverflow.com/questions/9934774/getting-generic-parameter-from-supertype-class
|
||||||
ParameterizedType parameterSuperClass = null;
|
ParameterizedType parameterSuperClass = null;
|
||||||
Type tempSuperClass = jreClass.getGenericSuperclass();
|
Type tempSuperClass = jreClass.getGenericSuperclass();
|
||||||
@@ -464,25 +468,25 @@ public class ASTFactory {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* public Constructor createEmptyConstructor(Class parent){ Block block = new Block(); block.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0)); block.statements.add(new SuperCall(block));
|
* public Constructor createEmptyConstructor(Class parent){ Block block = new Block(); block.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0)); block.statements.add(new SuperCall(block));
|
||||||
*
|
*
|
||||||
* return ASTFactory.createConstructor(parent, new ParameterList(), block); }
|
* return ASTFactory.createConstructor(parent, new ParameterList(), block); }
|
||||||
*
|
*
|
||||||
* public static Constructor createConstructor(Class superClass, ParameterList paralist, Block block){ block.parserPostProcessing(superClass);
|
* public static Constructor createConstructor(Class superClass, ParameterList paralist, Block block){ block.parserPostProcessing(superClass);
|
||||||
*
|
*
|
||||||
* Method method = ASTFactory.createMethod("<init>", paralist, block, superClass); method.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0));
|
* Method method = ASTFactory.createMethod("<init>", paralist, block, superClass); method.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0));
|
||||||
*
|
*
|
||||||
* return new Constructor(method, superClass); }
|
* return new Constructor(method, superClass); }
|
||||||
*
|
*
|
||||||
* public static Class createClass(String className, RefType type, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent) { // TODO bytecode createClass //String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara Class generatedClass = new Class(className, type, modifiers, supertypeGenPara); generatedClass.addField(ASTFactory.createEmptyConstructor(generatedClass));
|
* public static Class createClass(String className, RefType type, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent) { // TODO bytecode createClass //String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara Class generatedClass = new Class(className, type, modifiers, supertypeGenPara); generatedClass.addField(ASTFactory.createEmptyConstructor(generatedClass));
|
||||||
*
|
*
|
||||||
* generatedClass.parserPostProcessing(parent);
|
* generatedClass.parserPostProcessing(parent);
|
||||||
*
|
*
|
||||||
* return generatedClass; }
|
* return generatedClass; }
|
||||||
*
|
*
|
||||||
* public static Class createObject(){ return createClass(java.lang.Object.class); }
|
* public static Class createObject(){ return createClass(java.lang.Object.class); }
|
||||||
*
|
*
|
||||||
* public static Class createInterface(String className, RefType superClass, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent){ Class generatedClass = new Class(new JavaClassName(className), new ArrayList<Method>(), new ArrayList<Field>(), modifiers, true, superClass, new ArrayList<RefType>(), new GenericDeclarationList(), -1); generatedClass.parserPostProcessing(parent); return generatedClass; }
|
* public static Class createInterface(String className, RefType superClass, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent){ Class generatedClass = new Class(new JavaClassName(className), new ArrayList<Method>(), new ArrayList<Field>(), modifiers, true, superClass, new ArrayList<RefType>(), new GenericDeclarationList(), -1); generatedClass.parserPostProcessing(parent); return generatedClass; }
|
||||||
*
|
*
|
||||||
* public static RefType createObjectType(){ return createObjectClass().getType(); }
|
* public static RefType createObjectType(){ return createObjectClass().getType(); }
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ public class NameGenerator {
|
|||||||
public static void reset() {
|
public static void reset() {
|
||||||
strNextName = "A";
|
strNextName = "A";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetTo(String name) {
|
|
||||||
strNextName = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user