private void breakLineBefore(ASTNode node) { this.tm.firstTokenIn(node, -1).breakBefore(); }
private void breakLineBefore(ASTNode node) { this.tm.firstTokenIn(node, -1).breakBefore(); }
private void breakLineBefore(ASTNode node) { this.tm.firstTokenIn(node, -1).breakBefore(); }
private void handleBracePosition(Token openBraceToken, int closeBraceIndex, String bracePosition) { if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE)) { openBraceToken.breakBefore(); } else if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) { openBraceToken.breakBefore(); openBraceToken.indent(); if (closeBraceIndex + 1 < this.tm.size()) this.tm.get(closeBraceIndex + 1).unindent(); } else if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP)) { openBraceToken.setNextLineOnWrap(); } }
private void handleBracePosition(Token openBraceToken, int closeBraceIndex, String bracePosition) { if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE)) { openBraceToken.breakBefore(); } else if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) { openBraceToken.breakBefore(); openBraceToken.indent(); if (closeBraceIndex + 1 < this.tm.size()) this.tm.get(closeBraceIndex + 1).unindent(); } else if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP)) { openBraceToken.setNextLineOnWrap(); } }
private void handleBracePosition(Token openBraceToken, int closeBraceIndex, String bracePosition) { if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE)) { openBraceToken.breakBefore(); } else if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) { openBraceToken.breakBefore(); openBraceToken.indent(); if (closeBraceIndex + 1 < this.tm.size()) this.tm.get(closeBraceIndex + 1).unindent(); } else if (bracePosition.equals(DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP)) { openBraceToken.setNextLineOnWrap(); } }
@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; }
@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 protected boolean token(Token token, int index) { boolean isBetweenImports = index > WrapPreparator.this.importsStart && index < WrapPreparator.this.importsEnd; int lineBreaks = getLineBreaksToPreserve(getPrevious(), token, isBetweenImports); if (lineBreaks <= getLineBreaksBefore()) return true; if (lineBreaks == 1) { if ((!this.options2.join_wrapped_lines && token.isWrappable()) || index == 0) token.breakBefore(); } else if (lineBreaks > 1) { token.putLineBreaksBefore(lineBreaks); } return true; }
private void checkForceWrap(Token token, int index, int currentIndent) throws WrapRestartThrowable { // A token that will have smaller indent when wrapped than the current line indent, // should be wrapped because it's a low depth token following some complex wraps of higher depth. // This rule could not be implemented in getWrapPenalty() because a token's wrap indent may depend // on wraps in previous lines, which are not determined yet when the token's penalty is calculated. if (token.isWrappable() && this.options.wrap_outer_expressions_when_nested && getWrapIndent(token) < currentIndent) { WrapPolicy lineStartPolicy = this.tm.get(this.tm.findFirstTokenInLine(index, false, true)).getWrapPolicy(); if (lineStartPolicy != null && lineStartPolicy.wrapMode != WrapMode.FORCED) { token.breakBefore(); throw new WrapRestartThrowable(-1); } } }
@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; }
private void handleBreakBeforeTag(int start, int end, boolean isOpeningTag) { int firstPartIndex = tokenStartingAt(start); int lastPartIndex = tokenEndingAt(end); Token firstPartToken = this.ctm.get(firstPartIndex); firstPartToken.setWrapPolicy(null); if (isOpeningTag) { firstPartToken.breakBefore(); this.ctm.get(lastPartIndex + 1).clearSpaceBefore(); } else { firstPartToken.clearSpaceBefore(); } }
@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; }
private void handleBreakBeforeTag(int start, int end, boolean isOpeningTag) { int firstPartIndex = tokenStartingAt(start); int lastPartIndex = tokenEndingAt(end); Token firstPartToken = this.ctm.get(firstPartIndex); firstPartToken.setWrapPolicy(null); if (isOpeningTag) { firstPartToken.breakBefore(); this.ctm.get(lastPartIndex + 1).clearSpaceBefore(); } else { firstPartToken.clearSpaceBefore(); } }
private void handleBreakBeforeTag(int start, int end, boolean isOpeningTag) { int firstPartIndex = tokenStartingAt(start); int lastPartIndex = tokenEndingAt(end); Token firstPartToken = this.ctm.get(firstPartIndex); firstPartToken.setWrapPolicy(null); if (isOpeningTag) { firstPartToken.breakBefore(); this.ctm.get(lastPartIndex + 1).clearSpaceBefore(); } else { firstPartToken.clearSpaceBefore(); } }
@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(DoStatement node) { Statement body = node.getBody(); handleLoopBody(body); if (this.options.insert_new_line_before_while_in_do_statement || (!(body instanceof Block) && !(body instanceof EmptyStatement))) { Token whileToken = this.tm.firstTokenBefore(node.getExpression(), TokenNamewhile); whileToken.breakBefore(); } int lParen = this.tm.firstIndexBefore(node.getExpression(), 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(DoStatement node) { Statement body = node.getBody(); handleLoopBody(body); if (this.options.insert_new_line_before_while_in_do_statement || (!(body instanceof Block) && !(body instanceof EmptyStatement))) { Token whileToken = this.tm.firstTokenBefore(node.getExpression(), TokenNamewhile); whileToken.breakBefore(); } int lParen = this.tm.firstIndexBefore(node.getExpression(), 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(DoStatement node) { Statement body = node.getBody(); boolean sameLine = this.options.keep_simple_do_while_body_on_same_line; if (!sameLine) handleLoopBody(body); if (this.options.insert_new_line_before_while_in_do_statement || (!(body instanceof Block) && !(body instanceof EmptyStatement) && !sameLine)) { Token whileToken = this.tm.firstTokenBefore(node.getExpression(), TokenNamewhile); whileToken.breakBefore(); } int lParen = this.tm.firstIndexBefore(node.getExpression(), TokenNameLPAREN); int rParen = this.tm.firstIndexAfter(node.getExpression(), TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_if_while_statement); return true; }