Merge addPackages and simplifyRes and clear project
6
.gitignore
vendored
@ -23,3 +23,9 @@ bin
|
|||||||
|
|
||||||
#
|
#
|
||||||
manually/
|
manually/
|
||||||
|
|
||||||
|
logFiles/**
|
||||||
|
!logFiles/.gitkeep
|
||||||
|
|
||||||
|
src/main/java/de/dhbwstuttgart/parser/antlr/
|
||||||
|
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
Repositories: Branches: JavaCompilerCore: simplyRes
|
|
||||||
JavaCompilerPlugin: copy_libs
|
|
||||||
JavaCompilerCore > mvn install -Dskip.test=true
|
|
||||||
|
|
||||||
[INFO] Installing /Users/pl/workspace_oxygen/JavaCompilerCore/target/JavaTXcompiler-0.2.jar to /Users/pl/.m2/repository/de/dhbwstuttgart/JavaTXcompiler/0.2/JavaTXcompiler-0.2.jar
|
|
||||||
[INFO] Installing /Users/pl/workspace_oxygen/JavaCompilerCore/pom.xml to /Users/pl/.m2/repository/de/dhbwstuttgart/JavaTXcompiler/0.2/JavaTXcompiler-0.2.pom
|
|
||||||
[INFO] Installing /Users/pl/workspace_oxygen/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar to /Users/pl/.m2/repository/de/dhbwstuttgart/JavaTXcompiler/0.2/JavaTXcompiler-0.2-jar-with-dependencies.jar
|
|
||||||
[INFO] ------------------------------------------------------------------------
|
|
||||||
[INFO] BUILD SUCCESS
|
|
||||||
[INFO] ------------------------------------------------------------------------
|
|
||||||
[INFO] Total time: 23.279 s
|
|
||||||
[INFO] Finished at: 2019-09-17T09:31:30+02:00
|
|
||||||
[INFO] -------------------------------------
|
|
||||||
|
|
||||||
JavaCompilerCore > cd target
|
|
||||||
|
|
||||||
JavaCompilerCore/target > cp JavaTXcompiler-0.2.jar ../../Plugin_JCC/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/lib/JavaTXcompiler.jar
|
|
||||||
|
|
||||||
Im Eclipse: Plugin_JCC/JavaCompilerPlugin> mvn install
|
|
||||||
|
|
||||||
Plugin_JCC/JavaCompilerPlugin/releng/JavaCompilerPlugin.Update/target > cp JavaCompilerPlugin.Update-0.1.0-SNAPSHOT.zip ~/webdav/public_html/javatx/javatx_XXXXXX.zip
|
|
||||||
|
|
BIN
PluginBau.docx
@ -1,88 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
|
||||||
<html> <head>
|
|
||||||
<title>Java-TX Plugin</title></head>
|
|
||||||
<center>
|
|
||||||
<h1>Java-TX Plugin</h1>
|
|
||||||
</center>
|
|
||||||
<h2>Content</h2>
|
|
||||||
<ul>
|
|
||||||
<li><h4><a href="#introduction">Introduction</a></h4></li>
|
|
||||||
<li><h4><a href="newJavaTXProject/newJavaTXProject.html" >New Java-TX project</a></h4></li>
|
|
||||||
<li><h4><a href=" JavaTXExamples.zip" >Example project</a></h4></li>
|
|
||||||
<li><a href="usePlugin/usePlugin.html" >Using the plugin</a></li>
|
|
||||||
<li><h4><a href="install/install.html" >Installation</a></h4>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
<h2 id="introduction">Introduction</h2>
|
|
||||||
Java-TX (Java Type eXtended) is an extension of Java in which a global type inference algorithm and real function types are added. Since the end of the nineties features from functional program- ming languages have been transferred to Java. Parametric polymorphism extended by wildcards, called generics, were transfered to Java 5.0. Higher-order functions and lambda expression were introduced in Java 8. Java 8 uses functional interfaces as target types of lambda expressions in contrast to real function types as in functional programming languages.
|
|
||||||
The powerful feature type inference from functional programming languages is incorporated into Java, as into other object-oriented
|
|
||||||
languages, i.e. only in a restricted way called local type inference. Local type inference allows certain type annotations to be omitted. For instance, it is often not necessary to specify the type of a variable. Type parameters of classes in the new-statement can be left out. Return types of methods can often also be omitted. Local type inference is at its most pronounced in Scala. In Java 10 an extention of local type inference is introduced, where types of local variables can be replaced by the keyword var and inferred automatically during the compilation. In contrast to global type inference, local type inference allows types of recursive methods and lambda expressions not to be omitted.<br>
|
|
||||||
The Java-TX project contributes to the design of object-oriented languages by developing global type inference algorithms for Java-like languages.
|
|
||||||
|
|
||||||
<h3>First Example</h3>
|
|
||||||
The class <tt>Id</tt> has the method <tt>id</tt>. The type annotations are omitted.
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<pre> <code class="language-java">
|
|
||||||
class Id {
|
|
||||||
id(x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code> </pre>
|
|
||||||
The type inference algorithm inferrs the types, such that <tt>Id</tt> can be applied:
|
|
||||||
<pre>
|
|
||||||
new Id().id(1);
|
|
||||||
|
|
||||||
new Id().id("hallo");
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<h3>More complex example</h3>
|
|
||||||
<pre>
|
|
||||||
import java.lang.Integer;
|
|
||||||
import java.lang.Double;
|
|
||||||
import java.lang.String;
|
|
||||||
|
|
||||||
|
|
||||||
class OL {
|
|
||||||
m(x) { return x + x; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class OLMain {
|
|
||||||
main(x) {
|
|
||||||
var ol;
|
|
||||||
ol = new OL();
|
|
||||||
return ol.m(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
The type inference mechanism considers only imported types. Therefore <tt>Integer</tt> <tt>Double</tt>, and <tt>String</tt> are imported.
|
|
||||||
<br/>
|
|
||||||
As the operator <tt>+</tt> is overloaded by all numeric types and String the methods <tt>m</tt> in the class <tt>OL</tt> and <tt>main</tt> in the class <tt>OLMain</tt>, respectively, gets all these types. The generated classfile demonstrates this:
|
|
||||||
<pre>
|
|
||||||
> javap OL.class
|
|
||||||
Compiled from "OL.jav"
|
|
||||||
class OL {
|
|
||||||
public OL();
|
|
||||||
public java.lang.Integer m(java.lang.Integer);
|
|
||||||
public java.lang.Double m(java.lang.Double);
|
|
||||||
}
|
|
||||||
|
|
||||||
> javap OLMain.class
|
|
||||||
Compiled from "OLMain.jav"
|
|
||||||
class OLMain {
|
|
||||||
public OLMain();
|
|
||||||
public java.lang.Integer main(java.lang.Integer);
|
|
||||||
public java.lang.Double main(java.lang.Double);
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<address></address>
|
|
||||||
<!-- hhmts start -->Last modified: Fri Jun 1 16:43:55 CEST 2018 <!-- hhmts end -->
|
|
||||||
</body> </html>
|
|
Before Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 109 KiB |
@ -1,40 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
|
||||||
<html> <head>
|
|
||||||
<title>Install Java-TX Plugin</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>Install Java-TX Plugin</h1>
|
|
||||||
<ol>
|
|
||||||
<li>Select "Install New Software ..."<br>
|
|
||||||
<img width= 400 src="newsoftware.png" >
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Add ...<br>
|
|
||||||
<img width=550 src="availableSoftware1.png" >
|
|
||||||
</li>
|
|
||||||
<li>Insert address<br>
|
|
||||||
<img width=550 src="availableSoftware2.png" >
|
|
||||||
</li>
|
|
||||||
<li>Select installation<br>
|
|
||||||
<img width=550 src="selectInstallation.png" >
|
|
||||||
</li>
|
|
||||||
<li>Installation details<br>
|
|
||||||
<img width=550 src="installationDetails.png" >
|
|
||||||
</li>
|
|
||||||
<li>Accept license agreement<br>
|
|
||||||
<img width=550 src="licenseAgreement.png" >
|
|
||||||
</li>
|
|
||||||
<li>Install anyway<br>
|
|
||||||
<img width=450 src="installAnyway.png">
|
|
||||||
</li>
|
|
||||||
<li>Restart<br>
|
|
||||||
<img width=450 src="Restart.png">
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<address></address>
|
|
||||||
<!-- hhmts start -->Last modified: Fri Jun 1 11:57:15 CEST 2018 <!-- hhmts end -->
|
|
||||||
</body> </html>
|
|
@ -1,40 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
|
||||||
<html> <head>
|
|
||||||
<title>Install Java-TX Plugin</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h2>Install Java-TX Plugin</h2>
|
|
||||||
<ol>
|
|
||||||
<li>Select "Install New Software ..."<br>
|
|
||||||
<img width= 400 src="newsoftware.png" >
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Add ...<br>
|
|
||||||
<img width=550 src="availableSoftware1.png" >
|
|
||||||
</li>
|
|
||||||
<li>Insert address<br>
|
|
||||||
<img width=550 src="availableSoftware2.png" >
|
|
||||||
</li>
|
|
||||||
<li>Select installation<br>
|
|
||||||
<img width=550 src="selectInstallation.png" >
|
|
||||||
</li>
|
|
||||||
<li>Installation details<br>
|
|
||||||
<img width=550 src="installationDetails.png" >
|
|
||||||
</li>
|
|
||||||
<li>Accept license agreement<br>
|
|
||||||
<img width=550 src="licenseAgreement.png" >
|
|
||||||
</li>
|
|
||||||
<li>Install anyway<br>
|
|
||||||
<img width=450 src="installAnyway.png">
|
|
||||||
</li>
|
|
||||||
<li>Restart<br>
|
|
||||||
<img width=450 src="Restart.png">
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<address></address>
|
|
||||||
<!-- hhmts start -->Last modified: Fri Jun 1 12:05:43 CEST 2018 <!-- hhmts end -->
|
|
||||||
</body> </html>
|
|
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 93 KiB |
Before Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 76 KiB |
@ -1,34 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
|
||||||
<html> <head>
|
|
||||||
<title></title>
|
|
||||||
</head>
|
|
||||||
<h2>New Java-TX project in eclipse</h2>
|
|
||||||
<ol>
|
|
||||||
<li>New -> Java Project<br/>
|
|
||||||
<img width= 400 src="newJavaTXProject.png" >
|
|
||||||
</li>
|
|
||||||
<br/>
|
|
||||||
<li>Generate a jav-File folder<br/>
|
|
||||||
<img width= 550 src="newJavFolder1.png" ><br/><br/>
|
|
||||||
<img width= 550 src="newJavFolder2.png" >
|
|
||||||
</li>
|
|
||||||
<br/>
|
|
||||||
<li>Add jav-File folder as library<br/>
|
|
||||||
At the moment no package system is implemented, Therefore the compiled class files are in the jav-File folder. This has to be added as library:<br/>
|
|
||||||
<img width= 550 src="buildPath1.png" ><br/><br/>
|
|
||||||
<img width= 550 src="buildPath2.png" ><br/><br/>
|
|
||||||
<img width= 400 src="buildPath3.png" ><br/><br/>
|
|
||||||
<img width= 550 src="buildPath4.png" ><br/>
|
|
||||||
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
<body>
|
|
||||||
<h1></h1>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<address></address>
|
|
||||||
<!-- hhmts start -->Last modified: Fri Jun 1 16:50:02 CEST 2018 <!-- hhmts end -->
|
|
||||||
</body> </html>
|
|
Before Width: | Height: | Size: 150 KiB |
@ -1,24 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
|
||||||
<html> <head>
|
|
||||||
<title>Using the plugin</title>
|
|
||||||
</head>
|
|
||||||
<h2>Using the plugin</h2>
|
|
||||||
<ol>
|
|
||||||
<li>Overview<br/>
|
|
||||||
<img width=800 src="usePlugin1.png" >
|
|
||||||
</li>
|
|
||||||
<br/>
|
|
||||||
<li>Select types<br/>
|
|
||||||
If the method is overloaded the user can select types in the outline the right mouse button:<br/><br/>
|
|
||||||
<img src="usePlugin2.png" ><br/>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
<body>
|
|
||||||
<h1></h1>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<address></address>
|
|
||||||
<!-- hhmts start -->Last modified: Fri Jun 1 16:51:28 CEST 2018 <!-- hhmts end -->
|
|
||||||
</body> </html>
|
|
Before Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 33 KiB |
25
doc/Generics/generics.tex
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
\documentclass{article}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\section{Generics sind notwendig}
|
||||||
|
Generics können nicht ignoriert werden.
|
||||||
|
Folgender Fall ist Typisierbar:
|
||||||
|
|
||||||
|
\begin{program}
|
||||||
|
<T> T m1(T x){
|
||||||
|
return m2(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
m2(x){
|
||||||
|
m1(1);
|
||||||
|
m2("Test");
|
||||||
|
return m1(x);
|
||||||
|
}
|
||||||
|
\end{program}
|
||||||
|
|
||||||
|
Beim weglassen des Generics T wäre es aber nicht mehr möglich.
|
||||||
|
Dann erhält jeder Constraint, welcher in Verbindung mit der Methode m1 steht
|
||||||
|
den selben TPH.
|
||||||
|
|
||||||
|
\end{document}
|
0
logFiles/.gitkeep
Normal file
62
pom.xml
@ -79,7 +79,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.7</version>
|
<version>4.8-1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>antlr</id>
|
<id>antlr</id>
|
||||||
@ -88,28 +88,13 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
||||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
<outputDirectory>${project.basedir}/src/main/java/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
||||||
<arguments>
|
<arguments>
|
||||||
<argument>-package</argument>
|
<argument>-package</argument>
|
||||||
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
|
||||||
<id>aspParser</id>
|
|
||||||
<goals>
|
|
||||||
<goal>antlr4</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<sourceDirectory>src/main/antlr4/sat</sourceDirectory>
|
|
||||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
|
||||||
<arguments>
|
|
||||||
<argument>-package</argument>
|
|
||||||
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
|
||||||
</arguments>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
|
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -123,50 +108,18 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
<descriptorRefs>
|
<descriptorRefs>
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
</descriptorRefs>
|
</descriptorRefs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.reficio</groupId>
|
|
||||||
<artifactId>p2-maven-plugin</artifactId>
|
|
||||||
<version>1.1.2-SNAPSHOT</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>default-cli</id>
|
|
||||||
<configuration>
|
|
||||||
<artifacts>
|
|
||||||
<!-- specify your depencies here -->
|
|
||||||
<!-- groupId:artifactId:version -->
|
|
||||||
<artifact>
|
|
||||||
<id>de.dhbwstuttgart:JavaTXcompiler:0.2</id>
|
|
||||||
</artifact>
|
|
||||||
<artifact>
|
|
||||||
<id>org.reflections:reflections:0.9.11</id>
|
|
||||||
</artifact>
|
|
||||||
<artifact>
|
|
||||||
<id>com.google.guava:guava:22.0</id>
|
|
||||||
</artifact>
|
|
||||||
<artifact>
|
|
||||||
<id>javax.annotation:javax.annotation-api:1.3.1</id>
|
|
||||||
</artifact>
|
|
||||||
<artifact>
|
|
||||||
<id>org.glassfish:javax.annotation:3.1.1</id>
|
|
||||||
</artifact>
|
|
||||||
</artifacts>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<pluginRepositories>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>reficio</id>
|
|
||||||
<url>http://repo.reficio.org/maven/</url>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>maven-repository</id>
|
<id>maven-repository</id>
|
||||||
@ -179,6 +132,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<tycho.version>0.23.0</tycho.version>
|
<tycho.version>0.23.0</tycho.version>
|
||||||
|
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
||||||
</properties>
|
</properties>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.bytecode;
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -7,6 +8,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.FieldVisitor;
|
import org.objectweb.asm.FieldVisitor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
@ -81,13 +83,13 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
String type;
|
String type;
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
||||||
private String className;
|
private JavaClassName className;
|
||||||
private String pkgName;
|
private String pkgName;
|
||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private Collection<ResultSet> listOfResultSets;
|
private Collection<ResultSet> listOfResultSets;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private SourceFile sf;
|
private SourceFile sf;
|
||||||
private String path;
|
private File path;
|
||||||
|
|
||||||
private Optional<Constructor> fieldInitializations;
|
private Optional<Constructor> fieldInitializations;
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||||
byte[] bytecode;
|
byte[] bytecode;
|
||||||
HashMap<String, byte[]> classFiles;
|
HashMap<JavaClassName, byte[]> classFiles;
|
||||||
|
|
||||||
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
|
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
|
||||||
@ -118,24 +120,26 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
private GenericsGeneratorResultForClass generatedGenerics;
|
private GenericsGeneratorResultForClass generatedGenerics;
|
||||||
|
|
||||||
private Resolver resolver;
|
private Resolver resolver;
|
||||||
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String, byte[]> classFiles, Collection<ResultSet> listOfResultSets, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles, SourceFile sf,
|
public BytecodeGen(HashMap<JavaClassName, byte[]> classFiles, Collection<ResultSet> listOfResultSets, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles, SourceFile sf,
|
||||||
String path) {
|
File path, ClassLoader classLoader) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
|
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.pkgName = sf.getPkgName();
|
this.pkgName = sf.getPkgName();
|
||||||
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(SourceFile sourceFile) {
|
public void visit(SourceFile sourceFile) {
|
||||||
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, simplifyResultsForAllSourceFiles, sf, path);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, simplifyResultsForAllSourceFiles, sf, path, classLoader);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,22 +149,22 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
*
|
*
|
||||||
* @param name name of the class with which the bytecode is to be associated
|
* @param name name of the class with which the bytecode is to be associated
|
||||||
*/
|
*/
|
||||||
private void writeClass(String name) {
|
private void writeClass(JavaClassName name) {
|
||||||
bytecode = cw.toByteArray();
|
bytecode = cw.toByteArray();
|
||||||
classFiles.put(name, bytecode);
|
classFiles.put(name, bytecode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, byte[]> getClassFiles() {
|
public HashMap<JavaClassName, byte[]> getClassFiles() {
|
||||||
return classFiles;
|
return classFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
|
||||||
className = classOrInterface.getClassName().toString();
|
className = classOrInterface.getClassName();
|
||||||
|
|
||||||
cw.visitSource(className + ".jav", null);
|
cw.visitSource(className.getClassName() + ".jav", null);
|
||||||
|
|
||||||
isInterface = (classOrInterface.getModifiers() & 512) == 512;
|
isInterface = (classOrInterface.getModifiers() & 512) == 512;
|
||||||
|
|
||||||
@ -172,7 +176,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
// resultSet = listOfResultSets.get(0);
|
// resultSet = listOfResultSets.get(0);
|
||||||
boolean isVisited = false;
|
boolean isVisited = false;
|
||||||
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
||||||
generatedGenerics = simplifyResultsForAllSourceFiles.stream().map(sr->sr.getSimplifyResultsByName(pkgName, className)).findFirst().get();
|
generatedGenerics = simplifyResultsForAllSourceFiles.stream().map(sr->sr.getSimplifyResultsByName(className)).findFirst().get();
|
||||||
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||||
//for (ResultSet rs : listOfResultSets) {
|
//for (ResultSet rs : listOfResultSets) {
|
||||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||||
@ -199,7 +203,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println("Signature: => " + sig);
|
System.out.println("Signature: => " + sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString(), sig,
|
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString().replace(".", "/"), sig,
|
||||||
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||||
|
|
||||||
isVisited = true;
|
isVisited = true;
|
||||||
@ -269,7 +273,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
constructorPos += 1;
|
constructorPos += 1;
|
||||||
|
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, field, mv, paramsAndLocals, cw,
|
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, field, mv, paramsAndLocals, cw,
|
||||||
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, block, constructorPos);
|
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, block, constructorPos, classLoader);
|
||||||
if (!field.getParameterList().iterator().hasNext()
|
if (!field.getParameterList().iterator().hasNext()
|
||||||
&& !(field.block.statements.get(field.block.statements.size() - 1) instanceof ReturnVoid)) {
|
&& !(field.block.statements.get(field.block.statements.size() - 1) instanceof ReturnVoid)) {
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
@ -350,7 +354,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, method, mv, paramsAndLocals, cw,
|
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, method, mv, paramsAndLocals, cw,
|
||||||
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path);
|
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, classLoader);
|
||||||
|
|
||||||
mv.visitMaxs(0, 0);
|
mv.visitMaxs(0, 0);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.bytecode;
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.lang.invoke.CallSite;
|
import java.lang.invoke.CallSite;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
@ -14,7 +15,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.*;
|
import de.dhbwstuttgart.bytecode.utilities.*;
|
||||||
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
|
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr.Operation;
|
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr.Operation;
|
||||||
@ -45,7 +48,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
private Method m;
|
private Method m;
|
||||||
private MethodVisitor mv;
|
private MethodVisitor mv;
|
||||||
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||||
private String className;
|
private JavaClassName className;
|
||||||
private int lamCounter;
|
private int lamCounter;
|
||||||
private ClassWriter cw;
|
private ClassWriter cw;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
@ -54,7 +57,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
private HashMap<String, String> genericsAndBounds;
|
private HashMap<String, String> genericsAndBounds;
|
||||||
public boolean isBinaryExp = false;
|
public boolean isBinaryExp = false;
|
||||||
private String superClass;
|
private String superClass;
|
||||||
private String path;
|
private File path;
|
||||||
private SourceFile sf;
|
private SourceFile sf;
|
||||||
private IStatement statement = null;
|
private IStatement statement = null;
|
||||||
private boolean isReturnStmt = false;
|
private boolean isReturnStmt = false;
|
||||||
@ -71,16 +74,18 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
private boolean isRightSideALambda = false;
|
private boolean isRightSideALambda = false;
|
||||||
private KindOfLambda kindOfLambda;
|
private KindOfLambda kindOfLambda;
|
||||||
private HashMap<String, byte[]> classFiles;
|
private HashMap<JavaClassName, byte[]> classFiles;
|
||||||
|
|
||||||
private int constructorPos = 0;
|
private int constructorPos = 0;
|
||||||
|
|
||||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||||
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
// generate bytecode for constructor
|
// generate bytecode for constructor
|
||||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
public BytecodeGenMethod(JavaClassName className, String superClass, ResultSet resultSet, Method m, MethodVisitor mv,
|
||||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles,
|
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles,
|
||||||
SourceFile sf,String path, Block block, int constructorPos) {
|
SourceFile sf, File path, Block block, int constructorPos, ClassLoader classLoader) {
|
||||||
|
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
@ -98,16 +103,15 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.lamCounter = -1;
|
this.lamCounter = -1;
|
||||||
this.constructorPos = constructorPos;
|
this.constructorPos = constructorPos;
|
||||||
|
this.classLoader = classLoader;
|
||||||
if(block != null)
|
if(block != null)
|
||||||
this.blockFieldInit = block;
|
this.blockFieldInit = block;
|
||||||
this.m.block.accept(this);
|
this.m.block.accept(this);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
public BytecodeGenMethod(JavaClassName className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles, SourceFile sf,String path) {
|
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles, SourceFile sf,File path, ClassLoader classLoader) {
|
||||||
|
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
@ -124,14 +128,14 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.lamCounter = -1;
|
this.lamCounter = -1;
|
||||||
|
this.classLoader = classLoader;
|
||||||
if (!isInterface)
|
if (!isInterface)
|
||||||
this.m.block.accept(this);
|
this.m.block.accept(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(String className, ClassWriter cw, LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(JavaClassName className, ClassWriter cw, LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
int indexOfFirstParamLam, boolean isInterface, HashMap<JavaClassName, byte[]> classFiles, File path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds) {
|
HashMap<String, String> genericsAndBounds, ClassLoader classLoader) {
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.cw = cw;
|
this.cw = cw;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
@ -144,6 +148,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
|
this.classLoader = classLoader;
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
int i = indexOfFirstParamLam;
|
int i = indexOfFirstParamLam;
|
||||||
@ -172,6 +177,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Block block) {
|
public void visit(Block block) {
|
||||||
|
HashMap<String, Integer> paramsAndLocalsOld = new HashMap<>(paramsAndLocals);
|
||||||
for (Statement stmt : block.getStatements()) {
|
for (Statement stmt : block.getStatements()) {
|
||||||
stmt.accept(this);
|
stmt.accept(this);
|
||||||
if(stmt instanceof MethodCall) {
|
if(stmt instanceof MethodCall) {
|
||||||
@ -180,6 +186,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
mv.visitInsn(Opcodes.POP);
|
mv.visitInsn(Opcodes.POP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
paramsAndLocals = paramsAndLocalsOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -217,7 +224,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// ??
|
// ??
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
|
paramsAndLocals.put(localVarDecl.getName(), paramsAndLocals.size()+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -622,7 +629,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
String newDesc = addUsedVarsToDesugaredMethodDescriptor(lamDesc);
|
String newDesc = addUsedVarsToDesugaredMethodDescriptor(lamDesc);
|
||||||
// first check if capturing lambda then invokestatic or invokespecial
|
// first check if capturing lambda then invokestatic or invokespecial
|
||||||
Handle arg2 = new Handle(staticOrSpecial, this.className, desugaredMethodName, newDesc, false);
|
Handle arg2 = new Handle(staticOrSpecial, this.className.getClassName(), desugaredMethodName, newDesc, false);
|
||||||
// Descriptor of functional interface methode
|
// Descriptor of functional interface methode
|
||||||
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
||||||
// Desc: (this/nothing)TargetType
|
// Desc: (this/nothing)TargetType
|
||||||
@ -636,7 +643,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
new BytecodeGenMethod(className, cw,lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
new BytecodeGenMethod(className, cw,lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||||
classFiles,this.path, lamCounter, sf, genericsAndBoundsMethod,
|
classFiles,this.path, lamCounter, sf, genericsAndBoundsMethod,
|
||||||
genericsAndBounds);
|
genericsAndBounds, classLoader);
|
||||||
|
|
||||||
mvLambdaBody.visitMaxs(0, 0);
|
mvLambdaBody.visitMaxs(0, 0);
|
||||||
mvLambdaBody.visitEnd();
|
mvLambdaBody.visitEnd();
|
||||||
@ -756,7 +763,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
||||||
|
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader cLoader = this.classLoader;
|
||||||
// This will be used if the class is not standard class (not in API)
|
// This will be used if the class is not standard class (not in API)
|
||||||
ClassLoader cLoader2;
|
ClassLoader cLoader2;
|
||||||
|
|
||||||
@ -767,13 +774,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(),methCallType, typesOfParams, methods);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String superClass = "";
|
String superClass = "";
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
try {
|
||||||
superClass = helper.getSuperClass(receiverName);
|
superClass = helper.getSuperClass(receiverName.replace("/", "."));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String superClazz = superClass.replace("/", ".");
|
String superClazz = superClass.replace("/", ".");
|
||||||
@ -781,7 +788,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
||||||
System.out.println("Methods of " + superClass + " ");
|
System.out.println("Methods of " + superClass + " ");
|
||||||
|
|
||||||
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methCallType, typesOfParams, methods);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} catch (Exception e3) {
|
} catch (Exception e3) {
|
||||||
@ -797,7 +804,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null) {
|
||||||
boolean toCreate = !receiverName.equals(className) && helper.isInCurrPkg(clazz);
|
boolean toCreate = !receiverName.equals(className.getClassName()) && helper.isInCurrPkg(clazz);
|
||||||
if(toCreate) {
|
if(toCreate) {
|
||||||
try {
|
try {
|
||||||
mDesc = helper.getDesc(clazz);
|
mDesc = helper.getDesc(clazz);
|
||||||
@ -811,7 +818,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
cLoader2 = new DirectoryClassLoader(path, classLoader);
|
||||||
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
for(int i = 0; i<methods.length; i++) {
|
for(int i = 0; i<methods.length; i++) {
|
||||||
@ -832,7 +839,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
List<Boolean> argListMethCall = new LinkedList<>();
|
List<Boolean> argListMethCall = new LinkedList<>();
|
||||||
String receiverRefl="";
|
String receiverRefl="";
|
||||||
if(methodRefl == null && receiverName.equals(className)) {
|
if(methodRefl == null && receiverName.equals(className.getClassName())) {
|
||||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||||
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
@ -910,7 +917,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getTypes(List<Expression> arguments) {
|
private String[] getTypes(List<Expression> arguments) {
|
||||||
String[] types = new String[arguments.size()];
|
String[] types = new String[arguments.size()];
|
||||||
for(int i = 0; i<arguments.size(); ++i) {
|
for(int i = 0; i<arguments.size(); ++i) {
|
||||||
@ -936,6 +943,17 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean unbox(String demanded, String given) {
|
||||||
|
if (demanded.equals("java/lang/Boolean") && given.equals("boolean")) return true;
|
||||||
|
if (demanded.equals("java/lang/Integer") && given.equals("int")) return true;
|
||||||
|
if (demanded.equals("java/lang/Short") && given.equals("short")) return true;
|
||||||
|
if (demanded.equals("java/lang/Byte") && given.equals("byte")) return true;
|
||||||
|
if (demanded.equals("java/lang/Double") && given.equals("double")) return true;
|
||||||
|
if (demanded.equals("java/lang/Float") && given.equals("float")) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name name of a method
|
* @param name name of a method
|
||||||
* @param i number of parameters
|
* @param i number of parameters
|
||||||
@ -953,11 +971,15 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
for(java.lang.reflect.Method m : methods) {
|
for(java.lang.reflect.Method m : methods) {
|
||||||
if(name.equals(m.getName()) && i == m.getParameterCount() &&
|
if(name.equals(m.getName()) && i == m.getParameterCount() &&
|
||||||
(methCallType.equals(m.getReturnType().getName().replace(".", "/")) ||
|
(methCallType.equals(m.getReturnType().getName().replace(".", "/")) ||
|
||||||
m.getReturnType().getName().replace(".", "/").equals(Type.getInternalName(Object.class)))) {
|
m.getReturnType().getName().replace(".", "/").equals(Type.getInternalName(Object.class)) ||
|
||||||
|
unbox(methCallType, m.getReturnType().getName().replace(".", "/"))
|
||||||
|
) ) {
|
||||||
boolean typesEqual = true;
|
boolean typesEqual = true;
|
||||||
Class<?>[] pTypes = m.getParameterTypes();
|
Class<?>[] pTypes = m.getParameterTypes();
|
||||||
for(int j = 0; j<typesOfParams.length; ++j) {
|
for(int j = 0; j<typesOfParams.length; ++j) {
|
||||||
if(!typesOfParams[j].equals(pTypes[j].getName().replaceAll(".", "/")) && !pTypes[j].getName().replace(".", "/").equals(Type.getInternalName(Object.class))) {
|
if(!typesOfParams[j].replaceAll("/", ".").equals(pTypes[j].getName())
|
||||||
|
&& !unbox(typesOfParams[j], pTypes[j].getName())
|
||||||
|
&& !pTypes[j].getName().replace(".", "/").equals(Type.getInternalName(Object.class))) {
|
||||||
typesEqual = false;
|
typesEqual = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
@Override
|
@Override
|
||||||
public String visit(SuperWildcardType superWildcardType) {
|
public String visit(SuperWildcardType superWildcardType) {
|
||||||
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
||||||
return superWildcardType.getInnerType().toString().replace(".", "/");
|
//return superWildcardType.getInnerType().toString().replace(".", "/");
|
||||||
|
return superWildcardType.getInnerType().acceptTV(new TypeToDescriptor());
|
||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
@Override
|
@Override
|
||||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
||||||
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
//return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
||||||
|
return extendsWildcardType.getInnerType().acceptTV(new TypeToDescriptor());
|
||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
@ -75,7 +76,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
private final List<String> methodNameAndParamsT = new ArrayList<>();
|
private final List<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
private String pkgName;
|
private String pkgName;
|
||||||
private String className;
|
private JavaClassName className;
|
||||||
private Resolver resolver;
|
private Resolver resolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,7 +118,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
className = classOrInterface.getClassName().toString();
|
className = classOrInterface.getClassName();
|
||||||
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
||||||
|
|
||||||
boolean isVisited = false;
|
boolean isVisited = false;
|
||||||
|
@ -12,6 +12,7 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
@ -30,7 +31,7 @@ public class GenericsGenerator {
|
|||||||
class constraints: tphClass < tphMeth1, tphMeth1 < tphMeth2, tphMeth2 < Object
|
class constraints: tphClass < tphMeth1, tphMeth1 < tphMeth2, tphMeth2 < Object
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static GenericsGeneratorResultForClass generateConstraints(final String className, final TPHExtractor tphExtractor,
|
public static GenericsGeneratorResultForClass generateConstraints(final JavaClassName className, final TPHExtractor tphExtractor,
|
||||||
final List<String> tphsClass, final ConstraintsSimplierResult simplifiedConstraints) {
|
final List<String> tphsClass, final ConstraintsSimplierResult simplifiedConstraints) {
|
||||||
|
|
||||||
List<GenericsGeneratorResult> classConstraints = generateConstraintsForClass(tphExtractor,
|
List<GenericsGeneratorResult> classConstraints = generateConstraintsForClass(tphExtractor,
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
@ -37,9 +39,9 @@ public class GenericGenratorResultForSourceFile {
|
|||||||
genericGeneratorResultForAllClasses.add(sResClass);
|
genericGeneratorResultForAllClasses.add(sResClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {
|
public GenericsGeneratorResultForClass getSimplifyResultsByName(JavaClassName name) {
|
||||||
|
|
||||||
if (this.pkgName.equals(pkgName)) {
|
if (this.pkgName.equals(name.getPackageName())) {
|
||||||
return genericGeneratorResultForAllClasses.stream()
|
return genericGeneratorResultForAllClasses.stream()
|
||||||
.filter(sr -> sr.getClassName().equals(name))
|
.filter(sr -> sr.getClassName().equals(name))
|
||||||
.findAny()
|
.findAny()
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -14,11 +16,11 @@ import com.google.common.collect.Lists;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GenericsGeneratorResultForClass {
|
public class GenericsGeneratorResultForClass {
|
||||||
private final String className;
|
private final JavaClassName className;
|
||||||
private final List<GenericsGeneratorResult> classConstraints;
|
private final List<GenericsGeneratorResult> classConstraints;
|
||||||
private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints;
|
private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints;
|
||||||
|
|
||||||
public GenericsGeneratorResultForClass(String className) {
|
public GenericsGeneratorResultForClass(JavaClassName className) {
|
||||||
this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods());
|
this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -26,8 +28,8 @@ public class GenericsGeneratorResultForClass {
|
|||||||
* @param classConstraints
|
* @param classConstraints
|
||||||
* @param methodsAndTheirConstraints
|
* @param methodsAndTheirConstraints
|
||||||
*/
|
*/
|
||||||
public GenericsGeneratorResultForClass(String className, List<GenericsGeneratorResult> classConstraints,
|
public GenericsGeneratorResultForClass(JavaClassName className, List<GenericsGeneratorResult> classConstraints,
|
||||||
GenericGeneratorResultsForAllMethods methodsAndTheirConstraints) {
|
GenericGeneratorResultsForAllMethods methodsAndTheirConstraints) {
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.classConstraints = classConstraints;
|
this.classConstraints = classConstraints;
|
||||||
this.methodsAndTheirConstraints = methodsAndTheirConstraints;
|
this.methodsAndTheirConstraints = methodsAndTheirConstraints;
|
||||||
@ -36,7 +38,7 @@ public class GenericsGeneratorResultForClass {
|
|||||||
/**
|
/**
|
||||||
* @return the className
|
* @return the className
|
||||||
*/
|
*/
|
||||||
public String getClassName() {
|
public JavaClassName getClassName() {
|
||||||
return className;
|
return className;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
public class ByteCodeForFunNGenerator {
|
public class ByteCodeForFunNGenerator {
|
||||||
|
|
||||||
public static void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc, String path) {
|
public static void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc, File path) {
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
SignatureWriter methSig = new SignatureWriter();
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
@ -46,7 +46,7 @@ public class ByteCodeForFunNGenerator {
|
|||||||
writeClassFile(classWriter.toByteArray(), name, path);
|
writeClassFile(classWriter.toByteArray(), name, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateBCForFunN(ArgumentList argumentList, String methDesc, String path) {
|
public static void generateBCForFunN(ArgumentList argumentList, String methDesc, File path) {
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
SignatureWriter methSig = new SignatureWriter();
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
@ -75,12 +75,12 @@ public class ByteCodeForFunNGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void writeClassFile(byte[] bytecode, String name, String path) {
|
public static void writeClassFile(byte[] bytecode, String name, File path) {
|
||||||
FileOutputStream output;
|
FileOutputStream output;
|
||||||
try {
|
try {
|
||||||
System.out.println("generating " + name + ".class file...");
|
System.out.println("generating " + name + ".class file...");
|
||||||
output = new FileOutputStream(
|
output = new FileOutputStream(
|
||||||
new File(path + name + CONSTANTS.EXTENSIONCLASS));
|
new File(path , name + CONSTANTS.EXTENSIONCLASS));
|
||||||
output.write(bytecode);
|
output.write(bytecode);
|
||||||
output.close();
|
output.close();
|
||||||
System.out.println(name + ".class file generated");
|
System.out.println(name + ".class file generated");
|
||||||
|
@ -16,6 +16,7 @@ import javassist.NotFoundException;
|
|||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,7 +27,7 @@ public class MethodCallHelper {
|
|||||||
private MethodCall methCall;
|
private MethodCall methCall;
|
||||||
private SourceFile sourceFile;
|
private SourceFile sourceFile;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private String path;
|
private File path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param methCall
|
* @param methCall
|
||||||
@ -34,7 +35,7 @@ public class MethodCallHelper {
|
|||||||
* @param resultSet
|
* @param resultSet
|
||||||
* @param path TODO
|
* @param path TODO
|
||||||
*/
|
*/
|
||||||
public MethodCallHelper(MethodCall methCall, SourceFile sourceFile, ResultSet resultSet, String path) {
|
public MethodCallHelper(MethodCall methCall, SourceFile sourceFile, ResultSet resultSet, File path) {
|
||||||
this.methCall = methCall;
|
this.methCall = methCall;
|
||||||
this.sourceFile = sourceFile;
|
this.sourceFile = sourceFile;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -9,8 +10,29 @@ public class ConsoleInterface {
|
|||||||
private static final String directory = System.getProperty("user.dir");
|
private static final String directory = System.getProperty("user.dir");
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||||
List<File> input = Arrays.asList(args).stream().map((s -> new File(s))).collect(Collectors.toList());
|
List<File> input = new ArrayList<>();
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(input);
|
List<File> classpath = new ArrayList<>();
|
||||||
|
String outputPath = null;
|
||||||
|
Iterator<String> it = Arrays.asList(args).iterator();
|
||||||
|
while(it.hasNext()){
|
||||||
|
String arg = it.next();
|
||||||
|
if(arg.equals("-d")){
|
||||||
|
outputPath = it.next();
|
||||||
|
}else if(arg.startsWith("-d")) {
|
||||||
|
outputPath = arg.substring(2);
|
||||||
|
}else if(arg.equals("-cp") || arg.equals("-classpath")){
|
||||||
|
String[] cps = it.next().split(":");
|
||||||
|
for(String cp : cps){
|
||||||
|
classpath.add(new File(cp));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
input.add(new File(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath);
|
||||||
compiler.typeInference();
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,38 @@
|
|||||||
//PL 2018-12-19: typeInferenceOld nach typeInference uebertragen
|
//PL 2018-12-19: typeInferenceOld nach typeInference uebertragen
|
||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
|
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.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
@ -41,57 +58,140 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
//import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
//public static JavaTXCompiler INSTANCE;
|
//public static JavaTXCompiler INSTANCE;
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
Boolean resultmodel = true;
|
Boolean resultmodel = true;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||||
|
private final ClassLoader classLoader;
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
|
||||||
this(Arrays.asList(sourceFile));
|
|
||||||
//INSTANCE = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
|
this(Arrays.asList(sourceFile), null);
|
||||||
|
}
|
||||||
public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||||
this(sourceFile);
|
this(sourceFile);
|
||||||
this.log = log;
|
this.log = log;
|
||||||
//INSTANCE = this;
|
|
||||||
}
|
}
|
||||||
|
public JavaTXCompiler(List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
this(sourceFiles, null);
|
||||||
environment = new CompilationEnvironment(sources);
|
}
|
||||||
|
public JavaTXCompiler(List<File> sources, List<File> contextPath) throws IOException, ClassNotFoundException {
|
||||||
|
if(contextPath == null || contextPath.isEmpty()){
|
||||||
|
//When no contextPaths are given, the working directory is the sources root
|
||||||
|
contextPath = Lists.newArrayList(new File(System.getProperty("user.dir")));
|
||||||
|
}
|
||||||
|
classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader());
|
||||||
|
environment = new CompilationEnvironment(sources);
|
||||||
for (File s : sources) {
|
for (File s : sources) {
|
||||||
sourceFiles.put(s, parse(s));
|
sourceFiles.put(s, parse(s));
|
||||||
}
|
}
|
||||||
//INSTANCE = this;
|
//INSTANCE = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
for (SourceFile sf : sourceFiles.values()) {
|
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
}
|
|
||||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||||
|
ClassOrInterface objectClass = ASTFactory.createClass(
|
||||||
|
classLoader.loadClass(new JavaClassName("java.lang.Object").toString()));
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for (File forSourceFile : sourceFiles.keySet())
|
for (File forSourceFile : sourceFiles.keySet()){
|
||||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
classLoader.loadClass(name.toString()));
|
||||||
importedClasses.add(importedClass);
|
importedClasses.add(importedClass);
|
||||||
}
|
}
|
||||||
|
for(Class c : CompilationEnvironment.loadDefaultPackageClasses(forSourceFile, classLoader)){
|
||||||
|
ClassOrInterface importedClass = ASTFactory.createClass(c);
|
||||||
|
importedClasses.add(importedClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (File f : this.sourceFiles.keySet()) {
|
||||||
|
SourceFile sf = sourceFiles.get(f);
|
||||||
|
sf = new SourceFile(sf.getPkgName(),
|
||||||
|
sf.KlassenVektor.stream()
|
||||||
|
.map(cl -> new ClassOrInterface(cl))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new)),
|
||||||
|
sf.imports);
|
||||||
|
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
||||||
|
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
||||||
|
//Alle anderen Objekte werden nur kopiert.
|
||||||
|
SourceFile sf_new = sf;
|
||||||
|
sf.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, importedClasses, objectClass));
|
||||||
|
allClasses.addAll(sf.getClasses());
|
||||||
|
}
|
||||||
allClasses.addAll(importedClasses);
|
allClasses.addAll(importedClasses);
|
||||||
|
|
||||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addMethods(SourceFile sf, ClassOrInterface cl, List<ClassOrInterface> importedClasses, ClassOrInterface objectClass) {
|
||||||
|
if (!cl.areMethodsAdded()) {
|
||||||
|
ClassOrInterface superclass = null;
|
||||||
|
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||||
|
superclass = objectClass;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Optional<ClassOrInterface> optSuperclass =
|
||||||
|
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||||
|
cl.getSuperClass().getName())).findFirst();
|
||||||
|
if (optSuperclass.isPresent()) {
|
||||||
|
superclass = optSuperclass.get();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
optSuperclass =
|
||||||
|
sf.KlassenVektor.stream().filter(x -> x.getClassName().equals(
|
||||||
|
cl.getSuperClass().getName())).findFirst();
|
||||||
|
if (optSuperclass.isPresent()) {
|
||||||
|
superclass = optSuperclass.get();
|
||||||
|
addMethods(sf, superclass, importedClasses, objectClass);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//throw new ClassNotFoundException("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||||
|
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||||
|
|
||||||
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
||||||
|
while (paraIt.hasNext()) {
|
||||||
|
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
||||||
|
}
|
||||||
|
Iterator<Method> methodIt = superclass.getMethods().iterator();
|
||||||
|
//TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert werden
|
||||||
|
while(methodIt.hasNext()) {
|
||||||
|
Method m = methodIt.next();
|
||||||
|
ParameterList newParaList = new ParameterList(
|
||||||
|
m.getParameterList()
|
||||||
|
.getFormalparalist()
|
||||||
|
.stream()
|
||||||
|
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
||||||
|
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||||
|
//new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||||
|
(GenericDeclarationList)m.getGenerics(),
|
||||||
|
m.getOffset(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
cl.setMethodsAdded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||||
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
||||||
@ -122,7 +222,7 @@ public class JavaTXCompiler {
|
|||||||
for (JavaClassName name : forSourceFile.getImports()) {
|
for (JavaClassName name : forSourceFile.getImports()) {
|
||||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||||
ClassOrInterface importedClass = ASTFactory
|
ClassOrInterface importedClass = ASTFactory
|
||||||
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
.createClass(classLoader.loadClass(name.toString()));
|
||||||
importedClasses.add(importedClass);
|
importedClasses.add(importedClass);
|
||||||
allClasses.addAll(importedClasses);
|
allClasses.addAll(importedClasses);
|
||||||
}
|
}
|
||||||
@ -275,12 +375,14 @@ public class JavaTXCompiler {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
|
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
|
||||||
throws ClassNotFoundException {
|
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 (SourceFile sf : this.sourceFiles.values()) {
|
for (File f : this.sourceFiles.keySet()) {
|
||||||
|
SourceFile sf = sourceFiles.get(f);
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
allClasses.addAll(sf.getClasses());
|
allClasses.addAll(sf.getClasses());
|
||||||
|
allClasses.addAll(CompilationEnvironment.loadDefaultPackageClasses(f,classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
@ -291,7 +393,7 @@ public class JavaTXCompiler {
|
|||||||
logFile = logFile == null
|
logFile = logFile == null
|
||||||
? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName()))
|
? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName()))
|
||||||
: logFile;
|
: logFile;
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
urm = new UnifyResultModel(cons, finiteClosure);
|
urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
urm.addUnifyResultListener(resultListener);
|
urm.addUnifyResultListener(resultListener);
|
||||||
@ -428,13 +530,13 @@ public class JavaTXCompiler {
|
|||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||||
// logFile, log);
|
// logFile, log);
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()/*.stream().map(x -> {
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
for (Constraint<UnifyPair> y : x) {
|
for (Constraint<UnifyPair> y : x) {
|
||||||
ret.add(new HashSet<>(y));
|
ret.add(new HashSet<>(y));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
||||||
usedTasks);
|
usedTasks);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -443,26 +545,28 @@ public class JavaTXCompiler {
|
|||||||
return urm;
|
return urm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
public List<ResultSet> typeInference() 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 (SourceFile sf : this.sourceFiles.values()) {
|
for (File f : this.sourceFiles.keySet()) {
|
||||||
|
SourceFile sf = sourceFiles.get(f);
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
allClasses.addAll(sf.getClasses());
|
allClasses.addAll(sf.getClasses());
|
||||||
|
allClasses.addAll(CompilationEnvironment.loadDefaultPackageClasses(f,classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Writer logFile = // new OutputStreamWriter(new NullOutputStream());
|
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||||
// new FileWriter(new
|
// new FileWriter(new
|
||||||
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
||||||
+ sourceFiles.keySet().iterator().next().getName()));
|
+ sourceFiles.keySet().iterator().next().getName()));
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
System.out.println("xxx1");
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
||||||
UnifyType lhs, rhs;
|
UnifyType lhs, rhs;
|
||||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
||||||
@ -474,7 +578,9 @@ public class JavaTXCompiler {
|
|||||||
return x;
|
return x;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
logFile.write("Unify:" + unifyCons.toString());
|
logFile.write("Unify:" + unifyCons.toString());
|
||||||
|
System.out.println("Unify:" + unifyCons.toString());
|
||||||
unifyCons = unifyCons.map(distributeInnerVars);
|
unifyCons = unifyCons.map(distributeInnerVars);
|
||||||
logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
||||||
TypeUnify unify = new TypeUnify();
|
TypeUnify unify = new TypeUnify();
|
||||||
@ -482,6 +588,7 @@ public class JavaTXCompiler {
|
|||||||
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
||||||
for (SourceFile sf : this.sourceFiles.values()) {
|
for (SourceFile sf : this.sourceFiles.values()) {
|
||||||
logFile.write(ASTTypePrinter.print(sf));
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
}
|
}
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
@ -570,6 +677,23 @@ public class JavaTXCompiler {
|
|||||||
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
||||||
// JEWEILS ANDERE SEITE
|
// JEWEILS ANDERE SEITE
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//PL 2020-02-05 alle Oder-Constraints Receiver und Parameter werden auf variance 1 gesetzt
|
||||||
|
//Es wird davon ausgegangen, dass in OderConstraints in Bedingungen für Parameter die Typen der Argumente links stehen
|
||||||
|
//und die Typen der Rückgabewerte immer rechts stehen
|
||||||
|
|
||||||
|
/*
|
||||||
|
unifyCons.getOderConstraints().forEach(z -> z.forEach(y -> y.forEach(x -> {
|
||||||
|
if ((x.getLhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.SMALLERDOT) == 0) {
|
||||||
|
((PlaceholderType) x.getLhsType()).setVariance((byte)1);
|
||||||
|
}
|
||||||
|
else if ((x.getRhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.EQUALSDOT) == 0) {
|
||||||
|
((PlaceholderType) x.getRhsType()).setVariance((byte)-1);
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
*/
|
||||||
|
|
||||||
|
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
@ -594,13 +718,13 @@ public class JavaTXCompiler {
|
|||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||||
// logFile, log);
|
// logFile, log);
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()//.stream().map(x -> {
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
/*Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
for (Constraint<UnifyPair> y : x) {
|
for (Constraint<UnifyPair> y : x) {
|
||||||
ret.add(new HashSet<>(y));
|
ret.add(new HashSet<>(y));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||||
if (resultmodel) {
|
if (resultmodel) {
|
||||||
/* UnifyResultModel Anfang */
|
/* UnifyResultModel Anfang */
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
@ -708,12 +832,39 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile, classLoader),
|
||||||
new GenericsRegistry(null));
|
new GenericsRegistry(null));
|
||||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
SourceFile ret = generator.convert(tree, environment.packageCrawler, classLoader);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void generateBytecodForFile(File path, HashMap<JavaClassName, byte[]> classFiles, SourceFile sf,
|
||||||
|
List<ResultSet> typeinferenceResult) throws IOException {
|
||||||
|
try {
|
||||||
|
List<GenericGenratorResultForSourceFile> genericResults = getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult, genericResults, sf,path, classLoader);
|
||||||
|
bytecodeGen.visit(sf);
|
||||||
|
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles()
|
||||||
|
throws ClassNotFoundException, IOException {
|
||||||
|
List<GenericGenratorResultForSourceFile> result = new ArrayList<>();
|
||||||
|
for (File f : sourceFiles.keySet()) {
|
||||||
|
SourceFile sf = sourceFiles.get(f);
|
||||||
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
|
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
||||||
|
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
||||||
|
result.add(simplifyResOfSF);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles(
|
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles(
|
||||||
List<ResultSet> typeinferenceResult) throws ClassNotFoundException {
|
List<ResultSet> typeinferenceResult) throws ClassNotFoundException {
|
||||||
List<GenericGenratorResultForSourceFile> result = new ArrayList<>();
|
List<GenericGenratorResultForSourceFile> result = new ArrayList<>();
|
||||||
@ -726,8 +877,24 @@ public class JavaTXCompiler {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// um pfad erweitern
|
public void generateBytecode() throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
|
generateBytecode((File) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path - can be null, then class file output is in the same directory as the parsed source files
|
||||||
|
*/
|
||||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
|
if(path != null)
|
||||||
|
generateBytecode(new File(path));
|
||||||
|
else
|
||||||
|
generateBytecode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path - can be null, then class file output is in the same directory as the parsed source files
|
||||||
|
*/
|
||||||
|
public void generateBytecode(File path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = getGeneratedGenericResultsForAllSourceFiles(
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = getGeneratedGenericResultsForAllSourceFiles(
|
||||||
typeinferenceResult);
|
typeinferenceResult);
|
||||||
@ -735,35 +902,91 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param path
|
* @param outputPath - can be null, then class file output is in the same directory as the parsed source files
|
||||||
* @param typeinferenceResult
|
* @param typeinferenceResult
|
||||||
* @param simplifyResultsForAllSourceFiles
|
* @param simplifyResultsForAllSourceFiles
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void generateBytecode(String path, List<ResultSet> typeinferenceResult,
|
public void generateBytecode(File outputPath, List<ResultSet> typeinferenceResult,
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles) throws IOException {
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles) throws IOException {
|
||||||
for (File f : sourceFiles.keySet()) {
|
for (File f : sourceFiles.keySet()) {
|
||||||
HashMap<String, byte[]> classFiles = new HashMap<>();
|
HashMap<JavaClassName, byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
|
File path;
|
||||||
|
if(outputPath == null){
|
||||||
|
path = f.getParentFile(); //Set path to path of the parsed .jav file
|
||||||
|
}else{
|
||||||
|
path = new File(outputPath ,sf.getPkgName().replace(".","/")); //add package path to root path
|
||||||
|
}
|
||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles,
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles,
|
||||||
sf, path);
|
sf, path, classLoader);
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
writeClassFile(bytecodeGen.getClassFiles(), path);
|
writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeClassFile(HashMap<String, byte[]> classFiles, String path) throws IOException {
|
private void writeClassFile(HashMap<JavaClassName, byte[]> classFiles, File path) throws IOException {
|
||||||
FileOutputStream output;
|
FileOutputStream output;
|
||||||
for (String name : classFiles.keySet()) {
|
for (JavaClassName name : classFiles.keySet()) {
|
||||||
byte[] bytecode = classFiles.get(name);
|
byte[] bytecode = classFiles.get(name);
|
||||||
System.out.println("generating " + name + ".class file ...");
|
System.out.println("generating " + name + ".class file ...");
|
||||||
// output = new FileOutputStream(new File(System.getProperty("user.dir") +
|
// output = new FileOutputStream(new File(System.getProperty("user.dir") +
|
||||||
// "/testBytecode/generatedBC/" +name+".class"));
|
// "/testBytecode/generatedBC/" +name+".class"));
|
||||||
output = new FileOutputStream(new File(path + name + ".class"));
|
File outputFile = new File(path, name.getClassName() + ".class");
|
||||||
|
outputFile.getAbsoluteFile().getParentFile().mkdirs();
|
||||||
|
output = new FileOutputStream(outputFile);
|
||||||
output.write(bytecode);
|
output.write(bytecode);
|
||||||
output.close();
|
output.close();
|
||||||
System.out.println(name + ".class file generated");
|
System.out.println(name + ".class file generated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */
|
||||||
|
/**
|
||||||
|
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
|
||||||
|
*/
|
||||||
|
private static class TypeExchanger implements TypeVisitor<RefTypeOrTPHOrWildcardOrGeneric>{
|
||||||
|
|
||||||
|
private final HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs;
|
||||||
|
|
||||||
|
TypeExchanger(HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs){
|
||||||
|
this.gtvs = gtvs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
|
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||||
|
params.add(param.acceptTV(this));
|
||||||
|
}
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
|
||||||
|
SuperWildcardType ret = new SuperWildcardType(superWildcardType.getInnerType().acceptTV(this), superWildcardType.getOffset());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
||||||
|
return typePlaceholder; //TypePlaceholder der vererbert wird kann bei der Vererbung nicht instanziert werden.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
ExtendsWildcardType ret = new ExtendsWildcardType(extendsWildcardType.getInnerType().acceptTV(this), extendsWildcardType.getOffset());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
|
||||||
|
if(! gtvs.containsKey(genericRefType.getParsedName()))
|
||||||
|
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||||
|
return gtvs.get(genericRefType.getParsedName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,12 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import org.reflections.Reflections;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
import org.reflections.scanners.ResourcesScanner;
|
|
||||||
import org.reflections.scanners.SubTypesScanner;
|
|
||||||
import org.reflections.util.ClasspathHelper;
|
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
|
||||||
import org.reflections.util.FilterBuilder;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
@ -49,8 +43,7 @@ public class CompilationEnvironment {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//String bootClassPath = System.getProperty("sun.boot.class.path");
|
//String bootClassPath = System.getProperty("sun.boot.class.path");
|
||||||
// ClassLoader cl = ClassLoader.getPlatformClassLoader();
|
// DirectoryClassLoader cl = DirectoryClassLoader.getPlatformClassLoader();
|
||||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
|
||||||
String bootClassPath = System.getProperty("java.class.path");
|
String bootClassPath = System.getProperty("java.class.path");
|
||||||
librarys = new ArrayList<>();
|
librarys = new ArrayList<>();
|
||||||
for(String path : bootClassPath.split(File.pathSeparator)) {
|
for(String path : bootClassPath.split(File.pathSeparator)) {
|
||||||
@ -67,13 +60,44 @@ public class CompilationEnvironment {
|
|||||||
this.packageCrawler = new PackageCrawler(librarys);
|
this.packageCrawler = new PackageCrawler(librarys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException {
|
public JavaClassRegistry getRegistry(File forSourceFile, ClassLoader classLoader) throws ClassNotFoundException, IOException {
|
||||||
Map<String, Integer> allNames;
|
Map<String, Integer> allNames;
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
||||||
allNames = GatherNames.getNames(tree, packageCrawler);
|
allNames = GatherNames.getNames(tree, packageCrawler, classLoader);
|
||||||
|
for(Class c : loadDefaultPackageClasses(forSourceFile, classLoader)){
|
||||||
|
allNames.put(c.getName(), c.getTypeParameters().length);
|
||||||
|
}
|
||||||
return new JavaClassRegistry(allNames);
|
return new JavaClassRegistry(allNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Class> loadDefaultPackageClasses(File forSourceFile, ClassLoader classLoader) throws IOException, ClassNotFoundException {
|
||||||
|
List<Class> ret = new ArrayList<>();
|
||||||
|
String packageName = getPackageName(JavaTXParser.parse(forSourceFile));
|
||||||
|
//Set classLoader to include default package for this specific source file
|
||||||
|
File dir = new File(forSourceFile.getAbsoluteFile().getParent());
|
||||||
|
String dirPath = dir.toString() + "/";
|
||||||
|
if(packageName.length()>0)dirPath = dirPath.substring(0,dirPath.length() - packageName.length());
|
||||||
|
String path = dirPath;
|
||||||
|
ArrayList<File> defaultPath = Lists.newArrayList(new File(path));
|
||||||
|
classLoader = new DirectoryClassLoader(defaultPath, classLoader);
|
||||||
|
//Gather all names in the default package for this source file (classes that are imported by default)
|
||||||
|
File [] files = dir.listFiles((dir1, name) -> name.endsWith(".class"));
|
||||||
|
if(files != null)for (File classFile : files) {
|
||||||
|
String className = classFile.getName().substring(0,classFile.getName().length()-6);
|
||||||
|
ret.add(classLoader.loadClass(packageName + className));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPackageName(CompilationUnitContext forTree){
|
||||||
|
String packageName = "";
|
||||||
|
if(forTree.packageDeclaration() != null && forTree.packageDeclaration().Identifier() != null)
|
||||||
|
for(TerminalNode subPackage : forTree.packageDeclaration().Identifier()){
|
||||||
|
packageName += subPackage.toString() + ".";
|
||||||
|
}
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ClassOrInterface> getAllAvailableClasses() {
|
public List<ClassOrInterface> getAllAvailableClasses() {
|
||||||
List<ClassOrInterface> ret = new ArrayList<>();
|
List<ClassOrInterface> ret = new ArrayList<>();
|
||||||
for(Class c : new PackageCrawler(librarys).getAllAvailableClasses()){
|
for(Class c : new PackageCrawler(librarys).getAllAvailableClasses()){
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package de.dhbwstuttgart.environment;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DirectoryClassLoader extends URLClassLoader {
|
||||||
|
public DirectoryClassLoader(File directory, java.lang.ClassLoader parent) {
|
||||||
|
super(generateURLArray(dirToURL(directory)), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectoryClassLoader(List<File> directory, java.lang.ClassLoader parent) {
|
||||||
|
super(directory.stream().map(DirectoryClassLoader::dirToURL).collect(Collectors.toList()).toArray(new URL[0]), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static URL[] generateURLArray(URL url) {
|
||||||
|
return new URL[]{url};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static URL dirToURL(File url){
|
||||||
|
if(!url.isDirectory())throw new RuntimeException(url.toString() + " is not a directory");
|
||||||
|
try {
|
||||||
|
return url.toURI().toURL();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,11 +26,11 @@ public class PackageCrawler {
|
|||||||
|
|
||||||
public Set<Class<?>> getClassesInPackage(String packageName){
|
public Set<Class<?>> getClassesInPackage(String packageName){
|
||||||
/*
|
/*
|
||||||
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
|
List<DirectoryClassLoader> classLoadersList = new LinkedList<DirectoryClassLoader>();
|
||||||
classLoadersList.add(Thread.currentThread().getContextClassLoader());
|
classLoadersList.add(Thread.currentThread().getContextClassLoader());
|
||||||
classLoadersList.add(ClasspathHelper.staticClassLoader());
|
classLoadersList.add(ClasspathHelper.staticClassLoader());
|
||||||
classLoadersList.add(Thread.currentThread().getContextClassLoader().getParent());
|
classLoadersList.add(Thread.currentThread().getContextClassLoader().getParent());
|
||||||
classLoadersList.add(ClassLoader.getSystemClassLoader());
|
classLoadersList.add(DirectoryClassLoader.getSystemClassLoader());
|
||||||
String bootClassPath = System.getProperty("sun.boot.class.path");
|
String bootClassPath = System.getProperty("sun.boot.class.path");
|
||||||
ArrayList<URL> urlList = new ArrayList<>();
|
ArrayList<URL> urlList = new ArrayList<>();
|
||||||
for(String path : bootClassPath.split(";")) {
|
for(String path : bootClassPath.split(";")) {
|
||||||
@ -41,7 +41,7 @@ public class PackageCrawler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
URL[] urls = urlList.toArray(new URL[0]);
|
URL[] urls = urlList.toArray(new URL[0]);
|
||||||
classLoadersList.add(new URLClassLoader(urls, ClassLoader.getSystemClassLoader()));
|
classLoadersList.add(new URLClassLoader(urls, DirectoryClassLoader.getSystemClassLoader()));
|
||||||
*/
|
*/
|
||||||
Reflections reflections = new Reflections(new ConfigurationBuilder()
|
Reflections reflections = new Reflections(new ConfigurationBuilder()
|
||||||
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
|
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
|
||||||
|
@ -22,16 +22,16 @@ public class FCGenerator {
|
|||||||
*
|
*
|
||||||
* @param availableClasses - Alle geparsten Klassen
|
* @param availableClasses - Alle geparsten Klassen
|
||||||
*/
|
*/
|
||||||
public static Set<UnifyPair> toUnifyFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
public static Set<UnifyPair> toUnifyFC(Collection<ClassOrInterface> availableClasses, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
return toFC(availableClasses).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
|
return toFC(availableClasses, classLoader).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
HashSet<Pair> pairs = new HashSet<>();
|
HashSet<Pair> pairs = new HashSet<>();
|
||||||
//PL 2018-09-18: gtvs vor die for-Schleife gezogen, damit immer die gleichen Typeplaceholder eingesetzt werden.
|
//PL 2018-09-18: gtvs vor die for-Schleife gezogen, damit immer die gleichen Typeplaceholder eingesetzt werden.
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
||||||
for(ClassOrInterface cly : availableClasses){
|
for(ClassOrInterface cly : availableClasses){
|
||||||
pairs.addAll(getSuperTypes(cly, availableClasses, gtvs));
|
pairs.addAll(getSuperTypes(cly, availableClasses, gtvs, classLoader));
|
||||||
}
|
}
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ public class FCGenerator {
|
|||||||
* @param forType
|
* @param forType
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
return getSuperTypes(forType, availableClasses, new HashMap<>());
|
return getSuperTypes(forType, availableClasses, new HashMap<>(), classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +61,7 @@ public class FCGenerator {
|
|||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses,
|
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses,
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) throws ClassNotFoundException {
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
//Die GTVs, die in forType hinzukommen:
|
//Die GTVs, die in forType hinzukommen:
|
||||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> newGTVs = new HashMap<>();
|
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> newGTVs = new HashMap<>();
|
||||||
@ -86,7 +86,7 @@ public class FCGenerator {
|
|||||||
ClassOrInterface superClass;
|
ClassOrInterface superClass;
|
||||||
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
|
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
|
||||||
{
|
{
|
||||||
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(superType.getName().toString()));
|
superClass = ASTFactory.createClass(classLoader.loadClass(superType.getName().toString()));
|
||||||
}else{
|
}else{
|
||||||
superClass = hasSuperclass.get();
|
superClass = hasSuperclass.get();
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ public class FCGenerator {
|
|||||||
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
|
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
|
||||||
superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER));
|
superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER));
|
||||||
}else{
|
}else{
|
||||||
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
|
superTypes = getSuperTypes(superClass, availableClasses, newGTVs, classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
retList.add(ret);
|
retList.add(ret);
|
||||||
|
@ -17,6 +17,7 @@ import org.antlr.v4.runtime.Token;
|
|||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StatementGenerator {
|
public class StatementGenerator {
|
||||||
|
|
||||||
@ -209,7 +210,12 @@ public class StatementGenerator {
|
|||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
|
|
||||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
||||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream()
|
||||||
|
.map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart()))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||||
|
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||||
|
argTypes, methodInvocationContext.getStart());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,9 +285,24 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Statement convert(Java8Parser.ClassInstanceCreationExpressionContext stmt) {
|
private Statement convert(Java8Parser.ClassInstanceCreationExpressionContext newExpression) {
|
||||||
//TODO
|
Java8Parser.TypeArgumentsContext genericArgs = null;
|
||||||
throw new NotImplementedException();
|
if(newExpression.expressionName()!= null)throw new NotImplementedException();
|
||||||
|
if(newExpression.typeArgumentsOrDiamond()!= null){
|
||||||
|
if(newExpression.typeArgumentsOrDiamond().typeArguments()!=null){
|
||||||
|
genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(newExpression.typeArguments()!= null)throw new NotImplementedException();
|
||||||
|
|
||||||
|
TerminalNode identifier = newExpression.Identifier(0);
|
||||||
|
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
||||||
|
|
||||||
|
ArgumentList args = convert(newExpression.argumentList());
|
||||||
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
||||||
|
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
return new NewClass(newClass, args, null, argTypes, newExpression.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||||
@ -767,10 +788,14 @@ public class StatementGenerator {
|
|||||||
}else {
|
}else {
|
||||||
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
|
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
|
||||||
String methodName = ctxt.Identifier().toString();
|
String methodName = ctxt.Identifier().toString();
|
||||||
return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName, convert(ctxt.argumentList()), e.getStart());
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = ctxt.argumentList().expression().stream()
|
||||||
|
.map(x -> TypePlaceholder.fresh(e.getStart()))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName,
|
||||||
|
convert(ctxt.argumentList()), TypePlaceholder.fresh(e.getStart()), argTypes, e.getStart());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) {
|
private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -821,7 +846,10 @@ public class StatementGenerator {
|
|||||||
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
||||||
|
|
||||||
ArgumentList args = convert(newExpression.argumentList());
|
ArgumentList args = convert(newExpression.argumentList());
|
||||||
return new NewClass(newClass, args, newExpression.getStart());
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
||||||
|
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
return new NewClass(newClass, args, null, argTypes, newExpression.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java8Parser.LiteralContext literal) {
|
private Expression convert(Java8Parser.LiteralContext literal) {
|
||||||
@ -879,7 +907,12 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
||||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream()
|
||||||
|
.map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart()))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||||
|
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||||
|
argTypes, methodInvocationContext.getStart());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.net.URL;
|
||||||
import java.sql.Ref;
|
import java.sql.Ref;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -74,10 +75,10 @@ public class SyntaxTreeGenerator{
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler) throws ClassNotFoundException{
|
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler, ClassLoader classLoader) throws ClassNotFoundException{
|
||||||
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
|
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
|
||||||
List<ClassOrInterface> classes = new ArrayList<>();
|
List<ClassOrInterface> classes = new ArrayList<>();
|
||||||
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler);
|
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler, classLoader);
|
||||||
this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet());
|
this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet());
|
||||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||||
ClassOrInterface newClass;
|
ClassOrInterface newClass;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package de.dhbwstuttgart.parser.scope;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.net.URLClassLoader;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8BaseListener;
|
import de.dhbwstuttgart.parser.antlr.Java8BaseListener;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||||
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.PackageCrawler;
|
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||||
@ -15,7 +15,7 @@ import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
|||||||
|
|
||||||
public class GatherNames {
|
public class GatherNames {
|
||||||
|
|
||||||
public static Map<String, Integer> getNames(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages) throws ClassNotFoundException{
|
public static Map<String, Integer> getNames(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException{
|
||||||
Map<String, Integer> ret = new HashMap<>();
|
Map<String, Integer> ret = new HashMap<>();
|
||||||
String pkgName = getPackageName(ctx);
|
String pkgName = getPackageName(ctx);
|
||||||
String nameString = "";
|
String nameString = "";
|
||||||
@ -64,14 +64,12 @@ public class GatherNames {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.putAll(getImports(ctx, packages));
|
ret.putAll(getImports(ctx, packages, classLoader));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, Integer> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages) throws ClassNotFoundException {
|
public static Map<String, Integer> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
Map<String, Integer> ret = new HashMap<>();
|
Map<String, Integer> ret = new HashMap<>();
|
||||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
|
||||||
//ret.putAll(packages.getClassNames("java.lang"));
|
//ret.putAll(packages.getClassNames("java.lang"));
|
||||||
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
||||||
if(importDeclCtx.singleTypeImportDeclaration() != null){
|
if(importDeclCtx.singleTypeImportDeclaration() != null){
|
||||||
|
@ -84,7 +84,15 @@ public class JavaClassName {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return (packageName!=null ? packageName.toString() : "") + name;
|
return (packageName!=null ? packageName.toString() + "." : "") + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return (packageName!=null ? packageName.toString() : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassName(){
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +138,9 @@ class PackageName{
|
|||||||
String ret = "";
|
String ret = "";
|
||||||
if(names == null)return "";
|
if(names == null)return "";
|
||||||
for(String n : names)ret+=n+".";
|
for(String n : names)ret+=n+".";
|
||||||
|
if (ret != null && ret.length() > 0 && ret.charAt(ret.length() - 1) == '.') {
|
||||||
|
ret = ret.substring(0, ret.length() - 1);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Optional;
|
|||||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
*/
|
*/
|
||||||
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||||
|
private Boolean methodAdded = false; //wird benoetigt bei in JavaTXCompiler.getConstraints()
|
||||||
protected int modifiers;
|
protected int modifiers;
|
||||||
protected JavaClassName name;
|
protected JavaClassName name;
|
||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
@ -34,6 +35,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
private List<RefType> implementedInterfaces;
|
private List<RefType> implementedInterfaces;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
|
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||||
super(offset);
|
super(offset);
|
||||||
@ -50,6 +52,33 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
this.constructors = constructors;
|
this.constructors = constructors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* erzeugt fuer Fields, Konstruktoren und Methoden neue ArrayList-Objekte
|
||||||
|
* alle anderen Datenobjekte werden nur kopiert.
|
||||||
|
*/
|
||||||
|
public ClassOrInterface(ClassOrInterface cl){
|
||||||
|
super(cl.getOffset());
|
||||||
|
this.modifiers = cl.modifiers;
|
||||||
|
this.name = cl.name;
|
||||||
|
this.fields = new ArrayList<>(cl.fields);
|
||||||
|
this.fieldInitializations= cl.fieldInitializations;
|
||||||
|
this.genericClassParameters = cl.genericClassParameters;
|
||||||
|
this.superClass = cl.superClass;
|
||||||
|
this.isInterface = cl.isInterface;
|
||||||
|
this.implementedInterfaces = cl.implementedInterfaces;
|
||||||
|
this.methods = new ArrayList<>(cl.methods);
|
||||||
|
this.constructors = new ArrayList<>(cl.constructors);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Gets if it is added
|
||||||
|
public Boolean areMethodsAdded() {
|
||||||
|
return methodAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sets that it is added
|
||||||
|
public void setMethodsAdded() {
|
||||||
|
methodAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Gets class name
|
// Gets class name
|
||||||
public JavaClassName getClassName(){
|
public JavaClassName getClassName(){
|
||||||
return this.name;
|
return this.name;
|
||||||
|
@ -27,7 +27,7 @@ public class Constructor extends Method {
|
|||||||
*/
|
*/
|
||||||
protected static Block prepareBlock(Block constructorBlock /*, List<Statement> fieldInitializations new ArrayList<>() geloescht PL 2018-11-24 */){
|
protected static Block prepareBlock(Block constructorBlock /*, List<Statement> fieldInitializations new ArrayList<>() geloescht PL 2018-11-24 */){
|
||||||
List<Statement> statements = constructorBlock.getStatements();
|
List<Statement> statements = constructorBlock.getStatements();
|
||||||
statements.add(0, new SuperCall(constructorBlock.getOffset()));
|
statements.add(0, new SuperCall(null, null, constructorBlock.getOffset()));
|
||||||
/* statements.addAll(fieldInitializations); geloescht PL 2018-11-24 */
|
/* statements.addAll(fieldInitializations); geloescht PL 2018-11-24 */
|
||||||
return new Block(statements, constructorBlock.getOffset());
|
return new Block(statements, constructorBlock.getOffset());
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
private ExceptionList exceptionlist;
|
private ExceptionList exceptionlist;
|
||||||
private GenericDeclarationList generics;
|
private GenericDeclarationList generics;
|
||||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
|
public final Boolean isInherited;
|
||||||
|
|
||||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||||
GenericDeclarationList gtvDeclarations, Token offset) {
|
GenericDeclarationList gtvDeclarations, Token offset) {
|
||||||
@ -41,6 +42,19 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
this.parameterlist = parameterList;
|
this.parameterlist = parameterList;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.generics = gtvDeclarations;
|
this.generics = gtvDeclarations;
|
||||||
|
this.isInherited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||||
|
GenericDeclarationList gtvDeclarations, Token offset, Boolean isInherited) {
|
||||||
|
super(offset);
|
||||||
|
this.name = name;
|
||||||
|
this.modifier = modifier;
|
||||||
|
this.returnType = returnType;
|
||||||
|
this.parameterlist = parameterList;
|
||||||
|
this.block = block;
|
||||||
|
this.generics = gtvDeclarations;
|
||||||
|
this.isInherited = isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterList getParameterList() {
|
public ParameterList getParameterList() {
|
||||||
|
@ -26,6 +26,13 @@ public class SourceFile extends SyntaxTreeNode{
|
|||||||
this.imports = imports;
|
this.imports = imports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SourceFile(SourceFile sf) {
|
||||||
|
super(new NullToken());
|
||||||
|
this.KlassenVektor = new ArrayList<>(sf.KlassenVektor);
|
||||||
|
this.imports = new HashSet<>(sf.imports);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getPkgName(){
|
public String getPkgName(){
|
||||||
return this.pkgName;
|
return this.pkgName;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,11 @@ package de.dhbwstuttgart.syntaxtree.factory;
|
|||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@ -35,8 +38,15 @@ public class ASTFactory {
|
|||||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||||
konstruktoren.add(createConstructor(constructor, jreClass));
|
konstruktoren.add(createConstructor(constructor, jreClass));
|
||||||
}
|
}
|
||||||
for(java.lang.reflect.Method method : jreClass.getMethods()){
|
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||||
methoden.add(createMethod(method, jreClass));
|
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||||
|
Set<java.lang.reflect.Method> allInheritedMethods = new HashSet<>(allMethods);
|
||||||
|
allInheritedMethods.removeAll(allDeclaredMethods);
|
||||||
|
for(java.lang.reflect.Method method : allDeclaredMethods){
|
||||||
|
methoden.add(createMethod(method, jreClass, false));
|
||||||
|
}
|
||||||
|
for(java.lang.reflect.Method method : allInheritedMethods){
|
||||||
|
methoden.add(createMethod(method, jreClass, true));
|
||||||
}
|
}
|
||||||
List<Field> felder = new ArrayList<>();
|
List<Field> felder = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
||||||
@ -70,7 +80,7 @@ public class ASTFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
|
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
|
||||||
return new Field(field.getName(), createType(field.getType()), field.getModifiers(), new NullToken());
|
return new Field(field.getName(), createType(field.getGenericType()), field.getModifiers(), new NullToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static RefType createType(Class classType) {
|
//private static RefType createType(Class classType) {
|
||||||
@ -102,7 +112,7 @@ public class ASTFactory {
|
|||||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){
|
||||||
String name = jreMethod.getName();
|
String name = jreMethod.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
Type jreRetType;
|
Type jreRetType;
|
||||||
@ -126,7 +136,7 @@ public class ASTFactory {
|
|||||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
||||||
Token offset = new NullToken();
|
Token offset = new NullToken();
|
||||||
|
|
||||||
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset);
|
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
||||||
@ -189,11 +199,11 @@ public class ASTFactory {
|
|||||||
|
|
||||||
public static de.dhbwstuttgart.syntaxtree.GenericTypeVar createGeneric(TypeVariable jreTypeVar, String jreTVName, Class context, String parentMethod){
|
public static de.dhbwstuttgart.syntaxtree.GenericTypeVar createGeneric(TypeVariable jreTypeVar, String jreTVName, Class context, String parentMethod){
|
||||||
JavaClassName parentClass = new JavaClassName(context.getName());
|
JavaClassName parentClass = new JavaClassName(context.getName());
|
||||||
List<RefType> genericBounds = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> genericBounds = new ArrayList<>();
|
||||||
java.lang.reflect.Type[] bounds = jreTypeVar.getBounds();
|
java.lang.reflect.Type[] bounds = jreTypeVar.getBounds();
|
||||||
if(bounds.length > 0){
|
if(bounds.length > 0){
|
||||||
for(java.lang.reflect.Type bound : bounds){
|
for(java.lang.reflect.Type bound : bounds){
|
||||||
genericBounds.add((RefType) createType(bound));
|
genericBounds.add(createType(bound));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new de.dhbwstuttgart.syntaxtree.GenericTypeVar(jreTVName, genericBounds, new NullToken(), new NullToken());
|
return new de.dhbwstuttgart.syntaxtree.GenericTypeVar(jreTVName, genericBounds, new NullToken(), new NullToken());
|
||||||
|
@ -28,7 +28,7 @@ public class UnifyTypeFactory {
|
|||||||
|
|
||||||
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
||||||
|
|
||||||
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile) throws ClassNotFoundException {
|
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile, ClassLoader classLoader) throws ClassNotFoundException {
|
||||||
/*
|
/*
|
||||||
Die transitive Hülle muss funktionieren.
|
Die transitive Hülle muss funktionieren.
|
||||||
Man darf schreiben List<A> extends AL<A>
|
Man darf schreiben List<A> extends AL<A>
|
||||||
@ -39,7 +39,7 @@ public class UnifyTypeFactory {
|
|||||||
Generell dürfen sie immer die gleichen Namen haben.
|
Generell dürfen sie immer die gleichen Namen haben.
|
||||||
TODO: die transitive Hülle bilden
|
TODO: die transitive Hülle bilden
|
||||||
*/
|
*/
|
||||||
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses), logFile);
|
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses, classLoader), logFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
|
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
|
||||||
@ -119,6 +119,7 @@ public class UnifyTypeFactory {
|
|||||||
System.out.println("XXX"+innerType);
|
System.out.println("XXX"+innerType);
|
||||||
}
|
}
|
||||||
PlaceholderType ntph = new PlaceholderType(tph.getName());
|
PlaceholderType ntph = new PlaceholderType(tph.getName());
|
||||||
|
ntph.setVariance(tph.getVariance());
|
||||||
int in = PLACEHOLDERS.indexOf(ntph);
|
int in = PLACEHOLDERS.indexOf(ntph);
|
||||||
if (in == -1) {
|
if (in == -1) {
|
||||||
PLACEHOLDERS.add(ntph);
|
PLACEHOLDERS.add(ntph);
|
||||||
@ -149,8 +150,12 @@ public class UnifyTypeFactory {
|
|||||||
return constraints.map(UnifyTypeFactory::convert);
|
return constraints.map(UnifyTypeFactory::convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NEVER USED
|
||||||
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
|
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
|
||||||
return constraint.stream().map(UnifyTypeFactory::convert).collect(Collectors.toCollection(Constraint::new));
|
Constraint<UnifyPair> unifyPairConstraint = constraint.stream()
|
||||||
|
.map(UnifyTypeFactory::convert)
|
||||||
|
.collect(Collectors.toCollection( () -> new Constraint<UnifyPair> (constraint.isInherited(), convert(constraint.getExtendConstraint()))));
|
||||||
|
return unifyPairConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair convert(Pair p) {
|
public static UnifyPair convert(Pair p) {
|
||||||
|
@ -21,13 +21,24 @@ public class MethodCall extends Statement
|
|||||||
{
|
{
|
||||||
public final String name;
|
public final String name;
|
||||||
public final Receiver receiver;
|
public final Receiver receiver;
|
||||||
|
|
||||||
public final ArgumentList arglist;
|
public final ArgumentList arglist;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* noetig fuer Bytecodegenerierung
|
||||||
|
*/
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||||
|
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
|
||||||
|
|
||||||
|
|
||||||
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, Token offset){
|
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
super(retType,offset);
|
super(retType,offset);
|
||||||
this.arglist = argumentList;
|
this.arglist = argumentList;
|
||||||
this.name = methodName;
|
this.name = methodName;
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
|
this.receiverType = receiverType;
|
||||||
|
this.argTypes = argTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,8 +29,10 @@ public class NewClass extends MethodCall
|
|||||||
* @param args Argumente mit denen der New-Call aufgerufen wurde
|
* @param args Argumente mit denen der New-Call aufgerufen wurde
|
||||||
* @param start
|
* @param start
|
||||||
*/
|
*/
|
||||||
public NewClass(RefType newClass, ArgumentList args, Token start) {
|
public NewClass(RefType newClass, ArgumentList args, RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(), args, start);
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token start) {
|
||||||
|
super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(),
|
||||||
|
args, receiverType, argTypes, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
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;
|
||||||
|
|
||||||
@ -12,12 +13,14 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class SuperCall extends MethodCall
|
public class SuperCall extends MethodCall
|
||||||
{
|
{
|
||||||
public SuperCall(Token offset){
|
public SuperCall(RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
this(new ArgumentList(new ArrayList<Expression>(), offset),offset);
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
|
this(new ArgumentList(new ArrayList<Expression>(), offset), receiverType, argTypes, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuperCall(ArgumentList argumentList, Token offset){
|
public SuperCall(ArgumentList argumentList, RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, offset);
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
|
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, receiverType, argTypes, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ public class ThisCall extends MethodCall
|
|||||||
{
|
{
|
||||||
public ThisCall(Receiver receiver, ArgumentList arglist, int offset)
|
public ThisCall(Receiver receiver, ArgumentList arglist, int offset)
|
||||||
{
|
{
|
||||||
super(null, null, null, null, null);
|
super(null, null, null, null, null, null, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,12 @@ import org.antlr.v4.runtime.Token;
|
|||||||
public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||||
{
|
{
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wird bisher nicht genutzt
|
||||||
|
* setVariance muss ggf. auskommentiert werden.
|
||||||
|
*/
|
||||||
|
int variance = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +74,16 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* wird bisher nicht genutzt
|
||||||
|
public void setVariance(int variance) {
|
||||||
|
this.variance= variance;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getVariance() {
|
||||||
|
return this.variance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
|
@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.type.*;
|
|||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class OutputGenerator implements ASTVisitor{
|
public class OutputGenerator implements ASTVisitor{
|
||||||
private static final String TAB = " ";
|
private static final String TAB = " ";
|
||||||
@ -123,6 +124,11 @@ public class OutputGenerator implements ASTVisitor{
|
|||||||
f.accept(this);
|
f.accept(this);
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
}
|
}
|
||||||
|
Optional<Constructor> fI;
|
||||||
|
if ((fI = classOrInterface.getfieldInitializations()).isPresent()) {
|
||||||
|
out.append("Initializations:");
|
||||||
|
fI.get().accept(this);
|
||||||
|
}
|
||||||
for(Method m : classOrInterface.getMethods()){
|
for(Method m : classOrInterface.getMethods()){
|
||||||
out.append(tabs);
|
out.append(tabs);
|
||||||
m.accept(this);
|
m.accept(this);
|
||||||
|
@ -65,7 +65,7 @@ public class TypeInsertFactory {
|
|||||||
/* PL 2020-04-11 auskommentiert
|
/* PL 2020-04-11 auskommentiert
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(newResults);
|
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(newResults);
|
||||||
for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
|
for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
|
||||||
GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString());
|
GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName(cl.getClassName());
|
||||||
return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet, offset), resolvedType.getResultPair());
|
return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet, offset), resolvedType.getResultPair());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public class TypeInsertPlacer extends AbstractASTWalker{
|
|||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
GenericsGeneratorResultForClass generatedGenerics = simplifyResultsForAllSourceFiles
|
GenericsGeneratorResultForClass generatedGenerics = simplifyResultsForAllSourceFiles
|
||||||
.stream()
|
.stream()
|
||||||
.map(sr->sr.getSimplifyResultsByName(pkgName, classOrInterface.getClassName().toString()))
|
.map(sr->sr.getSimplifyResultsByName(classOrInterface.getClassName()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.get();
|
.get();
|
||||||
TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults, generatedGenerics);
|
TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults, generatedGenerics);
|
||||||
|
@ -17,13 +17,15 @@ public class MethodAssumption extends Assumption{
|
|||||||
private ClassOrInterface receiver;
|
private ClassOrInterface receiver;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||||
|
private final Boolean isInherited;
|
||||||
|
|
||||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited){
|
||||||
super(scope);
|
super(scope);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.retType = retType;
|
this.retType = retType;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
|
this.isInherited = isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -70,4 +72,8 @@ public class MethodAssumption extends Assumption{
|
|||||||
|
|
||||||
return receiverType;
|
return receiverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isInherited() {
|
||||||
|
return isInherited;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,47 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Constraint<A> extends HashSet<A> {
|
public class Constraint<A> extends HashSet<A> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
|
||||||
|
private Constraint<A> extendConstraint = null;
|
||||||
|
|
||||||
|
public Constraint() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint(Boolean isInherited) {
|
||||||
|
this.isInherited = isInherited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint(Boolean isInherited, Constraint<A> extendConstraint) {
|
||||||
|
this.isInherited = isInherited;
|
||||||
|
this.extendConstraint = extendConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsInherited(Boolean isInherited) {
|
||||||
|
this.isInherited = isInherited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isInherited() {
|
||||||
|
return isInherited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Constraint<A> getExtendConstraint() {
|
||||||
|
return extendConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtendConstraint(Constraint<A> c) {
|
||||||
|
extendConstraint = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " isInherited = " + isInherited
|
||||||
|
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||||
|
+ "\n" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toStringBase() {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.BinaryOperator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -29,7 +30,10 @@ public class ConstraintSet<A> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return cartesianProduct().toString();
|
BinaryOperator<String> b = (x,y) -> x+y;
|
||||||
|
return "\nUND:" + this.undConstraints.toString() + "\n" +
|
||||||
|
"ODER:" + this.oderConstraints.stream().reduce("", (x,y) -> x.toString()+ "\n" +y, b);
|
||||||
|
//cartesianProduct().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<List<Constraint<A>>> cartesianProduct(){
|
public Set<List<Constraint<A>>> cartesianProduct(){
|
||||||
@ -41,16 +45,49 @@ public class ConstraintSet<A> {
|
|||||||
return new GuavaSetOperations().cartesianProduct(allConstraints);
|
return new GuavaSetOperations().cartesianProduct(allConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <B> ConstraintSet<B> map(Function<? super A,? extends B> o) {
|
public <B> ConstraintSet<B> map(Function<? super A, ? extends B> o) {
|
||||||
|
Hashtable<Constraint<A>,Constraint<B>> CSA2CSB = new Hashtable<>();
|
||||||
ConstraintSet<B> ret = new ConstraintSet<>();
|
ConstraintSet<B> ret = new ConstraintSet<>();
|
||||||
ret.undConstraints = undConstraints.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new));
|
ret.undConstraints = undConstraints.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new));
|
||||||
List<Set<Constraint<B>>> newOder = new ArrayList<>();
|
List<Set<Constraint<B>>> newOder = new ArrayList<>();
|
||||||
|
/*
|
||||||
|
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||||
|
oderConstraint.forEach(as -> {
|
||||||
|
Constraint<B> newConst = as.stream()
|
||||||
|
.map(o)
|
||||||
|
.collect(Collectors.toCollection(
|
||||||
|
() -> new Constraint<B> (as.isInherited())));
|
||||||
|
CSA2CSB.put(as, newConst);} );
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||||
newOder.add(
|
newOder.add(
|
||||||
oderConstraint.parallelStream().map((Constraint<A> as) ->
|
oderConstraint.parallelStream().map((Constraint<A> as) -> {
|
||||||
as.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new))).collect(Collectors.toSet())
|
|
||||||
|
Constraint<B> newConst = as.stream()
|
||||||
|
.map(o)
|
||||||
|
.collect(Collectors.toCollection((as.getExtendConstraint() != null)
|
||||||
|
? () -> new Constraint<B> (as.isInherited(),
|
||||||
|
as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new)))
|
||||||
|
: () -> new Constraint<B> (as.isInherited())
|
||||||
|
));
|
||||||
|
|
||||||
|
//CSA2CSB.put(as, newConst);
|
||||||
|
|
||||||
|
return newConst;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Constraint<B> bs = CSA2CSB.get(as);
|
||||||
|
if (as.getExtendConstraint() != null) {
|
||||||
|
bs.setExtendConstraint(CSA2CSB.get(as.getExtendConstraint()));
|
||||||
|
}
|
||||||
|
return bs;
|
||||||
|
*/
|
||||||
|
}).collect(Collectors.toSet())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.oderConstraints = newOder;
|
ret.oderConstraints = newOder;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class TYPE {
|
|||||||
/*
|
/*
|
||||||
TODO: Hier eine Information erstellen nur mit den importierte Klassen einer einzigen SourceFile
|
TODO: Hier eine Information erstellen nur mit den importierte Klassen einer einzigen SourceFile
|
||||||
private TypeInferenceInformation getTypeInferenceInformation(sourceFile) {
|
private TypeInferenceInformation getTypeInferenceInformation(sourceFile) {
|
||||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
DirectoryClassLoader classLoader = DirectoryClassLoader.getSystemClassLoader();
|
||||||
Set<ClassOrInterface> classes = new HashSet<>();
|
Set<ClassOrInterface> classes = new HashSet<>();
|
||||||
|
|
||||||
for(SourceFile sourceFile : sfs){
|
for(SourceFile sourceFile : sfs){
|
||||||
|
@ -16,7 +16,10 @@ import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
|||||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.*;
|
import de.dhbwstuttgart.typeinference.constraints.*;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
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.UnifyPair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -159,13 +162,27 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
//Es wird in OderConstraints davon ausgegangen dass die Bedingungen für die Typen der Argumente links stehen
|
||||||
|
//und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler)
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
//Overloading:
|
//Overloading:
|
||||||
Set<Constraint> methodConstraints = new HashSet<>();
|
Set<Constraint<Pair>> methodConstraints = new HashSet<>();
|
||||||
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
||||||
GenericsResolver resolver = getResolverInstance();
|
GenericsResolver resolver = getResolverInstance();
|
||||||
methodConstraints.add(generateConstraint(methodCall, m, info, resolver));
|
Constraint<Pair> oneMethodConstraint = generateConstraint(methodCall, m, info, resolver);
|
||||||
|
methodConstraints.add(oneMethodConstraint);
|
||||||
|
|
||||||
|
Constraint<Pair> extendsOneMethodConstraint = oneMethodConstraint.stream()
|
||||||
|
.map(x -> (x.TA1 instanceof TypePlaceholder &&
|
||||||
|
x.GetOperator() == PairOperator.EQUALSDOT &&
|
||||||
|
!(x.TA2 instanceof TypePlaceholder))
|
||||||
|
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||||
|
: x)
|
||||||
|
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||||
|
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||||
|
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||||
|
methodConstraints.add(extendsOneMethodConstraint);
|
||||||
}
|
}
|
||||||
if(methodConstraints.size()<1){
|
if(methodConstraints.size()<1){
|
||||||
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());
|
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());
|
||||||
@ -222,6 +239,8 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
//Es wird in OderConstraints davon ausgegangen dass die Bedingungen für die Typen der Argumente links stehen
|
||||||
|
//und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler)
|
||||||
public void visit(BinaryExpr binary) {
|
public void visit(BinaryExpr binary) {
|
||||||
binary.lexpr.accept(this);
|
binary.lexpr.accept(this);
|
||||||
binary.rexpr.accept(this);
|
binary.rexpr.accept(this);
|
||||||
@ -248,7 +267,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -256,7 +275,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -264,7 +283,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(integer, binary.getType(), PairOperator.SMALLERDOT));
|
numeric.add(new Pair(integer, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -272,7 +291,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(longg, binary.getType(), PairOperator.SMALLERDOT));
|
numeric.add(new Pair(longg, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -280,7 +299,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(floatt, binary.getType(), PairOperator.SMALLERDOT));
|
numeric.add(new Pair(floatt, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -288,7 +307,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(doublee, binary.getType(), PairOperator.SMALLERDOT));
|
numeric.add(new Pair(doublee, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
/* PL auskommentiert Anfang 2018-07-17
|
/* PL auskommentiert Anfang 2018-07-17
|
||||||
@ -362,7 +381,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
//Rückgabetyp ist Boolean
|
//Rückgabetyp ist Boolean
|
||||||
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
|
|
||||||
//auskommentiert PL 2018-05-24
|
//auskommentiert PL 2018-05-24
|
||||||
//constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
|
//constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
|
||||||
@ -374,7 +393,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
The equality operators may be used to compare two operands that are convertible (§5.1.8) to numeric type, or two operands of type boolean or Boolean, or two operands that are each of either reference type or the null type. All other cases result in a compile-time error.
|
The equality operators may be used to compare two operands that are convertible (§5.1.8) to numeric type, or two operands of type boolean or Boolean, or two operands that are each of either reference type or the null type. All other cases result in a compile-time error.
|
||||||
*/
|
*/
|
||||||
//Der Equals Operator geht mit fast allen Typen, daher werden hier keine Constraints gesetzt
|
//Der Equals Operator geht mit fast allen Typen, daher werden hier keine Constraints gesetzt
|
||||||
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
}else{
|
}else{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -555,7 +574,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
|
|
||||||
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
||||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||||
Constraint methodConstraint = new Constraint();
|
Constraint<Pair> methodConstraint = new Constraint<>(assumption.isInherited());
|
||||||
ClassOrInterface receiverCl = assumption.getReceiver();
|
ClassOrInterface receiverCl = assumption.getReceiver();
|
||||||
/*
|
/*
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
@ -569,7 +588,13 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
||||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
|
methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
|
||||||
PairOperator.SMALLERDOT));
|
PairOperator.EQUALSDOT));//PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind.
|
||||||
|
|
||||||
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||||
|
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||||
|
// PairOperator.EQUALSDOT));
|
||||||
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
|
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||||
PairOperator.EQUALSDOT));
|
PairOperator.EQUALSDOT));
|
||||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||||
@ -584,6 +609,10 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType();
|
RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
||||||
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
||||||
|
|
||||||
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||||
|
// ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
||||||
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -611,7 +640,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}));
|
}, false));
|
||||||
}
|
}
|
||||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||||
for(Method m : cl.getMethods()){
|
for(Method m : cl.getMethods()){
|
||||||
@ -620,7 +649,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
|
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
|
||||||
|
|
||||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
||||||
createTypeScope(cl, m)));
|
createTypeScope(cl, m), m.isInherited));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,7 +684,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
for(Method m : cl.getConstructors()){
|
for(Method m : cl.getConstructors()){
|
||||||
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
||||||
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
||||||
info), createTypeScope(cl, m)));
|
info), createTypeScope(cl, m), m.isInherited));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -666,8 +695,11 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
protected Constraint<Pair> generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption,
|
protected Constraint<Pair> generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption,
|
||||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||||
Constraint methodConstraint = new Constraint();
|
Constraint methodConstraint = new Constraint();
|
||||||
|
//WELCHEN SINN MACHT DIESER CONSTRAINT???
|
||||||
|
//Ist er nicht immer classname <. classname und damit redundant?
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forConstructor.getType(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forConstructor.getType(),
|
||||||
PairOperator.SMALLERDOT));
|
PairOperator.SMALLERDOT));
|
||||||
|
//WELCHEN SINN MACHT DIESER CONSTRAINT???
|
||||||
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
||||||
return methodConstraint;
|
return methodConstraint;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
|||||||
public class Match implements IMatch {
|
public class Match implements IMatch {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
//vorne muss das Pattern stehen
|
||||||
//A<X> =. A<Integer> ==> True
|
//A<X> =. A<Integer> ==> True
|
||||||
//A<Integer> =. A<X> ==> False
|
//A<Integer> =. A<X> ==> False
|
||||||
public Optional<Unifier> match(ArrayList<UnifyPair> termsList) {
|
public Optional<Unifier> match(ArrayList<UnifyPair> termsList) {
|
||||||
|
@ -26,11 +26,15 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
|||||||
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.model.WildcardType;
|
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the type inference rules.
|
* Implementation of the type inference rules.
|
||||||
@ -43,6 +47,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
public RuleSet() {
|
public RuleSet() {
|
||||||
super();
|
super();
|
||||||
|
logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleSet(Writer logFile) {
|
RuleSet(Writer logFile) {
|
||||||
@ -627,7 +632,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Set<UnifyPair>>> oderConstraints) {
|
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Constraint<UnifyPair>>> oderConstraints) {
|
||||||
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
|
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
|
||||||
|
|
||||||
Stack<UnifyType> occuringTypes = new Stack<>();
|
Stack<UnifyType> occuringTypes = new Stack<>();
|
||||||
@ -674,16 +679,13 @@ public class RuleSet implements IRuleSet{
|
|||||||
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
|
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
|
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
|
||||||
Function<? super Set<UnifyPair>,? extends HashSet<UnifyPair>> applyUni = b -> b.stream().map(
|
Function<? super Constraint<UnifyPair>,? extends Constraint<UnifyPair>> applyUni = b -> b.stream().map(
|
||||||
x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new));
|
x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null)
|
||||||
List<Set<Set<UnifyPair>>> oderConstraintsRet = new ArrayList<>();
|
? () -> new Constraint<UnifyPair>(
|
||||||
for(Set<Set<UnifyPair>> oc : oderConstraints) {
|
b.isInherited(),
|
||||||
//Set<Set<UnifyPair>> ocRet = new HashSet<>();
|
b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)))
|
||||||
//for(Set<UnifyPair> cs : oc) {
|
: () -> new Constraint<UnifyPair>(b.isInherited())
|
||||||
Set<Set<UnifyPair>> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new));
|
));
|
||||||
oderConstraintsRet.add(csRet);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
|
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
|
||||||
/*
|
/*
|
||||||
oderConstraints = oderConstraints.stream().map(
|
oderConstraints = oderConstraints.stream().map(
|
||||||
|
@ -28,7 +28,7 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
@ -54,7 +54,7 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
@ -72,7 +72,7 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
@ -105,7 +105,7 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
try {
|
||||||
|
@ -18,7 +18,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> setToFlatten;
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +92,7 @@ public interface IRuleSet {
|
|||||||
* @param pairs The set of pairs where the subst rule should apply.
|
* @param pairs The set of pairs where the subst rule should apply.
|
||||||
* @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions.
|
* @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions.
|
||||||
*/
|
*/
|
||||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Set<UnifyPair>>> oderConstraints);
|
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Constraint<UnifyPair>>> oderConstraints);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the subst-Rule to a set of pairs (usually Eq').
|
* Applies the subst-Rule to a set of pairs (usually Eq').
|
||||||
|
@ -75,6 +75,17 @@ implements IFiniteClosure {
|
|||||||
|
|
||||||
// Build the transitive closure of the inheritance tree
|
// Build the transitive closure of the inheritance tree
|
||||||
for(UnifyPair pair : pairs) {
|
for(UnifyPair pair : pairs) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
logFile.write("Pair: " + pair + "\n");
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if(pair.getPairOp() != PairOperator.SMALLER)
|
if(pair.getPairOp() != PairOperator.SMALLER)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -93,13 +104,17 @@ implements IFiniteClosure {
|
|||||||
|
|
||||||
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
|
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
|
||||||
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
|
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
|
||||||
|
|
||||||
// Add edge
|
// Add edge
|
||||||
parentNode.addDescendant(childNode);
|
parentNode.addDescendant(childNode);
|
||||||
|
|
||||||
// Add edges to build the transitive closure
|
// Add edges to build the transitive closure
|
||||||
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
||||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
||||||
|
|
||||||
|
//PL eingefuegt 2020-05-07 File UnitTest InheritTest.java
|
||||||
|
this.inheritanceGraph.forEach((x,y) -> { if (y.getDescendants().contains(parentNode)) { y.addDescendant(childNode); y.addAllDescendant(childNode.getDescendants());};
|
||||||
|
if (y.getPredecessors().contains(childNode)) { y.addPredecessor(parentNode); y.addAllPredecessor(parentNode.getPredecessors());};} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the alternative representation with strings as keys
|
// Build the alternative representation with strings as keys
|
||||||
@ -655,6 +670,7 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||||
|
//try {logFile.write("left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||||
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
/*
|
/*
|
||||||
@ -711,13 +727,15 @@ implements IFiniteClosure {
|
|||||||
HashSet<UnifyPair> hs = new HashSet<>();
|
HashSet<UnifyPair> hs = new HashSet<>();
|
||||||
hs.add(up);
|
hs.add(up);
|
||||||
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||||
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
/*
|
||||||
|
//if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
{try {
|
{try {
|
||||||
logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("no LogFile");}}
|
System.err.println("no LogFile");}}
|
||||||
|
*/
|
||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
Predicate<UnifyPair> delFun = x -> !((x.getLhsType() instanceof PlaceholderType ||
|
Predicate<UnifyPair> delFun = x -> !((x.getLhsType() instanceof PlaceholderType ||
|
||||||
x.getRhsType() instanceof PlaceholderType)
|
x.getRhsType() instanceof PlaceholderType)
|
||||||
@ -732,17 +750,22 @@ implements IFiniteClosure {
|
|||||||
hs = new HashSet<>();
|
hs = new HashSet<>();
|
||||||
hs.add(up);
|
hs.add(up);
|
||||||
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||||
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
/*
|
||||||
|
//if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
{try {
|
{try {
|
||||||
logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("no LogFile");}}
|
System.err.println("no LogFile");}}
|
||||||
|
*/
|
||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
long greaterLen = greaterRes.stream().filter(delFun).count();
|
long greaterLen = greaterRes.stream().filter(delFun).count();
|
||||||
if (greaterLen == 0) return 1;
|
if (greaterLen == 0) return 1;
|
||||||
else return 0;
|
else {
|
||||||
|
//try {logFile.write("0 left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,15 @@ class Node<T> {
|
|||||||
descendant.addPredecessor(this);
|
descendant.addPredecessor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds some directed edges from this node to the descendant (this -> descendant)
|
||||||
|
*/
|
||||||
|
public void addAllDescendant(Set<Node<T>> allDescendants) {
|
||||||
|
for(Node<T> descendant: allDescendants) {
|
||||||
|
addDescendant(descendant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||||
*/
|
*/
|
||||||
@ -56,6 +65,15 @@ class Node<T> {
|
|||||||
predecessor.addDescendant(this);
|
predecessor.addDescendant(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds some directed edges from the predecessor to this node (predecessor -> this)
|
||||||
|
*/
|
||||||
|
public void addAllPredecessor(Set<Node<T>> allPredecessors) {
|
||||||
|
for(Node<T> predecessor: allPredecessors) {
|
||||||
|
addPredecessor(predecessor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content of this node.
|
* The content of this node.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public abstract class OrderingExtend<T> extends com.google.common.collect.Ordering<T> {
|
||||||
|
|
||||||
|
public List<T> maxElements(Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
while (iterable.iterator().hasNext()) {
|
||||||
|
Set<T> believe = new HashSet<>();
|
||||||
|
|
||||||
|
T max = max(iterable);
|
||||||
|
ret.add(max);
|
||||||
|
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T elem = it.next();
|
||||||
|
if (!(compare(max, elem) == 1) && !max.equals(elem)) {
|
||||||
|
believe.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iterable = believe;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> minElements(Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
while (iterable.iterator().hasNext()) {
|
||||||
|
Set<T> believe = new HashSet<>();
|
||||||
|
|
||||||
|
T min = min(iterable);
|
||||||
|
ret.add(min);
|
||||||
|
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T elem = it.next();
|
||||||
|
if (!(compare(min, elem) == -1) && !min.equals(elem)) {
|
||||||
|
believe.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iterable = believe;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<T> smallerEqThan(T elem, Iterable<T> iterable) {
|
||||||
|
List<T> ret = smallerThan(elem, iterable);
|
||||||
|
ret.add(elem);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> smallerThan(T elem, Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T itElem = it.next();
|
||||||
|
if (!itElem.equals(elem) && compare(elem, itElem) == 1) {
|
||||||
|
ret.add(itElem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> greaterEqThan(T elem, Iterable<T> iterable) {
|
||||||
|
List<T> ret = greaterThan(elem, iterable);
|
||||||
|
ret.add(elem);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> greaterThan(T elem, Iterable<T> iterable) {
|
||||||
|
ArrayList<T> ret = new ArrayList<>();
|
||||||
|
Iterator<T> it = iterable.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
T itElem = it.next();
|
||||||
|
if (!itElem.equals(elem) && (compare(elem, itElem) == -1)) {
|
||||||
|
ret.add(itElem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
@ -4,22 +4,25 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.Match;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||||
|
|
||||||
protected IFiniteClosure fc;
|
protected IFiniteClosure fc;
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
}}
|
}}
|
||||||
catch (ClassCastException e) {
|
catch (ClassCastException e) {
|
||||||
try {
|
try {
|
||||||
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() +"\n\n");
|
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() + " " + left.getGroundBasePair() + "\n\n");
|
||||||
((FiniteClosure)fc).logFile.flush();
|
((FiniteClosure)fc).logFile.flush();
|
||||||
}
|
}
|
||||||
catch (IOException ie) {
|
catch (IOException ie) {
|
||||||
@ -165,16 +168,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
left.add(p4);
|
left.add(p4);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((left.size() == 1) && right.size() == 1) {
|
|
||||||
if (left.iterator().next().getLhsType().getName().equals("AFS")) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
if (((right.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)right.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object")))
|
|
||||||
||((left.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)left.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object"))))
|
|
||||||
{
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<UnifyPair> lefteq = left.stream()
|
Set<UnifyPair> lefteq = left.stream()
|
||||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
@ -202,6 +196,135 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
||||||
// System.out.print("");
|
// System.out.print("");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//ODER-CONSTRAINT
|
||||||
|
Set<UnifyPair> leftBase = left.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> rightBase = right.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
Set<UnifyPair> lefteqOder = left.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
/*try {
|
||||||
|
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("y: " + y.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("y.getLhsType() : " + y.getLhsType() .toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("y.getRhsType(): " + y.getRhsType().toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("x.getPairOp(): " + x.getPairOp().toString() +"\n\n");
|
||||||
|
}
|
||||||
|
catch (IOException ie) {
|
||||||
|
} */
|
||||||
|
return (y.getLhsType() instanceof PlaceholderType &&
|
||||||
|
!(y.getRhsType() instanceof PlaceholderType) &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> righteqOder = right.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
return (y.getLhsType() instanceof PlaceholderType &&
|
||||||
|
!(y.getRhsType() instanceof PlaceholderType) &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> lefteqRet = left.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
return (y.getRhsType() instanceof PlaceholderType &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> righteqRet = right.stream()
|
||||||
|
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||||
|
return (y.getRhsType() instanceof PlaceholderType &&
|
||||||
|
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> leftleOder = left.stream()
|
||||||
|
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> rightleOder = right.stream()
|
||||||
|
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
/*
|
||||||
|
synchronized(this) {
|
||||||
|
try {
|
||||||
|
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException ie) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Integer compareEq;
|
||||||
|
if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) {
|
||||||
|
Match m = new Match();
|
||||||
|
if ((compareEq = compareEq(lefteqOder.iterator().next().getGroundBasePair(), righteqOder.iterator().next().getGroundBasePair())) == -1) {
|
||||||
|
ArrayList<UnifyPair> matchList =
|
||||||
|
rightleOder.stream().map(x -> {
|
||||||
|
UnifyPair leftElem = leftleOder.stream()
|
||||||
|
.filter(y -> y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
|
||||||
|
.findAny().get();
|
||||||
|
return new UnifyPair(x.getRhsType(), leftElem.getRhsType(), PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
if (m.match(matchList).isPresent()) {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result1: -1 \n\n"); } catch (IOException ie) {}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result1: 0 \n\n"); } catch (IOException ie) {}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else if (compareEq == 1) {
|
||||||
|
ArrayList<UnifyPair> matchList =
|
||||||
|
leftleOder.stream().map(x -> {
|
||||||
|
UnifyPair rightElem = rightleOder.stream()
|
||||||
|
.filter(y ->
|
||||||
|
y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
|
||||||
|
.findAny().get();
|
||||||
|
return new UnifyPair(x.getRhsType(), rightElem.getRhsType(), PairOperator.EQUALSDOT);})
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
if (m.match(matchList).isPresent()) {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result2: 1 \n\n"); } catch (IOException ie) {}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//try { ((FiniteClosure)fc).logFile.write("result2: 0 \n\n"); } catch (IOException ie) {}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
synchronized(this) {
|
||||||
|
try {
|
||||||
|
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
|
||||||
|
((FiniteClosure)fc).logFile.write("result3: 0 \n\n");
|
||||||
|
((FiniteClosure)fc).logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException ie) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -293,24 +416,25 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
} else {
|
} else {
|
||||||
if (leftlewc.size() > 0) {
|
if (leftlewc.size() > 0) {
|
||||||
Set<UnifyPair> subst;
|
Set<UnifyPair> subst;
|
||||||
if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
subst = leftlewc.stream().map(x -> {
|
||||||
subst = leftlewc.stream().map(x -> new UnifyPair(x.getLhsType(), x.getRhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new));
|
if (x.getLhsType() instanceof PlaceholderType) {
|
||||||
}
|
return new UnifyPair(x.getLhsType(), x.getRhsType(), PairOperator.EQUALSDOT);
|
||||||
else {
|
}
|
||||||
subst = leftlewc.stream().map(x -> new UnifyPair(x.getRhsType(), x.getLhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new));
|
else {
|
||||||
}
|
return new UnifyPair(x.getRhsType(), x.getLhsType(), PairOperator.EQUALSDOT);
|
||||||
|
}}).collect(Collectors.toCollection(HashSet::new));
|
||||||
Unifier uni = new Unifier();
|
Unifier uni = new Unifier();
|
||||||
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
|
||||||
lseq = uni.apply(lseq);
|
lseq = uni.apply(lseq);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<UnifyPair> subst;
|
Set<UnifyPair> subst;
|
||||||
if (rightlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
subst = rightlewc.stream().map(x -> {
|
||||||
subst = rightlewc.stream().map(x -> new UnifyPair(x.getLhsType(), x.getRhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new));
|
if (x.getLhsType() instanceof PlaceholderType) {
|
||||||
}
|
return new UnifyPair(x.getLhsType(), x.getRhsType(), PairOperator.EQUALSDOT);
|
||||||
else {
|
}
|
||||||
subst = rightlewc.stream().map(x -> new UnifyPair(x.getRhsType(), x.getLhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new));
|
else {
|
||||||
}
|
return new UnifyPair(x.getRhsType(), x.getLhsType(), PairOperator.EQUALSDOT);
|
||||||
|
}}).collect(Collectors.toCollection(HashSet::new));
|
||||||
Unifier uni = new Unifier();
|
Unifier uni = new Unifier();
|
||||||
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
||||||
rseq = uni.apply(rseq);
|
rseq = uni.apply(rseq);
|
||||||
|
@ -28,15 +28,6 @@ public class UnifyPair {
|
|||||||
* The operator that determines the relation between the left and right hand side type.
|
* The operator that determines the relation between the left and right hand side type.
|
||||||
*/
|
*/
|
||||||
private PairOperator pairOp;
|
private PairOperator pairOp;
|
||||||
|
|
||||||
/** wieder loesecn wird nicht mehr benoetigt PL 2018-03-31
|
|
||||||
* variance shows the variance of the pair
|
|
||||||
* -1: contravariant
|
|
||||||
* 1 covariant
|
|
||||||
* 0 invariant
|
|
||||||
* PL 2018-03-21
|
|
||||||
*/
|
|
||||||
private byte variance = 0;
|
|
||||||
|
|
||||||
private boolean undefinedPair = false;
|
private boolean undefinedPair = false;
|
||||||
|
|
||||||
@ -83,7 +74,6 @@ public class UnifyPair {
|
|||||||
pairOp = op;
|
pairOp = op;
|
||||||
substitution = uni;
|
substitution = uni;
|
||||||
basePair = base;
|
basePair = base;
|
||||||
this.variance = variance;
|
|
||||||
|
|
||||||
|
|
||||||
// Caching hashcode
|
// Caching hashcode
|
||||||
@ -125,14 +115,6 @@ public class UnifyPair {
|
|||||||
substitution.addAll(sup);
|
substitution.addAll(sup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getVariance() {
|
|
||||||
return variance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariance(byte v) {
|
|
||||||
variance = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUndefinedPair() {
|
public void setUndefinedPair() {
|
||||||
undefinedPair = true;
|
undefinedPair = true;
|
||||||
}
|
}
|
||||||
@ -156,6 +138,11 @@ public class UnifyPair {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<UnifyPair> getThisAndAllBases () {
|
||||||
|
Set<UnifyPair> ret = getAllBases();
|
||||||
|
ret.add(this);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
public Set<UnifyPair> getAllBases () {
|
public Set<UnifyPair> getAllBases () {
|
||||||
Set<UnifyPair> ret = new HashSet<>();
|
Set<UnifyPair> ret = new HashSet<>();
|
||||||
if (basePair != null) {
|
if (basePair != null) {
|
||||||
@ -213,11 +200,13 @@ public class UnifyPair {
|
|||||||
if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) {
|
if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!other.getBasePair().equals(basePair) ||
|
if (!other.getBasePair().equals(basePair) ||
|
||||||
!other.getAllSubstitutions().equals(getAllSubstitutions())) {
|
!other.getAllSubstitutions().equals(getAllSubstitutions())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return other.getPairOp() == pairOp
|
return other.getPairOp() == pairOp
|
||||||
&& other.getLhsType().equals(lhs)
|
&& other.getLhsType().equals(lhs)
|
||||||
@ -233,12 +222,14 @@ public class UnifyPair {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (lhs instanceof PlaceholderType) {
|
if (lhs instanceof PlaceholderType) {
|
||||||
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType()
|
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " "
|
||||||
+ " " + ((PlaceholderType)lhs).isWildcardable();
|
+ "WC: " + ((PlaceholderType)lhs).isWildcardable()
|
||||||
|
+ ", IT: " + ((PlaceholderType)lhs).isInnerType();
|
||||||
}
|
}
|
||||||
if (rhs instanceof PlaceholderType) {
|
if (rhs instanceof PlaceholderType) {
|
||||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType()
|
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " "
|
||||||
+ " " + ((PlaceholderType)rhs).isWildcardable();
|
+ "WC: " + ((PlaceholderType)rhs).isWildcardable()
|
||||||
|
+ ", IT: " + ((PlaceholderType)rhs).isInnerType();
|
||||||
}
|
}
|
||||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
||||||
}
|
}
|
||||||
|
63
src/test/java/AllgemeinTest.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class AllgemeinTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
//String className = "GenTest";
|
||||||
|
//String className = "Overloading_Generics";
|
||||||
|
//String className = "Generics";
|
||||||
|
//String className = "OverloadingMain";
|
||||||
|
//String className = "OverrideMain";
|
||||||
|
//String className = "OverrideMainRet";
|
||||||
|
//String className = "FCTest1";
|
||||||
|
//String className = "FCTest2";
|
||||||
|
//String className = "Pair";
|
||||||
|
//String className = "FCTest3";
|
||||||
|
//String className = "Var";
|
||||||
|
String className = "Put";
|
||||||
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||||
|
//compiler = new JavaTXCompiler(Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav")));
|
||||||
|
///*
|
||||||
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(path)),
|
||||||
|
Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/")));
|
||||||
|
//*/
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass(className);
|
||||||
|
//classToTest = loader.loadClass("Overloading_Generics");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance("A");
|
||||||
|
//classToTest = loader.loadClass("Overloading_Generics1");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("B");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
193
src/test/java/bytecode/InheritTest.java
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class InheritTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
|
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||||
|
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
|
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||||
|
private static List<ResultSet> typeinferenceResult;
|
||||||
|
private static List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTestAA = loader.loadClass("AA");
|
||||||
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestBB = loader.loadClass("BB");
|
||||||
|
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestCC = loader.loadClass("CC");
|
||||||
|
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestDD = loader.loadClass("DD");
|
||||||
|
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTest = loader.loadClass("Inherit");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInheritClassName() {
|
||||||
|
assertEquals("Inherit", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAAName() {
|
||||||
|
assertEquals("AA", classToTestAA.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBBName() {
|
||||||
|
assertEquals("BB", classToTestBB.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCCName() {
|
||||||
|
assertEquals("CC", classToTestCC.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDDName() {
|
||||||
|
assertEquals("DD", classToTestDD.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC, 5), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD, 5), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassAA);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassBB);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassCC);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassDD);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||||
|
}
|
||||||
|
}
|
211
src/test/java/bytecode/InheritTest2.java
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class InheritTest2 {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
|
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||||
|
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
|
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||||
|
private static List<ResultSet> typeinferenceResult;
|
||||||
|
private static List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTestAA = loader.loadClass("AA");
|
||||||
|
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestBB = loader.loadClass("BB");
|
||||||
|
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestCC = loader.loadClass("CC");
|
||||||
|
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTestDD = loader.loadClass("DD");
|
||||||
|
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit2.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
typeinferenceResult = compiler.typeInference();
|
||||||
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
classToTest = loader.loadClass("Inherit2");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInheritClassName() {
|
||||||
|
assertEquals("Inherit2", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAAName() {
|
||||||
|
assertEquals("AA", classToTestAA.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBBName() {
|
||||||
|
assertEquals("BB", classToTestBB.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCCName() {
|
||||||
|
assertEquals("CC", classToTestCC.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDDName() {
|
||||||
|
assertEquals("DD", classToTestDD.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB), "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||||
|
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD), "CC");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//PL 2020-05-12: Die folgenden Test funktionieren erst, wenn Generics im Bytecode implementiert sind
|
||||||
|
@Test
|
||||||
|
public void testmainVectorAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassAA);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
try {
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||||
|
}
|
||||||
|
catch (java.lang.reflect.InvocationTargetException e) {
|
||||||
|
testmainVectorCC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassBB);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
try {
|
||||||
|
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||||
|
}
|
||||||
|
catch (java.lang.reflect.InvocationTargetException e) {
|
||||||
|
testmainVectorCC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassCC);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
String erg;
|
||||||
|
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||||
|
erg.equals("CC")? "CC": "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainVectorDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||||
|
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||||
|
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||||
|
Vector v = new Vector<>();
|
||||||
|
v.add(instanceOfClassDD);
|
||||||
|
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||||
|
String erg;
|
||||||
|
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||||
|
erg.equals("CC")? "CC": "AA");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -35,7 +35,7 @@ public class OLTest {
|
|||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(pathToClassFile,typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("OL");
|
classToTest = loader.loadClass("OL");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
86
src/test/java/bytecode/PutTest.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class PutTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTest1;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClass1;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Put.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("Put");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutClassName() {
|
||||||
|
assertEquals("Put", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutElementVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
|
||||||
|
Vector<Integer> v_invoke = new Vector<>();
|
||||||
|
m.invoke(instanceOfClass, 5, v_invoke);
|
||||||
|
Vector<Integer> v = new Vector<>();
|
||||||
|
v.add(5);
|
||||||
|
assertEquals(v, v_invoke);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutElementStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Stack.class);
|
||||||
|
Stack<Integer> s_invoke = new Stack<>();
|
||||||
|
m.invoke(instanceOfClass, 5, s_invoke);
|
||||||
|
assertEquals(new Integer(5), s_invoke.pop());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMainVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("main", Object.class, Vector.class);
|
||||||
|
Vector<Integer> v_invoke = new Vector<>();
|
||||||
|
m.invoke(instanceOfClass, 6, v_invoke);
|
||||||
|
Vector<Integer> v = new Vector<>();
|
||||||
|
v.add(6);
|
||||||
|
assertEquals(v, v_invoke);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMainStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("main", Object.class, Stack.class);
|
||||||
|
Stack<Integer> s_invoke = new Stack<>();
|
||||||
|
m.invoke(instanceOfClass, 6, s_invoke);
|
||||||
|
assertEquals(new Integer(6), s_invoke.pop());
|
||||||
|
}
|
||||||
|
}
|
40
src/test/java/bytecode/mathStrucMatrixOPTest.java.txt
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class mathStrucMatrixOPTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
//PL 2019-10-24: laeuft nicht durch deshalb ersetzt
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucMatrixOp.jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("mathStrucMatrixOP");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
38
src/test/java/bytecode/mathStrucVectorAddTest.java.txt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class mathStrucVectorAddTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucVector.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("mathStrucVector");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor(Integer.class).newInstance("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,14 +14,14 @@ public class SuperInterfacesTest {
|
|||||||
public void test() throws ClassNotFoundException {
|
public void test() throws ClassNotFoundException {
|
||||||
Collection<ClassOrInterface> classes = new ArrayList<>();
|
Collection<ClassOrInterface> classes = new ArrayList<>();
|
||||||
classes.add(ASTFactory.createClass(TestClass.class));
|
classes.add(ASTFactory.createClass(TestClass.class));
|
||||||
System.out.println(FCGenerator.toFC(classes));
|
System.out.println(FCGenerator.toFC(classes, ClassLoader.getSystemClassLoader()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGeneric() throws ClassNotFoundException {
|
public void testGeneric() throws ClassNotFoundException {
|
||||||
Collection<ClassOrInterface> classes = new ArrayList<>();
|
Collection<ClassOrInterface> classes = new ArrayList<>();
|
||||||
classes.add(ASTFactory.createClass(TestClassGeneric.class));
|
classes.add(ASTFactory.createClass(TestClassGeneric.class));
|
||||||
System.out.println(FCGenerator.toFC(classes));
|
System.out.println(FCGenerator.toFC(classes, ClassLoader.getSystemClassLoader()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
52
src/test/java/packages/Bytecode.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class Bytecode extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecode() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"de/test/TestClass.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
|
||||||
|
URLClassLoader loader = new URLClassLoader(new URL[]{new URL("file://" + rootDirectory)});
|
||||||
|
Class<?> classToTest = loader.loadClass("de.test.TestClass");
|
||||||
|
Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"de/test/TestClass.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(rootDirectory + "de/test/output/");
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
URLClassLoader loader = new URLClassLoader(new URL[]{new URL("file://" + rootDirectory + "de/test/output/")});
|
||||||
|
Class<?> classToTest = loader.loadClass("de.test.TestClass");
|
||||||
|
Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
80
src/test/java/packages/CheckPackageFolder.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class CheckPackageFolder extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCorrectFolder1FileWithWrongPackageName() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTestWrongPackage.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "TestClass.class");
|
||||||
|
assertTrue(f.exists()); //Es ist erlaubt falsche package Namen zu verwenden. Warnung wäre optional
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCorrectFolder1File() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"TestClass.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "TestClass.class");
|
||||||
|
assertTrue(f.exists()); //Es ist erlaubt falsche package Namen zu verwenden. Warnung wäre optional
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCorrectFolder1FileAndOutputDirectory() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"TestClass.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "output/de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(rootDirectory+"output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists()); //Es ist erlaubt falsche package Namen zu verwenden. Warnung wäre optional
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dieser Test wird übersprungen, da der Bytecode-Generator nicht mit zwei Eingabedateien gleichzeitig umgehen kann
|
||||||
|
@Test
|
||||||
|
public void testCorrectFolder2Files() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(Arrays.asList(
|
||||||
|
new File(rootDirectory+"subpackage1/Test1.jav"),
|
||||||
|
new File(rootDirectory+"subpackage2/Test2.jav")
|
||||||
|
));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "subpackage1/Test1.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
File f2 = new File(rootDirectory + "subpackage2/Test2.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "subpackage1/Test1.class");
|
||||||
|
f2 = new File(rootDirectory + "subpackage2/Test2.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
assertTrue(f2.exists());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
133
src/test/java/packages/ConsoleInterfaceTest.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class ConsoleInterfaceTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFile() throws Exception {
|
||||||
|
File f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{rootDirectory + "de/test/TestClass.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithOutputDirectory() throws Exception {
|
||||||
|
File f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-d", rootDirectory + "de/test/output/" ,rootDirectory + "de/test/TestClass.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCpNotEndsWithSlash() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output" , rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOutputDirNotEndsWithSlash() throws Exception {
|
||||||
|
File f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-d", rootDirectory + "de/test/output" ,rootDirectory + "de/test/TestClass.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithClassPath() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/" ,rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithMultipleClassPath() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/:"+rootDirectory+"de",
|
||||||
|
rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithClassPathAndOutputDir() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/",
|
||||||
|
"-d"+rootDirectory + "de/test/output/" ,rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
108
src/test/java/packages/ImportTest.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class ImportTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
|
||||||
|
|
||||||
|
public ImportTest() throws ClassNotFoundException, IOException {
|
||||||
|
/*
|
||||||
|
Generate ToImport class in rootDirectory and in output-Directory
|
||||||
|
*/
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
compiler = new JavaTXCompiler(new File(rootDirectory+"ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
compiler = new JavaTXCompiler(new File(rootDirectory+"subpackage1/ToImport2.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/subpackage1/ToImport2.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
compiler = new JavaTXCompiler(new File(rootDirectory+"subpackage2/ToImport3.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/subpackage2/ToImport3.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecodeAndStandardOutputFolder() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportTwoClasses() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"ImportTest2.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "ImportTest2.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "ImportTest2.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportDefaultPackage() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"ImportTestDefault.jav")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "ImportTestDefault.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "ImportTestDefault.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
55
src/test/java/packages/LoadDefaultPackageClassesTest.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class LoadDefaultPackageClassesTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
|
||||||
|
|
||||||
|
public LoadDefaultPackageClassesTest() throws ClassNotFoundException, IOException {
|
||||||
|
/*
|
||||||
|
Generate ToImport class in rootDirectory and in output-Directory
|
||||||
|
*/
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"Gen.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode();
|
||||||
|
File f = new File(rootDirectory + "Gen.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLoadGenClass() throws IOException, ClassNotFoundException {
|
||||||
|
CompilationEnvironment.loadDefaultPackageClasses(new File( rootDirectory + "Test.jav"), ClassLoader.getSystemClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testURLClassLoader() throws IOException, ClassNotFoundException {
|
||||||
|
URLClassLoader cl = new URLClassLoader(new URL[]{new URL("file://"+rootDirectory)}, ClassLoader.getSystemClassLoader());
|
||||||
|
cl.loadClass("Gen");
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public void testE2E() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"OL.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode();
|
||||||
|
File f = new File(rootDirectory + "OL.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
compiler = new JavaTXCompiler(new File(rootDirectory+"OLMain.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode();
|
||||||
|
f = new File(rootDirectory + "OLMain.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
133
src/test/java/packages/OLOneFileTest.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class OLOneFileTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTest1;
|
||||||
|
private static Class<?> classToTest2;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClass1;
|
||||||
|
private static Object instanceOfClass2;
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = rootDirectory +"OLOneFile.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(fileToTest),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"de/test/output/")));
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("OLOneFile");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
classToTest1 = loader.loadClass("OLextendsOneFile");
|
||||||
|
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
classToTest2 = loader.loadClass("OLMainOneFile");
|
||||||
|
instanceOfClass2 = classToTest2.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLClassName() {
|
||||||
|
assertEquals("OLOneFile", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m2", Integer.class);
|
||||||
|
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m2", Double.class);
|
||||||
|
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m2", String.class);
|
||||||
|
String result = (String) m.invoke(instanceOfClass, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLextendsClassName() {
|
||||||
|
assertEquals("OLextendsOneFile", classToTest1.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testextendsInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getMethod("m2", Integer.class);
|
||||||
|
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testextendsDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getMethod("m2", Double.class);
|
||||||
|
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testextendsString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getMethod("m2", String.class);
|
||||||
|
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLMainClassName() {
|
||||||
|
assertEquals("OLMainOneFile", classToTest2.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", Integer.class);
|
||||||
|
Integer result = (Integer) main.invoke(instanceOfClass2, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", Double.class);
|
||||||
|
Double result = (Double) main.invoke(instanceOfClass2, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", String.class);
|
||||||
|
String result = (String) main.invoke(instanceOfClass2, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
}
|
147
src/test/java/packages/OLTest.java
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class OLTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTest1;
|
||||||
|
private static Class<?> classToTest2;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClass1;
|
||||||
|
private static Object instanceOfClass2;
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/OL.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "/de/test/output/");
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+ rootDirectory + "/de/test/output/")});
|
||||||
|
classToTest = loader.loadClass("de.test.OL");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OLextends.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/OLextends.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
|
||||||
|
//compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile), new URL("file://"+ rootDirectory + "/de/test/output/")});
|
||||||
|
classToTest1 = loader.loadClass("OLextends");
|
||||||
|
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/OLMain.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/OLMain.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
|
||||||
|
//compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile), new URL("file://"+ rootDirectory + "/de/test/output/")});
|
||||||
|
classToTest2 = loader.loadClass("OLMain");
|
||||||
|
instanceOfClass2 = classToTest2.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLClassName() {
|
||||||
|
assertEquals("de.test.OL", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||||
|
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||||
|
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", String.class);
|
||||||
|
String result = (String) m.invoke(instanceOfClass, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLextendsClassName() {
|
||||||
|
assertEquals("OLextends", classToTest1.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testextendsInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getMethod("m", Integer.class);
|
||||||
|
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testextendsDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getMethod("m", Double.class);
|
||||||
|
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testextendsString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getMethod("m", String.class);
|
||||||
|
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLMainClassName() {
|
||||||
|
assertEquals("OLMain", classToTest2.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", Integer.class);
|
||||||
|
Integer result = (Integer) main.invoke(instanceOfClass2, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", Double.class);
|
||||||
|
Double result = (Double) main.invoke(instanceOfClass2, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest2.getDeclaredMethod("main", String.class);
|
||||||
|
String result = (String) main.invoke(instanceOfClass2, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
}
|
21
src/test/java/packages/ParsePackageName.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ParsePackageName {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
@Test
|
||||||
|
public void parsePackage() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"TestClass.jav"));
|
||||||
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
|
assert sf.getPkgName().equals("de.test");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
src/test/java/packages/mathStrucMatrixOPTest.java.txt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class mathStrucMatrixOPTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
|
||||||
|
|
||||||
|
public mathStrucMatrixOPTest() throws ClassNotFoundException, IOException {
|
||||||
|
/*
|
||||||
|
Generate ToImport class in rootDirectory and in output-Directory
|
||||||
|
*/
|
||||||
|
/* PL 2020-01-07 kann z.Zt. nicht erzeugt werden (siehe Bug 170, http://bugzilla.ba-horb.de/show_bug.cgi?id=170)
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"mathStruc.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/mathStruc.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
*/
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"MatrixOP.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/MatrixOP.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"mathStrucMatrixOP.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "output/de/test/mathStrucMatrixOP.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/mathStrucMatrixOP.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
}
|
54
src/test/java/packages/mathStrucVectorTest.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class mathStrucVectorTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
|
||||||
|
|
||||||
|
public mathStrucVectorTest() throws ClassNotFoundException, IOException {
|
||||||
|
/*
|
||||||
|
Generate ToImport class in rootDirectory and in output-Directory
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* PL 2020-01-07 kann z.Zt. nicht erzeugt werden (siehe Bug 170, http://bugzilla.ba-horb.de/show_bug.cgi?id=170)
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"mathStruc.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/mathStruc.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
*/
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"vectorAdd.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/vectorAdd.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"mathStrucVector.jav")),
|
||||||
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "output/de/test/mathStrucVector.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
f = new File(rootDirectory + "output/de/test/mathStrucVector.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -29,6 +29,10 @@ public class JavaTXCompilerTest {
|
|||||||
execute(new File(rootDirectory+"fc.jav"));
|
execute(new File(rootDirectory+"fc.jav"));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
public void importTest() throws IOException, ClassNotFoundException {
|
||||||
|
execute(new File(rootDirectory+"Import.jav"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
public void lambda() throws IOException, ClassNotFoundException {
|
public void lambda() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Lambda.jav"));
|
execute(new File(rootDirectory+"Lambda.jav"));
|
||||||
}
|
}
|
||||||
|
12
src/test/resources/AllgemeinTest/FCTest1.jav
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.List;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class FCTest1 extends Vector<Vector<Integer>> {
|
||||||
|
fc1() {
|
||||||
|
var y;
|
||||||
|
var z;
|
||||||
|
y.add(z);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|