/** Checks whether the tested position is after some other position. */ public boolean isAfter(FormatTokenPosition testedPosition, FormatTokenPosition afterPosition) { if (testedPosition.getToken() == afterPosition.getToken()) { return (testedPosition.getOffset() > afterPosition.getOffset()); } else { // different tokens return isAfter(testedPosition.getToken(), afterPosition.getToken()); } }
public boolean isMultiLineComment(FormatTokenPosition pos) { TokenItem token = pos.getToken(); return (token == null) ? false : isMultiLineComment(token); }
/** Checks whether the tested position is after some other position. */ public boolean isAfter(FormatTokenPosition testedPosition, FormatTokenPosition afterPosition) { if (testedPosition.getToken() == afterPosition.getToken()) { return (testedPosition.getOffset() > afterPosition.getOffset()); } else { // different tokens return isAfter(testedPosition.getToken(), afterPosition.getToken()); } }
public boolean isMultiLineComment(FormatTokenPosition pos) { TokenItem token = pos.getToken(); return (token == null) ? false : isMultiLineComment(token); }
public boolean isNewLine(FormatTokenPosition pos) { return (pos.getToken() != null) && getChar(pos) == '\n'; }
public boolean isNewLine(FormatTokenPosition pos) { return (pos.getToken() != null) && getChar(pos) == '\n'; }
/** Find the first token in the chain. It should be used only when necessary * and possibly in situations when the start of the chain * was already reached by other methods, because this method * will extend the chain till the begining of the document. * @param token token from which the search for previous tokens will * start. It can be null in which case the last document token or last * token are attempted instead. */ public TokenItem findFirstToken(TokenItem token) { if (token == null) { // Try textStartPosition first token = (textStartPosition != null) ? textStartPosition.getToken() : null; if (token == null) { // Try starting of the formatting position next token = formatStartPosition.getToken(); if (token == null) { token = lastToken; if (token == null) { return null; } } } } while (token.getPrevious() != null) { token = token.getPrevious(); } return token; }
public FormatTokenPosition findLineFirstNonWhitespaceAndNonLeftBrace(FormatTokenPosition pos) { // first call the findLineFirstNonWhitespace FormatTokenPosition ftp = super.findLineFirstNonWhitespace(pos); if (ftp == null) { // no line start, no WS return null; } // now checks if the first non-whitespace char is "{" // if it is, find the next non-whitespace char if (!ftp.getToken().getImage().startsWith("{")) return ftp; // if the left brace is closed on the same line - "{ foo(); }" // it must be ignored. otherwise next statement is incorrectly indented // under the "f" and not under the "{" as expected FormatTokenPosition eolp = findNextEOL(ftp); TokenItem rbmt = findMatchingToken(ftp.getToken(), eolp != null ? eolp.getToken() : null, JavaTokenContext.RBRACE, false); if (rbmt != null) return ftp; FormatTokenPosition ftp_next = getNextPosition(ftp); if (ftp_next == null) return ftp; FormatTokenPosition ftp2 = findImportant(ftp_next, null, true, false); if (ftp2 != null) return ftp2; else return ftp; }