public int countLineBreaksBetween(Token previous, Token current) { int start = previous != null ? previous.originalEnd + 1 : 0; int end = current != null ? current.originalStart : this.source.length(); return countLineBreaksBetween(this.source, start, end); }
public int countLineBreaksBetween(Token previous, Token current) { int start = previous != null ? previous.originalEnd + 1 : 0; int end = current != null ? current.originalStart : this.source.length(); return countLineBreaksBetween(this.source, start, end); }
public int countLineBreaksBetween(Token previous, Token current) { int start = previous != null ? previous.originalEnd + 1 : 0; int end = current != null ? current.originalStart : this.source.length(); return countLineBreaksBetween(this.source, start, end); }
private List<Token> findStringLiteralsInLine(int lastTokenIndex) { List<Token> stringLiterals = new ArrayList<>(); Token previous = this.tm.get(lastTokenIndex); for (int i = lastTokenIndex - 1; i >= 0; i--) { Token token = this.tm.get(i); if (this.tm.countLineBreaksBetween(token, previous) > 0) break; if (token.tokenType == TokenNameStringLiteral) stringLiterals.add(token); previous = token; } Collections.reverse(stringLiterals); return stringLiterals; }
private List<Token> findStringLiteralsInLine(int lastTokenIndex) { List<Token> stringLiterals = new ArrayList<>(); Token previous = this.tm.get(lastTokenIndex); for (int i = lastTokenIndex - 1; i >= 0; i--) { Token token = this.tm.get(i); if (this.tm.countLineBreaksBetween(token, previous) > 0) break; if (token.tokenType == TokenNameStringLiteral) stringLiterals.add(token); previous = token; } Collections.reverse(stringLiterals); return stringLiterals; }
private List<Token> findStringLiteralsInLine(int lastTokenIndex) { List<Token> stringLiterals = new ArrayList<>(); Token previous = this.tm.get(lastTokenIndex); for (int i = lastTokenIndex - 1; i >= 0; i--) { Token token = this.tm.get(i); if (this.tm.countLineBreaksBetween(token, previous) > 0) break; if (token.tokenType == TokenNameStringLiteral) stringLiterals.add(token); previous = token; } Collections.reverse(stringLiterals); return stringLiterals; }
int getLineBreaksToPreserve(Token token1, Token token2, boolean isBetweenImports) { if (token1 != null) { List<Token> structure = token1.getInternalStructure(); if (structure != null && !structure.isEmpty()) token1 = structure.get(structure.size() - 1); } if (token2 != null) { List<Token> structure = token2.getInternalStructure(); if (structure != null && !structure.isEmpty()) token2 = structure.get(0); } int lineBreaks = WrapPreparator.this.tm.countLineBreaksBetween(token1, token2); if (isBetweenImports) return lineBreaks > 1 ? (this.options.blank_lines_between_import_groups + 1) : 0; int toPreserve = this.options.number_of_empty_lines_to_preserve; if (token1 != null && token2 != null) toPreserve++; // n empty lines = n+1 line breaks, except for file start and end return Math.min(lineBreaks, toPreserve); }
int getLineBreaksToPreserve(Token token1, Token token2, boolean isBetweenImports) { if (token1 != null) { List<Token> structure = token1.getInternalStructure(); if (structure != null && !structure.isEmpty()) token1 = structure.get(structure.size() - 1); } if (token2 != null) { List<Token> structure = token2.getInternalStructure(); if (structure != null && !structure.isEmpty()) token2 = structure.get(0); } int lineBreaks = WrapPreparator.this.tm.countLineBreaksBetween(token1, token2); if (isBetweenImports) return lineBreaks > 1 ? (this.options.blank_lines_between_import_groups + 1) : 0; int toPreserve = this.options.number_of_empty_lines_to_preserve; if (token1 != null && token2 != null) toPreserve++; // n empty lines = n+1 line breaks, except for file start and end return Math.min(lineBreaks, toPreserve); }
int getLineBreaksToPreserve(Token token1, Token token2, boolean isBetweenImports) { if (token1 != null) { List<Token> structure = token1.getInternalStructure(); if (structure != null && !structure.isEmpty()) token1 = structure.get(structure.size() - 1); } if (token2 != null) { List<Token> structure = token2.getInternalStructure(); if (structure != null && !structure.isEmpty()) token2 = structure.get(0); } int lineBreaks = WrapPreparator.this.tm.countLineBreaksBetween(token1, token2); if (isBetweenImports) return lineBreaks > 1 ? (this.options.blank_lines_between_import_groups + 1) : 0; int toPreserve = this.options.number_of_empty_lines_to_preserve; if (token1 != null && token2 != null) toPreserve++; // n empty lines = n+1 line breaks, except for file start and end return Math.min(lineBreaks, toPreserve); }
private boolean isNewGroup(ASTNode node, ASTNode previousNode) { if (previousNode == null) return true; int lineBreaks = 0; int from = this.tm.lastIndexIn(previousNode, -1); int to = this.tm.firstIndexIn(node, -1); Token previousToken = this.tm.get(from); for (int i = from + 1; i <= to; i++) { Token token = this.tm.get(i); lineBreaks += Math.min(this.tm.countLineBreaksBetween(previousToken, token), this.options.number_of_empty_lines_to_preserve + 1); previousToken = token; } return lineBreaks > this.options.align_fields_grouping_blank_lines; }
private boolean isNewGroup(BodyDeclaration declaration, BodyDeclaration previousDeclaration) { if (!(previousDeclaration instanceof FieldDeclaration)) return true; int lineBreaks = 0; int from = this.tm.lastIndexIn(previousDeclaration, -1); int to = this.tm.firstIndexIn(declaration, -1); Token previous = this.tm.get(from); for (int i = from + 1; i <= to; i++) { Token token = this.tm.get(i); lineBreaks += Math.min(this.tm.countLineBreaksBetween(previous, token), this.options.number_of_empty_lines_to_preserve + 1); previous = token; } return lineBreaks > this.options.align_fields_grouping_blank_lines; }
private boolean isNewGroup(BodyDeclaration declaration, BodyDeclaration previousDeclaration) { if (!(previousDeclaration instanceof FieldDeclaration)) return true; int lineBreaks = 0; int from = this.tm.lastIndexIn(previousDeclaration, -1); int to = this.tm.firstIndexIn(declaration, -1); Token previous = this.tm.get(from); for (int i = from + 1; i <= to; i++) { Token token = this.tm.get(i); lineBreaks += Math.min(this.tm.countLineBreaksBetween(previous, token), this.options.number_of_empty_lines_to_preserve + 1); previous = token; } return lineBreaks > this.options.align_fields_grouping_blank_lines; }
private void adjustEmptyLineAfter(int tokenIndex, int indentationAdjustment) { if (tokenIndex + 1 >= this.tm.size()) return; Token token = this.tm.get(tokenIndex); Token next = this.tm.get(tokenIndex + 1); if (this.tm.countLineBreaksBetween(token, next) < 2 || !this.options.indent_empty_lines) return; next.setEmptyLineIndentAdjustment(indentationAdjustment * this.options.indentation_size); }
private void disableFormattingExclusively(int openingTagIndex, int closingTagIndex) { Token openingTag = this.ctm.get(openingTagIndex); int noFormatStart = openingTag.originalEnd + 1; int noFormatEnd = this.ctm.get(closingTagIndex - 1).originalEnd; if (noFormatStart <= noFormatEnd) { Token noFormatToken = new Token(noFormatStart, noFormatEnd, TokenNameCOMMENT_JAVADOC); int commentStart = findCommentLineIndent(openingTagIndex); List<Token> lines = commentToLines(noFormatToken, commentStart); List<Token> tokensToReplace = this.commentStructure.subList(openingTagIndex + 1, closingTagIndex); tokensToReplace.clear(); tokensToReplace.addAll(lines); } else { this.commentStructure.subList(openingTagIndex + 1, closingTagIndex).clear(); Token closingTag = this.ctm.get(closingTagIndex); if (this.ctm.countLineBreaksBetween(openingTag, closingTag) == 0) { openingTag.clearLineBreaksAfter(); closingTag.clearLineBreaksBefore(); } } }
private void handleCompilerTags(Token commentToken, int commentIndex) { final String commentText = this.tm.toString(commentToken); final List<Token> structure = commentToken.getInternalStructure(); if (commentText.startsWith("//$FALL-THROUGH$") //$NON-NLS-1$ || commentText.startsWith("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ structure.get(1).clearSpaceBefore(); } if (commentText.contains("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ // make sure the whole line is not broken Token token = commentToken; for (int i = commentIndex; i > 0; i--) { Token left = this.tm.get(i - 1); if (this.tm.countLineBreaksBetween(left, token) > 0) break; token.clearLineBreaksBefore(); left.clearLineBreaksAfter(); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); token = left; } } }
private void handleCompilerTags(Token commentToken, int commentIndex) { final String commentText = this.tm.toString(commentToken); final List<Token> structure = commentToken.getInternalStructure(); if (commentText.startsWith("//$FALL-THROUGH$") //$NON-NLS-1$ || commentText.startsWith("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ structure.get(1).clearSpaceBefore(); } if (commentText.contains("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ // make sure the whole line is not broken Token token = commentToken; for (int i = commentIndex; i > 0; i--) { Token left = this.tm.get(i - 1); if (this.tm.countLineBreaksBetween(left, token) > 0) break; token.clearLineBreaksBefore(); left.clearLineBreaksAfter(); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); token = left; } } }
private void handleCompilerTags(Token commentToken, int commentIndex) { final String commentText = this.tm.toString(commentToken); final List<Token> structure = commentToken.getInternalStructure(); if (commentText.startsWith("//$FALL-THROUGH$") //$NON-NLS-1$ || commentText.startsWith("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ structure.get(1).clearSpaceBefore(); } if (commentText.contains("//$IDENTITY-COMPARISON$")) { //$NON-NLS-1$ // make sure the whole line is not broken Token token = commentToken; for (int i = commentIndex; i > 0; i--) { Token left = this.tm.get(i - 1); if (this.tm.countLineBreaksBetween(left, token) > 0) break; token.clearLineBreaksBefore(); left.clearLineBreaksAfter(); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); token = left; } } }
private void adjustEmptyLineAfter(int tokenIndex, int indentationAdjustment) { if (tokenIndex + 1 >= this.tm.size()) return; Token token = this.tm.get(tokenIndex); Token next = this.tm.get(tokenIndex + 1); if (this.tm.countLineBreaksBetween(token, next) < 2 || !this.options.indent_empty_lines) return; next.setEmptyLineIndentAdjustment(indentationAdjustment * this.options.indentation_size); }
private void disableFormattingExclusively(int openingTagIndex, int closingTagIndex) { Token openingTag = this.ctm.get(openingTagIndex); int noFormatStart = openingTag.originalEnd + 1; int noFormatEnd = this.ctm.get(closingTagIndex - 1).originalEnd; if (noFormatStart <= noFormatEnd) { Token noFormatToken = new Token(noFormatStart, noFormatEnd, TokenNameCOMMENT_JAVADOC); int commentStart = findCommentLineIndent(openingTagIndex); List<Token> lines = commentToLines(noFormatToken, commentStart); List<Token> tokensToReplace = this.commentStructure.subList(openingTagIndex + 1, closingTagIndex); tokensToReplace.clear(); tokensToReplace.addAll(lines); } else { this.commentStructure.subList(openingTagIndex + 1, closingTagIndex).clear(); Token closingTag = this.ctm.get(closingTagIndex); if (this.ctm.countLineBreaksBetween(openingTag, closingTag) == 0) { openingTag.clearLineBreaksAfter(); closingTag.clearLineBreaksBefore(); } } }
private void adjustEmptyLineAfter(int tokenIndex, int indentationAdjustment) { if (tokenIndex + 1 >= this.tm.size()) return; Token token = this.tm.get(tokenIndex); Token next = this.tm.get(tokenIndex + 1); if (this.tm.countLineBreaksBetween(token, next) < 2 || !this.options.indent_empty_lines) return; next.setEmptyLineIndentAdjustment(indentationAdjustment * this.options.indentation_size); }