@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(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(VariableDeclarationExpression node) { ASTNode parent = node.getParent(); if (parent instanceof ForStatement) { handleCommas(node.fragments(), this.options.insert_space_before_comma_in_for_inits, this.options.insert_space_after_comma_in_for_inits); } else if (parent instanceof ExpressionStatement) { handleCommas(node.fragments(), this.options.insert_space_before_comma_in_multiple_local_declarations, this.options.insert_space_after_comma_in_multiple_local_declarations); } this.tm.firstTokenAfter(node.getType(), -1).spaceBefore(); return true; }
@Override public boolean visit(VariableDeclarationExpression node) { ASTNode parent = node.getParent(); if (parent instanceof ForStatement) { handleCommas(node.fragments(), this.options.insert_space_before_comma_in_for_inits, this.options.insert_space_after_comma_in_for_inits); } else if (parent instanceof ExpressionStatement) { handleCommas(node.fragments(), this.options.insert_space_before_comma_in_multiple_local_declarations, this.options.insert_space_after_comma_in_multiple_local_declarations); } this.tm.firstTokenAfter(node.getType(), -1).spaceBefore(); return true; }
int openBraceIndex = this.tm.firstIndexIn(node, TokenNameLBRACE); int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE); Token whileToken = this.tm.firstTokenAfter(node, TokenNamewhile); int lastIndex = whileToken.getLineBreaksBefore() == 0 ? this.tm.lastIndexIn(parent, -1) : closeBraceIndex; tryKeepOnOneLine(openBraceIndex, closeBraceIndex, lastIndex, statements, oneLineOption);
@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; }
private void handleTokenAfter(ASTNode node, int tokenType, boolean spaceBefore, boolean spaceAfter) { if (spaceBefore || spaceAfter) { if (tokenType == TokenNameGREATER) { // there could be ">>" or ">>>" instead, get rid of them int index = this.tm.lastIndexIn(node, -1); for (int i = index; i < index + 2; i++) { Token token = this.tm.get(i); if (token.tokenType == TokenNameRIGHT_SHIFT || token.tokenType == TokenNameUNSIGNED_RIGHT_SHIFT) { this.tm.remove(i); for (int j = 0; j < (token.tokenType == TokenNameRIGHT_SHIFT ? 2 : 3); j++) { this.tm.insert(i + j, new Token(token.originalStart + j, token.originalStart + j, TokenNameGREATER)); } } } } Token token = this.tm.firstTokenAfter(node, tokenType); handleToken(token, spaceBefore, spaceAfter); } }
@Override public boolean visit(VariableDeclarationExpression node) { ASTNode parent = node.getParent(); if (parent instanceof ForStatement) { handleCommas(node.fragments(), this.options.insert_space_before_comma_in_for_inits, this.options.insert_space_after_comma_in_for_inits); } else if (parent instanceof ExpressionStatement) { handleCommas(node.fragments(), this.options.insert_space_before_comma_in_multiple_local_declarations, this.options.insert_space_after_comma_in_multiple_local_declarations); } this.tm.firstTokenAfter(node.getType(), -1).spaceBefore(); return true; }
private void handleTokenAfter(ASTNode node, int tokenType, boolean spaceBefore, boolean spaceAfter) { if (tokenType == TokenNameGREATER) { // there could be ">>" or ">>>" instead, get rid of them int index = this.tm.lastIndexIn(node, -1); for (int i = index; i < index + 2; i++) { Token token = this.tm.get(i); if (token.tokenType == TokenNameRIGHT_SHIFT || token.tokenType == TokenNameUNSIGNED_RIGHT_SHIFT) { this.tm.remove(i); for (int j = 0; j < (token.tokenType == TokenNameRIGHT_SHIFT ? 2 : 3); j++) { this.tm.insert(i + j, new Token(token.originalStart + j, token.originalStart + j, TokenNameGREATER)); } } } } if (spaceBefore || spaceAfter) { Token token = this.tm.firstTokenAfter(node, tokenType); handleToken(token, spaceBefore, spaceAfter); } }
private void handleTokenAfter(ASTNode node, int tokenType, boolean spaceBefore, boolean spaceAfter) { if (tokenType == TokenNameGREATER) { // there could be ">>" or ">>>" instead, get rid of them int index = this.tm.lastIndexIn(node, -1); for (int i = index; i < index + 2; i++) { Token token = this.tm.get(i); if (token.tokenType == TokenNameRIGHT_SHIFT || token.tokenType == TokenNameUNSIGNED_RIGHT_SHIFT) { this.tm.remove(i); for (int j = 0; j < (token.tokenType == TokenNameRIGHT_SHIFT ? 2 : 3); j++) { this.tm.insert(i + j, new Token(token.originalStart + j, token.originalStart + j, TokenNameGREATER)); } } } } if (spaceBefore || spaceAfter) { Token token = this.tm.firstTokenAfter(node, tokenType); handleToken(token, spaceBefore, spaceAfter); } }