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 int getStartingPosition(Token token) { int position = this.lineStartPosition + token.getAlign() + token.getIndent(); if (token.tokenType != TokenNameNotAToken) position += COMMENT_LINE_SEPARATOR_LENGTH; return position; }
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 int getStartingPosition(Token token) { int position = this.lineStartPosition + token.getAlign() + token.getIndent(); if (token.tokenType != TokenNameNotAToken) position += COMMENT_LINE_SEPARATOR_LENGTH; return position; }
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; } }
int getWrapIndent(Token token) { WrapPolicy policy = token.getWrapPolicy(); if (policy == null) return token.getIndent(); if (policy == WrapPolicy.FORCE_FIRST_COLUMN) return 0; Token wrapParent = this.tm.get(policy.wrapParentIndex); int wrapIndent = wrapParent.getIndent(); if (policy.indentOnColumn) { wrapIndent = this.tm.getPositionInLine(policy.wrapParentIndex); wrapIndent += this.tm.getLength(wrapParent, wrapIndent); if (wrapParent.isSpaceAfter() || this.tm.get(policy.wrapParentIndex + 1).isSpaceBefore()) wrapIndent++; } wrapIndent += policy.extraIndent; return this.tm.toIndent(wrapIndent, true); } }
public int getPositionInLine(int tokenIndex) { Token token = get(tokenIndex); // find the first token in line and calculate position of given token int firstTokenIndex = token.getLineBreaksBefore() > 0 ? tokenIndex : findFirstTokenInLine(tokenIndex); Token firstToken = get(firstTokenIndex); int startingPosition = toIndent(firstToken.getIndent(), firstToken.getWrapPolicy() != null); this.positionInLineCounter.value = tokenIndex; this.positionInLineCounter.counter = startingPosition; traverse(firstTokenIndex, this.positionInLineCounter); return Math.max(this.positionInLineCounter.counter, token.getAlign()); }
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 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); }
int getWrapIndent(Token token) { WrapPolicy policy = token.getWrapPolicy(); if (policy == null) return token.getIndent(); if (policy == WrapPolicy.FORCE_FIRST_COLUMN) return 0; Token wrapParent = this.tm.get(policy.wrapParentIndex); int wrapIndent = wrapParent.getIndent(); if (policy.indentOnColumn) { wrapIndent = this.tm.getPositionInLine(policy.wrapParentIndex); wrapIndent += this.tm.getLength(wrapParent, wrapIndent); Token next = this.tm.get(policy.wrapParentIndex + 1); if (wrapParent.isSpaceAfter() || (next.isSpaceBefore() && !next.isComment())) wrapIndent++; } wrapIndent += policy.extraIndent; return this.tm.toIndent(wrapIndent, 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 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(); } } }
public int getPositionInLine(int tokenIndex) { Token token = get(tokenIndex); if (token.getAlign() > 0) return get(tokenIndex).getAlign(); // find the first token in line and calculate position of given token int firstTokenIndex = token.getLineBreaksBefore() > 0 ? tokenIndex : findFirstTokenInLine(tokenIndex); Token firstToken = get(firstTokenIndex); int startingPosition = toIndent(firstToken.getIndent(), firstToken.getWrapPolicy() != null); if (firstTokenIndex == tokenIndex) return startingPosition; this.positionInLineCounter.value = tokenIndex; this.positionInLineCounter.counter = startingPosition; traverse(firstTokenIndex, this.positionInLineCounter); return this.positionInLineCounter.counter; }
public int getPositionInLine(int tokenIndex) { Token token = get(tokenIndex); if (token.getAlign() > 0) return get(tokenIndex).getAlign(); // find the first token in line and calculate position of given token int firstTokenIndex = token.getLineBreaksBefore() > 0 ? tokenIndex : findFirstTokenInLine(tokenIndex); Token firstToken = get(firstTokenIndex); int startingPosition = toIndent(firstToken.getIndent(), firstToken.getWrapPolicy() != null); if (firstTokenIndex == tokenIndex) return startingPosition; this.positionInLineCounter.value = tokenIndex; this.positionInLineCounter.counter = startingPosition; traverse(firstTokenIndex, this.positionInLineCounter); return this.positionInLineCounter.counter; }