diff --git a/README.md b/README.md index de2bb68..d0ae5bc 100644 --- a/README.md +++ b/README.md @@ -95,14 +95,6 @@ Tests and execution: - Typing and Type checking -> (src/test/java/semantic/EndToTypedAstTest) - -## Used Tools - -- [Maven 4.0](https://maven.apache.org/index.html) - - Used for automating the build process and managing dependencies. -- [ANTLR4 v.13.1](https://www.antlr.org/) - - Used to parse the input Java code into the Abstract Syntax Tree. - ## Used Tools - [Maven 4.0](https://maven.apache.org/index.html) @@ -140,10 +132,3 @@ Example (jar needs to be in the target directory) ``` DgenClass=true ``` - -## How to run tests - -```bash -mvn test -``` -Or start them manually in your IDE \ No newline at end of file diff --git a/ast.png b/ast.png new file mode 100644 index 0000000..fd3f2d9 Binary files /dev/null and b/ast.png differ diff --git a/src/main/java/main/Main.java b/src/main/java/main/Main.java index a596fae..9064196 100644 --- a/src/main/java/main/Main.java +++ b/src/main/java/main/Main.java @@ -15,7 +15,6 @@ import java.io.IOException; import java.nio.file.Paths; import java.util.Optional; - /** * Start miniCompiler using make: *

