@Override public boolean visit(AnonymousClassDeclaration node) { if (node.getParent() instanceof EnumConstantDeclaration) { handleBracedCode(node, null, this.options.brace_position_for_enum_constant, this.options.indent_body_declarations_compare_to_enum_constant_header); } else { handleBracedCode(node, null, this.options.brace_position_for_anonymous_type_declaration, this.options.indent_body_declarations_compare_to_type_header); } handleBodyDeclarations(node.bodyDeclarations()); return true; }
@Override public boolean visit(AnonymousClassDeclaration node) { if (node.getParent() instanceof EnumConstantDeclaration) { handleBracedCode(node, null, this.options.brace_position_for_enum_constant, this.options.indent_body_declarations_compare_to_enum_constant_header, this.options.insert_new_line_in_empty_enum_constant); } else { handleBracedCode(node, null, this.options.brace_position_for_anonymous_type_declaration, this.options.indent_body_declarations_compare_to_type_header, this.options.insert_new_line_in_empty_anonymous_type_declaration); } handleBodyDeclarations(node.bodyDeclarations()); return true; }
@Override public boolean visit(AnonymousClassDeclaration node) { if (node.getParent() instanceof EnumConstantDeclaration) { handleBracedCode(node, null, this.options.brace_position_for_enum_constant, this.options.indent_body_declarations_compare_to_enum_constant_header, this.options.insert_new_line_in_empty_enum_constant); } else { handleBracedCode(node, null, this.options.brace_position_for_anonymous_type_declaration, this.options.indent_body_declarations_compare_to_type_header, this.options.insert_new_line_in_empty_anonymous_type_declaration); } handleBodyDeclarations(node.bodyDeclarations()); return true; }
@Override public boolean visit(ModuleDeclaration node) { // using settings for type declaration and fields for now, add new settings if necessary breakLineBefore(node); handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration, this.options.indent_body_declarations_compare_to_type_header, this.options.insert_new_line_in_empty_type_declaration); List<ModuleDirective> statements = node.moduleStatements(); ModuleDirective previous = null; for (ModuleDirective statement : statements) { int blankLines = previous == null ? this.options.blank_lines_before_first_class_body_declaration : previous.getClass().equals(statement.getClass()) ? this.options.blank_lines_before_field : this.options.blank_lines_before_new_chunk; putBlankLinesBefore(statement, blankLines); previous = statement; } this.declarationModifierVisited = false; return true; }
@Override public boolean visit(ModuleDeclaration node) { // using settings for type declaration and fields for now, add new settings if necessary breakLineBefore(node); handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration, this.options.indent_body_declarations_compare_to_type_header); List<ModuleDirective> statements = node.moduleStatements(); ModuleDirective previous = null; for (ModuleDirective statement : statements) { int blankLines = previous == null ? this.options.blank_lines_before_first_class_body_declaration : previous.getClass().equals(statement.getClass()) ? this.options.blank_lines_before_field : this.options.blank_lines_before_new_chunk; putBlankLinesBefore(statement, blankLines); previous = statement; } this.declarationModifierVisited = false; return true; }
@Override public boolean visit(Block node) { List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } ASTNode parent = node.getParent(); if (parent.getLength() == 0) return true; // this is a fake block created by parsing in statements mode if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block); return true; }
@Override public boolean visit(TypeDeclaration node) { handleBodyDeclarations(node.bodyDeclarations()); if (node.getName().getStartPosition() == -1) return true; // this is a fake type created by parsing in class body mode breakLineBefore(node); handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration, this.options.indent_body_declarations_compare_to_type_header); this.declarationModifierVisited = false; return true; }
public boolean visit(TypeDeclaration node) { handleBodyDeclarations(node.bodyDeclarations()); if (node.getName().getStartPosition() == -1) return true; // this is a fake type created by parsing in class body mode breakLineBefore(node); handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration, this.options.indent_body_declarations_compare_to_type_header, this.options.insert_new_line_in_empty_type_declaration); this.declarationModifierVisited = false; return true; }
@Override public boolean visit(Block node) { if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node)) return true; List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } if (node.getParent().getLength() == 0) return true; // this is a fake block created by parsing in statements mode ASTNode parent = node.getParent(); if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block, this.options.insert_new_line_in_empty_block); return true; }
public boolean visit(TypeDeclaration node) { handleBodyDeclarations(node.bodyDeclarations()); if (node.getName().getStartPosition() == -1) return true; // this is a fake type created by parsing in class body mode breakLineBefore(node); handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration, this.options.indent_body_declarations_compare_to_type_header, this.options.insert_new_line_in_empty_type_declaration); this.declarationModifierVisited = false; return true; }
@Override public boolean visit(Block node) { if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node)) return true; List<Statement> statements = node.statements(); for (Statement statement : statements) { if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement)) breakLineBefore(statement); } if (node.getParent().getLength() == 0) return true; // this is a fake block created by parsing in statements mode ASTNode parent = node.getParent(); if (parent instanceof MethodDeclaration) return true; // braces have been handled in #visit(MethodDeclaration) String bracePosition = this.options.brace_position_for_block; if (parent instanceof SwitchStatement) { List<Statement> siblings = ((SwitchStatement) parent).statements(); int blockPosition = siblings.indexOf(node); boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase); if (isFirstInCase) bracePosition = this.options.brace_position_for_block_in_case; } else if (parent instanceof LambdaExpression) { bracePosition = this.options.brace_position_for_lambda_body; } handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block, this.options.insert_new_line_in_empty_block); return true; }
@Override public boolean visit(EnumDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_enum_declaration, this.options.indent_body_declarations_compare_to_enum_declaration_header); handleBodyDeclarations(node.bodyDeclarations()); List<EnumConstantDeclaration> enumConstants = node.enumConstants(); for (int i = 0; i < enumConstants.size(); i++) { EnumConstantDeclaration declaration = enumConstants.get(i); if (declaration.getJavadoc() != null) this.tm.firstTokenIn(declaration, TokenNameCOMMENT_JAVADOC).breakBefore(); if (declaration.getAnonymousClassDeclaration() != null && i < enumConstants.size() - 1) this.tm.firstTokenAfter(declaration, TokenNameCOMMA).breakAfter(); } // put breaks after semicolons int index = enumConstants.isEmpty() ? this.tm.firstIndexAfter(node.getName(), TokenNameLBRACE) + 1 : this.tm.firstIndexAfter(enumConstants.get(enumConstants.size() - 1), -1); for (;; index++) { Token token = this.tm.get(index); if (token.isComment()) continue; if (token.tokenType == TokenNameSEMICOLON) token.breakAfter(); else break; } this.declarationModifierVisited = false; return true; }
@Override public boolean visit(AnnotationTypeDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_annotation_type_declaration, this.options.indent_body_declarations_compare_to_annotation_declaration_header); handleBodyDeclarations(node.bodyDeclarations()); if (node.getModifiers() == 0) this.tm.firstTokenBefore(node.getName(), TokenNameAT).breakBefore(); this.declarationModifierVisited = false; return true; }
@Override public boolean visit(AnnotationTypeDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_annotation_type_declaration, this.options.indent_body_declarations_compare_to_annotation_declaration_header, this.options.insert_new_line_in_empty_annotation_declaration); handleBodyDeclarations(node.bodyDeclarations()); if (node.getModifiers() == 0) this.tm.firstTokenBefore(node.getName(), TokenNameAT).breakBefore(); this.declarationModifierVisited = false; return true; }
@Override public boolean visit(AnnotationTypeDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_annotation_type_declaration, this.options.indent_body_declarations_compare_to_annotation_declaration_header, this.options.insert_new_line_in_empty_annotation_declaration); handleBodyDeclarations(node.bodyDeclarations()); if (node.getModifiers() == 0) this.tm.firstTokenBefore(node.getName(), TokenNameAT).breakBefore(); this.declarationModifierVisited = false; return true; }
@Override public boolean visit(EnumDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_enum_declaration, this.options.indent_body_declarations_compare_to_enum_declaration_header, this.options.insert_new_line_in_empty_enum_declaration); handleBodyDeclarations(node.bodyDeclarations()); List<EnumConstantDeclaration> enumConstants = node.enumConstants(); for (int i = 0; i < enumConstants.size(); i++) { EnumConstantDeclaration declaration = enumConstants.get(i); if (declaration.getJavadoc() != null) this.tm.firstTokenIn(declaration, TokenNameCOMMENT_JAVADOC).breakBefore(); if (declaration.getAnonymousClassDeclaration() != null && i < enumConstants.size() - 1) this.tm.firstTokenAfter(declaration, TokenNameCOMMA).breakAfter(); } // put breaks after semicolons int index = enumConstants.isEmpty() ? this.tm.firstIndexAfter(node.getName(), TokenNameLBRACE) + 1 : this.tm.firstIndexAfter(enumConstants.get(enumConstants.size() - 1), -1); for (;; index++) { Token token = this.tm.get(index); if (token.isComment()) continue; if (token.tokenType == TokenNameSEMICOLON) token.breakAfter(); else break; } this.declarationModifierVisited = false; return true; }
@Override public boolean visit(EnumDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_enum_declaration, this.options.indent_body_declarations_compare_to_enum_declaration_header, this.options.insert_new_line_in_empty_enum_declaration); handleBodyDeclarations(node.bodyDeclarations()); List<EnumConstantDeclaration> enumConstants = node.enumConstants(); for (int i = 0; i < enumConstants.size(); i++) { EnumConstantDeclaration declaration = enumConstants.get(i); if (declaration.getJavadoc() != null) this.tm.firstTokenIn(declaration, TokenNameCOMMENT_JAVADOC).breakBefore(); if (declaration.getAnonymousClassDeclaration() != null && i < enumConstants.size() - 1) this.tm.firstTokenAfter(declaration, TokenNameCOMMA).breakAfter(); } // put breaks after semicolons int index = enumConstants.isEmpty() ? this.tm.firstIndexAfter(node.getName(), TokenNameLBRACE) + 1 : this.tm.firstIndexAfter(enumConstants.get(enumConstants.size() - 1), -1); for (;; index++) { Token token = this.tm.get(index); if (token.isComment()) continue; if (token.tokenType == TokenNameSEMICOLON) token.breakAfter(); else break; } this.declarationModifierVisited = false; return true; }
@Override public boolean visit(MethodDeclaration node) { this.declarationModifierVisited = false; int lParen = this.tm.firstIndexAfter(node.getName(), TokenNameLPAREN); int rParen = node.getBody() == null ? this.tm.lastIndexIn(node, TokenNameRPAREN) : this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_method_declaration); if (node.getBody() == null) return true; if (node.isConstructor()) { handleBracedCode(node.getBody(), null, this.options.brace_position_for_constructor_declaration, this.options.indent_statements_compare_to_body, this.options.insert_new_line_in_empty_method_body); } else { handleBracedCode(node.getBody(), null, this.options.brace_position_for_method_declaration, this.options.indent_statements_compare_to_body, this.options.insert_new_line_in_empty_method_body); Token openBrace = this.tm.firstTokenIn(node.getBody(), TokenNameLBRACE); if (openBrace.getLineBreaksAfter() > 0) // if not, these are empty braces openBrace.putLineBreaksAfter(this.options.blank_lines_at_beginning_of_method_body + 1); } return true; }
@Override public boolean visit(MethodDeclaration node) { this.declarationModifierVisited = false; int lParen = this.tm.firstIndexAfter(node.getName(), TokenNameLPAREN); int rParen = node.getBody() == null ? this.tm.lastIndexIn(node, TokenNameRPAREN) : this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_method_declaration); if (node.getBody() == null) return true; String bracePosition = node.isConstructor() ? this.options.brace_position_for_constructor_declaration : this.options.brace_position_for_method_declaration; handleBracedCode(node.getBody(), null, bracePosition, this.options.indent_statements_compare_to_body); Token openBrace = this.tm.firstTokenIn(node.getBody(), TokenNameLBRACE); if (openBrace.getLineBreaksAfter() > 0) // if not, these are empty braces openBrace.putLineBreaksAfter(this.options.blank_lines_at_beginning_of_method_body + 1); return true; }
@Override public boolean visit(MethodDeclaration node) { this.declarationModifierVisited = false; int lParen = this.tm.firstIndexAfter(node.getName(), TokenNameLPAREN); int rParen = node.getBody() == null ? this.tm.lastIndexIn(node, TokenNameRPAREN) : this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_method_declaration); if (node.getBody() == null) return true; String bracePosition = node.isConstructor() ? this.options.brace_position_for_constructor_declaration : this.options.brace_position_for_method_declaration; handleBracedCode(node.getBody(), null, bracePosition, this.options.indent_statements_compare_to_body, this.options.insert_new_line_in_empty_method_body); Token openBrace = this.tm.firstTokenIn(node.getBody(), TokenNameLBRACE); if (openBrace.getLineBreaksAfter() > 0) // if not, these are empty braces openBrace.putLineBreaksAfter(this.options.blank_lines_at_beginning_of_method_body + 1); return true; }