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 void traverseInternalStructure(Token token, int index) { List<Token> structure = token.getInternalStructure(); this.tm = new TokenManager(structure, this.parent.tm); this.counter = token.originalStart; this.sourceLimit = token.originalEnd + 1; this.parentTokenIndex = index; traverse(structure, 0); }
private void traverseInternalStructure(Token token, int index) { List<Token> structure = token.getInternalStructure(); this.tm = new TokenManager(structure, this.parent.tm); this.counter = token.originalStart; this.sourceLimit = token.originalEnd + 1; this.parentTokenIndex = index; traverse(structure, 0); }
private void traverseInternalStructure(Token token, int index) { List<Token> structure = token.getInternalStructure(); this.tm = new TokenManager(structure, this.parent.tm); this.counter = token.originalStart; this.sourceLimit = token.originalEnd + 1; this.parentTokenIndex = index; traverse(structure, 0); }
private void preserveWhitespace(Token commentToken, int commentIndex) { if (this.options.comment_preserve_white_space_between_code_and_line_comments && commentToken.getLineBreaksBefore() == 0 && commentIndex > 0) { commentToken.clearSpaceBefore(); List<Token> structure = commentToken.getInternalStructure(); if (structure != null && !structure.isEmpty()) structure.get(0).clearSpaceBefore(); Token previous = this.tm.get(commentIndex - 1); previous.clearSpaceAfter(); if (previous.originalEnd + 1 >= commentToken.originalStart) return; if (structure == null || structure.isEmpty()) { structure = new ArrayList<>(); structure.add(new Token(previous.originalEnd + 1, commentToken.originalEnd, TokenNameCOMMENT_LINE)); commentToken.setInternalStructure(structure); } else { structure.add(0, new Token(previous.originalEnd + 1, commentToken.originalStart - 1, TokenNameWHITESPACE)); } } }
private void preserveWhitespace(Token commentToken, int commentIndex) { if (this.options.comment_preserve_white_space_between_code_and_line_comments && commentToken.getLineBreaksBefore() == 0 && commentIndex > 0) { commentToken.clearSpaceBefore(); List<Token> structure = commentToken.getInternalStructure(); if (structure != null && !structure.isEmpty()) structure.get(0).clearSpaceBefore(); Token previous = this.tm.get(commentIndex - 1); previous.clearSpaceAfter(); if (previous.originalEnd + 1 >= commentToken.originalStart) return; if (structure == null || structure.isEmpty()) { structure = new ArrayList<>(); structure.add(new Token(previous.originalEnd + 1, commentToken.originalEnd, TokenNameCOMMENT_LINE)); commentToken.setInternalStructure(structure); } else { structure.add(0, new Token(previous.originalEnd + 1, commentToken.originalStart - 1, TokenNameWHITESPACE)); } } }
private void preserveWhitespace(Token commentToken, int commentIndex) { if (this.options.comment_preserve_white_space_between_code_and_line_comments && commentToken.getLineBreaksBefore() == 0 && commentIndex > 0) { commentToken.clearSpaceBefore(); List<Token> structure = commentToken.getInternalStructure(); if (structure != null && !structure.isEmpty()) structure.get(0).clearSpaceBefore(); Token previous = this.tm.get(commentIndex - 1); previous.clearSpaceAfter(); if (previous.originalEnd + 1 >= commentToken.originalStart) return; if (structure == null || structure.isEmpty()) { structure = new ArrayList<>(); structure.add(new Token(previous.originalEnd + 1, commentToken.originalEnd, TokenNameCOMMENT_LINE)); commentToken.setInternalStructure(structure); } else { structure.add(0, new Token(previous.originalEnd + 1, commentToken.originalStart - 1, TokenNameWHITESPACE)); } } }
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; } } }
@Override protected boolean token(Token traversed, int index) { if (index == this.value) { this.isNLSTagInLine = false; return false; } if (traversed.hasNLSTag()) { assert traversed.tokenType == TokenNameStringLiteral; this.isNLSTagInLine = true; } if (traversed.getAlign() > 0) this.counter = traversed.getAlign(); List<Token> internalStructure = traversed.getInternalStructure(); if (internalStructure != null && !internalStructure.isEmpty()) { assert traversed.tokenType == TokenNameCOMMENT_BLOCK || traversed.tokenType == TokenNameCOMMENT_JAVADOC; this.counter = TokenManager.this.commentWrapper.wrapMultiLineComment(traversed, this.counter, true, this.isNLSTagInLine); } else { this.counter += getLength(traversed, this.counter); } if (isSpaceAfter()) this.counter++; return true; } };
@Override protected boolean token(Token traversed, int index) { if (index == this.value) { this.isNLSTagInLine = false; return false; } if (traversed.hasNLSTag()) { assert traversed.tokenType == TokenNameStringLiteral; this.isNLSTagInLine = true; } if (traversed.getAlign() > 0) this.counter = traversed.getAlign(); List<Token> internalStructure = traversed.getInternalStructure(); if (internalStructure != null && !internalStructure.isEmpty()) { assert traversed.tokenType == TokenNameCOMMENT_BLOCK || traversed.tokenType == TokenNameCOMMENT_JAVADOC; this.counter = TokenManager.this.commentWrapper.wrapMultiLineComment(traversed, this.counter, true, this.isNLSTagInLine); } else { this.counter += getLength(traversed, this.counter); } if (isSpaceAfter()) this.counter++; return true; } };
private void wrapComments() { CommentWrapExecutor commentWrapper = new CommentWrapExecutor(this.tm, this.options); boolean isNLSTagInLine = false; for (int i = 0; i < this.tm.size(); i++) { Token token = this.tm.get(i); if (token.getLineBreaksBefore() > 0 || token.getLineBreaksAfter() > 0) isNLSTagInLine = false; if (token.hasNLSTag()) { assert token.tokenType == TokenNameStringLiteral; isNLSTagInLine = true; } List<Token> structure = token.getInternalStructure(); if (structure != null && !structure.isEmpty() && !isNLSTagInLine) { int startPosition = this.tm.getPositionInLine(i); if (token.tokenType == TokenNameCOMMENT_LINE) { commentWrapper.wrapLineComment(token, startPosition); } else { assert token.tokenType == TokenNameCOMMENT_BLOCK || token.tokenType == TokenNameCOMMENT_JAVADOC; commentWrapper.wrapMultiLineComment(token, startPosition, false, false); } } } }
private void wrapComments() { CommentWrapExecutor commentWrapper = new CommentWrapExecutor(this.tm, this.options); boolean isNLSTagInLine = false; for (int i = 0; i < this.tm.size(); i++) { Token token = this.tm.get(i); if (token.getLineBreaksBefore() > 0 || token.getLineBreaksAfter() > 0) isNLSTagInLine = false; if (token.hasNLSTag()) { assert token.tokenType == TokenNameStringLiteral; isNLSTagInLine = true; } List<Token> structure = token.getInternalStructure(); if (structure != null && !structure.isEmpty() && !isNLSTagInLine) { int startPosition = this.tm.getPositionInLine(i); if (token.tokenType == TokenNameCOMMENT_LINE) { commentWrapper.wrapLineComment(token, startPosition); } else { assert token.tokenType == TokenNameCOMMENT_BLOCK || token.tokenType == TokenNameCOMMENT_JAVADOC; commentWrapper.wrapMultiLineComment(token, startPosition, false, false); } } } }
private void wrapComments() { CommentWrapExecutor commentWrapper = new CommentWrapExecutor(this.tm, this.options); boolean isNLSTagInLine = false; for (int i = 0; i < this.tm.size(); i++) { Token token = this.tm.get(i); if (token.getLineBreaksBefore() > 0 || token.getLineBreaksAfter() > 0) isNLSTagInLine = false; if (token.hasNLSTag()) { assert token.tokenType == TokenNameStringLiteral; isNLSTagInLine = true; } List<Token> structure = token.getInternalStructure(); if (structure != null && !structure.isEmpty() && !isNLSTagInLine) { int startPosition = this.tm.getPositionInLine(i); if (token.tokenType == TokenNameCOMMENT_LINE) { commentWrapper.wrapLineComment(token, startPosition); } else { assert token.tokenType == TokenNameCOMMENT_BLOCK || token.tokenType == TokenNameCOMMENT_JAVADOC; commentWrapper.wrapMultiLineComment(token, startPosition, false, false); } } } }
public void handleBlockComment(int commentIndex) { Token commentToken = this.tm.get(commentIndex); boolean isFirstColumn = handleWhitespaceAround(commentIndex); if (handleFormatOnOffTags(commentToken)) return; boolean isHeader = this.tm.isInHeader(commentIndex); boolean formattingEnabled = (this.options.comment_format_block_comment && !isHeader) || (this.options.comment_format_header && isHeader); formattingEnabled = formattingEnabled && this.tm.charAt(commentToken.originalStart + 2) != '-'; if (formattingEnabled && tokenizeMultilineComment(commentToken)) { this.commentStructure = commentToken.getInternalStructure(); this.ctm = new TokenManager(this.commentStructure, this.tm); handleStringLiterals(this.tm.toString(commentToken), commentToken.originalStart); addSubstituteWraps(); } else { commentToken.setInternalStructure(commentToLines(commentToken, -1)); } if (this.options.never_indent_block_comments_on_first_column && isFirstColumn) { commentToken.setIndent(0); commentToken.setWrapPolicy(WrapPolicy.FORCE_FIRST_COLUMN); } }
public void handleBlockComment(int commentIndex) { Token commentToken = this.tm.get(commentIndex); boolean isFirstColumn = handleWhitespaceAround(commentIndex); if (handleFormatOnOffTags(commentToken)) return; boolean isHeader = this.tm.isInHeader(commentIndex); boolean formattingEnabled = (this.options.comment_format_block_comment && !isHeader) || (this.options.comment_format_header && isHeader); formattingEnabled = formattingEnabled && this.tm.charAt(commentToken.originalStart + 2) != '-'; if (formattingEnabled && tokenizeMultilineComment(commentToken)) { this.commentStructure = commentToken.getInternalStructure(); this.ctm = new TokenManager(this.commentStructure, this.tm); handleStringLiterals(this.tm.toString(commentToken), commentToken.originalStart); addSubstituteWraps(); } else { commentToken.setInternalStructure(commentToLines(commentToken, -1)); } if (this.options.never_indent_block_comments_on_first_column && isFirstColumn) { commentToken.setIndent(0); commentToken.setWrapPolicy(null); } }
public void handleBlockComment(int commentIndex) { Token commentToken = this.tm.get(commentIndex); boolean isFirstColumn = handleWhitespaceAround(commentIndex); if (handleFormatOnOffTags(commentToken)) return; boolean isHeader = this.tm.isInHeader(commentIndex); boolean formattingEnabled = (this.options.comment_format_block_comment && !isHeader) || (this.options.comment_format_header && isHeader); formattingEnabled = formattingEnabled && this.tm.charAt(commentToken.originalStart + 2) != '-'; if (formattingEnabled && tokenizeMultilineComment(commentToken)) { this.commentStructure = commentToken.getInternalStructure(); this.ctm = new TokenManager(this.commentStructure, this.tm); handleStringLiterals(this.tm.toString(commentToken), commentToken.originalStart); addSubstituteWraps(); } else { commentToken.setInternalStructure(commentToLines(commentToken, -1)); } if (this.options.never_indent_block_comments_on_first_column && isFirstColumn) { commentToken.setIndent(0); commentToken.setWrapPolicy(WrapPolicy.FORCE_FIRST_COLUMN); } }