/** Get first non-white character in document in backward direction. * The character right before the character at position offset will * be searched as first. * @param doc document to operate on * @param offset position in document where to start searching * @return position of the first non-white character or -1 */ public static int getFirstNonWhiteBwd(BaseDocument doc, int offset) throws BadLocationException { return getFirstNonWhiteBwd(doc, offset, 0); }
/** * Get first non-white character in document in backward direction. The * character right before the character at position offset will be searched * as first. * * @param doc * document to operate on * @param offset * position in document where to start searching * @return position of the first non-white character or -1 */ public static int getFirstNonWhiteBwd(BaseDocument doc, int offset) throws BadLocationException { return getFirstNonWhiteBwd(doc, offset, 0); }
public static int getFirstNonWhiteRow(BaseDocument doc, int offset, boolean downDir) throws BadLocationException { if (isRowWhite(doc, offset)) { if (downDir) { // search down for non-white line offset = getFirstNonWhiteFwd(doc, offset); } else { // search up for non-white line offset = getFirstNonWhiteBwd(doc, offset); } } return offset; }
public static int getFirstNonWhiteRow(BaseDocument doc, int offset, boolean downDir) throws BadLocationException { if (isRowWhite(doc, offset)) { if (downDir) { // search down for non-white line offset = getFirstNonWhiteFwd(doc, offset); } else { // search up for non-white line offset = getFirstNonWhiteBwd(doc, offset); } } return offset; }
/** * Get the last non-white character on the line. The document.isWhitespace() * is used to test whether the particular character is white space or not. * * @param doc * document to operate on * @param offset * position in document anywhere on the line * @return position of the last non-white char on the line or -1 if there's * no non-white character on that line. */ public static int getRowLastNonWhite(BaseDocument doc, int offset) throws BadLocationException { return getFirstNonWhiteBwd(doc, doc.op.getEOL(offset), doc.op.getBOL(offset)); }
/** Get the last non-white character on the line. * The document.isWhitespace() is used to test whether the particular * character is white space or not. * @param doc document to operate on * @param offset position in document anywhere on the line * @return position of the last non-white char on the line or -1 * if there's no non-white character on that line. */ public static int getRowLastNonWhite(BaseDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); Element lineElement = doc.getParagraphElement(offset); return getFirstNonWhiteBwd(doc, lineElement.getEndOffset() - 1, lineElement.getStartOffset() ); }
private int tryCountLines(Block block) throws BadLocationException { int searchOffset = block.getStartOffset() + 1; int firstNonWhiteFwd = Utilities.getFirstNonWhiteFwd(baseDocument, searchOffset); int startLineOffset = Utilities.getLineOffset(baseDocument, firstNonWhiteFwd == -1 ? searchOffset : firstNonWhiteFwd); int endLineOffset = Utilities.getLineOffset(baseDocument, Utilities.getFirstNonWhiteBwd(baseDocument, block.getEndOffset())); return countLinesBetweenLineOffsets(startLineOffset, endLineOffset); }
int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos); startPos = (startPos >= 0) ? (startPos + 1) : rsPos;
int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos); startPos = (startPos >= 0) ? (startPos + 1) : rsPos;
to = Utilities.getFirstNonWhiteBwd(doc, Utilities.getRowEnd(doc, to)) + 1; lineSelection = true; } catch (BadLocationException ex) {
public int processTextBatch(BaseDocument doc, int startPos, int endPos, boolean lastBatch) { try { int[] blks = getCommentBlocks(endPos, startPos); FinderFactory.CharArrayBwdFinder cmdFinder = new FinderFactory.CharArrayBwdFinder(COMMAND_SEPARATOR_CHARS); int lastSeparatorOffset = findOutsideBlocks(cmdFinder, startPos, endPos, blks); if (lastSeparatorOffset<1) return lastSeparatorOffset; TokenID separatorID = getTokenID(lastSeparatorOffset); if (separatorID.getNumericID() == JavaTokenContext.RBRACE_ID) { int matchingBrkPos[] = findMatchingBlock(lastSeparatorOffset, true); if (matchingBrkPos != null){ int prev = Utilities.getFirstNonWhiteBwd(getDocument(), matchingBrkPos[0]); if (getTokenID(prev).getNumericID() == JavaTokenContext.RBRACKET_ID){ return getLastCommandSeparator(prev); } } } if (separatorID.getNumericID() != JavaTokenContext.LBRACE_ID && separatorID.getNumericID() != JavaTokenContext.RBRACE_ID && separatorID.getNumericID() != JavaTokenContext.SEMICOLON_ID){ lastSeparatorOffset = processTextBatch(doc, lastSeparatorOffset, 0, lastBatch); } return lastSeparatorOffset; } catch (BadLocationException e) { e.printStackTrace(); return -1; } } };
int neOffset = Utilities.getFirstNonWhiteBwd(doc, caretOffset - 1); Indentation result = Indentation.NONE; if (neOffset != -1) {