Test directory cleanup

This commit is contained in:
luca9913 2023-06-21 09:37:58 +02:00
parent 78ad7bc003
commit 761dd48fa1
37 changed files with 3 additions and 1925 deletions

View File

@ -42,7 +42,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.0</version>
<version>9.5</version>
</dependency>
</dependencies>

View File

@ -1,70 +0,0 @@
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";
// String className = "Twice";
// String className = "TestSubTypless";
// String className = "addList";
// String className = "M";
// String className = "Wildcard_Andi";
// String className = "Box";
// String className = "Box_Main";
// String className = "wildcardPair";
// String className = "VectorConstAdd";
String className = "VectorNotObject";
// String className = "WildcardCaptureConversionTest";
// 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/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
// path = System.getProperty("user.dir")+"/src/test/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
// compiler = new JavaTXCompiler(Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/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");
}
}

View File

@ -1,4 +1,3 @@
package targetast;
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import org.junit.Ignore;
@ -6,10 +5,11 @@ import org.junit.Test;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.Vector;
import targetast.TestCodegen;
import static org.junit.Assert.*;
import static targetast.TestCodegen.generateClassFiles;

View File

@ -1,14 +0,0 @@
package general;
import java.io.File;
import java.io.FileFilter;
public class TestCleanUp {
public static void cleanUpDirectory(File directory, FileFilter fileFilter){
if(!directory.isDirectory()) throw new RuntimeException("Directory for bytecode generation is wrong!");
for (File file: directory.listFiles(fileFilter)) {
file.delete();
}
}
}

View File

@ -1,51 +0,0 @@
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();
}
}

View File

@ -1,62 +0,0 @@
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()); }
*/
}

View File

@ -1,131 +0,0 @@
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());
}
}

View File

@ -1,98 +0,0 @@
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());
}
}

View File

@ -1,42 +0,0 @@
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()); }
*/
}

View File

@ -1,131 +0,0 @@
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);
}
}

View File

@ -1,143 +0,0 @@
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);
}
}

View File

@ -1,22 +0,0 @@
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");
}
}
}

View File

@ -1,51 +0,0 @@
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());
}
}

View File

@ -1,46 +0,0 @@
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());
}
}

View File

@ -1,8 +0,0 @@
import java.lang.Boolean;
class Test{
method(){
if(true)i++;
if(true)i--;
else i++;
}}

View File

@ -1,3 +0,0 @@
class Matrix{
<A extends B, C extends B> String op = "String";
}

View File

@ -1,10 +0,0 @@
import java.lang.Object;
import java.lang.String;
class CastTest{
void methode(){
Object a;
String b;
a = (Object) b;
}
}

View File

@ -1,6 +0,0 @@
import java.lang.Object;
class C1 extends Object
{
m(para) { return para; }
}

View File

@ -1,11 +0,0 @@
class FeatherWeightJava {
mt4(a,b,c) { return a.add(b).sub(c) ; }
mt1(a) {return a; }
mt2(a) {return a.f; }
mt3(a) {return a.add(); }
}

View File

@ -1,8 +0,0 @@
import java.lang.String;
class FieldInitializationTest{
f;
void m(){
var var = "hallo";
}
}

View File

@ -1,5 +0,0 @@
package parser;
class Test<Typ>{
Typ a;
}

View File

