Tests refactored
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
Lucas 2024-06-25 18:05:26 +02:00
parent f9743efddc
commit cc6d26e17d
11 changed files with 111 additions and 117 deletions

View File

@ -20,13 +20,11 @@ import java.nio.file.Paths;
* <p> <code> cd .\src\test\ </code>
* <p> <code> make clean compile-raupenpiler </code>
* <p> Start Raupenpiler using jar:
* <p> <code> java.exe -jar path_to_jar\JavaCompiler-1.0-SNAPSHOT-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 -jar .\target\JavaCompiler-1.0-SNAPSHOT-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 {
if (args.length == 2) {
// args[0] is the input file path

View File

@ -53,7 +53,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) {
ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
for (SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
constructorNode.addParameter((ParameterNode) visit(parameter));
}
return constructorNode;
@ -61,18 +61,18 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
if(ctx.MainMethodDeclaration() != null) {
if (ctx.MainMethodDeclaration() != null) {
return new MainMethodNode((BlockNode) visit(ctx.block()));
} else {
if(ctx.type() != null) {
if (ctx.type() != null) {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
for (SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
return methodNode;
} else {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
for (SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
return methodNode;
@ -92,19 +92,19 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitStatement(SimpleJavaParser.StatementContext ctx) {
if(ctx.returnStatement() != null) {
if (ctx.returnStatement() != null) {
return visitReturnStatement(ctx.returnStatement());
} else if(ctx.localVariableDeclaration() != null) {
} else if (ctx.localVariableDeclaration() != null) {
return visitLocalVariableDeclaration(ctx.localVariableDeclaration());
} else if(ctx.block() != null) {
} else if (ctx.block() != null) {
return visitBlock(ctx.block());
} else if(ctx.whileStatement() != null) {
} else if (ctx.whileStatement() != null) {
return visitWhileStatement(ctx.whileStatement());
} else if(ctx.forStatement() != null) {
} else if (ctx.forStatement() != null) {
return visitForStatement(ctx.forStatement());
} else if(ctx.ifElseStatement() != null) {
} else if (ctx.ifElseStatement() != null) {
return visitIfElseStatement(ctx.ifElseStatement());
} else if(ctx.statementExpression() != null) {
} else if (ctx.statementExpression() != null) {
return visitStatementExpression(ctx.statementExpression());
}
return null;
@ -123,10 +123,10 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitBlock(SimpleJavaParser.BlockContext ctx) {
BlockNode blockNode = new BlockNode();
for(SimpleJavaParser.StatementContext statement : ctx.statement()) {
for (SimpleJavaParser.StatementContext statement : ctx.statement()) {
blockNode.addStatement((IStatementNode) visit(statement));
}
if(!blockNode.hasReturnStatement) {
if (!blockNode.hasReturnStatement) {
blockNode.addStatement(new ReturnStatementNode(null));
}
return blockNode;
@ -139,9 +139,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitForStatement(SimpleJavaParser.ForStatementContext ctx) {
if(ctx.statementExpression(0) != null) {
if (ctx.statementExpression(0) != null) {
return new ForStatementNode((IExpressionNode) visit(ctx.statementExpression(0)), (IExpressionNode) visit(ctx.expression()), (IExpressionNode) visit(ctx.statementExpression(1)));
} else if(ctx.localVariableDeclaration() != null) {
} else if (ctx.localVariableDeclaration() != null) {
return new ForStatementNode((IStatementNode) visit(ctx.localVariableDeclaration()), (IExpressionNode) visit(ctx.expression()), (IExpressionNode) visit(ctx.statementExpression(1)));
}
return null;
@ -149,8 +149,8 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitIfElseStatement(SimpleJavaParser.IfElseStatementContext ctx) {
IfElseStatementNode ifElseStatementNode = new IfElseStatementNode((IfStatementNode) visit(ctx.ifStatement()));
for(SimpleJavaParser.ElseStatementContext elseStatement : ctx.elseStatement()) {
IfElseStatementNode ifElseStatementNode = new IfElseStatementNode((IfStatementNode) visit(ctx.ifStatement()));
for (SimpleJavaParser.ElseStatementContext elseStatement : ctx.elseStatement()) {
ifElseStatementNode.addElseStatement((ElseStatementNode) visit(elseStatement));
}
return ifElseStatementNode;
@ -168,13 +168,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitStatementExpression(SimpleJavaParser.StatementExpressionContext ctx) {
if(ctx.assign() != null) {
if (ctx.assign() != null) {
return visitAssign(ctx.assign());
} else if(ctx.newDeclaration() != null) {
} else if (ctx.newDeclaration() != null) {
return visitNewDeclaration(ctx.newDeclaration());
} else if(ctx.methodCall() != null) {
} else if (ctx.methodCall() != null) {
return visitMethodCall(ctx.methodCall());
} else if(ctx.crementExpression() != null) {
} else if (ctx.crementExpression() != null) {
return visitCrementExpression(ctx.crementExpression());
}
return null;
@ -188,7 +188,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitNewDeclaration(SimpleJavaParser.NewDeclarationContext ctx) {
NewDeclarationStatementExpressionNode newDeclarationStatementExpressionNode = new NewDeclarationStatementExpressionNode(ctx.Identifier().getText());
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
for (SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
newDeclarationStatementExpressionNode.addExpression((IExpressionNode) visit(expression));
}
return newDeclarationStatementExpressionNode;
@ -197,10 +197,10 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitMethodCall(SimpleJavaParser.MethodCallContext ctx) {
MethodCallStatementExpressionNode methodCallStatementExpressionNode = new MethodCallStatementExpressionNode((TargetNode) visit(ctx.target()), ctx.Identifier().getText());
for(SimpleJavaParser.ChainedMethodContext chainedMethod : ctx.chainedMethod()) {
for (SimpleJavaParser.ChainedMethodContext chainedMethod : ctx.chainedMethod()) {
methodCallStatementExpressionNode.addChainedMethod((ChainedMethodNode) visit(chainedMethod));
}
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
for (SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
methodCallStatementExpressionNode.addExpression((IExpressionNode) visit(expression));
}
return methodCallStatementExpressionNode;
@ -208,13 +208,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitTarget(SimpleJavaParser.TargetContext ctx) {
if(ctx.This() != null) {
if (ctx.This() != null) {
return new TargetNode(true);
} else if(ctx.memberAccess() != null) {
} else if (ctx.memberAccess() != null) {
return new TargetNode((MemberAccessNode) visit(ctx.memberAccess()));
} else if(ctx.newDeclaration() != null) {
} else if (ctx.newDeclaration() != null) {
return new TargetNode((NewDeclarationStatementExpressionNode) visit(ctx.newDeclaration()));
} else if(ctx.Identifier() != null) {
} else if (ctx.Identifier() != null) {
return new TargetNode(ctx.Identifier().getText());
}
return null;
@ -223,7 +223,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitChainedMethod(SimpleJavaParser.ChainedMethodContext ctx) {
ChainedMethodNode chainedMethodNode = new ChainedMethodNode(ctx.Identifier().getText());
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
for (SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
chainedMethodNode.addExpression((IExpressionNode) visit(expression));
}
return chainedMethodNode;
@ -231,9 +231,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitCrementExpression(SimpleJavaParser.CrementExpressionContext ctx) {
if(ctx.incrementExpression() != null) {
if (ctx.incrementExpression() != null) {
return visitIncrementExpression(ctx.incrementExpression());
} else if(ctx.decrementExpression() != null) {
} else if (ctx.decrementExpression() != null) {
return visitDecrementExpression(ctx.decrementExpression());
}
return null;
@ -241,9 +241,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitIncrementExpression(SimpleJavaParser.IncrementExpressionContext ctx) {
if(ctx.prefixIncrementExpression() != null) {
if (ctx.prefixIncrementExpression() != null) {
return visitPrefixIncrementExpression(ctx.prefixIncrementExpression());
} else if(ctx.suffixIncrementExpression() != null) {
} else if (ctx.suffixIncrementExpression() != null) {
return visitSuffixIncrementExpression(ctx.suffixIncrementExpression());
}
return null;
@ -261,9 +261,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitDecrementExpression(SimpleJavaParser.DecrementExpressionContext ctx) {
if(ctx.prefixDecrementExpression() != null) {
if (ctx.prefixDecrementExpression() != null) {
return visitPrefixDecrementExpression(ctx.prefixDecrementExpression());
} else if(ctx.suffixDecrementExpression() != null) {
} else if (ctx.suffixDecrementExpression() != null) {
return visitSuffixDecrementExpression(ctx.suffixDecrementExpression());
}
return null;
@ -281,9 +281,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitExpression(SimpleJavaParser.ExpressionContext ctx) {
if(ctx.unaryExpression() != null) {
if (ctx.unaryExpression() != null) {
return visit(ctx.unaryExpression());
} else if(ctx.binaryExpression() != null) {
} else if (ctx.binaryExpression() != null) {
return visit(ctx.binaryExpression());
}
return null;
@ -291,19 +291,19 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitUnaryExpression(SimpleJavaParser.UnaryExpressionContext ctx) {
if(ctx.This() != null) {
if (ctx.This() != null) {
return new UnaryExpressionNode(ctx.This().getText());
} else if(ctx.Identifier() != null) {
} else if (ctx.Identifier() != null) {
return new UnaryExpressionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
} else if (ctx.memberAccess() != null) {
return new UnaryExpressionNode((MemberAccessNode) visitMemberAccess(ctx.memberAccess()));
} else if(ctx.value() != null) {
} else if (ctx.value() != null) {
return new UnaryExpressionNode((ValueNode) visitValue(ctx.value()));
} else if(ctx.notExpression() != null) {
} else if (ctx.notExpression() != null) {
return new UnaryExpressionNode((NotExpressionNode) visitNotExpression(ctx.notExpression()));
} else if(ctx.statementExpression() != null) {
} else if (ctx.statementExpression() != null) {
return new UnaryExpressionNode((IStatementNode) visitStatementExpression(ctx.statementExpression()));
} else if(ctx.expression() != null) {
} else if (ctx.expression() != null) {
return new UnaryExpressionNode((IExpressionNode) visitExpression(ctx.expression()));
}
return null;
@ -312,7 +312,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitMemberAccess(SimpleJavaParser.MemberAccessContext ctx) {
MemberAccessNode memberAccessNode;
if(ctx.This() != null) {
if (ctx.This() != null) {
memberAccessNode = new MemberAccessNode(true);
} else {
memberAccessNode = new MemberAccessNode(false);
@ -325,13 +325,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitValue(SimpleJavaParser.ValueContext ctx) {
if(ctx.IntValue() != null) {
if (ctx.IntValue() != null) {
return new ValueNode(EnumValueNode.INT_VALUE, ctx.IntValue().getText());
} else if(ctx.BooleanValue() != null) {
} else if (ctx.BooleanValue() != null) {
return new ValueNode(EnumValueNode.BOOLEAN_VALUE, ctx.BooleanValue().getText());
} else if(ctx.CharValue() != null) {
} else if (ctx.CharValue() != null) {
return new ValueNode(EnumValueNode.CHAR_VALUE, ctx.CharValue().getText());
} else if(ctx.NullValue() != null) {
} else if (ctx.NullValue() != null) {
return new ValueNode(EnumValueNode.NULL_VALUE, ctx.NullValue().getText());
}
return null;
@ -345,9 +345,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitBinaryExpression(SimpleJavaParser.BinaryExpressionContext ctx) {
if(ctx.calculationExpression() != null) {
if (ctx.calculationExpression() != null) {
return visit(ctx.calculationExpression());
} else if(ctx.nonCalculationExpression() != null) {
} else if (ctx.nonCalculationExpression() != null) {
return visit(ctx.nonCalculationExpression());
}
return null;
@ -355,9 +355,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitCalculationExpression(SimpleJavaParser.CalculationExpressionContext ctx) {
if(ctx.calculationExpression() != null) {
if (ctx.calculationExpression() != null) {
return new CalculationExpressionNode((CalculationExpressionNode) visit(ctx.calculationExpression()), ctx.LineOperator().getText(), (DotExpressionNode) visit(ctx.dotExpression()));
} else if(ctx.dotExpression() != null) {
} else if (ctx.dotExpression() != null) {
return new CalculationExpressionNode((DotExpressionNode) visit(ctx.dotExpression()));
}
return null;
@ -365,9 +365,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitDotExpression(SimpleJavaParser.DotExpressionContext ctx) {
if(ctx.dotExpression() != null) {
if (ctx.dotExpression() != null) {
return new DotExpressionNode((DotExpressionNode) visit(ctx.dotExpression()), ctx.DotOperator().getText(), (DotSubstractionExpressionNode) visit(ctx.dotSubtractionExpression()));
} else if(ctx.dotSubtractionExpression() != null) {
} else if (ctx.dotSubtractionExpression() != null) {
return new DotExpressionNode((DotSubstractionExpressionNode) visit(ctx.dotSubtractionExpression()));
}
return null;
@ -375,13 +375,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitDotSubtractionExpression(SimpleJavaParser.DotSubtractionExpressionContext ctx) {
if(ctx.IntValue() != null) {
if (ctx.IntValue() != null) {
return new DotSubstractionExpressionNode(new ValueNode(EnumValueNode.INT_VALUE, ctx.IntValue().getText()));
} else if(ctx.Identifier() != null) {
} else if (ctx.Identifier() != null) {
return new DotSubstractionExpressionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
} else if (ctx.memberAccess() != null) {
return new DotSubstractionExpressionNode((MemberAccessNode) visit(ctx.memberAccess()));
} else if(ctx.methodCall() != null && ctx.calculationExpression() != null) {
} else if (ctx.methodCall() != null && ctx.calculationExpression() != null) {
return new DotSubstractionExpressionNode((MethodCallStatementExpressionNode) visit(ctx.methodCall()), (CalculationExpressionNode) visit(ctx.calculationExpression()));
}
return null;
@ -394,15 +394,15 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitAssignableExpression(SimpleJavaParser.AssignableExpressionContext ctx) {
if(ctx.Identifier() != null) {
if (ctx.Identifier() != null) {
return new AssignableExpressionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
} else if (ctx.memberAccess() != null) {
return new AssignableExpressionNode((MemberAccessNode) visit(ctx.memberAccess()));
}
return null;
}
public ITypeNode createTypeNode(String identifier){
public ITypeNode createTypeNode(String identifier) {
return switch (identifier) {
case "int" -> new BaseType(TypeEnum.INT);
case "boolean" -> new BaseType(TypeEnum.BOOL);

View File

@ -1,18 +1,11 @@
package parser;
import ast.BlockNode;
import ast.ClassNode;
import ast.LiteralNode;
import ast.ProgramNode;
import ast.expression.ExpressionNode;
import ast.member.FieldNode;
import ast.member.MemberNode;
import ast.member.MethodNode;
import ast.parameter.ParameterListNode;
import ast.parameter.ParameterNode;
import ast.statement.ReturnStatementNode;
import ast.statement.StatementNode;
import ast.type.*;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.jupiter.api.BeforeEach;
@ -49,9 +42,9 @@ public class ParserTest {
tokenStream.fill();
// Prepare the expected results
List<Token> actualTokens = tokenStream.getTokens();
List<String> expectedTokens = Arrays.asList("public", "class", "Name", "{", "}", "<EOF>");
List<String> expectedTokenTypes = Arrays.asList(null, null, "IDENTIFIER", null, null, "EOF");
List<String> expectedTokenTypes = Arrays.asList("AccessModifier", "Class", "Identifier", "OpenCurlyBracket", "ClosedCurlyBracket", "EOF");
List<Token> actualTokens = tokenStream.getTokens();
// Compare the actual tokens and their types to the expected tokens and their types
assertEquals(expectedTokens.size(), actualTokens.size());
@ -76,33 +69,32 @@ public class ParserTest {
ParseTree parseTree = parser.program(); // parse the input
//Variante 1 (geht)
String expectedParseTreeAsString = "(program (classDeclaration public class Name { }))";
String actualParseTreeAsString = parseTree.toStringTree(parser);
String expectedParseTreeAsString = "(program (classDeclaration (accessType public) class Name { }))";
assertEquals(actualParseTreeAsString, expectedParseTreeAsString);
assertEquals(expectedParseTreeAsString, actualParseTreeAsString);
//Variante 2 (geht nicht)
// Variante 2 (geht nicht)
// - Sollte es gehen und es liegt am Parser? (keine Ahnung) -> Bitte Fehler (actual und expected) durchlesen
Map<String, Object> actualTreeStructure = buildTreeStructure(parseTree, parser);
// ist die Methode parseStringToTree() korrekt? -> (glaub nicht)
Map<String, Object> expectedTreeStructure = parseStringToTree(expectedParseTreeAsString);
Map<String, Object> actualTreeStructure = buildTreeStructure(parseTree, parser);
assertEquals(actualTreeStructure, expectedTreeStructure);
// assertEquals(expectedTreeStructure, actualTreeStructure);
}
@Test
public void astBuilderTest() {
// TODO: Implement this test method
// ---------------- Aktuellen CompilerInput nachbauen ----------------
ProgramNode startNode = new ProgramNode();
// ---------------- Alter CompilerInput nachgebaut ----------------
// ProgramNode startNode = new ProgramNode();
// public class CompilerInput {}
ClassNode compilerInputClass = new ClassNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), "CompilerInput");
// ClassNode compilerInputClass = new ClassNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), "CompilerInput");
// public int a;
compilerInputClass.addMember(new FieldNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), new BaseTypeNode(EnumTypeNode.INT), "a"));
// compilerInputClass.addMember(new FieldNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), new BaseTypeNode(EnumTypeNode.INT), "a"));
// public static int testMethod(char x) { return 0; }
compilerInputClass.addMember(
/* compilerInputClass.addMember(
new MethodNode(
new AccessTypeNode(EnumAccessTypeNode.PUBLIC),
new BaseTypeNode(EnumTypeNode.INT),
@ -122,28 +114,48 @@ public class ParserTest {
)
);
*/
//compilerInputClass.addClass(testClass);
startNode.addClass(compilerInputClass);
startNode.addClass(testClass);
// ---------------- Aktuellen CompilerInput nachbauen ----------------
// startNode.addClass(compilerInputClass);
// startNode.addClass(testClass);
// ---------------- Leere Klasse nachgebaut ----------------
ProgramNode expectedASTEmptyClass = new ProgramNode();
// public class Name {}
ClassNode nameClass = new ClassNode("public", "Name");
expectedASTEmptyClass.addClass(nameClass);
// ---------------- Leere Klasse erzeugt ----------------
// init
CharStream inputCharStream = CharStreams.fromString("public class Name {}");
SimpleJavaLexer lexer = new SimpleJavaLexer(inputCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
tokenStream.fill();
/* Parser -> Parsetree */
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTreeEmptyClass = parser.program(); // parse the input
/* AST builder -> AST */
ASTBuilder astBuilder = new ASTBuilder();
// ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ProgramNode actualASTEmptyClass = (ProgramNode) new ASTBuilder().visit(parseTreeEmptyClass);
//String actualASTasString = new ASTBuilder().visit(parseTree).toString();
// ProgramNode actualAST = new ASTBuilder().visit(parseTree);
// ProgramNode expectedAST = new ProgramNode();
// expectedAST.add(new ProgramNode.ClassNode("Name", new ProgramNode()));
// ---------------- Vergleichen ----------------
String expectedASTasString = expectedASTEmptyClass.toString();
String actualASTasString = new ASTBuilder().visit(parseTreeEmptyClass).toString();
// Wie vergleiche ich das?
assertEquals(expectedASTasString, actualASTasString);
assertEquals(expectedASTEmptyClass, actualASTEmptyClass);
}
@ -196,7 +208,7 @@ public class ParserTest {
for (char ch : input.toCharArray()) {
if (ch == '(') {
if (depth == 0) {
if (currentToken.length() > 0) {
if (!currentToken.isEmpty()) {
node.put("node", currentToken.toString().trim());
currentToken.setLength(0);
}
@ -213,7 +225,7 @@ public class ParserTest {
currentToken.append(ch);
}
} else if (Character.isWhitespace(ch) && depth == 0) {
if (currentToken.length() > 0) {
if (!currentToken.isEmpty()) {
node.put("node", currentToken.toString().trim());
currentToken.setLength(0);
}
@ -222,7 +234,7 @@ public class ParserTest {
}
}
if (currentToken.length() > 0) {
if (!currentToken.isEmpty()) {
node.put("node", currentToken.toString().trim());
}

View File

@ -1,5 +1,3 @@
package resources;
public class AllFeaturesClassExample {
int a;
boolean b;

View File

@ -1,5 +1,3 @@
package resources;
public class CombinedExample {
int number;
boolean flag;

View File

@ -1,5 +1,3 @@
package resources;
public class MoreFeaturesClassExample {
int hallo;
private class Inner {

View File

@ -1,5 +1,3 @@
package resources.featureTests;
public class BooleanOperations {
boolean flag;

View File

@ -1,5 +1,3 @@
package resources.featureTests;
public class CharManipulation {
char letter;

View File

@ -1,5 +1,3 @@
package resources.featureTests;
public class ConditionalStatements {
int number;

View File

@ -1,5 +1,3 @@
package resources.featureTests;
public class LoopExamples {
public static void main(String[] args) {
// For loop example

View File

@ -1,5 +1,3 @@
package resources.featureTests;
public class MethodOverloading {
public int add(int a, int b) {
return a + b;