public int findSourcePositionInLine(int position) { int lineStartPosition = position; char c; while (lineStartPosition > 0 && (c = charAt(lineStartPosition)) != '\r' && c != '\n') lineStartPosition--; int positionInLine = getLength(lineStartPosition, position - 1, 0); return positionInLine; }
public int findSourcePositionInLine(int position) { int lineStartPosition = position; char c; while (lineStartPosition > 0 && (c = charAt(lineStartPosition)) != '\r' && c != '\n') lineStartPosition--; int positionInLine = getLength(lineStartPosition, position - 1, 0); return positionInLine; }
public int findSourcePositionInLine(int position) { int lineStartPosition = position; char c; while (lineStartPosition > 0 && (c = charAt(lineStartPosition)) != '\r' && c != '\n') lineStartPosition--; int positionInLine = getLength(lineStartPosition, position - 1, 0); return positionInLine; }
/** * @param token the token to measure * @param startPosition position in line of the first character (affects tabs calculation) * @return actual length of given token, considering tabs and escaping characters as HTML entities */ public int getLength(Token token, int startPosition) { int length = getLength(token.originalStart, token.originalEnd, startPosition); if (token.isToEscape()) { if (token.getLineBreaksBefore() > 0 && charAt(token.originalStart) == '@') { length += 4; // 4 = "@".length() - "@".length() } else if (token.tokenType == TokenNameNotAToken) { Matcher matcher = COMMENT_LINE_ANNOTATION_PATTERN.matcher(token.toString(this.source)); if (matcher.find()) { length += 4; // 4 = "@".length() - "@".length() } } } return length; }
/** * @param token the token to measure * @param startPosition position in line of the first character (affects tabs calculation) * @return actual length of given token, considering tabs and escaping characters as HTML entities */ public int getLength(Token token, int startPosition) { int length = getLength(token.originalStart, token.originalEnd, startPosition); if (token.isToEscape()) { if (token.getLineBreaksBefore() > 0 && charAt(token.originalStart) == '@') { length += 4; // 4 = "@".length() - "@".length() } else if (token.tokenType == TokenNameNotAToken) { Matcher matcher = COMMENT_LINE_ANNOTATION_PATTERN.matcher(token.toString(this.source)); if (matcher.find()) { length += 4; // 4 = "@".length() - "@".length() } } } return length; }
/** * @param token the token to measure * @param startPosition position in line of the first character (affects tabs calculation) * @return actual length of given token, considering tabs and escaping characters as HTML entities */ public int getLength(Token token, int startPosition) { int length = getLength(token.originalStart, token.originalEnd, startPosition); if (token.isToEscape()) { if (token.getLineBreaksBefore() > 0 && charAt(token.originalStart) == '@') { length += 4; // 4 = "@".length() - "@".length() } else if (token.tokenType == TokenNameNotAToken) { Matcher matcher = COMMENT_LINE_ANNOTATION_PATTERN.matcher(token.toString(this.source)); if (matcher.find()) { length += 4; // 4 = "@".length() - "@".length() } } } return length; }
private int tryToFitInOneLine(List<Token> structure, int startPosition, boolean noWrap) { int position = startPosition; boolean hasWrapPotential = false; boolean wasSpaceAfter = false; for (int i = 0; i < structure.size(); i++) { Token token = structure.get(i); if (token.getLineBreaksBefore() > 0 || token.getLineBreaksAfter() > 0) { assert !noWrap; // comment already wrapped return -1; } if (!wasSpaceAfter && token.isSpaceBefore()) position++; position += this.tm.getLength(token, position); wasSpaceAfter = token.isSpaceAfter(); if (wasSpaceAfter) position++; WrapPolicy policy = token.getWrapPolicy(); if (i > 1 && (policy == null || policy == WrapPolicy.SUBSTITUTE_ONLY)) hasWrapPotential = true; } if (position <= this.lineLimit || noWrap || !hasWrapPotential) return position; return -1; }
private int findCommentLineIndent(int commentFragmentIndex) { int position = this.ctm.get(commentFragmentIndex).originalStart; int lastNonWhitespace = position; while (--position > 0) { char c = this.ctm.charAt(position); if (c == '\r' || c == '\n') break; if (!ScannerHelper.isWhitespace(c)) lastNonWhitespace = position; } if (lastNonWhitespace > 0 && this.ctm.charAt(lastNonWhitespace - 1) == ' ') lastNonWhitespace--; return this.ctm.getLength(position, lastNonWhitespace - 1, 0); }
private int tryToFitInOneLine(List<Token> structure, int startPosition, boolean noWrap) { int position = startPosition; boolean hasWrapPotential = false; boolean wasSpaceAfter = false; for (int i = 0; i < structure.size(); i++) { Token token = structure.get(i); if (token.getLineBreaksBefore() > 0 || token.getLineBreaksAfter() > 0) { assert !noWrap; // comment already wrapped return -1; } if (!wasSpaceAfter && token.isSpaceBefore()) position++; position += this.tm.getLength(token, position); wasSpaceAfter = token.isSpaceAfter(); if (wasSpaceAfter) position++; WrapPolicy policy = token.getWrapPolicy(); if (i > 1 && (policy == null || policy == WrapPolicy.SUBSTITUTE_ONLY)) hasWrapPotential = true; } if (position <= this.lineLimit || noWrap || !hasWrapPotential) return position; return -1; }
private int findCommentLineIndent(int commentFragmentIndex) { int position = this.ctm.get(commentFragmentIndex).originalStart; int lastNonWhitespace = position; while (--position > 0) { char c = this.ctm.charAt(position); if (c == '\r' || c == '\n') break; if (!ScannerHelper.isWhitespace(c)) lastNonWhitespace = position; } if (lastNonWhitespace > 0 && this.ctm.charAt(lastNonWhitespace - 1) == ' ') lastNonWhitespace--; return this.ctm.getLength(position, lastNonWhitespace - 1, 0); }
private int findCommentLineIndent(int commentFragmentIndex) { int position = this.ctm.get(commentFragmentIndex).originalStart; int lastNonWhitespace = position; while (--position > 0) { char c = this.ctm.charAt(position); if (c == '\r' || c == '\n') break; if (!ScannerHelper.isWhitespace(c)) lastNonWhitespace = position; } if (lastNonWhitespace > 0 && this.ctm.charAt(lastNonWhitespace - 1) == ' ') lastNonWhitespace--; return this.ctm.getLength(position, lastNonWhitespace - 1, 0); }
@Override protected boolean token(Token token, int index) { if (index == this.stoppingIndex) return false; if (getLineBreaksBefore() > 0) this.counter = Aligner.this.tm.getPositionInLine(index); if (token.getAlign() > 0) this.counter = token.getAlign(); this.counter += Aligner.this.tm.getLength(token, this.counter); if (isSpaceAfter() && getLineBreaksAfter() == 0) this.counter++; this.maxPosition = Math.max(this.maxPosition, this.counter); return true; }
@Override protected boolean token(Token token, int index) { if (index == this.stoppingIndex) return false; if (getLineBreaksBefore() > 0) this.counter = FieldAligner.this.tm.getPositionInLine(index); if (token.getAlign() > 0) this.counter = token.getAlign(); this.counter += FieldAligner.this.tm.getLength(token, this.counter); if (isSpaceAfter() && getLineBreaksAfter() == 0) this.counter++; this.maxPosition = Math.max(this.maxPosition, this.counter); return true; }
@Override protected boolean token(Token token, int index) { if (index == this.stoppingIndex) return false; if (getLineBreaksBefore() > 0) this.counter = FieldAligner.this.tm.getPositionInLine(index); if (token.getAlign() > 0) this.counter = token.getAlign(); this.counter += FieldAligner.this.tm.getLength(token, this.counter); if (isSpaceAfter() && getLineBreaksAfter() == 0) this.counter++; this.maxPosition = Math.max(this.maxPosition, 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; } };
@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 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); } } } }
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); } }
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); } }
int getWrapIndent(Token token) { WrapPolicy policy = token.getWrapPolicy(); if (policy == null) return token.getIndent(); if (this.options.never_indent_line_comments_on_first_column && token.tokenType == TokenNameCOMMENT_LINE && token.getIndent() == 0) return 0; if (this.options.never_indent_block_comments_on_first_column && token.tokenType == TokenNameCOMMENT_BLOCK && token.getIndent() == 0) 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); } }