Erste Tests und die Möglichkeit generateBytecode null als Pfad zu übergeben
This commit is contained in:
parent
766e71bb3a
commit
09a6aec65d
25
doc/Generics/generics.tex
Normal file
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}
|
@ -762,7 +762,7 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param path
|
* @param path - 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
|
||||||
@ -775,7 +775,11 @@ public class JavaTXCompiler {
|
|||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles,
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles,
|
||||||
sf, path);
|
sf, path);
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
writeClassFile(bytecodeGen.getClassFiles(), path);
|
String packagePath = sf.getPkgName().replace(".","/");
|
||||||
|
if(path == null){
|
||||||
|
path = f.getPath();
|
||||||
|
}
|
||||||
|
writeClassFile(bytecodeGen.getClassFiles(), path + packagePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
src/test/java/packages/Bytecode.java
Normal file
25
src/test/java/packages/Bytecode.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Bytecode extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
@Test
|
||||||
|
public void testSetPackageNameInBytecode() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
File f = new File(rootDirectory + "Test.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
compiler.generateBytecode(null);
|
||||||
|
f = new File(rootDirectory + "Test.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
}
|
20
src/test/java/packages/CheckPackageFolder.java
Normal file
20
src/test/java/packages/CheckPackageFolder.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CheckPackageFolder extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCorrectFolder1File() throws IOException, ClassNotFoundException {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTestWrongPackage.jav"));
|
||||||
|
assertTrue(true); //Es ist erlaubt falsche package Namen zu verwenden. Warnung wäre optional
|
||||||
|
}
|
||||||
|
}
|
@ -2,33 +2,20 @@ package packages;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import typeinference.JavaTXCompilerTest;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ParsePackageName {
|
public class ParsePackageName {
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
@Test
|
@Test
|
||||||
public void parsePackage() throws IOException, ClassNotFoundException {
|
public void parsePackage() throws IOException, ClassNotFoundException {
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
|
||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
assert sf.getPkgName().equals("de.test");
|
||||||
System.out.println(ASTPrinter.print(sf));
|
|
||||||
}
|
}
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
package Test;
|
|
||||||
|
|
||||||
class TestClass{}
|
|
@ -0,0 +1,3 @@
|
|||||||
|
package de.test;
|
||||||
|
|
||||||
|
class TestClass{}
|
@ -0,0 +1,3 @@
|
|||||||
|
package de.tesst;
|
||||||
|
|
||||||
|
class TestClass{}
|
19
vorgehen.md
19
vorgehen.md
@ -9,3 +9,22 @@
|
|||||||
* macht es hier einen Unterschied?
|
* macht es hier einen Unterschied?
|
||||||
* es ändert sich nur der Namen der Typen
|
* es ändert sich nur der Namen der Typen
|
||||||
* das ist schon in JavaClassName enthalten
|
* das ist schon in JavaClassName enthalten
|
||||||
|
|
||||||
|
## Java verhalten
|
||||||
|
* das verhalten von Java soll kopiert werden
|
||||||
|
* Java kompiliert in den gleichen Ordner wie die source file
|
||||||
|
* Java erhält eine liste von Source Files, die es kompilieren soll
|
||||||
|
* anhand von deren Standort lassen sich relativ die Position von kompilierten Class-files bestimmen
|
||||||
|
|
||||||
|
* -cp path or -classpath path
|
||||||
|
Specifies where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, then the
|
||||||
|
user class path is the current directory. See Setting the Class Path.
|
||||||
|
|
||||||
|
* Compiler kontrolliert nicht, ob package im korrekten Ordner ist
|
||||||
|
* auch keine Warnung
|
||||||
|
* unser kompiler könnte aber trotzdem zumindes eine Warnung ausgeben
|
||||||
|
|
||||||
|
### -d Parameter
|
||||||
|
* Optional
|
||||||
|
* damit lässt sich ein andere ort zur Ausgabe der Class-files bestimmen
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user