public void finishUp() { this.tm.traverse(0, new TokenTraverser() { boolean isPreviousJIDP = false; @Override protected boolean token(Token token, int index) { // put space between consecutive keywords, numbers or identifiers char c = SpacePreparator.this.tm.charAt(token.originalStart); boolean isJIDP = ScannerHelper.isJavaIdentifierPart(c); if ((isJIDP || c == '@') && this.isPreviousJIDP) getPrevious().spaceAfter(); this.isPreviousJIDP = isJIDP; switch (token.tokenType) { case TokenNamePLUS: if (getNext().tokenType == TokenNamePLUS || getNext().tokenType == TokenNamePLUS_PLUS) token.spaceAfter(); break; case TokenNameMINUS: if (getNext().tokenType == TokenNameMINUS || getNext().tokenType == TokenNameMINUS_MINUS) token.spaceAfter(); break; } return true; } }); } }
public void finishUp() { this.tm.traverse(0, new TokenTraverser() { boolean isPreviousJIDP = false; @Override protected boolean token(Token token, int index) { // put space between consecutive keywords, numbers or identifiers char c = SpacePreparator.this.tm.charAt(token.originalStart); boolean isJIDP = ScannerHelper.isJavaIdentifierPart(c); if ((isJIDP || c == '@') && this.isPreviousJIDP) getPrevious().spaceAfter(); this.isPreviousJIDP = isJIDP; switch (token.tokenType) { case TokenNamePLUS: if (getNext().tokenType == TokenNamePLUS || getNext().tokenType == TokenNamePLUS_PLUS) token.spaceAfter(); break; case TokenNameMINUS: if (getNext().tokenType == TokenNameMINUS || getNext().tokenType == TokenNameMINUS_MINUS) token.spaceAfter(); break; } return true; } }); } }
public void finishUp() { this.tm.traverse(0, new TokenTraverser() { boolean isPreviousJIDP = false; @Override protected boolean token(Token token, int index) { // put space between consecutive keywords, numbers or identifiers char c = SpacePreparator.this.tm.charAt(token.originalStart); boolean isJIDP = ScannerHelper.isJavaIdentifierPart(c); if ((isJIDP || c == '@') && this.isPreviousJIDP) getPrevious().spaceAfter(); this.isPreviousJIDP = isJIDP; switch (token.tokenType) { case TokenNamePLUS: if (getNext().tokenType == TokenNamePLUS || getNext().tokenType == TokenNamePLUS_PLUS) token.spaceAfter(); break; case TokenNameMINUS: if (getNext().tokenType == TokenNameMINUS || getNext().tokenType == TokenNameMINUS_MINUS) token.spaceAfter(); break; } return true; } }); } }
public int findMaxPosition(int fromIndex, int toIndex) { this.counter = Aligner.this.tm.getPositionInLine(fromIndex); this.stoppingIndex = toIndex; this.maxPosition = 0; Aligner.this.tm.traverse(fromIndex, this); return this.maxPosition; } }
public int findMaxPosition(int fromIndex, int toIndex) { this.counter = FieldAligner.this.tm.getPositionInLine(fromIndex); this.stoppingIndex = toIndex; this.maxPosition = 0; FieldAligner.this.tm.traverse(fromIndex, this); return this.maxPosition; } }
public int findMaxPosition(int fromIndex, int toIndex) { this.counter = FieldAligner.this.tm.getPositionInLine(fromIndex); this.stoppingIndex = toIndex; this.maxPosition = 0; FieldAligner.this.tm.traverse(fromIndex, this); return this.maxPosition; } }
/** * @return index of the last token in line */ public int analyzeLine(int startIndex, int indent) { Token startToken = WrapExecutor.this.tm.get(startIndex); this.counter = WrapExecutor.this.tm.toIndent(indent, startToken.isWrappable()); this.lineIndent = indent; this.firstPotentialWrap = -1; this.extraLines = 0; this.extraLinesPerComment.clear(); this.topPriorityGroupStarts.clear(); this.currentTopPriorityGroupEnd = -1; this.isNLSTagInLine = false; return WrapExecutor.this.tm.traverse(startIndex, this); }
/** * @return index of the last token in line */ public int analyzeLine(int startIndex, int indent) { Token startToken = WrapExecutor.this.tm.get(startIndex); assert startToken.getLineBreaksBefore() > 0; this.counter = WrapExecutor.this.tm.toIndent(indent, startToken.isWrappable()); this.lineIndent = indent; this.firstPotentialWrap = -1; this.activeTopPriorityWrap = -1; this.minStructureDepth = Integer.MAX_VALUE; this.extraLines = 0; this.isNextLineWrapped = false; this.extraLinesPerComment.clear(); this.topPriorityGroupStarts.clear(); this.currentTopPriorityGroupEnd = -1; this.isNLSTagInLine = false; int lastIndex = WrapExecutor.this.tm.traverse(startIndex, this); return lastIndex + (this.isNextLineWrapped ? 1 : 0); }
/** * @return index of the last token in line */ public int analyzeLine(int startIndex, int indent) { Token startToken = WrapExecutor.this.tm.get(startIndex); assert startToken.getLineBreaksBefore() > 0; this.counter = WrapExecutor.this.tm.toIndent(indent, startToken.isWrappable()); this.lineIndent = indent; this.firstPotentialWrap = -1; this.activeTopPriorityWrap = -1; this.minStructureDepth = Integer.MAX_VALUE; this.extraLines = 0; this.isNextLineWrapped = false; this.extraLinesPerComment.clear(); this.topPriorityGroupStarts.clear(); this.currentTopPriorityGroupEnd = -1; this.isNLSTagInLine = false; int lastIndex = WrapExecutor.this.tm.traverse(startIndex, this); return lastIndex + (this.isNextLineWrapped ? 1 : 0); }
public void executeWraps() { int index = 0; while (index < this.tm.size()) { Token token = this.tm.get(index); while (true) { try { int currentIndent = getWrapIndent(token); this.wrapSearchResults.clear(); index = applyWraps(index, currentIndent); break; } catch (WrapRestartThrowable e) { handleTopPriorityWraps(e); } } this.wrapSearchResults.clear(); this.usedTopPriorityWraps.clear(); } this.tm.traverse(0, new NLSTagHandler()); }
/** * {@inheritDoc} */ public TextEdit format(int kind, String source, IRegion[] regions, int indentationLevel, String lineSeparator) { if (!regionsSatisfiesPreconditions(regions, source.length())) { throw new IllegalArgumentException(); } this.formatRegions = Arrays.asList(regions); updateWorkingOptions(indentationLevel, lineSeparator, kind); if ((kind & K_COMMENTS_MASK) != 0) return formatComments(source, kind & K_COMMENTS_MASK); if (prepareFormattedCode(source, kind) == null) return this.tokens.isEmpty() ? new MultiTextEdit() : null; MultiTextEdit result = new MultiTextEdit(); TextEditsBuilder resultBuilder = new TextEditsBuilder(this.sourceString, this.formatRegions, this.tokenManager, this.workingOptions); this.tokenManager.traverse(0, resultBuilder); for (TextEdit edit : resultBuilder.getEdits()) { result.addChild(edit); } return result; }
/** * {@inheritDoc} */ @Override public TextEdit format(int kind, String source, IRegion[] regions, int indentationLevel, String lineSeparator) { if (!regionsSatisfiesPreconditions(regions, source.length())) { throw new IllegalArgumentException(); } this.formatRegions = Arrays.asList(regions); updateWorkingOptions(indentationLevel, lineSeparator, kind); if ((kind & K_COMMENTS_MASK) != 0) return formatComments(source, kind & K_COMMENTS_MASK); if (prepareFormattedCode(source, kind) == null) return this.tokens.isEmpty() ? new MultiTextEdit() : null; MultiTextEdit result = new MultiTextEdit(); TextEditsBuilder resultBuilder = new TextEditsBuilder(this.sourceString, this.formatRegions, this.tokenManager, this.workingOptions); this.tokenManager.traverse(0, resultBuilder); for (TextEdit edit : resultBuilder.getEdits()) { result.addChild(edit); } return result; }
/** * {@inheritDoc} */ public TextEdit format(int kind, String source, IRegion[] regions, int indentationLevel, String lineSeparator) { if (!regionsSatisfiesPreconditions(regions, source.length())) { throw new IllegalArgumentException(); } this.formatRegions = regions; updateWorkingOptions(indentationLevel, lineSeparator, kind); if ((kind & K_COMMENTS_MASK) != 0) return formatComments(source, kind & K_COMMENTS_MASK); if (prepareFormattedCode(source, kind) == null) return this.tokens.isEmpty() ? new MultiTextEdit() : null; MultiTextEdit result = new MultiTextEdit(); TextEditsBuilder resultBuilder = new TextEditsBuilder(this.sourceString, regions, this.tokenManager, this.workingOptions); this.tokenManager.traverse(0, resultBuilder); for (TextEdit edit : resultBuilder.getEdits()) { result.addChild(edit); } return result; }
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()); }
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; }
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(); } }