diff --git a/src/main/java/parser/astBuilder/ASTBuilder.java b/src/main/java/parser/astBuilder/ASTBuilder.java index 55750a5..fcabdfa 100644 --- a/src/main/java/parser/astBuilder/ASTBuilder.java +++ b/src/main/java/parser/astBuilder/ASTBuilder.java @@ -207,10 +207,17 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { crement = (IStatementNode) visit(ctx.statementExpression(i)); } - BlockNode forBlock = (BlockNode) visit(ctx.blockStatement()); + BlockNode forBlock = new BlockNode(); + + BlockNode forStatements = (BlockNode) visit(ctx.blockStatement()); + if(forStatements != null) { + forBlock.addStatement((IStatementNode) forStatements); + } if(crement != null){ - forBlock.addStatement((crement)); + BlockNode forCrement = new BlockNode(); + forCrement.addStatement((crement)); + forBlock.addStatement(forCrement); } WhileNode While = new WhileNode(condition, forBlock); diff --git a/src/test/java/parser/AstBuilderTest.java b/src/test/java/parser/AstBuilderTest.java index 38a601c..f239a41 100644 --- a/src/test/java/parser/AstBuilderTest.java +++ b/src/test/java/parser/AstBuilderTest.java @@ -200,6 +200,20 @@ class AstBuilderTest { //assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); } + //Noch nicht speziell Increment nur zum Development Testen per Debug + @Test + @DisplayName("Increment Test") + public void incrementTest(){ + ClassNode classNode = Helper.generateEmptyClass("TestClass"); + classNode.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a")); + + ProgramNode expected = new ProgramNode(); + expected.addClass(classNode); + + ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Increment.java"); + assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); + } + diff --git a/src/test/resources/input/javaCases/Increment.java b/src/test/resources/input/javaCases/Increment.java new file mode 100644 index 0000000..9560a9b --- /dev/null +++ b/src/test/resources/input/javaCases/Increment.java @@ -0,0 +1,12 @@ +public class Increment { + + public int test; + + public void increment(int p) { + test = p++; + + for(int i = 1; i<=10, i++) { + int a = 5; + } + } +}