@Override public boolean accept(ASTVisitor action) { if (action.shouldVisitStatements) { switch (action.visit(this)) { case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_SKIP: return true; default: break; } } if (init != null) if (!init.accept(action)) return false; if (condition != null) if (!condition.accept(action)) return false; if (iterationExpression != null) if (!iterationExpression.accept(action)) return false; if (body != null) if (!body.accept(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_SKIP: return true; default: break; } } return true; }
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) { if (statement instanceof IASTCompoundStatement) { // TODO hsr existiert noch eine methode statement.accept(visitor); if (!isDoStatement) { scribe.newLine(); } compoundNoNewLine = false; } else if (statement instanceof IASTNullStatement) { statement.accept(visitor); scribe.newLine(); } else { scribe.incrementIndentationLevel(); scribe.newLine(); statement.accept(visitor); scribe.decrementIndentationLevel(); } }
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) { scribe.printLBrace(); scribe.newLine(); for (IASTStatement statements : getNestedStatements(compoundStatement)) { statements.accept(visitor); } if (hasFreestandingComments(compoundStatement)) { writeFreeStandingComments(compoundStatement); } if (decrementIndentationLevelOneMore) { scribe.decrementIndentationLevel(); decrementIndentationLevelOneMore = false; } scribe.printRBrace(); }
/** * Prints a statement. * * @param statement the statement * @param newLine if true print a newline if statement usually have one. * @return {@link ASTVisitor#PROCESS_SKIP} */ protected int writeStatement(IASTStatement statement, boolean newLine) { if (statement instanceof IASTAmbiguousStatement) { // TODO HSR Leo test statement.accept(visitor); newLine = false; } else if (statement instanceof IASTExpressionStatement) { writeExpressionStatement((IASTExpressionStatement) statement); // usually newLine } else if (statement instanceof IASTDeclarationStatement) { writeDeclarationStatement((IASTDeclarationStatement) statement); newLine = false; } else if (statement instanceof IASTNullStatement) { writeNullStatement((IASTNullStatement) statement); // usually newLine } else if (statement instanceof IASTReturnStatement) { writeReturnStatement((IASTReturnStatement) statement); // usually newLine } else if (statement instanceof IASTGotoStatement) { writeGotoStatement((IASTGotoStatement) statement); // usually newLine } else if (statement instanceof IASTLabelStatement) { writeLabelStatement((IASTLabelStatement) statement); newLine = false; } else if (statement instanceof IASTCaseStatement) { writeCaseStatement((IASTCaseStatement) statement); // usually newLine } else if (statement instanceof IASTDefaultStatement) { writeDefaultStatement((IASTDefaultStatement) statement); } else if (statement instanceof IASTContinueStatement) { writeContinueStatement((IASTContinueStatement) statement); // usually newLine } else if (statement instanceof IASTCompoundStatement) { writeCompoundStatement((IASTCompoundStatement) statement); if (compoundNoNewLine) { newLine = false; compoundNoNewLine = false; } } else if (statement instanceof IASTBreakStatement) { writeBreakStatement((IASTBreakStatement) statement); // usually newLine } else if (statement instanceof IASTSwitchStatement) { writeSwitchStatement((IASTSwitchStatement) statement); newLine = false; } else if (statement instanceof IASTIfStatement) { writeIfStatement((IASTIfStatement) statement); newLine = false; } else if (statement instanceof IASTWhileStatement) { writeWhileStatement((IASTWhileStatement) statement); newLine = false; } else if (statement instanceof IASTForStatement) { writeForStatement((IASTForStatement) statement); newLine = false; } else if (statement instanceof ICPPASTRangeBasedForStatement) { writeForStatement((ICPPASTRangeBasedForStatement) statement); newLine = false; } else if (statement instanceof IASTDoStatement) { writeDoStatement((IASTDoStatement) statement); newLine = true; } else if (statement instanceof ICPPASTTryBlockStatement) { writeTryBlockStatement((ICPPASTTryBlockStatement) statement); newLine = false; } else if (statement instanceof ICPPASTCatchHandler) { writeCatchHandler((ICPPASTCatchHandler) statement); newLine = false; } else if (statement instanceof IASTProblemStatement) { throw new ProblemRuntimeException((IASTProblemStatement) statement); } if (hasTrailingComments(statement)) { writeTrailingComments(statement, newLine); } else if (newLine) { scribe.newLine(); } return ASTVisitor.PROCESS_SKIP; }