Compare commits
3 Commits
ed25868ff7
...
chainedMet
Author | SHA1 | Date | |
---|---|---|---|
|
1ffcd79265 | ||
|
5cd1ec2d05 | ||
|
49195c754c |
@@ -1,58 +0,0 @@
|
||||
# Kurzdokumentation
|
||||
|
||||
## Aufgabenverteilung
|
||||
|
||||
### Maximilian Stahl und Jannik Rombach:
|
||||
- **Scanner**
|
||||
- **Parser**
|
||||
- **AST**
|
||||
- **AstBuilder**
|
||||
- **Modul: ast**
|
||||
- Alle
|
||||
- **Modul: parser**
|
||||
- Alle
|
||||
- **Modul: visitor**
|
||||
- Alle
|
||||
- **Testmodul: parser**
|
||||
- AstBuildertest.java
|
||||
- Helper.java
|
||||
- **Testfiles: singleFeatureTests**
|
||||
- Alle
|
||||
|
||||
### Johannes Ehlert:
|
||||
- **Semantische Analyse**
|
||||
- **Modul: semantic**
|
||||
- **Modul: typecheck**
|
||||
- **Testmodul: parser**
|
||||
- AstBuildertest.java
|
||||
- **Testfiles: typedAstFeatureTests**
|
||||
- Großteil
|
||||
- **Testfiles: typedAstExceptionsTests**
|
||||
- Großteil
|
||||
|
||||
### David Große:
|
||||
- **Bytecodegenerator**
|
||||
- **Modul: bytecode**
|
||||
- Alle
|
||||
|
||||
### Lucas Janker:
|
||||
- **Tests**
|
||||
- **Modul: main**
|
||||
- Alle
|
||||
- **Testmodul: main**
|
||||
- Alle
|
||||
- **Testmodul: parser**
|
||||
- ScannerTest.java
|
||||
- ParserTest.java
|
||||
- **Testmodul: semantic**
|
||||
- **Testfiles: combinedFeatureTests**
|
||||
- Alle
|
||||
- **Testfiles: failureTests**
|
||||
- Alle
|
||||
- **Testfiles: Alle**
|
||||
- Refactoring
|
||||
- **Ordnerstrukturen**
|
||||
- Großteil
|
||||
- **Build**
|
||||
- **Makefile**
|
||||
- **Dokumentation**
|
8
pom.xml
8
pom.xml
@@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.11.0-M2</version>
|
||||
<version>5.9.3</version> <!-- Change the version as needed -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -44,12 +44,6 @@
|
||||
<version>3.26.0</version>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
|
@@ -5,6 +5,7 @@ import bytecode.visitor.MethodVisitor;
|
||||
import visitor.Visitable;
|
||||
|
||||
public class MainMethodNode extends MethodNode implements Visitable {
|
||||
public BlockNode block;
|
||||
|
||||
public MainMethodNode(BlockNode block) {
|
||||
this.block = block;
|
||||
|
@@ -2,7 +2,6 @@ package ast.statementexpressions.methodcallstatementnexpressions;
|
||||
|
||||
import ast.expressions.IExpressionNode;
|
||||
import ast.statements.IStatementNode;
|
||||
import ast.type.type.ITypeNode;
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import typechecker.TypeCheckResult;
|
||||
@@ -12,7 +11,6 @@ import java.util.List;
|
||||
|
||||
public class MethodCallNode implements IStatementNode {
|
||||
public TargetNode target;
|
||||
public ITypeNode type;
|
||||
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
|
||||
public String identifier;
|
||||
public List<IExpressionNode> parameters = new ArrayList<>();
|
||||
|
@@ -13,11 +13,6 @@ public class WhileNode implements IStatementNode {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult accept(SemanticVisitor visitor) {
|
||||
return visitor.analyze(this);
|
||||
|
@@ -13,7 +13,6 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
/**
|
||||
@@ -21,9 +20,9 @@ import java.util.Optional;
|
||||
* <p> <code> cd .\src\test\ </code>
|
||||
* <p> <code> make clean compile-raupenpiler </code>
|
||||
* <p> Start Raupenpiler using jar:
|
||||
* <p> <code> java.exe -DgenJar=true_OR_false -DgenClass=true_OR_false -jar path_to_jar\JavaCompiler-1.0-jar-with-dependencies.jar 'path_to_input_file.java' 'path_to_output_directory' </code>
|
||||
* <p> <code> java.exe -jar path_to_jar\JavaCompiler-1.0-jar-with-dependencies.jar 'path_to_input_file.java' 'path_to_output_directory' </code>
|
||||
* <p> Example (jar needs to be in the target directory, compile with make or mvn package first):
|
||||
* <code> java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code>
|
||||
* <code> java.exe -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code>
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -92,28 +91,16 @@ public class Main {
|
||||
|
||||
/*------------------------- Semantic Analyzer -> typed AST -------------------------*/
|
||||
// Use the SemanticAnalyzer to generate a typed AST
|
||||
ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
||||
//ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
||||
// Log the typed AST
|
||||
RaupenLogger.logSemanticAnalyzer(typedAst);
|
||||
|
||||
if(SemanticAnalyzer.errors.isEmpty()){
|
||||
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
||||
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
|
||||
|
||||
final boolean genJar = Optional.ofNullable(System.getProperty("genJar")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
|
||||
final boolean genClass = Optional.ofNullable(System.getProperty("genClass")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
|
||||
|
||||
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, genJar, genClass);
|
||||
assert typedAst != null;
|
||||
byteCodeGenerator.visit((ProgramNode) typedAst);
|
||||
// Log the bytecode generation
|
||||
RaupenLogger.logBytecodeGenerator();
|
||||
} else {
|
||||
for(Exception exception : SemanticAnalyzer.errors){
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
RaupenLogger.logSemanticAnalyzer(abstractSyntaxTree);
|
||||
|
||||
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
||||
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
|
||||
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, true, true);
|
||||
assert abstractSyntaxTree != null;
|
||||
byteCodeGenerator.visit((ProgramNode) abstractSyntaxTree);
|
||||
// Log the bytecode generation
|
||||
RaupenLogger.logBytecodeGenerator();
|
||||
}
|
||||
}
|
@@ -599,4 +599,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
default -> new ReferenceType(identifier);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
package parser.generated;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
package parser.generated;
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
package parser.generated;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
package parser.generated;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||
package parser.generated;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
|
@@ -21,7 +21,6 @@ import ast.statementexpressions.AssignableNode;
|
||||
import ast.statementexpressions.NewDeclarationNode;
|
||||
import ast.statementexpressions.crementexpressions.DecrementNode;
|
||||
import ast.statementexpressions.crementexpressions.IncrementNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||
import ast.statements.*;
|
||||
@@ -30,7 +29,6 @@ import ast.type.EnumAccessModifierNode;
|
||||
import ast.type.ValueNode;
|
||||
import ast.type.type.*;
|
||||
import com.sun.jdi.IntegerType;
|
||||
import semantic.context.ClassContext;
|
||||
import semantic.context.Context;
|
||||
import semantic.exceptions.*;
|
||||
import typechecker.TypeCheckResult;
|
||||
@@ -165,11 +163,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
|
||||
@Override
|
||||
public TypeCheckResult analyze(FieldNode toCheck) {
|
||||
if (toCheck.type instanceof ReferenceType referenceType) {
|
||||
if (!context.containsClass(referenceType.getIdentifier())) {
|
||||
errors.add(new NotDeclaredException(referenceType.getIdentifier() + " not declared"));
|
||||
}
|
||||
}
|
||||
if (currentFields.get(toCheck.identifier) != null) {
|
||||
errors.add(new AlreadyDeclaredException("Already declared " + toCheck.identifier));
|
||||
return new TypeCheckResult(false, null);
|
||||
@@ -177,8 +170,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
currentFields.put(toCheck.identifier, toCheck.type);
|
||||
}
|
||||
return new TypeCheckResult(true, null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,7 +224,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
}
|
||||
for (IStatementNode statementNode : blockNode.statements) {
|
||||
var result = statementNode.accept(this);
|
||||
if (!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)) {
|
||||
if(!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)){
|
||||
if (result.getType() != null) {
|
||||
if (blockReturnType == null) {
|
||||
blockReturnType = result.getType();
|
||||
@@ -258,10 +249,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
} else {
|
||||
if (currentFields.get(toCheck.identifier) != null) {
|
||||
var type = currentFields.get(toCheck.identifier);
|
||||
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
memberAccessNode.identifiers.add(toCheck.identifier);
|
||||
toCheck.memberAccess = memberAccessNode;
|
||||
toCheck.setTypeNode(type);
|
||||
return new TypeCheckResult(true, type);
|
||||
} else if (currentScope.getLocalVar(toCheck.identifier) != null) {
|
||||
@@ -288,6 +275,13 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
currentNullType = oldNullType;
|
||||
var valid = true;
|
||||
|
||||
// This check currently handles things like :
|
||||
/**
|
||||
* private int i;
|
||||
* void foo(int i){
|
||||
* i = i;
|
||||
* }
|
||||
*/
|
||||
if (assignable.equals(rExpression)) {
|
||||
errors.add(new TypeMismatchException("Cannot assign to self"));
|
||||
valid = false;
|
||||
@@ -324,66 +318,33 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
@Override
|
||||
public TypeCheckResult analyze(MethodCallNode toCheck) {
|
||||
|
||||
if (toCheck.target != null) {
|
||||
if (toCheck.target.identifier != null) {
|
||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||
if (targetType == null) {
|
||||
targetType = currentFields.get(toCheck.target.identifier);
|
||||
}
|
||||
if (targetType instanceof ReferenceType reference) {
|
||||
if (!toCheck.chainedMethods.isEmpty()) {
|
||||
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
|
||||
var type = getTypeFromMethod(chainedMethod, reference);
|
||||
if (type instanceof ReferenceType referenceType)
|
||||
reference = referenceType;
|
||||
else
|
||||
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
|
||||
}
|
||||
}
|
||||
var type = getTypeFromMethod(toCheck, reference);
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else {
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (toCheck.target.thisTar != null) {
|
||||
if (toCheck.target.thisTar) {
|
||||
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
}
|
||||
}
|
||||
if (toCheck.target.identifier != null) {
|
||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||
if (targetType == null) {
|
||||
targetType = currentFields.get(toCheck.target.identifier);
|
||||
}
|
||||
if (targetType instanceof ReferenceType reference) {
|
||||
var type = getTypeFromMethod(toCheck, reference);
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else {
|
||||
var result = toCheck.target.accept(this);
|
||||
if (result.getType() instanceof ReferenceType reference) {
|
||||
return new TypeCheckResult(true, getTypeFromMethod(toCheck, reference));
|
||||
}
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
ReferenceType reference = new ReferenceType(currentClass.identifier);
|
||||
if (!toCheck.chainedMethods.isEmpty()) {
|
||||
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
|
||||
var type = getTypeFromMethod(chainedMethod, reference);
|
||||
if (type instanceof ReferenceType referenceType)
|
||||
reference = referenceType;
|
||||
else
|
||||
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
|
||||
if (toCheck.target.thisTar) {
|
||||
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
}
|
||||
} else {
|
||||
var result = toCheck.target.accept(this);
|
||||
if (result.getType() instanceof ReferenceType reference) {
|
||||
return new TypeCheckResult(true, getTypeFromMethod(toCheck, reference));
|
||||
}
|
||||
}
|
||||
var type = getTypeFromMethod(toCheck, reference);
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else {
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
@@ -422,9 +383,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
|
||||
if (context.containsClass(toCheck.identifier)) {
|
||||
return new TypeCheckResult(true, new ReferenceType(toCheck.identifier));
|
||||
} else {
|
||||
throw new RuntimeException("Cannot find class " + toCheck.identifier);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -534,10 +495,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
if (currentScope.contains(unary.identifier)) {
|
||||
return new TypeCheckResult(valid, currentScope.getLocalVar(unary.identifier));
|
||||
} else if (currentFields.get(unary.identifier) != null) {
|
||||
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
memberAccessNode.identifiers.add(unary.identifier);
|
||||
unary.memberAccess = memberAccessNode;
|
||||
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
|
||||
} else if (unary.statement != null) {
|
||||
var result = unary.statement.accept(this);
|
||||
@@ -567,16 +524,8 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
public TypeCheckResult analyze(MemberAccessNode memberAccessNode) {
|
||||
|
||||
ITypeNode currentType = null;
|
||||
int start = 0;
|
||||
if(!memberAccessNode.identifiers.isEmpty()){
|
||||
if(currentFields.get(memberAccessNode.identifiers.get(0)) != null){
|
||||
memberAccessNode.identifiers.add(0, currentClass.identifier);
|
||||
start = 1;
|
||||
}
|
||||
}
|
||||
for (int i = start; i < memberAccessNode.identifiers.size(); i++) {
|
||||
|
||||
String s = memberAccessNode.identifiers.get(i);
|
||||
for (String s : memberAccessNode.identifiers) {
|
||||
if (currentType == null) {
|
||||
if (currentScope.getLocalVar(s) != null) {
|
||||
currentType = currentScope.getLocalVar(s);
|
||||
@@ -671,37 +620,4 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ITypeNode getTypeFromMethod(ChainedMethodNode toCheck, ReferenceType reference) {
|
||||
var classContext = context.getClass(reference.getIdentifier());
|
||||
|
||||
var methods = classContext.getMethods();
|
||||
for (var method : methods) {
|
||||
if (toCheck.identifier.equals(method.getIdentifier())) {
|
||||
if (method.getParameters().size() == toCheck.expressions.size() && !(method instanceof ConstructorNode)) {
|
||||
boolean same = true;
|
||||
for (int i = 0; i < method.getParameters().size(); i++) {
|
||||
var result1 = method.getParameters().get(i).accept(this);
|
||||
var result2 = toCheck.expressions.get(i).accept(this);
|
||||
if (!Objects.equals(result1.getType(), result2.getType())) {
|
||||
same = false;
|
||||
}
|
||||
}
|
||||
if (same) {
|
||||
if (method.accesModifier.accessType == EnumAccessModifierNode.PUBLIC) {
|
||||
if (method.getType() == null) {
|
||||
return new BaseType(TypeEnum.VOID);
|
||||
}
|
||||
return method.getType();
|
||||
} else {
|
||||
errors.add(new NotVisibleException("This Method is not Visible"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -21,10 +21,6 @@ public class Context {
|
||||
return classes.get(identifier);
|
||||
}
|
||||
|
||||
public HashMap<String, ClassContext> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
|
||||
public boolean containsClass(String identifier) {
|
||||
return classes.containsKey(identifier);
|
||||
}
|
||||
|
@@ -1,3 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: main.Main
|
||||
|
@@ -2,13 +2,15 @@ public class Compiler {
|
||||
public int add(int i, int j) {
|
||||
return i+j;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
int a = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public class Node {
|
||||
public void main() {
|
||||
Compiler compiler = new Compiler();
|
||||
int i = compiler.add(5, 8);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
src/main/resources/output/output.jar
Normal file
BIN
src/main/resources/output/output.jar
Normal file
Binary file not shown.
@@ -9,8 +9,8 @@ compile-javac:
|
||||
|
||||
compile-raupenpiler:
|
||||
cd ../.. ; mvn -DskipTests install
|
||||
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
|
||||
cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler
|
||||
cd ../.. ; mvn exec:java -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' "
|
||||
# cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler
|
||||
|
||||
test: compile-javac compile-raupenpiler test-javac test-raupenpiler
|
||||
|
||||
@@ -36,10 +36,8 @@ clean:
|
||||
rm -f ./resources/output/raupenpiler/*.class
|
||||
# clean logs
|
||||
rm -f ../main/resources/logs/*.log
|
||||
# clean test/java/main folders from .class files for End-to-End tests
|
||||
# clean test/main folders from .class files for End-to-End tests
|
||||
rm -f ./java/main/*.class
|
||||
# clean javac output from combinedFeatureTests
|
||||
rm -f ./resources/input/combinedFeatureTests/*.class
|
||||
rm -f ./resources/input/singleFeatureTests/*.class
|
||||
rm -f ./resources/input/typedAstFeatureTests/*.class
|
||||
# clean javac output from featureTests
|
||||
rm -f ./resources/input/featureTests/*.class
|
||||
|
||||
|
@@ -1,95 +1,177 @@
|
||||
package main;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import ast.ASTNode;
|
||||
import ast.ProgramNode;
|
||||
import bytecode.ByteCodeGenerator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import parser.astBuilder.ASTBuilder;
|
||||
import parser.generated.SimpleJavaLexer;
|
||||
import parser.generated.SimpleJavaParser;
|
||||
import semantic.SemanticAnalyzer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class E2EReflectionsTest {
|
||||
|
||||
|
||||
private CharStream mockInputCharStream;
|
||||
private String outputDirectoryPath;
|
||||
private SimpleJavaLexer mockLexer;
|
||||
private CommonTokenStream mockTokenStream;
|
||||
private SimpleJavaParser mockParser;
|
||||
private ParseTree mockParseTree;
|
||||
private ASTBuilder mockASTBuilder;
|
||||
private ASTNode mockASTNode;
|
||||
private SemanticAnalyzer mockSemanticAnalyzer;
|
||||
private ASTNode mockTypedAST;
|
||||
private ByteCodeGenerator mockByteCodeGenerator;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
mockInputCharStream = mock(CharStream.class);
|
||||
outputDirectoryPath = "path/to/output";
|
||||
mockLexer = mock(SimpleJavaLexer.class);
|
||||
mockTokenStream = mock(CommonTokenStream.class);
|
||||
mockParser = mock(SimpleJavaParser.class);
|
||||
mockParseTree = mock(ParseTree.class);
|
||||
mockASTBuilder = mock(ASTBuilder.class);
|
||||
mockASTNode = mock(ASTNode.class);
|
||||
mockSemanticAnalyzer = mock(SemanticAnalyzer.class);
|
||||
mockTypedAST = mock(ASTNode.class);
|
||||
mockByteCodeGenerator = mock(ByteCodeGenerator.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void AllFeaturesClassExampleTest(){
|
||||
try {
|
||||
Main.main(new String[]{"src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java", "src/test/resources/output/raupenpiler"});
|
||||
// Get the system Java compiler
|
||||
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
|
||||
// Assert that the compiler is available
|
||||
assertNotNull(javac, "Java Compiler is not available");
|
||||
javac.run(null, null, null, "src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java");
|
||||
public void testCompileFile() throws Exception {
|
||||
// Mock the dependencies
|
||||
SimpleJavaLexer mockLexer = mock(SimpleJavaLexer.class);
|
||||
CommonTokenStream mockTokenStream = mock(CommonTokenStream.class);
|
||||
SimpleJavaParser mockParser = mock(SimpleJavaParser.class);
|
||||
ParseTree mockParseTree = mock(ParseTree.class);
|
||||
ASTBuilder mockASTBuilder = mock(ASTBuilder.class);
|
||||
ASTNode mockASTNode = mock(ASTNode.class);
|
||||
SemanticAnalyzer mockSemanticAnalyzer = mock(SemanticAnalyzer.class);
|
||||
ASTNode mockTypedAST = mock(ASTNode.class);
|
||||
ByteCodeGenerator mockByteCodeGenerator = mock(ByteCodeGenerator.class);
|
||||
|
||||
Class<?> clazz = Class.forName("src.resources.input.combinedFeatureTests.AllFeaturesClassExample");
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
// Class<?> clazz = classLoader.loadClass("main.AllFeaturesClassExample");
|
||||
// Mock the behavior
|
||||
when(mockLexer.nextToken()).thenReturn(null);
|
||||
when(mockTokenStream.getTokens()).thenReturn(new ArrayList<>());
|
||||
when(mockParser.program()).thenReturn((SimpleJavaParser.ProgramContext) mockParseTree);
|
||||
when(mockASTBuilder.visit(mockParseTree)).thenReturn(mockASTNode);
|
||||
when(SemanticAnalyzer.generateTast(mockASTNode)).thenReturn(mockTypedAST);
|
||||
|
||||
// Class Name
|
||||
assertEquals("main.AllFeaturesClassExample", clazz.getName());
|
||||
// Use reflection to invoke the compileFile method
|
||||
Method compileFileMethod = main.Main.class.getDeclaredMethod("compileFile", CharStream.class, String.class);
|
||||
compileFileMethod.setAccessible(true);
|
||||
|
||||
// Constructors
|
||||
Constructor<?>[] actualConstructors = clazz.getDeclaredConstructors();
|
||||
assertTrue(actualConstructors.length > 0, "No constructors found");
|
||||
compileFileMethod.invoke(null, mockInputCharStream, outputDirectoryPath);
|
||||
|
||||
Constructor<?> expectedConstructor = clazz.getConstructor(int.class, boolean.class, char.class);
|
||||
// Verify each step
|
||||
verify(mockLexer, times(1)).nextToken();
|
||||
verify(mockTokenStream, times(1)).getTokens();
|
||||
verify(mockParser, times(1)).program();
|
||||
verify(mockASTBuilder, times(1)).visit(mockParseTree);
|
||||
verify(mockSemanticAnalyzer, times(1)).generateTast(mockASTNode);
|
||||
verify(mockByteCodeGenerator, times(1)).visit((ProgramNode) mockTypedAST);
|
||||
}
|
||||
|
||||
boolean constructorFound = false;
|
||||
for (Constructor<?> constructor : actualConstructors) {
|
||||
if (constructor.equals(expectedConstructor)) {
|
||||
constructorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(constructorFound, "Expected constructor not found in actual constructors");
|
||||
@Test
|
||||
public void testCompileFile2() throws Exception {
|
||||
// Mock the behavior
|
||||
when(mockLexer.nextToken()).thenReturn(null);
|
||||
when(mockTokenStream.getTokens()).thenReturn(new ArrayList<>());
|
||||
when(mockParser.program()).thenReturn((SimpleJavaParser.ProgramContext) mockParseTree);
|
||||
when(mockASTBuilder.visit(mockParseTree)).thenReturn(mockASTNode);
|
||||
when(SemanticAnalyzer.generateTast(mockASTNode)).thenReturn(mockTypedAST);
|
||||
|
||||
// Methods
|
||||
Method[] actualMethodNames = clazz.getDeclaredMethods();
|
||||
assertTrue(actualMethodNames.length > 0);
|
||||
for (Method method : actualMethodNames) {
|
||||
System.out.println("Method: " + method.getName());
|
||||
}
|
||||
// Use reflection to invoke the compileFile method
|
||||
Method compileFileMethod = main.Main.class.getDeclaredMethod("compileFile", CharStream.class, String.class);
|
||||
compileFileMethod.setAccessible(true);
|
||||
|
||||
// Method Names
|
||||
String[] expectedMethodNames = {
|
||||
"controlStructures",
|
||||
"logicalOperations",
|
||||
"add",
|
||||
"subtract",
|
||||
"multiply",
|
||||
"divide",
|
||||
"modulo",
|
||||
"main"
|
||||
};
|
||||
compileFileMethod.invoke(null, mockInputCharStream, outputDirectoryPath);
|
||||
|
||||
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");
|
||||
// Verify each step
|
||||
verify(mockLexer, times(1)).nextToken();
|
||||
verify(mockTokenStream, times(1)).getTokens();
|
||||
verify(mockParser, times(1)).program();
|
||||
verify(mockASTBuilder, times(1)).visit(mockParseTree);
|
||||
verify(mockSemanticAnalyzer, times(1)).generateTast(mockASTNode);
|
||||
verify(mockByteCodeGenerator, times(1)).visit((ProgramNode) mockTypedAST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testLexer() {
|
||||
// Mock the behavior
|
||||
when(mockLexer.nextToken()).thenReturn(null);
|
||||
|
||||
// Test the lexer
|
||||
SimpleJavaLexer lexer = new SimpleJavaLexer(mockInputCharStream);
|
||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||
tokenStream.fill();
|
||||
|
||||
assertNotNull(tokenStream.getTokens());
|
||||
verify(mockLexer, atLeastOnce()).nextToken();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParser() {
|
||||
// Mock the behavior
|
||||
when(mockParser.program()).thenReturn((SimpleJavaParser.ProgramContext) mockParseTree);
|
||||
|
||||
// Test the parser
|
||||
SimpleJavaParser parser = new SimpleJavaParser(mockTokenStream);
|
||||
ParseTree parseTree = parser.program();
|
||||
|
||||
assertNotNull(parseTree);
|
||||
verify(mockParser, times(1)).program();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASTBuilder() {
|
||||
// Mock the behavior
|
||||
when(mockASTBuilder.visit(mockParseTree)).thenReturn(mockASTNode);
|
||||
|
||||
// Test the AST builder
|
||||
ASTBuilder astBuilder = new ASTBuilder();
|
||||
ASTNode abstractSyntaxTree = astBuilder.visit(mockParseTree);
|
||||
|
||||
assertNotNull(abstractSyntaxTree);
|
||||
verify(mockASTBuilder, times(1)).visit(mockParseTree);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSemanticAnalyzer() {
|
||||
// Mock the behavior
|
||||
when(SemanticAnalyzer.generateTast(mockASTNode)).thenReturn(mockTypedAST);
|
||||
|
||||
// Test the semantic analyzer
|
||||
ASTNode typedAst = SemanticAnalyzer.generateTast(mockASTNode);
|
||||
|
||||
assertNotNull(typedAst);
|
||||
verify(mockSemanticAnalyzer, times(1)).generateTast(mockASTNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteCodeGenerator() {
|
||||
// Test the bytecode generator
|
||||
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, true, true);
|
||||
byteCodeGenerator.visit((ProgramNode) mockTypedAST);
|
||||
|
||||
verify(mockByteCodeGenerator, times(1)).visit((ProgramNode) mockTypedAST);
|
||||
}
|
||||
}
|
||||
|
||||
|
48
src/test/java/main/FailureTest.java
Normal file
48
src/test/java/main/FailureTest.java
Normal file
@@ -0,0 +1,48 @@
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
46
src/test/java/main/FeatureTest.java
Normal file
46
src/test/java/main/FeatureTest.java
Normal file
@@ -0,0 +1,46 @@
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
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() 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/failureTests");
|
||||
File folder2 = new File("src/test/resources/input/typedAstExceptionsTest");
|
||||
|
||||
List<File> files = getJavaFilesFromDirectory(folder1);
|
||||
files.addAll(getJavaFilesFromDirectory(folder2));
|
||||
|
||||
|
||||
if (!files.isEmpty()) {
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,145 +0,0 @@
|
||||
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
|
||||
}
|
@@ -14,19 +14,23 @@ import ast.members.*;
|
||||
import ast.parameters.ParameterNode;
|
||||
import ast.statementexpressions.AssignNode;
|
||||
import ast.statementexpressions.AssignableNode;
|
||||
import ast.statementexpressions.NewDeclarationNode;
|
||||
import ast.statementexpressions.crementexpressions.CrementType;
|
||||
import ast.statementexpressions.crementexpressions.DecrementNode;
|
||||
import ast.statementexpressions.crementexpressions.IncrementNode;
|
||||
import ast.statementexpressions.NewDeclarationNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||
import ast.statements.*;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||
import ast.statements.BlockNode;
|
||||
import ast.statements.LocalVariableDeclarationNode;
|
||||
import ast.statements.ReturnNode;
|
||||
import ast.type.AccessModifierNode;
|
||||
import ast.type.EnumValueNode;
|
||||
import ast.type.ValueNode;
|
||||
import ast.type.type.BaseType;
|
||||
import ast.type.type.ReferenceType;
|
||||
import ast.type.type.TypeEnum;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -35,106 +39,104 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DisplayName("Untyped Abstract Syntax Tree")
|
||||
class AstBuilderTest {
|
||||
|
||||
private final static String directoryPath = "src/test/resources/input/singleFeatureTests/";
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty Class Test")
|
||||
public void emptyClassTest() {
|
||||
ClassNode emptyClass = Helper.generateEmptyClass("EmptyClass");
|
||||
public void emptyClassTest(){
|
||||
ClassNode emptyClass = Helper.generateEmptyClass("TestClass");
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(emptyClass);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "EmptyClass.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/EmptyClass.java");
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Multiple Empty Classes Test")
|
||||
public void multipleEmptyClassesTest() {
|
||||
ClassNode class1 = Helper.generateEmptyClass("MultipleClasses");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass1");
|
||||
ClassNode class2 = Helper.generateEmptyClass("TestClass2");
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
expected.addClass(class2);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "MultipleClasses.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/MultipleClasses.java");
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty Class Test with Constructor")
|
||||
public void emptyClassWithConstructorTest() {
|
||||
ClassNode class1 = Helper.generateEmptyClass("EmptyClassWithConstructor");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "EmptyClassWithConstructor.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/EmptyClassWithConstructor.java");
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Field Test")
|
||||
public void fieldTest() {
|
||||
ClassNode class1 = Helper.generateEmptyClass("Field");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "Field.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Field.java");
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Field Test with Accessmodifier")
|
||||
public void fieldTestWithModifier() {
|
||||
ClassNode class1 = Helper.generateEmptyClass("FieldWithAccessModifier");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "FieldWithAccessModifier.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/FieldWithAccessModifier.java");
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Comments Ignore Test")
|
||||
public void commentsIgnoreTest() {
|
||||
ClassNode class1 = Helper.generateEmptyClass("Comments");
|
||||
@DisplayName("Commments Ignore Test")
|
||||
public void commmentsIgnoreTest(){
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "Comments.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Comments.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor Parameter Test")
|
||||
public void constructorParameterTest() {
|
||||
@DisplayName("Constructor Paramerter Test")
|
||||
public void constructorParameterTest(){
|
||||
BlockNode block = new BlockNode();
|
||||
block.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "ConstructorParameter", block);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "ConstructorParameter");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorParameter.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorParameter.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("This Dot Test")
|
||||
public void thisDotTest() {
|
||||
public void thisDotTest(){
|
||||
BlockNode block = new BlockNode();
|
||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||
memberAccess.addIdentifier("a");
|
||||
@@ -146,23 +148,23 @@ class AstBuilderTest {
|
||||
|
||||
block.addStatement(new AssignNode(assignable, expression));
|
||||
block.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "ThisDot", block);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "ThisDot");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "ThisDot.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ThisDot.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor This Dot Test")
|
||||
public void constructorThisDotTest() {
|
||||
public void constructorThisDotTest(){
|
||||
BlockNode block = new BlockNode();
|
||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||
memberAccess.addIdentifier("a");
|
||||
@@ -173,25 +175,25 @@ class AstBuilderTest {
|
||||
|
||||
block.addStatement(new AssignNode(assignable, expression));
|
||||
block.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "ConstructorThisDot", block);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "ConstructorThisDot");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorThisDot.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorThisDot.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Void Methoden Test")
|
||||
public void voidMethodenTest() {
|
||||
ClassNode class1 = Helper.generateEmptyClass("VoidMethod");
|
||||
public void voidMethodenTest(){
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
BlockNode block = new BlockNode();
|
||||
block.addStatement(new ReturnNode(null));
|
||||
class1.addMember(new MethodNode("public", null, true, "test", block));
|
||||
@@ -199,14 +201,14 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "VoidMethod.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/VoidMethod.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor Method call Test")
|
||||
public void constructorMethodCallTest() {
|
||||
public void constructorMethodCallTest(){
|
||||
BlockNode blockCon = new BlockNode();
|
||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||
memberAccess.addIdentifier("a");
|
||||
@@ -217,13 +219,13 @@ class AstBuilderTest {
|
||||
|
||||
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "ConstructorMethodCall", blockCon);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
|
||||
BlockNode blockMethod = new BlockNode();
|
||||
blockMethod.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "1"))));
|
||||
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "ConstructorMethodCall");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||
class1.addMember(constructor);
|
||||
class1.addMember(method);
|
||||
@@ -231,14 +233,14 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorMethodCall.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorMethodCall.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor Method call Parameters Test")
|
||||
public void constructorMethodCallParametersTest() {
|
||||
public void constructorMethodCallParametersTest(){
|
||||
BlockNode blockCon = new BlockNode();
|
||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||
memberAccess.addIdentifier("a");
|
||||
@@ -251,7 +253,7 @@ class AstBuilderTest {
|
||||
|
||||
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "ConstructorMethodCallParameters", blockCon);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||
|
||||
BlockNode blockMethod = new BlockNode();
|
||||
@@ -259,7 +261,7 @@ class AstBuilderTest {
|
||||
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
||||
method.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "ConstructorMethodCallParameters");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||
class1.addMember(constructor);
|
||||
class1.addMember(method);
|
||||
@@ -267,14 +269,14 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "ConstructorMethodCallParameters.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorMethodCallParameters.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Char Test")
|
||||
public void charTest() {
|
||||
public void charTest(){
|
||||
BlockNode blockCon = new BlockNode();
|
||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||
memberAccess.addIdentifier("a");
|
||||
@@ -287,7 +289,7 @@ class AstBuilderTest {
|
||||
|
||||
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "Char", blockCon);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
||||
|
||||
BlockNode blockMethod = new BlockNode();
|
||||
@@ -295,7 +297,7 @@ class AstBuilderTest {
|
||||
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.CHAR), false, "testMethod", blockMethod);
|
||||
method.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "Char");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.CHAR), "a"));
|
||||
class1.addMember(constructor);
|
||||
class1.addMember(method);
|
||||
@@ -303,14 +305,14 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "Char.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Char.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Null Test")
|
||||
public void nullTest() {
|
||||
public void nullTest(){
|
||||
BlockNode blockCon = new BlockNode();
|
||||
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||
memberAccess.addIdentifier("a");
|
||||
@@ -319,16 +321,16 @@ class AstBuilderTest {
|
||||
|
||||
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "Null", blockCon);
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "Null");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new ReferenceType("Null"), "a"));
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "Null.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Null.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -337,9 +339,9 @@ class AstBuilderTest {
|
||||
@DisplayName("Self Reference Test")
|
||||
public void selfReferneceTest(){
|
||||
|
||||
ClassNode testClass = Helper.generateEmptyClass("SelfReference");
|
||||
ClassNode testClass = Helper.generateEmptyClass("TestClass");
|
||||
|
||||
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("SelfReference"),"selfReference");
|
||||
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("TestClass"),"testClass");
|
||||
|
||||
BlockNode testMethod1Block = new BlockNode();
|
||||
testMethod1Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(new TargetNode(true), "testMethod2"))));
|
||||
@@ -350,10 +352,10 @@ class AstBuilderTest {
|
||||
MethodNode testMethod2 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod2", testMethod2Block);
|
||||
|
||||
BlockNode testMethod3Block = new BlockNode();
|
||||
testMethod3Block.addStatement(new LocalVariableDeclarationNode(new ReferenceType("SelfReference"),"selfReference1", "=", new UnaryNode(new NewDeclarationNode("SelfReference")))); // Assing einfach "=" ?
|
||||
testMethod3Block.addStatement(new LocalVariableDeclarationNode(new ReferenceType("TestClass"),"testClass1", "=", new UnaryNode(new NewDeclarationNode("TestClass")))); // Assing einfach "=" ?
|
||||
MemberAccessNode methodAccess = new MemberAccessNode(false);
|
||||
methodAccess.addIdentifier("selfReference1");
|
||||
methodAccess.addIdentifier("selfReference");
|
||||
methodAccess.addIdentifier("testClass1");
|
||||
methodAccess.addIdentifier("testClass");
|
||||
TargetNode methodTarget = new TargetNode(methodAccess);
|
||||
testMethod3Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(methodTarget,"testMethod1"))));
|
||||
MethodNode testMethod3 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod3", testMethod3Block);
|
||||
@@ -366,7 +368,7 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(testClass);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "SelfReference.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/SelfReference.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -374,7 +376,7 @@ class AstBuilderTest {
|
||||
@Test
|
||||
@DisplayName("Variable Compare Test")
|
||||
public void variableCompareTest(){
|
||||
ClassNode class1 = Helper.generateEmptyClass("VariableCompare");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
UnaryNode trueValue = new UnaryNode(new ValueNode(EnumValueNode.BOOLEAN_VALUE,"true"));
|
||||
UnaryNode falseValue = new UnaryNode(new ValueNode(EnumValueNode.BOOLEAN_VALUE,"false"));
|
||||
|
||||
@@ -417,7 +419,7 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "VariableCompare.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/variableCompare.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -425,7 +427,7 @@ class AstBuilderTest {
|
||||
@Test
|
||||
@DisplayName("Variable Calculation Test")
|
||||
public void variableCalculationTest(){
|
||||
ClassNode class1 = Helper.generateEmptyClass("VariableCalculation");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
|
||||
BlockNode aPlusBBlock = new BlockNode();
|
||||
aPlusBBlock.addStatement(new ReturnNode(new CalculationNode(new CalculationNode(new DotNode(new DotSubstractionNode("a"))), "+", new DotNode(new DotSubstractionNode("b")))));
|
||||
@@ -487,7 +489,7 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "VariableCalculation.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/variableCalculation.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -495,7 +497,7 @@ class AstBuilderTest {
|
||||
@Test
|
||||
@DisplayName("Main Method Test")
|
||||
public void mainMethodTest(){
|
||||
ClassNode class1 = Helper.generateEmptyClass("MainMethod");
|
||||
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||
|
||||
BlockNode block = new BlockNode();
|
||||
block.addStatement(new ReturnNode(null));
|
||||
@@ -505,7 +507,7 @@ class AstBuilderTest {
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "MainMethod.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/MainMethod.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -526,13 +528,13 @@ class AstBuilderTest {
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "While");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "While.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/While.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -557,13 +559,13 @@ class AstBuilderTest {
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "DoWhile");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "DoWhile.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/DoWhile.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
@@ -593,13 +595,13 @@ class AstBuilderTest {
|
||||
blockCon.addStatement(new ReturnNode(null));
|
||||
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||
|
||||
ClassNode class1 = new ClassNode("public", "For");
|
||||
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||
class1.addMember(constructor);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(class1);
|
||||
|
||||
ASTNode actual = Helper.generateAST(directoryPath + "For.java");
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/For.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import semantic.exceptions.NotDeclaredException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -39,14 +38,17 @@ public class EndToTypedAstTest {
|
||||
|
||||
CharStream codeCharStream = null;
|
||||
try {
|
||||
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/typedAstFeatureTests/CorrectTest.java"));
|
||||
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/typedAstFeaturesTests/CorrectTest.java"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
|
||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||
|
||||
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
||||
ParseTree parseTree = parser.program();
|
||||
ParseTree parseTree = parser.program(); // parse the input
|
||||
|
||||
/* ------------------------- AST builder -> AST ------------------------- */
|
||||
ASTBuilder astBuilder = new ASTBuilder();
|
||||
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
||||
|
||||
@@ -109,12 +111,11 @@ public class EndToTypedAstTest {
|
||||
} else {
|
||||
System.out.println("The provided path is not a directory.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void featureTest() {
|
||||
String directoryPath = "src/test/resources/input/typedAstFeatureTests";
|
||||
String directoryPath = "src/test/resources/input/typedAstFeaturesTests";
|
||||
File folder = new File(directoryPath);
|
||||
if (folder.isDirectory()) {
|
||||
File[] files = folder.listFiles((_, name) -> name.endsWith(".java"));
|
||||
|
@@ -2,4 +2,112 @@ package semantic;
|
||||
|
||||
public class SemanticTest {
|
||||
|
||||
|
||||
public void test(){
|
||||
|
||||
}
|
||||
|
||||
public void test(int a, boolean b){
|
||||
|
||||
}
|
||||
|
||||
public void test(boolean b, int a){
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void alreadyDeclaredLocalFieldVar() {
|
||||
// ProgramNode programNode = new ProgramNode();
|
||||
// List<ClassNode> classList = new ArrayList<>();
|
||||
// AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC);
|
||||
// ClassNode classNode = new ClassNode(accessTypeNode, "testClass");
|
||||
//
|
||||
// SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
|
||||
// ASTNode tast = semanticAnalyzer.generateTast(ast);
|
||||
//
|
||||
// MemberNode memberNode2 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar");
|
||||
// classNode.members.add(memberNode2);
|
||||
//
|
||||
// classList.add(classNode);
|
||||
// programNode.classes = classList;
|
||||
//
|
||||
// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
|
||||
//
|
||||
// assertEquals(1, SemanticAnalyzer.errors.size());
|
||||
// assertInstanceOf(AlreadyDeclaredException.class, SemanticAnalyzer.errors.getFirst());
|
||||
// assertNull(typedAst);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldWorkWithNoError() {
|
||||
// ProgramNode programNode = new ProgramNode();
|
||||
// List<ClassNode> classList = new ArrayList<>();
|
||||
// AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC);
|
||||
// ClassNode classNode = new ClassNode(accessTypeNode, "testClass");
|
||||
//
|
||||
// SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
|
||||
// ASTNode tast = semanticAnalyzer.generateTast(ast);
|
||||
//
|
||||
// assertEquals(semanticAnalyzer.errors.size(), 0);
|
||||
// assertNotNull(tast);
|
||||
//
|
||||
// MemberNode memberNode3 = getMemberNode(accessTypeNode);
|
||||
// classNode.members.add(memberNode3);
|
||||
//
|
||||
// classList.add(classNode);
|
||||
// programNode.classes = classList;
|
||||
//
|
||||
// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
|
||||
//
|
||||
// assertEquals(0, SemanticAnalyzer.errors.size());
|
||||
// assertEquals(programNode, typedAst);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * This method is used to create a MemberNode representing a method.
|
||||
// * It first creates a list of ParameterNodes and adds a ParameterNode to it.
|
||||
// * Then, it creates a ParameterListNode using the list of ParameterNodes.
|
||||
// * After that, it creates a list of StatementNodes and adds a StatementNode to it by calling the getStatementNode method.
|
||||
// * Finally, it creates a MethodNode using the provided AccessTypeNode, a BaseTypeNode representing the return type of the method,
|
||||
// * the method name, the ParameterListNode, and the list of StatementNodes, and returns this MethodNode.
|
||||
// *
|
||||
// * @param accessTypeNode The AccessTypeNode representing the access type of the method.
|
||||
// * @return The created MemberNode representing the method.
|
||||
// */
|
||||
//private static MemberNode getMemberNode(AccessTypeNode accessTypeNode) {
|
||||
// List<ParameterNode> parameterNodeList = new ArrayList<>();
|
||||
// ParameterNode parameterNode1 = new ParameterNode(new BaseTypeNode(EnumTypeNode.INT), "param1");
|
||||
// parameterNodeList.add(parameterNode1);
|
||||
// ParameterListNode parameterListNode = new ParameterListNode(parameterNodeList);
|
||||
//
|
||||
// List<StatementNode> statementNodeList = new ArrayList<>();
|
||||
//
|
||||
// StatementNode statementNode1 = getStatementNode();
|
||||
// statementNodeList.add(statementNode1);
|
||||
//
|
||||
// return new MethodNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar2", parameterListNode, statementNodeList);
|
||||
//}
|
||||
//
|
||||
// /**
|
||||
// * This method is used to create a StatementNode for an assignment operation.
|
||||
// * It first creates two IdentifierExpressionNodes for 'this' and 'objectVar'.
|
||||
// * Then, it creates a BinaryExpressionNode to represent the operation 'this.objectVar'.
|
||||
// * After that, it creates a LiteralNode to represent the integer value 1.
|
||||
// * Finally, it creates another BinaryExpressionNode to represent the assignment operation 'this.objectVar = 1',
|
||||
// * and wraps this expression in an AssignmentStatementNode.
|
||||
// *
|
||||
// * @return The created AssignmentStatementNode representing the assignment operation 'this.objectVar = 1'.
|
||||
// */
|
||||
//private static StatementNode getStatementNode() {
|
||||
// ExpressionNode expressionNodeObjectVariableLeft = new IdentifierExpressionNode("this");
|
||||
// ExpressionNode expressionNodeObjectVariableRight = new IdentifierExpressionNode("objectVar");
|
||||
//
|
||||
// ExpressionNode expressionNodeLeft = new BinaryExpressionNode(expressionNodeObjectVariableLeft, expressionNodeObjectVariableRight, ExpresssionOperator.DOT);
|
||||
//
|
||||
// ExpressionNode expressionNodeRight = new LiteralNode(1);
|
||||
//
|
||||
// BinaryExpressionNode expressionNode = new BinaryExpressionNode(expressionNodeLeft, expressionNodeRight, ExpresssionOperator.ASSIGNMENT);
|
||||
//
|
||||
// return new AssignmentStatementNode(expressionNode);
|
||||
//}
|
||||
}
|
@@ -4,7 +4,7 @@ public class AllFeaturesClassExample {
|
||||
char c;
|
||||
|
||||
// Konstruktor
|
||||
public AllFeaturesClassExample(int a, boolean b, char c) {
|
||||
AllFeaturesClassExample(int a, boolean b, char c) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
@@ -14,54 +14,47 @@ public class AllFeaturesClassExample {
|
||||
void controlStructures() {
|
||||
// if-else Anweisung
|
||||
if (a > 10) {
|
||||
// System.out.println("a ist größer als 10");
|
||||
} else {
|
||||
// System.out.println("a ist nicht größer als 10");
|
||||
}
|
||||
|
||||
// while Schleife
|
||||
while (a > 0) {
|
||||
// System.out.println("a ist " + a);
|
||||
a--;
|
||||
}
|
||||
int c = 0;
|
||||
|
||||
// for Schleife
|
||||
for (int i = 0; i < 5; i++) {
|
||||
c++;
|
||||
// System.out.println("for Schleife Iteration: " + i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Methode zur Arbeit mit logischen Operatoren
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
boolean greaterThan(int a, int b) {
|
||||
return a > b;
|
||||
void mathOperations() {
|
||||
// Addition
|
||||
int sum = a + 5;
|
||||
// Subtraktion
|
||||
int difference = a - 5;
|
||||
// Multiplikation
|
||||
int product = a * 5;
|
||||
// Division
|
||||
int quotient = a / 5;
|
||||
// Modulo
|
||||
int remainder = a % 5;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
23
src/test/resources/input/CombinedExample.java
Normal file
23
src/test/resources/input/CombinedExample.java
Normal file
@@ -0,0 +1,23 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
16
src/test/resources/input/CompilerInput.java
Normal file
16
src/test/resources/input/CompilerInput.java
Normal file
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
src/test/resources/input/MoreFeaturesClassExample.java
Normal file
6
src/test/resources/input/MoreFeaturesClassExample.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class MoreFeaturesClassExample {
|
||||
int hallo;
|
||||
private class Inner {
|
||||
int hallo2;
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,8 +1,8 @@
|
||||
class Char {
|
||||
class TestClass{
|
||||
|
||||
char a;
|
||||
|
||||
public Char(char a){
|
||||
public TestClass(char a){
|
||||
this.a = testMethod(a);
|
||||
}
|
||||
|
@@ -3,6 +3,6 @@
|
||||
Mutliple Line Comment. Ignore
|
||||
|
||||
*/
|
||||
class Comments{
|
||||
class TestClass{
|
||||
private int a; // Ignore
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
public class ConstructorMethodCall {
|
||||
class TestClass {
|
||||
|
||||
int a;
|
||||
|
||||
public ConstructorMethodCall(){
|
||||
public TestClass(){
|
||||
this.a = testMethod();
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
class ConstructorMethodCallParameters {
|
||||
class TestClass {
|
||||
|
||||
int a;
|
||||
|
||||
public ConstructorMethodCallParameters(int a){
|
||||
public TestClass(int a){
|
||||
this.a = testMethod(a);
|
||||
}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
class TestClass {
|
||||
public TestClass(int a, int b){
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
class TestClass{
|
||||
|
||||
private int a;
|
||||
|
||||
public TestClass(int a){
|
||||
this.a = a;
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
class DoWhile{
|
||||
class TestClass{
|
||||
|
||||
public DoWhile(){
|
||||
public TestClass(){
|
||||
int i = 0;
|
||||
|
||||
do{
|
1
src/test/resources/input/javaCases/EmptyClass.java
Normal file
1
src/test/resources/input/javaCases/EmptyClass.java
Normal file
@@ -0,0 +1 @@
|
||||
class TestClass {}
|
@@ -0,0 +1,5 @@
|
||||
public class TestClass {
|
||||
public TestClass() {
|
||||
|
||||
}
|
||||
}
|
3
src/test/resources/input/javaCases/Field.java
Normal file
3
src/test/resources/input/javaCases/Field.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public class TestClass {
|
||||
int a;
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
public class TestClass {
|
||||
public int a;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
class For{
|
||||
class TestClass{
|
||||
|
||||
public For(){
|
||||
public TestClass(){
|
||||
for(int i = 0; i < 10; i++){
|
||||
int a;
|
||||
}
|
@@ -5,7 +5,7 @@ public class Increment {
|
||||
public void increment(int p) {
|
||||
test = p++;
|
||||
|
||||
for(int i = 1; i<=10; i++) {
|
||||
for(int i = 1; i<=10, i++) {
|
||||
int a = 5;
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
class MainMethod{
|
||||
class TestClass{
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
3
src/test/resources/input/javaCases/MultipleClasses.java
Normal file
3
src/test/resources/input/javaCases/MultipleClasses.java
Normal file
@@ -0,0 +1,3 @@
|
||||
class TestClass1 {}
|
||||
|
||||
class TestClass2{}
|
8
src/test/resources/input/javaCases/Null.java
Normal file
8
src/test/resources/input/javaCases/Null.java
Normal file
@@ -0,0 +1,8 @@
|
||||
class TestClass{
|
||||
|
||||
int a;
|
||||
|
||||
public TestClass(){
|
||||
this.a = null;
|
||||
}
|
||||
}
|
18
src/test/resources/input/javaCases/SelfReference.java
Normal file
18
src/test/resources/input/javaCases/SelfReference.java
Normal file
@@ -0,0 +1,18 @@
|
||||
class TestClass{
|
||||
|
||||
TestClass testClass;
|
||||
|
||||
int testMethod1() {
|
||||
return this.testMethod2();
|
||||
}
|
||||
|
||||
int testMethod2() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int testMethod3(){
|
||||
TestClass testClass1 = new TestClass();
|
||||
return testClass1.testClass.testMethod1();
|
||||
}
|
||||
|
||||
}
|
10
src/test/resources/input/javaCases/SwitchCase.java
Normal file
10
src/test/resources/input/javaCases/SwitchCase.java
Normal file
@@ -0,0 +1,10 @@
|
||||
class TestClass{
|
||||
|
||||
TestClasd (){
|
||||
switch (a){
|
||||
case 1:
|
||||
b = 1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
class ThisDot {
|
||||
class TestClass{
|
||||
|
||||
public int a;
|
||||
|
||||
public ThisDot() {
|
||||
public TestClass() {
|
||||
this.a = 1;
|
||||
}
|
||||
}
|
3
src/test/resources/input/javaCases/VoidMethod.java
Normal file
3
src/test/resources/input/javaCases/VoidMethod.java
Normal file
@@ -0,0 +1,3 @@
|
||||
class TestClass{
|
||||
void test(){}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
class While{
|
||||
class TestClass{
|
||||
|
||||
public While(){
|
||||
public TestClass(){
|
||||
int i = 10;
|
||||
|
||||
while ( i > 0){
|
@@ -1,4 +1,4 @@
|
||||
class VariableCalculation{
|
||||
class TestClass{
|
||||
|
||||
int aPlusB(int a, int b){
|
||||
return a + b;
|
@@ -1,4 +1,4 @@
|
||||
class VariableCompare{
|
||||
class TestClass{
|
||||
|
||||
boolean trueMethod() {
|
||||
return true;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
class ConstructorParameter {
|
||||
public ConstructorParameter(int a, int b){
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
class ConstructorThisDot {
|
||||
|
||||
private int a;
|
||||
|
||||
public ConstructorThisDot(int a){
|
||||
this.a = a;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
class EmptyClass {}
|
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
public class EmptyClassWithConstructor {
|
||||
public EmptyClassWithConstructor() {
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
class Field {
|
||||
int a;
|
||||
}
|
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
public class FieldWithAccessModifier {
|
||||
public int a;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
class MultipleClasses {}
|
||||
|
||||
class TestClass2{}
|
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
class Null{
|
||||
|
||||
Null a;
|
||||
|
||||
public Null(){
|
||||
this.a = null;
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -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();
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user