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; }
private String getEscapedTokenString(Token token) { if (token.getLineBreaksBefore() > 0 && charAt(token.originalStart) == '@') { return "@" + this.source.substring(token.originalStart + 1, token.originalEnd + 1); //$NON-NLS-1$ } else if (token.tokenType == TokenNameNotAToken) { String text = token.toString(this.source); Matcher matcher = COMMENT_LINE_ANNOTATION_PATTERN.matcher(text); if (matcher.find()) { return matcher.group(1) + "@" + text.substring(matcher.end(2)); //$NON-NLS-1$ } } return token.toString(this.source); }
private String getEscapedTokenString(Token token) { if (token.getLineBreaksBefore() > 0 && charAt(token.originalStart) == '@') { return "@" + this.source.substring(token.originalStart + 1, token.originalEnd + 1); //$NON-NLS-1$ } else if (token.tokenType == TokenNameNotAToken) { String text = token.toString(this.source); Matcher matcher = COMMENT_LINE_ANNOTATION_PATTERN.matcher(text); if (matcher.find()) { return matcher.group(1) + "@" + text.substring(matcher.end(2)); //$NON-NLS-1$ } } return token.toString(this.source); }
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 String getEscapedTokenString(Token token) { if (token.getLineBreaksBefore() > 0 && charAt(token.originalStart) == '@') { return "@" + this.source.substring(token.originalStart + 1, token.originalEnd + 1); //$NON-NLS-1$ } else if (token.tokenType == TokenNameNotAToken) { String text = token.toString(this.source); Matcher matcher = COMMENT_LINE_ANNOTATION_PATTERN.matcher(text); if (matcher.find()) { return matcher.group(1) + "@" + text.substring(matcher.end(2)); //$NON-NLS-1$ } } return token.toString(this.source); }
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); }
/** * @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 void handleReference(ASTNode node) { ASTNode parent = node.getParent(); if ((parent instanceof TagElement) && ((TagElement) parent).isNested()) { int firstIndex = tokenStartingAt(node.getStartPosition()); int lastIndex = tokenEndingAt(node.getStartPosition() + node.getLength() - 1); if (this.ctm.charAt(this.ctm.get(lastIndex + 1).originalStart) == '}') lastIndex++; for (int i = firstIndex; i <= lastIndex; i++) { Token token = this.ctm.get(i); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); } } }
private void handleReference(ASTNode node) { ASTNode parent = node.getParent(); if ((parent instanceof TagElement) && ((TagElement) parent).isNested()) { int firstIndex = tokenStartingAt(node.getStartPosition()); int lastIndex = tokenEndingAt(node.getStartPosition() + node.getLength() - 1); if (this.ctm.charAt(this.ctm.get(lastIndex + 1).originalStart) == '}') lastIndex++; for (int i = firstIndex; i <= lastIndex; i++) { Token token = this.ctm.get(i); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); } } }
private void handleReference(ASTNode node) { ASTNode parent = node.getParent(); if ((parent instanceof TagElement) && ((TagElement) parent).isNested()) { int firstIndex = tokenStartingAt(node.getStartPosition()); int lastIndex = tokenEndingAt(node.getStartPosition() + node.getLength() - 1); if (this.ctm.charAt(this.ctm.get(lastIndex + 1).originalStart) == '}') lastIndex++; for (int i = firstIndex; i <= lastIndex; i++) { Token token = this.ctm.get(i); token.setWrapPolicy(WrapPolicy.DISABLE_WRAP); } } }
@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; } });
private void addSubstituteWraps() { int commentStart = this.ctm.get(0).originalStart; for (int i = 1; i < this.ctm.size() - 1; i++) { Token token = this.ctm.get(i); boolean touchesPrevious = token.originalStart == this.ctm.get(i - 1).originalEnd + 1; if (touchesPrevious && token.getWrapPolicy() == null && token.getLineBreaksBefore() == 0) { boolean allowWrap = this.allowSubstituteWrapping[token.originalStart - commentStart]; token.setWrapPolicy(allowWrap ? WrapPolicy.SUBSTITUTE_ONLY : WrapPolicy.DISABLE_WRAP); } for (int pos = token.originalStart + 1; pos < token.originalEnd; pos++) { if (!this.allowSubstituteWrapping[pos - commentStart]) continue; char c = this.ctm.charAt(pos); if (!ScannerHelper.isJavaIdentifierPart(c)) { this.ctm.get(tokenStartingAt(pos)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); this.ctm.get(tokenStartingAt(pos + 1)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } } } }
private void addSubstituteWraps() { int commentStart = this.ctm.get(0).originalStart; for (int i = 1; i < this.ctm.size() - 1; i++) { Token token = this.ctm.get(i); boolean touchesPrevious = token.originalStart == this.ctm.get(i - 1).originalEnd + 1; if (touchesPrevious && token.getWrapPolicy() == null && token.getLineBreaksBefore() == 0) { boolean allowWrap = this.allowSubstituteWrapping[token.originalStart - commentStart]; token.setWrapPolicy(allowWrap ? WrapPolicy.SUBSTITUTE_ONLY : WrapPolicy.DISABLE_WRAP); } for (int pos = token.originalStart + 1; pos < token.originalEnd; pos++) { if (!this.allowSubstituteWrapping[pos - commentStart]) continue; char c = this.ctm.charAt(pos); if (!ScannerHelper.isJavaIdentifierPart(c)) { this.ctm.get(tokenStartingAt(pos)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); this.ctm.get(tokenStartingAt(pos + 1)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } } } }
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); } }
private void addSubstituteWraps() { Token previous = this.ctm.get(0); int commentStart = previous.originalStart; for (int i = 1; i < this.ctm.size() - 1; i++) { Token token = this.ctm.get(i); boolean touchesPrevious = token.originalStart == this.ctm.get(i - 1).originalEnd + 1; if (touchesPrevious && token.getLineBreaksBefore() == 0 && previous.getLineBreaksAfter() == 0 && token.getWrapPolicy() == null) { boolean allowWrap = this.allowSubstituteWrapping[token.originalStart - commentStart]; token.setWrapPolicy(allowWrap ? WrapPolicy.SUBSTITUTE_ONLY : WrapPolicy.DISABLE_WRAP); } for (int pos = token.originalStart + 1; pos < token.originalEnd; pos++) { if (!this.allowSubstituteWrapping[pos - commentStart]) continue; char c = this.ctm.charAt(pos); if (!ScannerHelper.isJavaIdentifierPart(c)) { this.ctm.get(tokenStartingAt(pos)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); this.ctm.get(tokenStartingAt(pos + 1)).setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } } previous = token; } }