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 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 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 handleSeparateLineTag(int startPos, int endPos) { int openingTagIndex = tokenStartingAt(startPos); if (openingTagIndex > 1 && this.lastFormatCodeClosingTagIndex == openingTagIndex - 1) { Token token = this.ctm.get(openingTagIndex - 1); assert token.getLineBreaksAfter() == 2; token.clearLineBreaksAfter(); token.breakAfter(); } handleBreakBeforeTag(startPos, endPos, true); handleBreakAfterTag(startPos, endPos); }
private void handleSeparateLineTag(int startPos, int endPos) { int openingTagIndex = tokenStartingAt(startPos); if (openingTagIndex > 1 && this.lastFormatCodeClosingTagIndex == openingTagIndex - 1) { Token token = this.ctm.get(openingTagIndex - 1); assert token.getLineBreaksAfter() == 2; token.clearLineBreaksAfter(); token.breakAfter(); } handleBreakBeforeTag(startPos, endPos, true); handleBreakAfterTag(startPos, endPos); }
private void handleSeparateLineTag(int startPos, int endPos) { int openingTagIndex = tokenStartingAt(startPos); if (openingTagIndex > 1 && this.lastFormatCodeClosingTagIndex == openingTagIndex - 1) { Token token = this.ctm.get(openingTagIndex - 1); assert token.getLineBreaksAfter() == 2; token.clearLineBreaksAfter(); token.breakAfter(); } handleBreakBeforeTag(startPos, endPos, true); handleBreakAfterTag(startPos, endPos); }
prev.clearLineBreaksAfter(); Token token = this.tm.get(i); token.clearLineBreaksBefore();
private void preserveExistingLineBreaks() { // normally n empty lines = n+1 line breaks, but not at the file start and end Token first = this.tm.get(0); int startingBreaks = first.getLineBreaksBefore(); first.clearLineBreaksBefore(); first.putLineBreaksBefore(startingBreaks - 1); this.tm.traverse(0, new TokenTraverser() { boolean join_wrapped_lines = WrapPreparator.this.options.join_wrapped_lines; @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 > 1 || (!this.join_wrapped_lines && token.isWrappable()) || index == 0) token.putLineBreaksBefore(lineBreaks); return true; } }); Token last = this.tm.get(this.tm.size() - 1); last.clearLineBreaksAfter(); int endingBreaks = getLineBreaksToPreserve(last, null, false); if (endingBreaks > 0) { last.putLineBreaksAfter(endingBreaks); } else if ((this.kind & (CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.K_MODULE_INFO)) != 0 && this.options.insert_new_line_at_end_of_file_if_missing) { last.breakAfter(); } }
private void preserveExistingLineBreaks() { // normally n empty lines = n+1 line breaks, but not at the file start and end Token first = this.tm.get(0); int startingBreaks = first.getLineBreaksBefore(); first.clearLineBreaksBefore(); first.putLineBreaksBefore(startingBreaks - 1); this.tm.traverse(0, new TokenTraverser() { boolean join_wrapped_lines = WrapPreparator.this.options.join_wrapped_lines; @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 > 1 || (!this.join_wrapped_lines && token.isWrappable()) || index == 0) token.putLineBreaksBefore(lineBreaks); return true; } }); Token last = this.tm.get(this.tm.size() - 1); last.clearLineBreaksAfter(); int endingBreaks = getLineBreaksToPreserve(last, null, false); if (endingBreaks > 0) { last.putLineBreaksAfter(endingBreaks); } else if ((this.kind & (CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.K_MODULE_INFO)) != 0 && this.options.insert_new_line_at_end_of_file_if_missing) { last.breakAfter(); } }
last.clearLineBreaksAfter(); int endingBreaks = getLineBreaksToPreserve(last, null, false); if (endingBreaks > 0) {
previous.clearLineBreaksAfter(); } else if (existingBreaksAfter <= existingBreaksBefore && next != null
previous.clearLineBreaksAfter(); } else if (existingBreaksAfter <= existingBreaksBefore && next != null
previous.clearLineBreaksAfter(); } else if (existingBreaksAfter <= existingBreaksBefore && next != null