public void finishUp() { // the visits only noted where indents increase and decrease, // now prepare actual indent values int currentIndent = this.options.initial_indentation_level; for (Token token : this.tm) { currentIndent += token.getIndent(); token.setIndent(currentIndent * this.options.indentation_size); } } }
public void finishUp() { // the visits only noted where indents increase and decrease, // now prepare actual indent values int currentIndent = this.options.initial_indentation_level; for (Token token : this.tm) { currentIndent += token.getIndent(); token.setIndent(currentIndent * this.options.indentation_size); } } }
public void finishUp() { // the visits only noted where indents increase and decrease, // now prepare actual indent values int currentIndent = this.options.initial_indentation_level; for (Token token : this.tm) { currentIndent += token.getIndent(); token.setIndent(currentIndent * this.options.indentation_size); } } }
private void newLine(Token token, int index) { while (!this.stack.isEmpty() && index > this.stack.peek().getWrapPolicy().groupEndIndex) this.stack.pop(); if (token.getWrapPolicy() != null) { token.setIndent(getWrapIndent(token)); handleOnColumnIndent(index, token.getWrapPolicy()); this.stack.push(token); } else if (this.stack.isEmpty()) { this.initialIndent = token.getIndent(); WrapExecutor.this.wrapSearchResults.clear(); } this.currentIndent = this.stack.isEmpty() ? this.initialIndent : this.stack.peek().getIndent(); token.setIndent(this.currentIndent); this.nextWrap = findWrapsCached(index, this.currentIndent).nextWrap; } }
private void newLine(Token token, int index) { while (!this.stack.isEmpty() && index > this.stack.peek().getWrapPolicy().groupEndIndex) this.stack.pop(); if (token.getWrapPolicy() != null) { token.setIndent(getWrapIndent(token)); handleOnColumnIndent(index, token.getWrapPolicy()); this.stack.push(token); } else if (this.stack.isEmpty()) { this.initialIndent = token.getIndent(); WrapExecutor.this.wrapSearchResults.clear(); } this.currentIndent = this.stack.isEmpty() ? this.initialIndent : this.stack.peek().getIndent(); token.setIndent(this.currentIndent); this.nextWrap = findWrapsCached(index, this.currentIndent).nextWrap; } }
private void applyFormatOff() { for (Token[] offPair : this.tokenManager.getDisableFormatTokenPairs()) { final int offStart = offPair[0].originalStart; final int offEnd = offPair[1].originalEnd; offPair[0].setWrapPolicy(null); offPair[0] .setIndent(Math.min(offPair[0].getIndent(), this.tokenManager.findSourcePositionInLine(offStart))); final List<IRegion> result = new ArrayList<>(); for (IRegion region : this.formatRegions) { final int start = region.getOffset(), end = region.getOffset() + region.getLength() - 1; if (offEnd < start || end < offStart) { result.add(region); } else if (offStart <= start && end <= offEnd) { // whole region off } else { if (start < offStart) result.add(new Region(start, offStart - start)); if (offEnd < end) result.add(new Region(offEnd + 1, end - offEnd)); } } this.formatRegions = result; } }
private void disableFormatting(int startIndex, int endIndex) { Token startToken = this.ctm.get(startIndex), endToken = this.ctm.get(endIndex); Token noFormatToken = new Token(startToken.originalStart, endToken.originalEnd, TokenNameCOMMENT_JAVADOC); List<Token> tokensToReplace = this.commentStructure.subList(startIndex, endIndex + 1); if (this.ctm.countLineBreaksBetween(startToken, endToken) == 0) { tokensToReplace.clear(); tokensToReplace.add(noFormatToken); } else { int commentStart = findCommentLineIndent(startIndex); tokensToReplace.clear(); tokensToReplace.addAll(commentToLines(noFormatToken, commentStart)); } Token first = tokensToReplace.get(0), last = tokensToReplace.get(tokensToReplace.size() - 1); if (startToken.isSpaceBefore()) first.spaceBefore(); first.putLineBreaksBefore(startToken.getLineBreaksBefore()); first.setWrapPolicy(startToken.getWrapPolicy()); if (endToken.isSpaceAfter()) last.spaceAfter(); last.putLineBreaksAfter(endToken.getLineBreaksAfter()); for (Token token : tokensToReplace) if (token.tokenType == TokenNameCOMMENT_JAVADOC) token.setIndent(startToken.getIndent()); }
private void splitToken(Token token, int tokenIndex, int splitPosition) { assert splitPosition > token.originalStart && splitPosition <= token.originalEnd; Token part1 = new Token(token.originalStart, splitPosition - 1, token.tokenType); Token part2 = new Token(splitPosition, token.originalEnd, token.tokenType); if (token.isSpaceBefore()) part1.spaceBefore(); part1.putLineBreaksBefore(token.getLineBreaksBefore()); if (token.isSpaceAfter()) part2.spaceAfter(); part2.putLineBreaksAfter(token.getLineBreaksAfter()); part1.setIndent(token.getIndent()); part2.setIndent(token.getIndent()); part1.setWrapPolicy(token.getWrapPolicy()); this.commentStructure.set(tokenIndex, part1); this.commentStructure.add(tokenIndex + 1, part2); }
private void splitToken(Token token, int tokenIndex, int splitPosition) { assert splitPosition > token.originalStart && splitPosition <= token.originalEnd; Token part1 = new Token(token.originalStart, splitPosition - 1, token.tokenType); Token part2 = new Token(splitPosition, token.originalEnd, token.tokenType); if (token.isSpaceBefore()) part1.spaceBefore(); part1.putLineBreaksBefore(token.getLineBreaksBefore()); if (token.isSpaceAfter()) part2.spaceAfter(); part2.putLineBreaksAfter(token.getLineBreaksAfter()); part1.setIndent(token.getIndent()); part2.setIndent(token.getIndent()); part1.setWrapPolicy(token.getWrapPolicy()); this.commentStructure.set(tokenIndex, part1); this.commentStructure.add(tokenIndex + 1, part2); }
private void splitToken(Token token, int tokenIndex, int splitPosition) { assert splitPosition > token.originalStart && splitPosition <= token.originalEnd; Token part1 = new Token(token.originalStart, splitPosition - 1, token.tokenType); Token part2 = new Token(splitPosition, token.originalEnd, token.tokenType); if (token.isSpaceBefore()) part1.spaceBefore(); part1.putLineBreaksBefore(token.getLineBreaksBefore()); if (token.isSpaceAfter()) part2.spaceAfter(); part2.putLineBreaksAfter(token.getLineBreaksAfter()); part1.setIndent(token.getIndent()); part2.setIndent(token.getIndent()); part1.setWrapPolicy(token.getWrapPolicy()); this.commentStructure.set(tokenIndex, part1); this.commentStructure.add(tokenIndex + 1, part2); }
public void applyFormatOff() { if (this.formatOffTagPairs == null) return; for (Token[] pair : this.formatOffTagPairs) { int index1 = findIndex(pair[0].originalStart, -1, false); int index2 = findIndex(pair[1].originalEnd, -1, false); pair[0] = get(index1); pair[1] = get(index2); Token unformatted = new Token(pair[0].originalStart, pair[1].originalEnd, TokenNameWHITESPACE); unformatted.setIndent(Math.min(pair[0].getIndent(), findSourcePositionInLine(pair[0].originalStart))); unformatted.putLineBreaksBefore(pair[0].getLineBreaksBefore()); if (pair[0].isSpaceBefore()) unformatted.spaceBefore(); unformatted.putLineBreaksAfter(pair[1].getLineBreaksAfter()); if (pair[1].isSpaceAfter()) unformatted.spaceAfter(); this.tokens.set(index1, unformatted); this.tokens.subList(index1 + 1, index2 + 1).clear(); } } }
@Override public void endVisit(TagElement node) { String tagName = node.getTagName(); if (tagName == null || tagName.length() <= 1) handleHtml(node); if (TagElement.TAG_SEE.equals(tagName)) handleStringLiterals(this.tm.toString(node), node.getStartPosition()); if (PARAM_TAGS.contains(tagName) && this.options.comment_indent_parameter_description) { // tokens in the first line should not be indented int startIndex = this.ctm.findIndex(node.getStartPosition(), -1, false); if (this.ctm.get(startIndex).tokenType != TokenNameNotAToken) { int endIndex = this.ctm.lastIndexIn(node, -1); int range = this.options.indentation_size; for (int i = startIndex + 2; i <= endIndex && range > 0; i++) { Token token = this.ctm.get(i); if (token.getLineBreaksBefore() > 0) break; assert token.getIndent() >= this.options.indentation_size; token.setIndent(token.getIndent() - this.options.indentation_size); if (token.getLineBreaksAfter() > 0) break; range -= this.ctm.getLength(token, 0) + (token.isSpaceBefore() ? 1 : 0); } } } }
@Override protected boolean token(Token token, int index) { if (index == 0 || getLineBreaksBefore() > 0) { newLine(token, index); } else if ((this.nextWrap != null && index == this.nextWrap.wrapTokenIndex) || checkForceWrap(token, index, this.currentIndent) || (token.isNextLineOnWrap() && WrapExecutor.this.tm .get(WrapExecutor.this.tm.findFirstTokenInLine(index)).isWrappable())) { token.breakBefore(); newLine(token, index); } else { token.setIndent(this.currentIndent); } return true; }
@Override protected boolean token(Token token, int index) { if (index == 0 || getLineBreaksBefore() > 0) { newLine(token, index); } else if ((this.nextWrap != null && index == this.nextWrap.wrapTokenIndex) || checkForceWrap(token, index, this.currentIndent) || (token.isNextLineOnWrap() && WrapExecutor.this.tm .get(WrapExecutor.this.tm.findFirstTokenInLine(index)).isWrappable())) { token.breakBefore(); newLine(token, index); } else { token.setIndent(this.currentIndent); } return true; }
private void cleanupHTMLElement(int openingTagIndex, int closingTagIndex, boolean formattedCode) { Token previous = this.ctm.get(openingTagIndex); int indent = previous.getIndent(); for (int i = openingTagIndex + 1; i < closingTagIndex; i++) { Token token = this.ctm.get(i); token.setToEscape(true); if (formattedCode && (token.getLineBreaksBefore() > 0 || previous.getLineBreaksAfter() > 0)) token.setAlign(indent); previous = token; } for (int i = closingTagIndex; i < this.ctm.size(); i++) { Token token = this.ctm.get(i); if (token.getIndent() == 0) break; token.setIndent(indent); previous = token; } }
private void cleanupHTMLElement(int openingTagIndex, int closingTagIndex, boolean formattedCode) { Token previous = this.ctm.get(openingTagIndex); int indent = previous.getIndent(); for (int i = openingTagIndex + 1; i < closingTagIndex; i++) { Token token = this.ctm.get(i); token.setToEscape(true); if (formattedCode && (token.getLineBreaksBefore() > 0 || previous.getLineBreaksAfter() > 0)) token.setAlign(indent); previous = token; } for (int i = closingTagIndex; i < this.ctm.size(); i++) { Token token = this.ctm.get(i); if (token.getIndent() == 0) break; token.setIndent(indent); previous = token; } }
private void cleanupHTMLElement(int openingTagIndex, int closingTagIndex, boolean formattedCode) { Token previous = this.ctm.get(openingTagIndex); int indent = previous.getIndent(); for (int i = openingTagIndex + 1; i < closingTagIndex; i++) { Token token = this.ctm.get(i); token.setToEscape(true); if (formattedCode && (token.getLineBreaksBefore() > 0 || previous.getLineBreaksAfter() > 0)) token.setAlign(indent); previous = token; } for (int i = closingTagIndex; i < this.ctm.size(); i++) { Token token = this.ctm.get(i); if (token.getIndent() == 0) break; token.setIndent(indent); previous = token; } }
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); } }