private void handleSemicolon(ASTNode node) { if (this.options.insert_space_before_semicolon) { Token lastToken = this.tm.lastTokenIn(node, -1); if (lastToken.tokenType == TokenNameSEMICOLON) lastToken.spaceBefore(); } }
private void handleSemicolon(ASTNode node) { if (this.options.insert_space_before_semicolon) { Token lastToken = this.tm.lastTokenIn(node, -1); if (lastToken.tokenType == TokenNameSEMICOLON) lastToken.spaceBefore(); } }
private void handleSemicolon(ASTNode node) { if (this.options.insert_space_before_semicolon) { Token lastToken = this.tm.lastTokenIn(node, -1); if (lastToken.tokenType == TokenNameSEMICOLON) lastToken.spaceBefore(); } }
@Override public boolean preVisit2(ASTNode node) { this.currentDepth++; assert this.wrapIndexes.isEmpty() && this.secondaryWrapIndexes.isEmpty() && this.wrapPenalties.isEmpty(); assert this.wrapParentIndex == -1 && this.wrapGroupEnd == -1; boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0; if (isMalformed) { this.tm.addDisableFormatTokenPair(this.tm.firstTokenIn(node, -1), this.tm.lastTokenIn(node, -1)); } return !isMalformed; }
@Override public boolean preVisit2(ASTNode node) { this.currentDepth++; assert this.wrapIndexes.isEmpty() && this.secondaryWrapIndexes.isEmpty() && this.wrapPenalties.isEmpty(); assert this.wrapParentIndex == -1 && this.wrapGroupEnd == -1; boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0; if (isMalformed) { this.tm.addDisableFormatTokenPair(this.tm.firstTokenIn(node, -1), this.tm.lastTokenIn(node, -1)); } return !isMalformed; }
@Override public boolean preVisit2(ASTNode node) { this.currentDepth++; assert this.wrapIndexes.isEmpty() && this.secondaryWrapIndexes.isEmpty() && this.wrapPenalties.isEmpty(); assert this.wrapParentIndex == -1 && this.wrapGroupEnd == -1; boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0; if (isMalformed) { this.tm.addDisableFormatTokenPair(this.tm.firstTokenIn(node, -1), this.tm.lastTokenIn(node, -1)); } return !isMalformed; }
private void handleAnnotation(Annotation node, boolean handleParenthesis) { handleToken(node, TokenNameAT, false, this.options.insert_space_after_at_in_annotation); if (handleParenthesis) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_annotation, this.options.insert_space_after_opening_paren_in_annotation); if (this.options.insert_space_before_closing_paren_in_annotation) this.tm.lastTokenIn(node, TokenNameRPAREN).spaceBefore(); } ASTNode parent = node.getParent(); boolean skipSpaceAfter = parent instanceof Annotation || parent instanceof MemberValuePair || (parent instanceof AnnotationTypeMemberDeclaration && ((AnnotationTypeMemberDeclaration) parent).getDefault() == node) || parent instanceof ArrayInitializer; if (!skipSpaceAfter) this.tm.lastTokenIn(node, -1).spaceAfter(); }
private void handleAnnotation(Annotation node, boolean handleParenthesis) { handleToken(node, TokenNameAT, false, this.options.insert_space_after_at_in_annotation); if (handleParenthesis) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_annotation, this.options.insert_space_after_opening_paren_in_annotation); if (this.options.insert_space_before_closing_paren_in_annotation) this.tm.lastTokenIn(node, TokenNameRPAREN).spaceBefore(); } ASTNode parent = node.getParent(); boolean skipSpaceAfter = parent instanceof Annotation || parent instanceof MemberValuePair || (parent instanceof AnnotationTypeMemberDeclaration && ((AnnotationTypeMemberDeclaration) parent).getDefault() == node) || parent instanceof ArrayInitializer; if (!skipSpaceAfter) this.tm.lastTokenIn(node, -1).spaceAfter(); }
private void handleAnnotation(Annotation node, boolean handleParenthesis) { handleToken(node, TokenNameAT, false, this.options.insert_space_after_at_in_annotation); if (handleParenthesis) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_annotation, this.options.insert_space_after_opening_paren_in_annotation); if (this.options.insert_space_before_closing_paren_in_annotation) this.tm.lastTokenIn(node, TokenNameRPAREN).spaceBefore(); } ASTNode parent = node.getParent(); boolean skipSpaceAfter = parent instanceof Annotation || parent instanceof MemberValuePair || (parent instanceof AnnotationTypeMemberDeclaration && ((AnnotationTypeMemberDeclaration) parent).getDefault() == node) || parent instanceof ArrayInitializer; if (!skipSpaceAfter) this.tm.lastTokenIn(node, -1).spaceAfter(); }
@Override public boolean visit(PackageDeclaration node) { int blanks = this.options.blank_lines_before_package; if (blanks > 0) { List<Annotation> annotations = node.annotations(); int firstTokenIndex = annotations.isEmpty() ? this.tm.firstIndexBefore(node.getName(), TokenNamepackage) : this.tm.firstIndexIn(annotations.get(0), -1); this.tm.get(firstTokenIndex).putLineBreaksBefore(blanks + 1); } this.tm.lastTokenIn(node, TokenNameSEMICOLON).putLineBreaksAfter(this.options.blank_lines_after_package + 1); this.declarationModifierVisited = false; return true; }
@Override public void endVisit(SingleVariableDeclaration node) { // this must be endVisit in case a space added by a visit on a child node needs to be cleared if (node.isVarargs()) { handleTokenBefore(node.getName(), TokenNameELLIPSIS, this.options.insert_space_before_ellipsis, this.options.insert_space_after_ellipsis); List<Annotation> varargsAnnotations = node.varargsAnnotations(); if (!varargsAnnotations.isEmpty()) { this.tm.firstTokenIn(varargsAnnotations.get(0), TokenNameAT).spaceBefore(); this.tm.lastTokenIn(varargsAnnotations.get(varargsAnnotations.size() - 1), -1).clearSpaceAfter(); } } else { handleToken(node.getName(), TokenNameIdentifier, true, false); } }
@Override public boolean visit(PackageDeclaration node) { int blanks = this.options.blank_lines_before_package; if (blanks > 0) { List<Annotation> annotations = node.annotations(); int firstTokenIndex = annotations.isEmpty() ? this.tm.firstIndexBefore(node.getName(), TokenNamepackage) : this.tm.firstIndexIn(annotations.get(0), -1); this.tm.get(firstTokenIndex).putLineBreaksBefore(blanks + 1); } this.tm.lastTokenIn(node, TokenNameSEMICOLON).putLineBreaksAfter(this.options.blank_lines_after_package + 1); this.declarationModifierVisited = false; return true; }
@Override public void endVisit(SingleVariableDeclaration node) { // this must be endVisit in case a space added by a visit on a child node needs to be cleared if (node.isVarargs()) { handleTokenBefore(node.getName(), TokenNameELLIPSIS, this.options.insert_space_before_ellipsis, this.options.insert_space_after_ellipsis); List<Annotation> varargsAnnotations = node.varargsAnnotations(); if (!varargsAnnotations.isEmpty()) { this.tm.firstTokenIn(varargsAnnotations.get(0), TokenNameAT).spaceBefore(); this.tm.lastTokenIn(varargsAnnotations.get(varargsAnnotations.size() - 1), -1).clearSpaceAfter(); } } else { handleToken(node.getName(), TokenNameIdentifier, true, false); } }
@Override public void endVisit(SingleVariableDeclaration node) { // this must be endVisit in case a space added by a visit on a child node needs to be cleared if (node.isVarargs()) { handleTokenBefore(node.getName(), TokenNameELLIPSIS, this.options.insert_space_before_ellipsis, this.options.insert_space_after_ellipsis); List<Annotation> varargsAnnotations = node.varargsAnnotations(); if (!varargsAnnotations.isEmpty()) { this.tm.firstTokenIn(varargsAnnotations.get(0), TokenNameAT).spaceBefore(); this.tm.lastTokenIn(varargsAnnotations.get(varargsAnnotations.size() - 1), -1).clearSpaceAfter(); } } else { handleToken(node.getName(), TokenNameIdentifier, true, false); } }
@Override public boolean visit(PackageDeclaration node) { int blanks = this.options.blank_lines_before_package; if (blanks > 0) { List<Annotation> annotations = node.annotations(); int firstTokenIndex = annotations.isEmpty() ? this.tm.firstIndexBefore(node.getName(), TokenNamepackage) : this.tm.firstIndexIn(annotations.get(0), -1); this.tm.get(firstTokenIndex).putLineBreaksBefore(blanks + 1); } this.tm.lastTokenIn(node, TokenNameSEMICOLON).putLineBreaksAfter(this.options.blank_lines_after_package + 1); this.declarationModifierVisited = false; return true; }
private void handleInvocation(ASTNode invocationNode, ASTNode nodeBeforeOpeningParen, ASTNode nodeAfterClosingParen) { if (handleEmptyParens(nodeBeforeOpeningParen, this.options.insert_space_between_empty_parens_in_method_invocation)) { handleToken(nodeBeforeOpeningParen, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_method_invocation, false); } else { handleToken(nodeBeforeOpeningParen, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_method_invocation, this.options.insert_space_after_opening_paren_in_method_invocation); if (this.options.insert_space_before_closing_paren_in_method_invocation) { Token closingParen = nodeAfterClosingParen == null ? this.tm.lastTokenIn(invocationNode, TokenNameRPAREN) : this.tm.firstTokenBefore(nodeAfterClosingParen, TokenNameRPAREN); closingParen.spaceBefore(); } } }
private void handleInvocation(ASTNode invocationNode, ASTNode nodeBeforeOpeningParen, ASTNode nodeAfterClosingParen) { if (handleEmptyParens(nodeBeforeOpeningParen, this.options.insert_space_between_empty_parens_in_method_invocation)) { handleToken(nodeBeforeOpeningParen, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_method_invocation, false); } else { handleToken(nodeBeforeOpeningParen, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_method_invocation, this.options.insert_space_after_opening_paren_in_method_invocation); if (this.options.insert_space_before_closing_paren_in_method_invocation) { Token closingParen = nodeAfterClosingParen == null ? this.tm.lastTokenIn(invocationNode, TokenNameRPAREN) : this.tm.firstTokenBefore(nodeAfterClosingParen, TokenNameRPAREN); closingParen.spaceBefore(); } } }
private void handleInvocation(ASTNode invocationNode, ASTNode nodeBeforeOpeningParen, ASTNode nodeAfterClosingParen) { if (handleEmptyParens(nodeBeforeOpeningParen, this.options.insert_space_between_empty_parens_in_method_invocation)) { handleToken(nodeBeforeOpeningParen, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_method_invocation, false); } else { handleToken(nodeBeforeOpeningParen, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_method_invocation, this.options.insert_space_after_opening_paren_in_method_invocation); if (this.options.insert_space_before_closing_paren_in_method_invocation) { Token closingParen = nodeAfterClosingParen == null ? this.tm.lastTokenIn(invocationNode, TokenNameRPAREN) : this.tm.firstTokenBefore(nodeAfterClosingParen, TokenNameRPAREN); closingParen.spaceBefore(); } } }
@Override public boolean visit(IfStatement node) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_if, this.options.insert_space_after_opening_paren_in_if); Statement thenStatement = node.getThenStatement(); int closingParenIndex = this.tm.firstIndexBefore(thenStatement, TokenNameRPAREN); handleToken(this.tm.get(closingParenIndex), this.options.insert_space_before_closing_paren_in_if, /* space before then statement may be needed if it will stay on the same line */ !(thenStatement instanceof Block) && !this.tm.get(closingParenIndex + 1).isComment()); if (thenStatement instanceof Block && this.tm.isGuardClause((Block) thenStatement)) { handleToken(thenStatement, TokenNameLBRACE, false, true); this.tm.lastTokenIn(node, TokenNameRBRACE).spaceBefore(); } handleSemicolon(thenStatement); return true; }
@Override public boolean visit(IfStatement node) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_if, this.options.insert_space_after_opening_paren_in_if); Statement thenStatement = node.getThenStatement(); int closingParenIndex = this.tm.firstIndexBefore(thenStatement, TokenNameRPAREN); handleToken(this.tm.get(closingParenIndex), this.options.insert_space_before_closing_paren_in_if, /* space before then statement may be needed if it will stay on the same line */ !(thenStatement instanceof Block) && !this.tm.get(closingParenIndex + 1).isComment()); if (thenStatement instanceof Block && this.tm.isGuardClause((Block) thenStatement)) { handleToken(thenStatement, TokenNameLBRACE, false, true); this.tm.lastTokenIn(node, TokenNameRBRACE).spaceBefore(); } handleSemicolon(thenStatement); return true; }