@ -1,62 +0,0 @@
package parser;
import static org.junit.Assert.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import org.junit.Test;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class GeneralParserTest {
private static final String rootDirectory = System.getProperty("user.dir") + "/src/test/java/parser/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("NewTest.jav");
filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav");
filenames.add("CastTest.jav");
filenames.add("StatementsTest.jav");
// filenames.add("Methods.jav");
filenames.add("ImportTestGeneric.jav");
// filenames.add("BoundedParameter.jav");
// filenames.add("GenericFieldVarTest.jav");
filenames.add("FieldVarTest.jav");
filenames.add("StructuralTypes.jav");
filenames.add("ExtendsTest.jav");
filenames.add("PackageNameTest.jav");
filenames.add("AntlrTest.jav");
// filenames.add("Java17Rules.jav");
// filenames.add("NestedPattern.jav");
try {
for (String filename : filenames) {
System.out.println(filename);
File sf = new File(rootDirectory + filename);
JavaTXCompiler compiler = new JavaTXCompiler(sf);
System.out.println(ASTPrinter.print(compiler.sourceFiles.get(sf)));
}
// new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory +
// s)).collect(Collectors.toList()));
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}

View File

@ -1,3 +0,0 @@
class Test{
<A> A var;
}

View File

@ -1,4 +0,0 @@
import java.util.*;
class ImportTest{
}

View File

@ -1,4 +0,0 @@
import java.util.ArrayList;
class ImportTest{
}

View File

@ -1,5 +0,0 @@
import java.util.List;
class ImportTest{
List<ImportTest> test;
}

View File

@ -1,621 +0,0 @@
/* Test Case für antlr4-Grammatik für Java 17
Typen wurden aus der originalen Datei entfernt
Quelle: https://github.com/antlr/grammars-v4/blob/master/java/java/examples/AllInOne17.java */
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* https://openjdk.java.net/jeps/361
*/
class SwitchExpressions {
final static private C = 10;
static class SC1 {
final static C = 100;
}
enum E1 {
ONE;
}
fn1(n) {
final var k = 4;
var r = switch (n) {
case 1, 2, 3 + 3, k, C, SC1.C -> 3 + SC1.C;
case 20 -> 3 + 4 + C - k;
case 21 -> {
int ff = 222;
yield ff;
}
case 22 -> {
yield 33 + 3;
}
case 99 -> {
throw new RuntimeException("");
}
default -> 0;
};
return r;
}
fn2(s) {
return switch (s) {
//case null -> "n";
case "a" -> "";
case "b", "c" -> "a";
default -> "o";
};
}
fn3(final t) {
return switch (t) {
case 1 -> 2;
default -> t;
};
}
fn4() {
fn1(switch (1) {
case 1 -> 0;
case 2 -> 2;
default -> 1;
});
}
fn5() {
var e = E1.ONE;
return switch (e) {
case ONE -> 0;
//default -> 1;
};
}
fn6() {
switch (1) {
case 1 -> {
}
}
}
fn7() {
switch (1) {
case 1 -> {
}
case 2 -> {
}
}
}
fn8() {
var i = 1;
switch (1) {
}
var f = 2;
switch (2) {
case 2 -> {
f = 3;
}
}
}
fn9(s) {
switch (s) {
case "" -> {
}
default -> {
}
}
}
fn10() {
var i = switch (1) {
case 1 -> switch (2) {
case 2 -> 0;
default -> 2;
};
default -> 2;
};
}
fn11() {
switch (1) {
case 1 -> throw new RuntimeException("");
}
}
fn12() {
var v = 1;
var n = switch (1) {
case 1:
var g = 1;
System.out.println();
yield v;
default:
yield 3;
};
return n;
}
fn13() {
int n;
switch (1) {
case 1 -> n = 1;
}
}
fn14() {
switch (1) {
default -> {
}
}
var n = 1;
var m = switch (n) {
case 1 -> 2;
case 2 -> 2;
default -> 1;
};
var m = switch (n) {
case 2:
yield 2;
default:
yield 3;
};
}
}
/**
* https://openjdk.java.net/jeps/394
*/
class PatternMatching4instanceof {
fn1(n) {
if (n instanceof Long var) {
var v = var;
} else if (n instanceof open) {
var v = open;
} else if (n instanceof Byte) {
//
} else {
throw new RuntimeException("");
}
if (!(n instanceof l)) ;
if (n instanceof final @Dummy @Dummy2 l && l.byteValue() == 1
|| n instanceof @Dummy @Dummy2 final b && b.intValue() == 1) ;
if (n instanceof Long) ;
if (n instanceof ox) ;
if (n instanceof l) ;
if (n instanceof final l) ;
if (n instanceof @Dummy l) ;
if (n instanceof @Dummy @Dummy2 l) ;
if (n instanceof final @Dummy l) ;
if (n instanceof final @Dummy @Dummy2 l) ;
if (n instanceof @Dummy final Long l) ;
if (n instanceof @Dummy @Dummy2 final l) ;
}
}
/**
* https://openjdk.java.net/jeps/406
class PatternMatching4switchExp {
f(i) {
}
f1(obj) {
switch (obj) {
case null -> f(0);
case s -> f(1);
case a -> f(2);
default -> f(-1);
}
}
f2(obj) {
switch (obj) {
case null -> f(0);
case l -> f(1);
case i -> f(1);
case a -> f(2);
default -> f(-1);
}
}
f3(o) {
switch (o) {
case null:
case l:
f(0);
break;
default:
break;
}
}
enum E1 {
var;
}
f4() {
var var = E1.var;
switch (var) {
case var:
return;
default:
break;
}
switch (var) {
case var -> {
}
default -> {
}
}
}
f5(n) {
return switch (n) {
case l && l.intValue() == 1 && l.byteValue() == 1 -> l.byteValue();
case var -> var.byteValue();
case i -> i.byteValue();
default -> throw new RuntimeException("");
};
}
f6(obj) {
b = true;
return switch (obj) {
case var && b -> t -> var;
default -> t -> "Default string";
};
}
dummy() {
return 0;
}
f7(obj) {
b = true;
b2 = true;
b3 = true;
return switch (obj) {
case (((s) && (b && b2)) && s.length() > 0 && dummy() == 1) -> t -> s;
case (((i && b && b2) && (b && b2)) && b3 && (b && b2)) -> t -> "";
case (((i && b && b2) && (b && b2)) && b3 && (b && b2 && !b3)) -> {
yield t -> "";
}
case final l && (b ? b2 : b3) -> {
yield t -> "";
}
default -> t -> "Default string";
};
}
f8(o, i) {
switch (i) {
case 1, 2:
case 3, 4: {
}
}
switch (o) {
case b: {
}
default: {
}
}
var f = switch (o) {
case final l: {
yield switch (o) {
case b -> 1;
default -> 0;
};
}
default: {
yield 1;
}
};
}
}*/
/**
* https://openjdk.java.net/jeps/395
*/
class Records {
interface I1 {
}
final record R1(x) {
R1(x) {
this.x = x;
}
enum E {
ONE;
record ER() {
}
}
class C {
record CR() {
}
}
interface I {
record IR() {
}
}
final static private record R() implements I1 {
}
final static protected record R2() implements I1 {
}
final static public record R3() implements I1 {
}
final static record R4() implements I1 {
}
}
record R2() {
public interface TM1 {
AR() {
}
}
}
record R3<T>(x, y) {
}
record R4<T>(x, y) implements I1 {
}
fn1() {
final record Pt<T, G extends Number>(x, y) implements I1, R1.I {
fn(T t) {
}
f() {
}
//final int x; implicitly defined
Pt(x, y) {
this.x = x;
this.y = y;
}
//private int c = 1; not allowed
private final static C = 1; //allowed
static class C {
}
}
p = new Pt<>(1, 2);
p.fn(1L);
}
}
/**
* https://openjdk.java.net/jeps/409
*/
class SealedClasses {
interface I1 {
}
class C0 {
}
sealed class SC1 extends C0 implements I1 permits FC1, FC2 {
}
sealed class SC2 {
f() {
var non = 1;
var sealed = 2;
var ns = non - sealed;
var permits = 1;
var record = 1;
}
}
final class FC1 extends SC1 {
}
final class FC2 extends SC1 {
}
non-sealed class NSC1 extends SC2 {
}
class C1 extends NSC1 {
}
}
class Ids {
class oo {
class opens<T> {
enum E {
provides;
}
class provides<S> {
f() {
var b1 = new opens<>().new provides<>() {
};
var b2 = new opens().new provides() {
};
}
g() {
var e = E.provides;
switch (e) {
case provides:
break;
}
}
var() {
return null;
}
get() {
return null;
}
class with<S> {
}
static class SS<R> {
interface Sup<T> {
get();
}
}
h() {
var o = get().var();
var s = @Issue1897.Dum1 provides<Long>.with<Long>::new;
}
class R {
f() {
}
}
}
}
}
static class opens {
enum requires {
opens;
}
public static with(s) {
}
interface with {
default f() {
}
}
class exports implements with {
g() {
with.super.f();
}
}
@interface to {
}
class module {
public static with(String s) {
try {
} catch (var) {
}
}
}
record provides(to) {
f() {
opens o = new opens();
var b = (opens, with) -> 1L;
var c = opens.module::<Byte>with;
}
}
}
}
class Yield {
f(o) {
final var yield = 1;
return switch (o) {
case l -> {
//var yield = 1;
yield yield;
}
default -> {
yield yield;
}
};
}
yield(yield){
return yield;
}
}
class IF_PERMITS {
final class T1 implements I1 {
}
final class T2 implements I1 {
}
interface I2 {
}
sealed interface I1 extends I2 permits T1, T2 {
}
}

View File

@ -1,16 +0,0 @@
import java.lang.String;
record Point(int x, int y) {}
interface Shape {}
record Rectangle(Point upperLeft, Point lowerRight) implements Shape {}
class PatternMatching {
void printCoordinatesOfUpperLeftPoint(Shape shape)
{
switch (shape) {
case Rectangle(Point(int x, int y), Point lowerRight) -> System.out.println("x: " + x + " / y: " + y + " / lowerRight: " + lowerRight);
default -> System.out.println("not a rectangle");
}
}
}

View File

@ -1,5 +0,0 @@
class NewTest {
main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new
NewTest(3)); }
}

