Huge Changes in TestFiles, ReflectionsTest, much more
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
27baa429b4
commit
b072af346b
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@ -6,6 +6,11 @@
|
|||||||
<option name="name" value="Central Repository" />
|
<option name="name" value="Central Repository" />
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven_central" />
|
||||||
|
<option name="name" value="Maven Central" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="central" />
|
<option name="id" value="central" />
|
||||||
<option name="name" value="Maven Central repository" />
|
<option name="name" value="Maven Central repository" />
|
||||||
|
21
pom.xml
21
pom.xml
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.9.3</version> <!-- Change the version as needed -->
|
<version>5.11.0-M2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -44,6 +44,18 @@
|
|||||||
<version>3.26.0</version>
|
<version>3.26.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.11.0-M2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -78,4 +90,11 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven_central</id>
|
||||||
|
<name>Maven Central</name>
|
||||||
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
</project>
|
</project>
|
@ -31,12 +31,15 @@ test-raupenpiler:
|
|||||||
clean:
|
clean:
|
||||||
# clean output folders
|
# clean output folders
|
||||||
rm -f ../main/resources/output/*.class
|
rm -f ../main/resources/output/*.class
|
||||||
|
rm -f ../main/resources/output/*.jar
|
||||||
rm -f ./resources/output/javac/*.class
|
rm -f ./resources/output/javac/*.class
|
||||||
rm -f ./resources/output/raupenpiler/*.class
|
rm -f ./resources/output/raupenpiler/*.class
|
||||||
# clean logs
|
# clean logs
|
||||||
rm -f ../main/resources/logs/*.log
|
rm -f ../main/resources/logs/*.log
|
||||||
# clean test/java/main folders from .class files for End-to-End tests
|
# clean test/java/main folders from .class files for End-to-End tests
|
||||||
rm -f ./java/main/*.class
|
rm -f ./java/main/*.class
|
||||||
# clean javac output from featureTests
|
# clean javac output from combinedFeatureTests
|
||||||
rm -f ./resources/input/featureTests/*.class
|
rm -f ./resources/input/combinedFeatureTests/*.class
|
||||||
|
rm -f ./resources/input/singleFeatureTests/*.class
|
||||||
|
rm -f ./resources/input/typedAstFeatureTests/*.class
|
||||||
|
|
||||||
|
81
src/test/java/main/E2EReflectionsTest.java
Normal file
81
src/test/java/main/E2EReflectionsTest.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class E2EReflectionsTest {
|
||||||
|
@Test
|
||||||
|
public void AllFeaturesClassExampleTest(){
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName("resources.input.combinedFeatureTests.AllFeaturesClassExample");
|
||||||
|
|
||||||
|
// Class Name
|
||||||
|
assertEquals("main.AllFeaturesClassExample", clazz.getName());
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
Constructor<?>[] actualConstructors = clazz.getDeclaredConstructors();
|
||||||
|
assertTrue(actualConstructors.length > 0, "No constructors found");
|
||||||
|
|
||||||
|
Constructor<?> expectedConstructor = clazz.getConstructor(int.class, boolean.class, char.class);
|
||||||
|
|
||||||
|
boolean constructorFound = false;
|
||||||
|
for (Constructor<?> constructor : actualConstructors) {
|
||||||
|
if (constructor.equals(expectedConstructor)) {
|
||||||
|
constructorFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(constructorFound, "Expected constructor not found in actual constructors");
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
Method[] actualMethodNames = clazz.getDeclaredMethods();
|
||||||
|
assertTrue(actualMethodNames.length > 0);
|
||||||
|
for (Method method : actualMethodNames) {
|
||||||
|
System.out.println("Method: " + method.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method Names
|
||||||
|
String[] expectedMethodNames = {
|
||||||
|
"controlStructures",
|
||||||
|
"logicalOperations",
|
||||||
|
"add",
|
||||||
|
"subtract",
|
||||||
|
"multiply",
|
||||||
|
"divide",
|
||||||
|
"modulo",
|
||||||
|
"main"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Method method : actualMethodNames) {
|
||||||
|
assertTrue(Arrays.asList(expectedMethodNames).contains(method.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
Field[] actualFields = clazz.getDeclaredFields();
|
||||||
|
assertTrue(actualFields.length > 0, "No fields found");
|
||||||
|
|
||||||
|
Field expectedField = clazz.getDeclaredField("c");
|
||||||
|
assertEquals(expectedField.getType(), char.class);
|
||||||
|
|
||||||
|
boolean fieldFound = false;
|
||||||
|
for (Field field : actualFields) {
|
||||||
|
if (field.equals(expectedField)) {
|
||||||
|
fieldFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(fieldFound, "Expected field not found in actual fields");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,48 +0,0 @@
|
|||||||
package main;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import javax.tools.JavaCompiler;
|
|
||||||
import javax.tools.ToolProvider;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class FailureTest {
|
|
||||||
/**
|
|
||||||
* This test method checks if invalid Java files fail to compile as expected.
|
|
||||||
* It uses the JavaCompiler from the ToolProvider to compile the files.
|
|
||||||
* The test passes if all the files fail to compile.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void areTestFilesActuallyFailTest() {
|
|
||||||
// Get the system Java compiler
|
|
||||||
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
|
||||||
// Assert that the compiler is available
|
|
||||||
assertNotNull(javac, "Java Compiler is not available");
|
|
||||||
|
|
||||||
String directoryPath = "src/test/resources/input/failureTests";
|
|
||||||
File folder = new File(directoryPath);
|
|
||||||
|
|
||||||
if (folder.isDirectory()) {
|
|
||||||
File[] files = folder.listFiles((dir, name) -> name.endsWith(".java"));
|
|
||||||
|
|
||||||
if (files != null) {
|
|
||||||
for (File file : files) {
|
|
||||||
// Try to compile the file and get the result
|
|
||||||
// The run method returns 0 if the compilation was successful, and non-zero otherwise
|
|
||||||
int result = javac.run(null, null, null, file.getPath());
|
|
||||||
|
|
||||||
// Assert that the compilation failed (i.e., the result is non-zero)
|
|
||||||
assertTrue(result != 0, "Expected compilation failure for " + file.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("No files found in the directory.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("The provided path is not a directory.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
|||||||
package main;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import javax.tools.JavaCompiler;
|
|
||||||
import javax.tools.ToolProvider;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class FeatureTest {
|
|
||||||
/**
|
|
||||||
* This test method checks if valid Java files compile successfully.
|
|
||||||
* It uses the JavaCompiler from the ToolProvider to compile the files.
|
|
||||||
* The test passes if all the files compile without errors.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void areTestFilesActuallyValid() {
|
|
||||||
// Get the system Java compiler
|
|
||||||
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
|
||||||
// Assert that the compiler is available
|
|
||||||
assertNotNull(javac, "Java Compiler is not available");
|
|
||||||
|
|
||||||
String directoryPath = "src/test/resources/input/featureTests";
|
|
||||||
File folder = new File(directoryPath);
|
|
||||||
|
|
||||||
if (folder.isDirectory()) {
|
|
||||||
File[] files = folder.listFiles((dir, name) -> name.endsWith(".java"));
|
|
||||||
|
|
||||||
if (files != null) {
|
|
||||||
for (File file : files) {
|
|
||||||
// Try to compile the file and get the result
|
|
||||||
// The run method returns 0 if the compilation was successful, and non-zero otherwise
|
|
||||||
int result = javac.run(null, null, null, file.getPath());
|
|
||||||
|
|
||||||
// Assert that the compilation succeeded (i.e., the result is zero)
|
|
||||||
assertEquals(0, result, "Expected compilation success for " + file.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("No files found in the directory.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("The provided path is not a directory.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
104
src/test/java/main/InputFilesTest.java
Normal file
104
src/test/java/main/InputFilesTest.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class InputFilesTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test method checks if valid Java files compile successfully.
|
||||||
|
* It uses the JavaCompiler from the ToolProvider to compile the files.
|
||||||
|
* The test passes if all the files compile without errors.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void areTestFilesActuallyValid() throws IOException {
|
||||||
|
// Get the system Java compiler
|
||||||
|
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
||||||
|
// Assert that the compiler is available
|
||||||
|
assertNotNull(javac, "Java Compiler is not available");
|
||||||
|
|
||||||
|
File folder1 = new File("src/test/resources/input/combinedFeatureTests");
|
||||||
|
File folder2 = new File("src/test/resources/input/singleFeatureTests");
|
||||||
|
File folder3 = new File("src/test/resources/input/typedAstFeatureTests");
|
||||||
|
|
||||||
|
List<File> files = getJavaFilesFromDirectory(folder1);
|
||||||
|
files.addAll(getJavaFilesFromDirectory(folder2));
|
||||||
|
files.addAll(getJavaFilesFromDirectory(folder3));
|
||||||
|
|
||||||
|
if (!files.isEmpty()) {
|
||||||
|
for (File file : files) {
|
||||||
|
// Try to compile the file and get the result
|
||||||
|
int result = javac.run(null, null, null, file.getPath());
|
||||||
|
|
||||||
|
// Assert that the compilation succeeded (i.e., the result is zero)
|
||||||
|
assertEquals(0, result, "Expected compilation success for " + file.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("No files found in the directories.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test method checks if invalid Java files fail to compile as expected.
|
||||||
|
* It uses the JavaCompiler from the ToolProvider to compile the files.
|
||||||
|
* The test passes if all the files fail to compile.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void areTestFilesActuallyFails() {
|
||||||
|
// Get the system Java compiler
|
||||||
|
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
||||||
|
// Assert that the compiler is available
|
||||||
|
assertNotNull(javac, "Java Compiler is not available");
|
||||||
|
|
||||||
|
String directoryPath = "src/test/resources/input/failureTests";
|
||||||
|
File folder = new File(directoryPath);
|
||||||
|
|
||||||
|
if (folder.isDirectory()) {
|
||||||
|
File[] files = folder.listFiles((dir, name) -> name.endsWith(".java"));
|
||||||
|
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
// Try to compile the file and get the result
|
||||||
|
// The run method returns 0 if the compilation was successful, and non-zero otherwise
|
||||||
|
int result = javac.run(null, null, null, file.getPath());
|
||||||
|
|
||||||
|
// Assert that the compilation failed (i.e., the result is non-zero)
|
||||||
|
assertTrue(result != 0, "Expected compilation failure for " + file.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("No files found in the directory.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("The provided path is not a directory.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get all .java files from a directory.
|
||||||
|
*
|
||||||
|
* @param directory the directory to search for .java files
|
||||||
|
* @return a list of .java files
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
*/
|
||||||
|
private List<File> getJavaFilesFromDirectory(File directory) throws IOException {
|
||||||
|
if (directory.isDirectory()) {
|
||||||
|
return Files.list(directory.toPath())
|
||||||
|
.filter(path -> path.toString().endsWith(".java"))
|
||||||
|
.map(java.nio.file.Path::toFile)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
System.out.println("The provided path is not a directory: " + directory.getPath());
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
145
src/test/java/main/ReflectionsTest.java
Normal file
145
src/test/java/main/ReflectionsTest.java
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class ReflectionsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSimpleJavaLexerClass() throws ClassNotFoundException, NoSuchMethodException {
|
||||||
|
Class<?> clazz = Class.forName("parser.generated.SimpleJavaLexer");
|
||||||
|
|
||||||
|
// Class Name
|
||||||
|
assertEquals("parser.generated.SimpleJavaLexer", clazz.getName());
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
Constructor<?>[] actualConstructors = clazz.getDeclaredConstructors();
|
||||||
|
assertTrue(actualConstructors.length > 0, "No constructors found");
|
||||||
|
|
||||||
|
Constructor<?> expectedConstructor = clazz.getConstructor(CharStream.class);
|
||||||
|
|
||||||
|
boolean constructorFound = false;
|
||||||
|
for (Constructor<?> constructor : actualConstructors) {
|
||||||
|
if (constructor.equals(expectedConstructor)) {
|
||||||
|
constructorFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(constructorFound, "Expected constructor not found in actual constructors");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
Method[] actualMethodNames = clazz.getDeclaredMethods();
|
||||||
|
assertTrue(actualMethodNames.length > 0);
|
||||||
|
Arrays.stream(actualMethodNames).forEach(method -> System.out.println("Method: " + method.getName()));
|
||||||
|
|
||||||
|
List<String> expectedMethodNames = Arrays.asList(
|
||||||
|
"getTokenNames",
|
||||||
|
"getVocabulary",
|
||||||
|
"getGrammarFileName",
|
||||||
|
"getRuleNames",
|
||||||
|
"getSerializedATN",
|
||||||
|
"getChannelNames",
|
||||||
|
"getModeNames",
|
||||||
|
"getATN",
|
||||||
|
"makeRuleNames",
|
||||||
|
"makeLiteralNames",
|
||||||
|
"makeSymbolicNames"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (Method method : actualMethodNames) {
|
||||||
|
assertTrue(expectedMethodNames.contains(method.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String expectedMethodName : expectedMethodNames) {
|
||||||
|
boolean methodFound = false;
|
||||||
|
for (Method method : actualMethodNames) {
|
||||||
|
if (method.getName().equals(expectedMethodName)) {
|
||||||
|
methodFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(methodFound, "Expected method " + expectedMethodName + " not found in actual methods");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
Field[] actualFieldNames = clazz.getDeclaredFields();
|
||||||
|
assertTrue(actualFieldNames.length > 0);
|
||||||
|
Arrays.stream(actualFieldNames).forEach(field -> System.out.println("Field: " + field.getName()));
|
||||||
|
|
||||||
|
List<String> expectedFieldNames = Arrays.asList(
|
||||||
|
"_decisionToDFA",
|
||||||
|
"_sharedContextCache",
|
||||||
|
"channelNames",
|
||||||
|
"modeNames",
|
||||||
|
"ruleNames",
|
||||||
|
"_LITERAL_NAMES",
|
||||||
|
"_SYMBOLIC_NAMES",
|
||||||
|
"VOCABULARY",
|
||||||
|
"tokenNames",
|
||||||
|
"_serializedATN",
|
||||||
|
"_ATN"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (Field field : actualFieldNames) {
|
||||||
|
assertTrue(expectedFieldNames.contains(field.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSimpleJavaParserClass() throws ClassNotFoundException {
|
||||||
|
Class<?> clazz = Class.forName("parser.generated.SimpleJavaParser");
|
||||||
|
|
||||||
|
// Class Name
|
||||||
|
assertEquals("parser.generated.SimpleJavaParser", clazz.getName());
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
|
||||||
|
assertTrue(constructors.length > 0);
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
Method[] methods = clazz.getDeclaredMethods();
|
||||||
|
assertTrue(methods.length > 0);
|
||||||
|
Arrays.stream(methods).forEach(method -> System.out.println("Method: " + method.getName()));
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
assertTrue(fields.length > 0);
|
||||||
|
Arrays.stream(fields).forEach(field -> System.out.println("Field: " + field.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testASTBuilderClass() throws ClassNotFoundException {
|
||||||
|
Class<?> clazz = Class.forName("parser.astBuilder.ASTBuilder");
|
||||||
|
|
||||||
|
// Class Name
|
||||||
|
assertEquals("parser.astBuilder.ASTBuilder", clazz.getName());
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
|
||||||
|
assertTrue(constructors.length > 0);
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
Method[] methods = clazz.getDeclaredMethods();
|
||||||
|
assertTrue(methods.length > 0);
|
||||||
|
Arrays.stream(methods).forEach(method -> System.out.println("Method: " + method.getName()));
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
assertTrue(fields.length > 0);
|
||||||
|
Arrays.stream(fields).forEach(field -> System.out.println("Field: " + field.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Similarly, you can add tests for SemanticAnalyzer and ByteCodeGenerator
|
||||||
|
}
|
@ -43,104 +43,106 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
@DisplayName("Untyped Abstract Syntax Tree")
|
@DisplayName("Untyped Abstract Syntax Tree")
|
||||||
class AstBuilderTest {
|
class AstBuilderTest {
|
||||||
|
|
||||||
|
private final static String directoryPath = "src/test/resources/input/singleFeatureTests/";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Empty Class Test")
|
@DisplayName("Empty Class Test")
|
||||||
public void emptyClassTest(){
|
public void emptyClassTest() {
|
||||||
ClassNode emptyClass = Helper.generateEmptyClass("TestClass");
|
ClassNode emptyClass = Helper.generateEmptyClass("EmptyClass");
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(emptyClass);
|
expected.addClass(emptyClass);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/EmptyClass.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "EmptyClass.java");
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Multiple Empty Classes Test")
|
@DisplayName("Multiple Empty Classes Test")
|
||||||
public void multipleEmptyClassesTest() {
|
public void multipleEmptyClassesTest() {
|
||||||
ClassNode class1 = Helper.generateEmptyClass("TestClass1");
|
ClassNode class1 = Helper.generateEmptyClass("MultipleClasses");
|
||||||
ClassNode class2 = Helper.generateEmptyClass("TestClass2");
|
ClassNode class2 = Helper.generateEmptyClass("TestClass2");
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
expected.addClass(class2);
|
expected.addClass(class2);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/MultipleClasses.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "MultipleClasses.java");
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Empty Class Test with Constructor")
|
@DisplayName("Empty Class Test with Constructor")
|
||||||
public void emptyClassWithConstructorTest() {
|
public void emptyClassWithConstructorTest() {
|
||||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
ClassNode class1 = Helper.generateEmptyClass("EmptyClassWithConstructor");
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/EmptyClassWithConstructor.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "EmptyClassWithConstructor.java");
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Field Test")
|
@DisplayName("Field Test")
|
||||||
public void fieldTest() {
|
public void fieldTest() {
|
||||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
ClassNode class1 = Helper.generateEmptyClass("Field");
|
||||||
class1.addMember(new FieldNode(null, new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Field.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "Field.java");
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Field Test with Accessmodifier")
|
@DisplayName("Field Test with Accessmodifier")
|
||||||
public void fieldTestWithModifier() {
|
public void fieldTestWithModifier() {
|
||||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
ClassNode class1 = Helper.generateEmptyClass("FieldWithAccessModifier");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/FieldWithAccessModifier.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "FieldWithAccessModifier.java");
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Commments Ignore Test")
|
@DisplayName("Comments Ignore Test")
|
||||||
public void commmentsIgnoreTest(){
|
public void commentsIgnoreTest() {
|
||||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
ClassNode class1 = Helper.generateEmptyClass("Comments");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Comments.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "Comments.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Constructor Paramerter Test")
|
@DisplayName("Constructor Parameter Test")
|
||||||
public void constructorParameterTest(){
|
public void constructorParameterTest() {
|
||||||
BlockNode block = new BlockNode();
|
BlockNode block = new BlockNode();
|
||||||
block.addStatement(new ReturnNode(null));
|
block.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
ConstructorNode constructor = new ConstructorNode("public", "ConstructorParameter", block);
|
||||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "ConstructorParameter");
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorParameter.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorParameter.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("This Dot Test")
|
@DisplayName("This Dot Test")
|
||||||
public void thisDotTest(){
|
public void thisDotTest() {
|
||||||
BlockNode block = new BlockNode();
|
BlockNode block = new BlockNode();
|
||||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
memberAccess.addIdentifier("a");
|
memberAccess.addIdentifier("a");
|
||||||
@ -152,23 +154,23 @@ class AstBuilderTest {
|
|||||||
|
|
||||||
block.addStatement(new AssignNode(assignable, expression));
|
block.addStatement(new AssignNode(assignable, expression));
|
||||||
block.addStatement(new ReturnNode(null));
|
block.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
ConstructorNode constructor = new ConstructorNode("public", "ThisDot", block);
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "ThisDot");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ThisDot.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "ThisDot.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Constructor This Dot Test")
|
@DisplayName("Constructor This Dot Test")
|
||||||
public void constructorThisDotTest(){
|
public void constructorThisDotTest() {
|
||||||
BlockNode block = new BlockNode();
|
BlockNode block = new BlockNode();
|
||||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
memberAccess.addIdentifier("a");
|
memberAccess.addIdentifier("a");
|
||||||
@ -179,25 +181,25 @@ class AstBuilderTest {
|
|||||||
|
|
||||||
block.addStatement(new AssignNode(assignable, expression));
|
block.addStatement(new AssignNode(assignable, expression));
|
||||||
block.addStatement(new ReturnNode(null));
|
block.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
ConstructorNode constructor = new ConstructorNode("public", "ConstructorThisDot", block);
|
||||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "ConstructorThisDot");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorThisDot.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorThisDot.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Void Methoden Test")
|
@DisplayName("Void Methoden Test")
|
||||||
public void voidMethodenTest(){
|
public void voidMethodenTest() {
|
||||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
ClassNode class1 = Helper.generateEmptyClass("VoidMethod");
|
||||||
BlockNode block = new BlockNode();
|
BlockNode block = new BlockNode();
|
||||||
block.addStatement(new ReturnNode(null));
|
block.addStatement(new ReturnNode(null));
|
||||||
class1.addMember(new MethodNode("public", null, true, "test", block));
|
class1.addMember(new MethodNode("public", null, true, "test", block));
|
||||||
@ -205,14 +207,14 @@ class AstBuilderTest {
|
|||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/VoidMethod.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "VoidMethod.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Constructor Method call Test")
|
@DisplayName("Constructor Method call Test")
|
||||||
public void constructorMethodCallTest(){
|
public void constructorMethodCallTest() {
|
||||||
BlockNode blockCon = new BlockNode();
|
BlockNode blockCon = new BlockNode();
|
||||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
memberAccess.addIdentifier("a");
|
memberAccess.addIdentifier("a");
|
||||||
@ -223,13 +225,13 @@ class AstBuilderTest {
|
|||||||
|
|
||||||
blockCon.addStatement(new AssignNode(assignable, expression));
|
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||||
blockCon.addStatement(new ReturnNode(null));
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
ConstructorNode constructor = new ConstructorNode("public", "ConstructorMethodCall", blockCon);
|
||||||
|
|
||||||
BlockNode blockMethod = new BlockNode();
|
BlockNode blockMethod = new BlockNode();
|
||||||
blockMethod.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "1"))));
|
blockMethod.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "1"))));
|
||||||
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "ConstructorMethodCall");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
class1.addMember(method);
|
class1.addMember(method);
|
||||||
@ -237,14 +239,14 @@ class AstBuilderTest {
|
|||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorMethodCall.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorMethodCall.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Constructor Method call Parameters Test")
|
@DisplayName("Constructor Method call Parameters Test")
|
||||||
public void constructorMethodCallParametersTest(){
|
public void constructorMethodCallParametersTest() {
|
||||||
BlockNode blockCon = new BlockNode();
|
BlockNode blockCon = new BlockNode();
|
||||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
memberAccess.addIdentifier("a");
|
memberAccess.addIdentifier("a");
|
||||||
@ -257,7 +259,7 @@ class AstBuilderTest {
|
|||||||
|
|
||||||
blockCon.addStatement(new AssignNode(assignable, expression));
|
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||||
blockCon.addStatement(new ReturnNode(null));
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
ConstructorNode constructor = new ConstructorNode("public", "ConstructorMethodCallParameters", blockCon);
|
||||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
BlockNode blockMethod = new BlockNode();
|
BlockNode blockMethod = new BlockNode();
|
||||||
@ -265,7 +267,7 @@ class AstBuilderTest {
|
|||||||
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
||||||
method.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
method.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "ConstructorMethodCallParameters");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
class1.addMember(method);
|
class1.addMember(method);
|
||||||
@ -273,14 +275,14 @@ class AstBuilderTest {
|
|||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorMethodCallParameters.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorMethodCallParameters.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Char Test")
|
@DisplayName("Char Test")
|
||||||
public void charTest(){
|
public void charTest() {
|
||||||
BlockNode blockCon = new BlockNode();
|
BlockNode blockCon = new BlockNode();
|
||||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
memberAccess.addIdentifier("a");
|
memberAccess.addIdentifier("a");
|
||||||
@ -293,7 +295,7 @@ class AstBuilderTest {
|
|||||||
|
|
||||||
blockCon.addStatement(new AssignNode(assignable, expression));
|
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||||
blockCon.addStatement(new ReturnNode(null));
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
ConstructorNode constructor = new ConstructorNode("public", "Char", blockCon);
|
||||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
||||||
|
|
||||||
BlockNode blockMethod = new BlockNode();
|
BlockNode blockMethod = new BlockNode();
|
||||||
@ -301,7 +303,7 @@ class AstBuilderTest {
|
|||||||
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.CHAR), false, "testMethod", blockMethod);
|
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.CHAR), false, "testMethod", blockMethod);
|
||||||
method.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
method.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "Char");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.CHAR), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.CHAR), "a"));
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
class1.addMember(method);
|
class1.addMember(method);
|
||||||
@ -309,14 +311,14 @@ class AstBuilderTest {
|
|||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Char.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "Char.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Null Test")
|
@DisplayName("Null Test")
|
||||||
public void nullTest(){
|
public void nullTest() {
|
||||||
BlockNode blockCon = new BlockNode();
|
BlockNode blockCon = new BlockNode();
|
||||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
memberAccess.addIdentifier("a");
|
memberAccess.addIdentifier("a");
|
||||||
@ -325,65 +327,65 @@ class AstBuilderTest {
|
|||||||
|
|
||||||
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
|
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
|
||||||
blockCon.addStatement(new ReturnNode(null));
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
ConstructorNode constructor = new ConstructorNode("public", "Null", blockCon);
|
||||||
|
|
||||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
ClassNode class1 = new ClassNode("public", "Null");
|
||||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
class1.addMember(constructor);
|
class1.addMember(constructor);
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(class1);
|
expected.addClass(class1);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Null.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "Null.java");
|
||||||
|
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Self Reference Test")
|
@DisplayName("Self Reference Test")
|
||||||
public void selfReferneceTest(){
|
public void selfReferneceTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Variable Compare Test")
|
@DisplayName("Variable Compare Test")
|
||||||
public void variableCompareTest(){
|
public void variableCompareTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Variable Calculation Test")
|
@DisplayName("Variable Calculation Test")
|
||||||
public void variableCalculationTest(){
|
public void variableCalculationTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Main Method Test")
|
@DisplayName("Main Method Test")
|
||||||
public void mainMethodTest(){
|
public void mainMethodTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("While Test")
|
@DisplayName("While Test")
|
||||||
public void whileTest(){
|
public void whileTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Do While Test")
|
@DisplayName("Do While Test")
|
||||||
public void doWhileTest(){
|
public void doWhileTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("For Test")
|
@DisplayName("For Test")
|
||||||
public void forTest(){
|
public void forTest() {
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
@ -391,26 +393,16 @@ class AstBuilderTest {
|
|||||||
//Noch nicht speziell Increment nur zum Development Testen per Debug
|
//Noch nicht speziell Increment nur zum Development Testen per Debug
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Increment Test")
|
@DisplayName("Increment Test")
|
||||||
public void incrementTest(){
|
public void incrementTest() {
|
||||||
ClassNode classNode = Helper.generateEmptyClass("TestClass");
|
ClassNode classNode = Helper.generateEmptyClass("Increment");
|
||||||
classNode.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
classNode.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
ProgramNode expected = new ProgramNode();
|
ProgramNode expected = new ProgramNode();
|
||||||
expected.addClass(classNode);
|
expected.addClass(classNode);
|
||||||
|
|
||||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Increment.java");
|
ASTNode actual = Helper.generateAST(directoryPath + "Increment.java");
|
||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -38,17 +38,14 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
CharStream codeCharStream = null;
|
CharStream codeCharStream = null;
|
||||||
try {
|
try {
|
||||||
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/typedAstFeaturesTests/CorrectTest.java"));
|
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/typedAstFeatureTests/CorrectTest.java"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
|
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
|
||||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||||
|
|
||||||
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
||||||
ParseTree parseTree = parser.program(); // parse the input
|
ParseTree parseTree = parser.program();
|
||||||
|
|
||||||
/* ------------------------- AST builder -> AST ------------------------- */
|
|
||||||
ASTBuilder astBuilder = new ASTBuilder();
|
ASTBuilder astBuilder = new ASTBuilder();
|
||||||
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
||||||
|
|
||||||
@ -115,7 +112,7 @@ public class EndToTypedAstTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void featureTest() {
|
public void featureTest() {
|
||||||
String directoryPath = "src/test/resources/input/typedAstFeaturesTests";
|
String directoryPath = "src/test/resources/input/typedAstFeatureTests";
|
||||||
File folder = new File(directoryPath);
|
File folder = new File(directoryPath);
|
||||||
if (folder.isDirectory()) {
|
if (folder.isDirectory()) {
|
||||||
File[] files = folder.listFiles((_, name) -> name.endsWith(".java"));
|
File[] files = folder.listFiles((_, name) -> name.endsWith(".java"));
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
public class CombinedExample {
|
|
||||||
int number;
|
|
||||||
boolean flag;
|
|
||||||
char letter;
|
|
||||||
|
|
||||||
public CombinedExample(int number, boolean flag, char letter) {
|
|
||||||
this.number = number;
|
|
||||||
this.flag = flag;
|
|
||||||
this.letter = letter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void displayValues() {
|
|
||||||
System.out.println("Number: " + number);
|
|
||||||
System.out.println("Flag: " + flag);
|
|
||||||
System.out.println("Letter: " + letter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
CombinedExample obj = new CombinedExample(10, true, 'X');
|
|
||||||
obj.displayValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
|||||||
public class CompilerInput {
|
|
||||||
|
|
||||||
public int a;
|
|
||||||
|
|
||||||
public static int testMethod(char x){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
public static int testMethod(char x, int a){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
public class MoreFeaturesClassExample {
|
|
||||||
int hallo;
|
|
||||||
private class Inner {
|
|
||||||
int hallo2;
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,19 +9,12 @@ public class AllFeaturesClassExample {
|
|||||||
this.b = b;
|
this.b = b;
|
||||||
this.c = c;
|
this.c = c;
|
||||||
}
|
}
|
||||||
private class InnerClass {
|
|
||||||
void innerMethod() {
|
|
||||||
System.out.println("Inner class method");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Methode zur Demonstration von Kontrollstrukturen
|
// Methode zur Demonstration von Kontrollstrukturen
|
||||||
void controlStructures() {
|
void controlStructures() {
|
||||||
// if-else Anweisung
|
// if-else Anweisung
|
||||||
if (a > 10) {
|
if (a > 10) {
|
||||||
System.out.println("a ist größer als 10");
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("a ist nicht größer als 10");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// while Schleife
|
// while Schleife
|
||||||
@ -32,35 +25,41 @@ public class AllFeaturesClassExample {
|
|||||||
|
|
||||||
// for Schleife
|
// for Schleife
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
System.out.println("for Schleife Iteration: " + i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch Anweisung
|
|
||||||
switch (c) {
|
|
||||||
case 'a':
|
|
||||||
System.out.println("c ist ein 'a'");
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
System.out.println("c ist ein 'b'");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("c ist nicht 'a' oder 'b'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methode zur Arbeit mit logischen Operatoren
|
// Methode zur Arbeit mit logischen Operatoren
|
||||||
void logicalOperations() {
|
void logicalOperations() {
|
||||||
// Logische UND-Operation
|
// Logische UND-Operation
|
||||||
if (b && a > 5) {
|
if (b && a > 5) {
|
||||||
System.out.println("a ist größer als 5 und b ist wahr");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logische ODER-Operation
|
// Logische ODER-Operation
|
||||||
if (b || a < 5) {
|
if (b || a < 5) {
|
||||||
System.out.println("b ist wahr oder a ist kleiner als 5");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int add(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int subtract(int a, int b) {
|
||||||
|
return a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int multiply(int a, int b) {
|
||||||
|
return a * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int divide(int a, int b) {
|
||||||
|
return a / b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int modulo(int a, int b) {
|
||||||
|
return a % b;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
AllFeaturesClassExample obj = new AllFeaturesClassExample(12, true, 'a');
|
AllFeaturesClassExample obj = new AllFeaturesClassExample(12, true, 'a');
|
||||||
obj.controlStructures();
|
obj.controlStructures();
|
@ -1,5 +0,0 @@
|
|||||||
class TestClass {
|
|
||||||
public TestClass(int a, int b){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
class TestClass{
|
|
||||||
|
|
||||||
private int a;
|
|
||||||
|
|
||||||
public TestClass(int a){
|
|
||||||
this.a = a;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
class TestClass {}
|
|
@ -1,5 +0,0 @@
|
|||||||
public class TestClass {
|
|
||||||
public TestClass() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
public class TestClass {
|
|
||||||
int a;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
public class TestClass {
|
|
||||||
public int a;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
class TestClass1 {}
|
|
||||||
|
|
||||||
class TestClass2{}
|
|
@ -1,8 +0,0 @@
|
|||||||
class TestClass{
|
|
||||||
|
|
||||||
int a;
|
|
||||||
|
|
||||||
public TestClass(){
|
|
||||||
this.a = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
class TestClass{
|
|
||||||
|
|
||||||
TestClass testClass;
|
|
||||||
|
|
||||||
int testMethod1() {
|
|
||||||
return this.testMethod2()
|
|
||||||
}
|
|
||||||
|
|
||||||
int testMethod2() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int testMehtod3(){
|
|
||||||
TestClass testClass1 = new TestClass();
|
|
||||||
return testClass1.testClass.testMethod1();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
class TestClass{
|
|
||||||
void test(){}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
class TestClass{
|
|
||||||
|
|
||||||
boolean true(){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean false(){
|
|
||||||
return false();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean trueAndTrue(){
|
|
||||||
return true && true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean trueAndFalse(){
|
|
||||||
return true && true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean falseAndFalse(){
|
|
||||||
return false && false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean trueOrFalse(){
|
|
||||||
return true || false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean falseOrFalse(){
|
|
||||||
return false || false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
class TestClass{
|
class Char {
|
||||||
|
|
||||||
char a;
|
char a;
|
||||||
|
|
||||||
public TestClass(char a){
|
public Char(char a){
|
||||||
this.a = testMethod(a);
|
this.a = testMethod(a);
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,6 @@
|
|||||||
Mutliple Line Comment. Ignore
|
Mutliple Line Comment. Ignore
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class TestClass{
|
class Comments{
|
||||||
private int a; // Ignore
|
private int a; // Ignore
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
class TestClass {
|
public class ConstructorMethodCall {
|
||||||
|
|
||||||
int a;
|
int a;
|
||||||
|
|
||||||
public TestClass(){
|
public ConstructorMethodCall(){
|
||||||
this.a = testMethod();
|
this.a = testMethod();
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
class TestClass {
|
class ConstructorMethodCallParameters {
|
||||||
|
|
||||||
int a;
|
int a;
|
||||||
|
|
||||||
public TestClass(int a){
|
public ConstructorMethodCallParameters(int a){
|
||||||
this.a = testMethod(a);
|
this.a = testMethod(a);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
class ConstructorParameter {
|
||||||
|
public ConstructorParameter(int a, int b){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
class ConstructorThisDot {
|
||||||
|
|
||||||
|
private int a;
|
||||||
|
|
||||||
|
public ConstructorThisDot(int a){
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
class TestClass{
|
class DoWhile{
|
||||||
|
|
||||||
public TestClass(){
|
public DoWhile(){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
do{
|
do{
|
||||||
i++
|
i++;
|
||||||
}while(i < 10);
|
}while(i < 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1 @@
|
|||||||
|
class EmptyClass {}
|
@ -0,0 +1,5 @@
|
|||||||
|
public class EmptyClassWithConstructor {
|
||||||
|
public EmptyClassWithConstructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
3
src/test/resources/input/singleFeatureTests/Field.java
Normal file
3
src/test/resources/input/singleFeatureTests/Field.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class Field {
|
||||||
|
int a;
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
public class FieldWithAccessModifier {
|
||||||
|
public int a;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
class TestClass{
|
class For{
|
||||||
|
|
||||||
public TestClass(){
|
public For(){
|
||||||
for(int i = 0; i < 10; i++){
|
for(int i = 0; i < 10; i++){
|
||||||
int a;
|
int a;
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ public class Increment {
|
|||||||
public void increment(int p) {
|
public void increment(int p) {
|
||||||
test = p++;
|
test = p++;
|
||||||
|
|
||||||
for(int i = 1; i<=10, i++) {
|
for(int i = 1; i<=10; i++) {
|
||||||
int a = 5;
|
int a = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
class TestClass{
|
class MainMethod{
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
}
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
class MultipleClasses {}
|
||||||
|
|
||||||
|
class TestClass2{}
|
8
src/test/resources/input/singleFeatureTests/Null.java
Normal file
8
src/test/resources/input/singleFeatureTests/Null.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class Null{
|
||||||
|
|
||||||
|
int a;
|
||||||
|
|
||||||
|
public Null(){
|
||||||
|
// this.a = null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
class SelfReference{
|
||||||
|
|
||||||
|
SelfReference selfReference;
|
||||||
|
|
||||||
|
int testMethod1() {
|
||||||
|
return this.testMethod2();
|
||||||
|
}
|
||||||
|
|
||||||
|
int testMethod2() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int testMehtod3(){
|
||||||
|
SelfReference selfReference1 = new SelfReference();
|
||||||
|
return selfReference1.selfReference.testMethod1();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
class TestClass{
|
class ThisDot {
|
||||||
|
|
||||||
public int a;
|
public int a;
|
||||||
|
|
||||||
public TestClass() {
|
public ThisDot() {
|
||||||
this.a = 1;
|
this.a = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
class TestClass{
|
class VariableCalculationTest{
|
||||||
|
|
||||||
int aPlusB(int a, int b){
|
int aPlusB(int a, int b){
|
||||||
return a + b;
|
return a + b;
|
@ -0,0 +1,30 @@
|
|||||||
|
class VariableCompareTest{
|
||||||
|
|
||||||
|
boolean trueMethod(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean falseMethod(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean trueAndTrue(){
|
||||||
|
return trueMethod() && trueMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean trueAndFalse(){
|
||||||
|
return trueMethod() && falseMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean falseAndFalse(){
|
||||||
|
return falseMethod() && falseMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean trueOrFalse(){
|
||||||
|
return trueMethod() || falseMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean falseOrFalse(){
|
||||||
|
return falseMethod() || falseMethod();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
class VoidMethod{
|
||||||
|
void test(){}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
class TestClass{
|
class While{
|
||||||
|
|
||||||
public TestClass(){
|
public While(){
|
||||||
int i = 10;
|
int i = 10;
|
||||||
|
|
||||||
while ( i > 0){
|
while ( i > 0){
|
@ -1,4 +1,4 @@
|
|||||||
public class Test {
|
public class CallMethodFromObjekt {
|
||||||
|
|
||||||
public int firstInt;
|
public int firstInt;
|
||||||
public Car ca;
|
public Car ca;
|
||||||
@ -7,7 +7,6 @@ public class Test {
|
|||||||
return ca.getSpeed();
|
return ca.getSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Car{
|
public class Car{
|
||||||
|
|
||||||
@ -17,4 +16,5 @@ public class Car{
|
|||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
public class Test{
|
public class CorrectMemberAccess{
|
||||||
|
|
||||||
public Car c;
|
public Car c;
|
||||||
|
|
||||||
@ -6,9 +6,8 @@ public class Test{
|
|||||||
return c.getSpeed();
|
return c.getSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Car{
|
private class Car{
|
||||||
|
|
||||||
private int speed;
|
private int speed;
|
||||||
|
|
||||||
@ -16,4 +15,5 @@ public class Car{
|
|||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
public class Test{
|
public class CorrectMethodParameter{
|
||||||
|
|
||||||
public void test(int x){
|
public void test(int x){
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
public class Test{
|
public class CorrectNonCalcTest{
|
||||||
|
|
||||||
public void test(boolean b){
|
public void test(boolean b){
|
||||||
if(b == true){
|
if(b == true){
|
@ -1,4 +1,4 @@
|
|||||||
public class Example {
|
public class CorrectReturnType {
|
||||||
|
|
||||||
public static int testMethod(int x){
|
public static int testMethod(int x){
|
||||||
return x;
|
return x;
|
@ -0,0 +1,21 @@
|
|||||||
|
public class CorrectTest {
|
||||||
|
int a;
|
||||||
|
boolean b;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
public void controlStructures(int adf, boolean bool) {
|
||||||
|
if (a > (10 + 8)) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while (a > adf) {
|
||||||
|
a--;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
public class AllFeaturesClassExample {
|
public class FullTest {
|
||||||
int a;
|
int a;
|
||||||
boolean b;
|
boolean b;
|
||||||
char c;
|
char c;
|
||||||
@ -18,7 +18,7 @@ public class AllFeaturesClassExample {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// void logicalOperations() {
|
// void logicalOperations() {
|
||||||
// // Logische UND-Operation
|
// // Logische UND-Operation
|
||||||
@ -62,3 +62,4 @@ public class Car {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
public class Car{
|
public class IfExpressionBoolean{
|
||||||
|
|
||||||
public void test(boolean boo){
|
public void test(boolean boo){
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
public class Car{
|
public class IfReturn{
|
||||||
|
|
||||||
public int getSpeed(boolean bool, int a, int b){
|
public int getSpeed(boolean bool, int a, int b){
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
public class Test{
|
public class SelectRightOverloadedMethod{
|
||||||
|
|
||||||
public int i;
|
public int i;
|
||||||
public boolean b;
|
public boolean b;
|
@ -1,4 +1,4 @@
|
|||||||
public class Car{
|
public class ThisDotMethod{
|
||||||
|
|
||||||
private int speed;
|
private int speed;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
public class Car{
|
public class VoidReturnTypeIF{
|
||||||
|
|
||||||
private int speed;
|
private int speed;
|
||||||
|
|
@ -1,38 +0,0 @@
|
|||||||
public class AllFeaturesClassExample {
|
|
||||||
int a;
|
|
||||||
boolean b;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
public void controlStructures(int adf, boolean bool) {
|
|
||||||
if (a > (10 + 8)) {
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while (a > adf) {
|
|
||||||
a--;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// void logicalOperations() {
|
|
||||||
// Logische UND-Operation
|
|
||||||
// if (b && a > 5) {
|
|
||||||
// System.out.println("a ist größer als 5 und b ist wahr");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Logische ODER-Operation
|
|
||||||
// if (b || a < 5) {
|
|
||||||
// System.out.println("b ist wahr oder a ist kleiner als 5");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
// AllFeaturesClassExample obj = new AllFeaturesClassExample(12, true, 'a');
|
|
||||||
// obj.controlStructures();
|
|
||||||
// }
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user