cd .\src\test\ diff --git a/src/main/resources/logs/test b/src/main/resources/logs/test new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/main/E2EReflectionsTest.java b/src/test/java/main/E2EReflectionsTest.java index 28c95ed..d7d1bb6 100644 --- a/src/test/java/main/E2EReflectionsTest.java +++ b/src/test/java/main/E2EReflectionsTest.java @@ -1,7 +1,6 @@ package main; import java.io.IOException; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -9,2010 +8,171 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; - -import org.junit.jupiter.api.Test; - import javax.tools.JavaCompiler; import javax.tools.ToolProvider; - +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class E2EReflectionsTest { + @Test public void CharTest() { - final String FILE_NAME = "Char"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("Char"); } @Test public void CommentsTest() { - final String FILE_NAME = "Comments"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("Comments"); } @Test public void ConstructorMethodCallTest() { - final String FILE_NAME = "ConstructorMethodCall"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("ConstructorMethodCall"); } @Test public void ConstructorMethodCallParametersTest() { - final String FILE_NAME = "ConstructorMethodCallParameters"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("ConstructorMethodCallParameters"); } @Test public void ConstructorParameterTest() { - final String FILE_NAME = "ConstructorParameter"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("ConstructorParameter"); } @Test public void ConstructorThisDotTest() { - final String FILE_NAME = "ConstructorThisDot"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("ConstructorThisDot"); } @Test public void DoWhileTest() { - final String FILE_NAME = "DoWhile"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("DoWhile"); } @Test public void EmptyClassTest() { - final String FILE_NAME = "EmptyClass"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("EmptyClass"); } @Test public void EmptyClassWithConstructorTest() { - final String FILE_NAME = "EmptyClassWithConstructor"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("EmptyClassWithConstructor"); } @Test public void FieldTest() { - final String FILE_NAME = "Field"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("Field"); } @Test public void FieldWithAccessModifierTest() { - final String FILE_NAME = "FieldWithAccessModifier"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("FieldWithAccessModifier"); } @Test public void ForTest() { - final String FILE_NAME = "For"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("For"); } - @Test public void IfTest() { - final String FILE_NAME = "If"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("If"); } + @Test public void IfElseTest() { - final String FILE_NAME = "IfElse"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("IfElse"); } + @Test public void IfElseIfElseTest() { - final String FILE_NAME = "IfElseIfElse"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("IfElseIfElse"); } + @Test public void IncrementTest() { - final String FILE_NAME = "Increment"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("Increment"); } + @Test public void MainMethodTest() { - final String FILE_NAME = "MainMethod"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("MainMethod"); } + @Test public void MultipleClassesTest() { - final String FILE_NAME = "MultipleClasses"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("MultipleClasses"); } + @Test public void NullTest() { - final String FILE_NAME = "Null"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("Null"); } + @Test public void SelfReferenceTest() { - final String FILE_NAME = "SelfReference"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("SelfReference"); } + @Test public void ThisDotTest() { - final String FILE_NAME = "ThisDot"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("ThisDot"); } + @Test public void VariableCalculationTest() { - final String FILE_NAME = "VariableCalculation"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("VariableCalculation"); } + @Test public void VariableCompareTest() { - final String FILE_NAME = "VariableCompare"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("VariableCompare"); } + @Test public void VoidMethodTest() { - final String FILE_NAME = "VoidMethod"; - try { - // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); - // Get the system Java compiler - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); - // Assert that the compiler is available - assertNotNull(javac, "Java Compiler is not available"); - // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); - - // Load the javac class - Path javacClassPath = Paths.get("src/test/resources/output/javac"); - ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); - - // Load the miniCompiler class - Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); - ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - - - // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - - - // Constructors - Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); - Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { - assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); - if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { - assertEquals(c.getName(), miniCompilerConstructor.getName()); - } - } - } - - - // Methods - Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); - Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - - assertEquals(javacMethods.length, miniCompilerMethods.length); - - for (int i = 0; i < javacMethods.length; i++) { - assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); - assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); - assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); - } - - - // Fields - Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); - Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - - for (Field field : javacLoadedClassDeclaredFields) { - for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { - if (field.getName().equals(miniCompilerField.getName())) { - assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); - } - } - } - - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } + runTest("VoidMethod"); } + @Test public void WhileTest() { - final String FILE_NAME = "While"; + runTest("While"); + } + + // Helper method to eliminate redundancy + private void runTest(String fileName) { try { // compile with miniCompiler - Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java", "src/test/resources/output/miniCompiler"}); + Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + fileName + ".java", "src/test/resources/output/miniCompiler"}); // Get the system Java compiler JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); // Assert that the compiler is available assertNotNull(javac, "Java Compiler is not available"); // compile with javac - javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".java"); - moveFile("src/test/resources/input/singleFeatureTests/" + FILE_NAME + ".class", "src/test/resources/output/javac/" + FILE_NAME + ".class"); + javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + fileName + ".java"); + moveFile("src/test/resources/input/singleFeatureTests/" + fileName + ".class", "src/test/resources/output/javac/" + fileName + ".class"); // Load the javac class Path javacClassPath = Paths.get("src/test/resources/output/javac"); ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()}); - Class javacLoadedClass = javacClassLoader.loadClass(FILE_NAME); + Class javacLoadedClass = javacClassLoader.loadClass(fileName); // Load the miniCompiler class Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler"); ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()}); - Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(FILE_NAME); - + Class miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(fileName); // Class Name - assertEquals(FILE_NAME, javacLoadedClass.getName()); - assertEquals(FILE_NAME, miniCompilerLoadedClass.getName()); - + assertEquals(fileName, javacLoadedClass.getName()); + assertEquals(fileName, miniCompilerLoadedClass.getName()); // Constructors Constructor[] javacConstructors = javacLoadedClass.getDeclaredConstructors(); Constructor[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors(); - assertEquals(javacConstructors.length, miniCompilerConstructors.length); - - for(Constructor c : javacConstructors) { - for(Constructor miniCompilerConstructor : miniCompilerConstructors) { + for (Constructor c : javacConstructors) { + for (Constructor miniCompilerConstructor : miniCompilerConstructors) { assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount()); if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) { assertEquals(c.getName(), miniCompilerConstructor.getName()); @@ -2020,47 +180,38 @@ public class E2EReflectionsTest { } } - // Methods Method[] javacMethods = javacLoadedClass.getDeclaredMethods(); Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods(); - assertEquals(javacMethods.length, miniCompilerMethods.length); - for (int i = 0; i < javacMethods.length; i++) { assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName()); assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType()); assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount()); - // assertEquals(javacMethods[i].getModifiers(), miniCompilerMethods[i].getModifiers()); } - // Fields Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields(); Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields(); - assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length); - for (Field field : javacLoadedClassDeclaredFields) { for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) { if (field.getName().equals(miniCompilerField.getName())) { assertEquals(field.getType(), miniCompilerField.getType()); - // assertEquals(field.getModifiers(), miniCompilerField.getModifiers()); } } } - } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { e.printStackTrace(); } catch (Exception e) { throw new RuntimeException(e); } } - // Helpers + // Helper method to move file public static void moveFile(String sourceFilePath, String destinationFilePath) throws IOException { Path sourcePath = Paths.get(sourceFilePath); Path destinationPath = Paths.get(destinationFilePath); Files.move(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING); } -} \ No newline at end of file +} diff --git a/src/test/resources/input/singleFeatureTests/Char.java b/src/test/resources/input/singleFeatureTests/Char.java deleted file mode 100644 index 54ff6fa..0000000 --- a/src/test/resources/input/singleFeatureTests/Char.java +++ /dev/null @@ -1,12 +0,0 @@ -class Char { - - char a; - - public Char(char a){ - this.a = testMethod(a); - } - - char testMethod(char a){ - return a; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/Comments.java b/src/test/resources/input/singleFeatureTests/Comments.java deleted file mode 100644 index fbf3e12..0000000 --- a/src/test/resources/input/singleFeatureTests/Comments.java +++ /dev/null @@ -1,8 +0,0 @@ -/* - - Mutliple Line Comment. Ignore - - */ -class Comments{ - private int a; // Ignore -} diff --git a/src/test/resources/input/singleFeatureTests/ConstructorMethodCall.java b/src/test/resources/input/singleFeatureTests/ConstructorMethodCall.java deleted file mode 100644 index 2e0c4a8..0000000 --- a/src/test/resources/input/singleFeatureTests/ConstructorMethodCall.java +++ /dev/null @@ -1,12 +0,0 @@ -public class ConstructorMethodCall { - - int a; - - public ConstructorMethodCall(){ - this.a = testMethod(); - } - - int testMethod(){ - return 1; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/ConstructorMethodCallParameters.java b/src/test/resources/input/singleFeatureTests/ConstructorMethodCallParameters.java deleted file mode 100644 index 61f83e1..0000000 --- a/src/test/resources/input/singleFeatureTests/ConstructorMethodCallParameters.java +++ /dev/null @@ -1,12 +0,0 @@ -class ConstructorMethodCallParameters { - - int a; - - public ConstructorMethodCallParameters(int a){ - this.a = testMethod(a); - } - - int testMethod(int a){ - return a; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/ConstructorParameter.java b/src/test/resources/input/singleFeatureTests/ConstructorParameter.java deleted file mode 100644 index 1d821ca..0000000 --- a/src/test/resources/input/singleFeatureTests/ConstructorParameter.java +++ /dev/null @@ -1,5 +0,0 @@ -class ConstructorParameter { - public ConstructorParameter(int a, int b){ - - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/ConstructorThisDot.java b/src/test/resources/input/singleFeatureTests/ConstructorThisDot.java deleted file mode 100644 index 8e8077b..0000000 --- a/src/test/resources/input/singleFeatureTests/ConstructorThisDot.java +++ /dev/null @@ -1,8 +0,0 @@ -class ConstructorThisDot { - - private int a; - - public ConstructorThisDot(int a){ - this.a = a; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/DoWhile.java b/src/test/resources/input/singleFeatureTests/DoWhile.java deleted file mode 100644 index db1b1ab..0000000 --- a/src/test/resources/input/singleFeatureTests/DoWhile.java +++ /dev/null @@ -1,10 +0,0 @@ -class DoWhile{ - - public DoWhile(){ - int i = 0; - - do{ - i++; - }while(i < 10); - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/EmptyClass.java b/src/test/resources/input/singleFeatureTests/EmptyClass.java deleted file mode 100644 index 1d9bc30..0000000 --- a/src/test/resources/input/singleFeatureTests/EmptyClass.java +++ /dev/null @@ -1 +0,0 @@ -class EmptyClass {} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/EmptyClassWithConstructor.java b/src/test/resources/input/singleFeatureTests/EmptyClassWithConstructor.java deleted file mode 100644 index 5d7333a..0000000 --- a/src/test/resources/input/singleFeatureTests/EmptyClassWithConstructor.java +++ /dev/null @@ -1,5 +0,0 @@ -public class EmptyClassWithConstructor { - public EmptyClassWithConstructor() { - - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/Field.java b/src/test/resources/input/singleFeatureTests/Field.java deleted file mode 100644 index 218857c..0000000 --- a/src/test/resources/input/singleFeatureTests/Field.java +++ /dev/null @@ -1,3 +0,0 @@ -class Field { - int a; -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/FieldWithAccessModifier.java b/src/test/resources/input/singleFeatureTests/FieldWithAccessModifier.java deleted file mode 100644 index 6bb9e11..0000000 --- a/src/test/resources/input/singleFeatureTests/FieldWithAccessModifier.java +++ /dev/null @@ -1,3 +0,0 @@ -public class FieldWithAccessModifier { - public int a; -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/For.java b/src/test/resources/input/singleFeatureTests/For.java deleted file mode 100644 index f8f0fd6..0000000 --- a/src/test/resources/input/singleFeatureTests/For.java +++ /dev/null @@ -1,8 +0,0 @@ -class For{ - - public For(){ - for(int i = 0; i < 10; i++){ - int a; - } - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/If.java b/src/test/resources/input/singleFeatureTests/If.java deleted file mode 100644 index a83dbbf..0000000 --- a/src/test/resources/input/singleFeatureTests/If.java +++ /dev/null @@ -1,8 +0,0 @@ -public class If { - public If() { - int intValue = 5; - if(intValue == 5) { - intValue--; - } - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/IfElse.java b/src/test/resources/input/singleFeatureTests/IfElse.java deleted file mode 100644 index a3a597a..0000000 --- a/src/test/resources/input/singleFeatureTests/IfElse.java +++ /dev/null @@ -1,10 +0,0 @@ -public class IfElse { - public IfElse() { - int intValue = 5; - if(intValue == 5) { - intValue--; - } else { - intValue++; - } - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/IfElseIfElse.java b/src/test/resources/input/singleFeatureTests/IfElseIfElse.java deleted file mode 100644 index b20fb7e..0000000 --- a/src/test/resources/input/singleFeatureTests/IfElseIfElse.java +++ /dev/null @@ -1,12 +0,0 @@ -public class IfElseIfElse { - public IfElseIfElse() { - int intValue = 5; - if(intValue == 5) { - intValue--; - } else if(intValue ==4) { - intValue++; - } else { - intValue++; - } - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/Increment.java b/src/test/resources/input/singleFeatureTests/Increment.java deleted file mode 100644 index d2789c9..0000000 --- a/src/test/resources/input/singleFeatureTests/Increment.java +++ /dev/null @@ -1,12 +0,0 @@ -public class Increment { - - public int test; - - public void increment(int p) { - test = p++; - - for(int i = 1; i<=10; i++) { - int a = 5; - } - } -} diff --git a/src/test/resources/input/singleFeatureTests/MainMethod.java b/src/test/resources/input/singleFeatureTests/MainMethod.java deleted file mode 100644 index b6079ae..0000000 --- a/src/test/resources/input/singleFeatureTests/MainMethod.java +++ /dev/null @@ -1,5 +0,0 @@ -class MainMethod{ - - public static void main(String[] args) { - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/MultipleClasses.java b/src/test/resources/input/singleFeatureTests/MultipleClasses.java deleted file mode 100644 index dda277c..0000000 --- a/src/test/resources/input/singleFeatureTests/MultipleClasses.java +++ /dev/null @@ -1,3 +0,0 @@ -class MultipleClasses {} - -class TestClass2{} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/Null.java b/src/test/resources/input/singleFeatureTests/Null.java deleted file mode 100644 index 1c843fa..0000000 --- a/src/test/resources/input/singleFeatureTests/Null.java +++ /dev/null @@ -1,8 +0,0 @@ -class Null{ - - Null a; - - public Null(){ - this.a = null; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/SelfReference.java b/src/test/resources/input/singleFeatureTests/SelfReference.java deleted file mode 100644 index 93bed9e..0000000 --- a/src/test/resources/input/singleFeatureTests/SelfReference.java +++ /dev/null @@ -1,18 +0,0 @@ -class SelfReference{ - - SelfReference selfReference; - - int testMethod1() { - return this.testMethod2(); - } - - int testMethod2() { - return 1; - } - - int testMethod3(){ - SelfReference selfReference1 = new SelfReference(); - return selfReference1.selfReference.testMethod1(); - } - -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/ThisDot.java b/src/test/resources/input/singleFeatureTests/ThisDot.java deleted file mode 100644 index 4d3a41e..0000000 --- a/src/test/resources/input/singleFeatureTests/ThisDot.java +++ /dev/null @@ -1,8 +0,0 @@ -class ThisDot { - - public int a; - - public ThisDot() { - this.a = 1; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/VariableCalculation.java b/src/test/resources/input/singleFeatureTests/VariableCalculation.java deleted file mode 100644 index 847b1a6..0000000 --- a/src/test/resources/input/singleFeatureTests/VariableCalculation.java +++ /dev/null @@ -1,34 +0,0 @@ -class VariableCalculation{ - - int aPlusB(int a, int b){ - return a + b; - } - - int aMinusB(int a, int b){ - return a - b; - } - - int aTimeB(int a, int b){ - return a * b; - } - - int aDivB(int a, int b){ - return a / b; - } - - int complexCalc (int a, int b){ - return a * b / 1 * 3; - } - - boolean aSmallerB (int a, int b){ - return a < b; - } - - boolean aGreaterB (int a, int b){ - return a > b; - } - - boolean aEqualsB (int a, int b){ - return a == b; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/VariableCompare.java b/src/test/resources/input/singleFeatureTests/VariableCompare.java deleted file mode 100644 index 70f2a39..0000000 --- a/src/test/resources/input/singleFeatureTests/VariableCompare.java +++ /dev/null @@ -1,30 +0,0 @@ -class VariableCompare{ - - boolean trueMethod() { - return true; - } - - boolean falseMethod(){ - return false; - } - - boolean trueAndTrueMethod(){ - return true && true; - } - - boolean trueAndFalseMethod(){ - return true && false; - } - - boolean falseAndFalseMethod(){ - return false && false; - } - - boolean trueOrTrueMethod(){ - return true || true; - } - - boolean falseOrFalseMethod(){ - return false || false; - } -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/VoidMethod.java b/src/test/resources/input/singleFeatureTests/VoidMethod.java deleted file mode 100644 index 0d45373..0000000 --- a/src/test/resources/input/singleFeatureTests/VoidMethod.java +++ /dev/null @@ -1,3 +0,0 @@ -class VoidMethod{ - void test(){} -} \ No newline at end of file diff --git a/src/test/resources/input/singleFeatureTests/While.java b/src/test/resources/input/singleFeatureTests/While.java deleted file mode 100644 index 01dc5fc..0000000 --- a/src/test/resources/input/singleFeatureTests/While.java +++ /dev/null @@ -1,10 +0,0 @@ -class While{ - - public While(){ - int i = 10; - - while ( i > 0){ - i--; - } - } -} \ No newline at end of file diff --git a/src/test/resources/output/javac/test b/src/test/resources/output/javac/test new file mode 100644 index 0000000..e69de29