@Override public boolean visit(LineComment node) { int commentIndex = this.tm.firstIndexIn(node, TokenNameCOMMENT_LINE); handleLineComment(commentIndex); return true; }
@Override public boolean visit(BlockComment node) { int commentIndex = this.tm.firstIndexIn(node, TokenNameCOMMENT_BLOCK); handleBlockComment(commentIndex); return true; }
@Override public boolean visit(CompilationUnit node) { List<ImportDeclaration> imports = node.imports(); if (!imports.isEmpty()) { this.importsStart = this.tm.firstIndexIn(imports.get(0), -1); this.importsEnd = this.tm.lastIndexIn(imports.get(imports.size() - 1), -1); } return true; }
private void handleVariableDeclarations(List<VariableDeclarationFragment> fragments) { if (fragments.size() > 1) { this.wrapParentIndex = this.tm.firstIndexIn(fragments.get(0), -1); prepareElementsList(fragments, TokenNameCOMMA, -1); this.wrapIndexes.remove(0); handleWrap(this.options.alignment_for_multiple_fields); } }
public int getIdentifierIndex(TokenManager tm) { if (this.accessExpression instanceof FieldAccess) return tm.firstIndexIn(((FieldAccess) this.accessExpression).getName(), TokenNameIdentifier); if (this.accessExpression instanceof QualifiedName) return tm.firstIndexIn(((QualifiedName) this.accessExpression).getName(), TokenNameIdentifier); if (this.accessExpression instanceof ThisExpression) return tm.lastIndexIn(this.accessExpression, TokenNamethis); if (this.accessExpression instanceof SuperFieldAccess) return tm.lastIndexIn(this.accessExpression, TokenNamesuper); throw new AssertionError(); } }
private void findHeader() { if (this.astRoot instanceof CompilationUnit) { CompilationUnit unit = (CompilationUnit) this.astRoot; List<TypeDeclaration> types = unit.types(); ASTNode firstElement = types.isEmpty() ? unit.getPackage() : types.get(0); if (firstElement != null) { int headerEndIndex = this.tokenManager.firstIndexIn(firstElement, -1); this.tokenManager.setHeaderEndIndex(headerEndIndex); } } }
@Override public boolean visit(ThrowStatement node) { int returnTokenIndex = this.tm.firstIndexIn(node, TokenNamethrow); if (this.tm.get(returnTokenIndex + 1).tokenType != TokenNameLPAREN || this.options.insert_space_before_parenthesized_expression_in_throw) { this.tm.get(returnTokenIndex).spaceAfter(); } return true; }
private void putBlankLinesBefore(ASTNode node, int linesCount) { int index = this.tm.firstIndexIn(node, -1); while (index > 0 && this.tm.get(index - 1).tokenType == TokenNameCOMMENT_JAVADOC) index--; this.tm.get(index).putLineBreaksBefore(linesCount + 1); }
private boolean handleEmptyBrackets(ASTNode nodeContainingBrackets, boolean insertSpace) { int openingIndex = this.tm.firstIndexIn(nodeContainingBrackets, TokenNameLBRACKET); if (this.tm.get(openingIndex + 1).tokenType == TokenNameRBRACKET) { if (insertSpace) this.tm.get(openingIndex).spaceAfter(); return true; } return false; }
@Override public boolean visit(ReturnStatement node) { if (node.getExpression() != null) { int returnTokenIndex = this.tm.firstIndexIn(node, TokenNamereturn); if (!(node.getExpression() instanceof ParenthesizedExpression) || this.options.insert_space_before_parenthesized_expression_in_return) { this.tm.get(returnTokenIndex).spaceAfter(); } } return true; }
@Override public boolean visit(ReturnStatement node) { if (node.getExpression() != null) { int returnTokenIndex = this.tm.firstIndexIn(node, TokenNamereturn); if (!(node.getExpression() instanceof ParenthesizedExpression) || this.options.insert_space_before_parenthesized_expression_in_return) { this.tm.get(returnTokenIndex).spaceAfter(); } } return true; }
@Override public boolean visit(CatchClause node) { if (this.options.insert_new_line_before_catch_in_try_statement) breakLineBefore(node); int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_catch_clause); return true; }
@Override public boolean visit(LambdaExpression node) { int lParen = this.tm.firstIndexIn(node, -1); if (this.tm.get(lParen).tokenType == TokenNameLPAREN) { int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_lambda_declaration); } return true; }
@Override public boolean visit(EnhancedForStatement node) { if (!this.options.keep_simple_for_body_on_same_line) handleLoopBody(node.getBody()); int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_for_statement); return true; }
@Override public boolean visit(ForStatement node) { handleLoopBody(node.getBody()); int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_for_statement); return true; }
@Override public boolean visit(EnhancedForStatement node) { handleLoopBody(node.getBody()); int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_for_statement); return true; }
@Override public boolean visit(WhileStatement node) { handleLoopBody(node.getBody()); int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexAfter(node.getExpression(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_if_while_statement); return true; }
@Override public boolean visit(TryStatement node) { if (node.getFinally() != null && this.options.insert_new_line_before_finally_in_try_statement) { this.tm.firstTokenBefore(node.getFinally(), TokenNamefinally).breakBefore(); } if (!node.resources().isEmpty()) { int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_try_clause); } return true; }
@Override public boolean visit(TryStatement node) { if (node.getFinally() != null && this.options.insert_new_line_before_finally_in_try_statement) { this.tm.firstTokenBefore(node.getFinally(), TokenNamefinally).breakBefore(); } if (!node.resources().isEmpty()) { int lParen = this.tm.firstIndexIn(node, TokenNameLPAREN); int rParen = this.tm.firstIndexBefore(node.getBody(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_try_clause); } return true; }
private void indent(ASTNode node) { int startIndex = this.tm.firstIndexIn(node, -1); while (startIndex > 0 && this.tm.get(startIndex - 1).isComment()) startIndex--; this.tm.get(startIndex).indent(); int lastIndex = this.tm.lastIndexIn(node, -1); if (lastIndex + 1 < this.tm.size()) this.tm.get(lastIndex + 1).unindent(); }