View File

@ -1,12 +0,0 @@
import java.lang.Integer;
class OpratorTest {
m(Integer a, Integer b) {
c = a+b;
// d = a-b;
// e = a*b;
// f = a/b;
return c;
}
}

View File

@ -1,9 +0,0 @@
import java.lang.Integer;
import java.lang.Comparable;
class PackageNameTest{
java.lang.Integer test(a){return a;}
Comparable<Integer> test2(a){return a;}
}

View File

@ -1,8 +0,0 @@
class Statements{
public void methodeTest(){
methodeTest();
return null;
}
}

View File

@ -1,5 +0,0 @@
class A {
mt(x, y, z) { return x.sub(y).add(z); }
}

View File

@ -1,14 +0,0 @@
class WhileTest{
void methode(){
Boolean test;
do{
test=test;
}while(test);
while(test){
test = test;
}
return;
}
}

View File

@ -1,112 +0,0 @@
package typeinference;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
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 java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Meth_GenTest {
public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
/*
* @Test public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); }
*
* @Test public void lambda() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda.jav")); }
*
* @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); }
*
* @Test public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); }
*
* @Test public void mathStruc() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"mathStruc.jav")); }
*
* @Test public void generics() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Generics.jav")); }
*
* @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); }
*
* @Test public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.jav")); }
*/
@Test
public void matrix() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Meth_Gen.jav"));
}
/*
* @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }
*
* @Test public void lambdaRunnable() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"LambdaRunnable.jav")); }
*
* @Test public void expressions() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Expressions.jav")); }
*
* @Test public void matrixFC() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FC_Matrix.jav")); }
*/
private static class TestResultSet {
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
// filesToTest.add(new File(rootDirectory+"fc.jav"));
// filesToTest.add(new File(rootDirectory+"Lambda.jav"));
// filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
// filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
// filesToTest.add(new File(rootDirectory+"Vector.jav"));
// filesToTest.add(new File(rootDirectory+"Generics.jav"));
// filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
// filesToTest.add(new File(rootDirectory+"Matrix.jav"));
// filesToTest.add(new File(rootDirectory+"Import.jav"));
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for (File f : compiler.sourceFiles.keySet()) {
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
for (File f : compiler.sourceFiles.keySet()) {
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
// List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size() > 0;
Set<String> insertedTypes = new HashSet<>();
for (ResultSet resultSet : results) {
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size() > 0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for (TypeInsert tip : result) {
insertedTypes.add(tip.insert(content));
}
}
for (String s : insertedTypes) {
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@ -1,125 +0,0 @@
package typeinference;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
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 java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class UnifyTest {
public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
/*
* @Test public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); }
*
* @Test public void lambda() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda.jav")); }
*
*/
/*
* @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }
*/
/*
* @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); }
*/
/*
* @Test public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); }
*
* @Test public void lambdafield() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"LambdaField.jav")); }
*
* @Test public void mathStruc() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"mathStruc.jav")); }
*
* @Test public void generics() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Generics.jav")); }
*/
/*
* @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); }
*/
/*
* @Test public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.jav")); }
*/
@Test
public void matrix() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Matrix.jav"));
// JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav"));
// compiler.generateBytecode();
}
/*
* @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }
*
* @Test public void lambdaRunnable() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"LambdaRunnable.jav")); }
*
* @Test public void expressions() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Expressions.jav")); }
*
* @Test public void matrixFC() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FC_Matrix.jav")); }
*/
private static class TestResultSet {
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
// filesToTest.add(new File(rootDirectory+"fc.jav"));
// filesToTest.add(new File(rootDirectory+"Lambda.jav"));
// filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
// filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
// filesToTest.add(new File(rootDirectory+"Vector.jav"));
// filesToTest.add(new File(rootDirectory+"Generics.jav"));
// filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
// filesToTest.add(new File(rootDirectory+"Matrix.jav"));
// filesToTest.add(new File(rootDirectory+"Import.jav"));
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for (File f : compiler.sourceFiles.keySet()) {
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
for (File f : compiler.sourceFiles.keySet()) {
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
// List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size() > 0;
Set<String> insertedTypes = new HashSet<>();
for (ResultSet resultSet : results) {
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size() > 0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for (TypeInsert tip : result) {
insertedTypes.add(tip.insert(content));
}
}
for (String s : insertedTypes) {
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@ -1,5 +0,0 @@
package visualisation;
public class ToString {
}