/** * Get first non-white character in document in forward direction * * @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 getFirstNonWhiteFwd(BaseDocument doc, int offset) throws BadLocationException { return getFirstNonWhiteFwd(doc, offset, -1); }
/** Get first non-white character in document in forward direction * @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 getFirstNonWhiteFwd(BaseDocument doc, int offset) throws BadLocationException { return getFirstNonWhiteFwd(doc, offset, -1); }
private static int[] getInstantiationBlock(BaseDocument doc, int[] identifierBlock) throws BadLocationException { if (identifierBlock != null) { int nwPos = Utilities.getFirstNonWhiteFwd(doc, identifierBlock[1]); if ((nwPos >= 0) && (doc.getChars(nwPos, 1)[0] == '<')) { return new int[] { identifierBlock[0], nwPos + 1 }; } } return null; }
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 first 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 first non-white char on the line or -1 if there's * no non-white character on that line. */ public static int getRowFirstNonWhite(BaseDocument doc, int offset) throws BadLocationException { return getFirstNonWhiteFwd(doc, doc.op.getBOL(offset), doc.op.getEOL(offset)); }
private static int[] getFunctionBlock(BaseDocument doc, int[] identifierBlock) throws BadLocationException { if (identifierBlock != null) { int nwPos = Utilities.getFirstNonWhiteFwd(doc, identifierBlock[1]); if ((nwPos >= 0) && (doc.getChars(nwPos, 1)[0] == '(')) { return new int[] { identifierBlock[0], nwPos + 1 }; } if ((nwPos >= 0) && (doc.getChars(nwPos, 1)[0] == '<')) { int eoi = findEndOfInstantiation(doc, nwPos); nwPos = Utilities.getFirstNonWhiteFwd(doc, eoi); if ((nwPos >= 0) && (doc.getChars(nwPos, 1)[0] == '(')) { return new int[] { identifierBlock[0], nwPos + 1 }; } } } return null; }
/** Is the identifier at the position a function call? * It first checks whether there is a identifier under * the cursor and then it searches for the function call * character - usually '('. * @param identifierBlock int[2] block delimiting the identifier * @return int[2] block or null if there's no function call */ public int[] getFunctionBlock(int[] identifierBlock) throws BadLocationException { if (identifierBlock != null) { int nwPos = Utilities.getFirstNonWhiteFwd(getDocument(), identifierBlock[1]); if ((nwPos >= 0) && (getDocument().getChars(nwPos, 1)[0] == '(')) { return new int[] { identifierBlock[0], nwPos + 1 }; } } return null; }
private boolean isQuoteCompletablePosition(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos == doc.getLength()) { // there's no other character to test return true; } else { // test that we are in front of ) , " or ' ... etc. int eol = Utilities.getRowEnd(doc, dotPos); if ((dotPos == eol) || (eol == -1)) { return false; } int firstNonWhiteFwd = Utilities.getFirstNonWhiteFwd(doc, dotPos, eol); if (firstNonWhiteFwd == -1) { return false; } char chr = doc.getChars(firstNonWhiteFwd, 1)[0]; return ((chr == ')') || (chr == ',') || (chr == '+') || (chr == '}') || (chr == ';') || (chr == ']')); } }
/** * Is the identifier at the position a function call? It first checks * whether there is a identifier under the cursor and then it searches for * the function call character - usually '('. * * @param identifierBlock * int[2] block delimiting the identifier * @return int[2] block or null if there's no function call */ public int[] getFunctionBlock(int[] identifierBlock) throws BadLocationException { if (identifierBlock != null) { int nwPos = Utilities.getFirstNonWhiteFwd(getDocument(), identifierBlock[1]); if ((nwPos >= 0) && (getDocument().getChars(nwPos, 1)[0] == '(')) { return new int[] { identifierBlock[0], nwPos + 1 }; } } return null; }
nonWhite = Utilities.getFirstNonWhiteFwd(doc, rowStart);
/** Get the first 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 first non-white char on the line or -1 * if there's no non-white character on that line. */ public static int getRowFirstNonWhite(BaseDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); Element lineElement = doc.getParagraphElement(offset); return getFirstNonWhiteFwd(doc, lineElement.getStartOffset(), lineElement.getEndOffset() - 1 ); }
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); }
private boolean isQuoteCompletablePosition(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos == doc.getLength()) { // there's no other character to test return true; } else { // test that we are in front of ) , " or ' ... etc. int eol = Utilities.getRowEnd(doc, dotPos); if ((dotPos == eol) || (eol == -1)) { return false; } int firstNonWhiteFwd = Utilities.getFirstNonWhiteFwd(doc, dotPos, eol); if (firstNonWhiteFwd == -1) { return false; } char chr = doc.getChars(firstNonWhiteFwd, 1)[0]; if (chr == '%' && (RubyUtils.isRhtmlDocument(doc) || RubyUtils.isYamlDocument(doc)) ) { return true; } return ((chr == ')') || (chr == ',') || (chr == '+') || (chr == '}') || (chr == ';') || (chr == ']') || (chr == '/')); } }
int first = Utilities.getFirstNonWhiteFwd(doc, textBegin+token.length(), Utilities.getRowEnd(doc, textBegin)); if (first == -1) {
public void format(FormatWriter fw) { //System.out.println("format in layer"); // NOI18N BaseDocument doc = (BaseDocument)fw.getDocument(); int dotPos = fw.getOffset(); if (doc != null && dotPos > 0) { try { int firstNonEmptyRow = 0; firstNonEmptyRow = Utilities.getFirstNonWhiteRow(doc, dotPos-1, false); if (firstNonEmptyRow == -1) return; int rstart = Utilities.getRowStart(doc, firstNonEmptyRow); int fNonWhite = Utilities.getFirstNonWhiteFwd(doc, rstart); doc.insertString(dotPos, doc.getText(rstart, fNonWhite-rstart), null); }catch(BadLocationException e) { ErrorManager.getDefault().notify(ErrorManager.WARNING, e); } } }
if (token.id() == RhtmlTokenId.HTML && doc.getText(dotPos-1, 1).charAt(0) == '<') { int first = Utilities.getFirstNonWhiteFwd(doc, dotPos, Utilities.getRowEnd(doc, dotPos)); if (first == -1) { doc.insertString(dotPos, "%%>", null); // NOI18N int first = Utilities.getFirstNonWhiteFwd(doc, dotPos, Utilities.getRowEnd(doc, dotPos)); if (first == -1) { doc.insertString(dotPos, "%%>", null); // NOI18N
from = Utilities.getFirstNonWhiteFwd(doc, Utilities.getRowStart(doc, from)); to = Utilities.getFirstNonWhiteBwd(doc, Utilities.getRowEnd(doc, to)) + 1; lineSelection = true;
boolean insert = onlyWhitespaceFollows; if (!insert) { int firstNonWhiteFwd = Utilities.getFirstNonWhiteFwd(doc, dotPos, sectionEnd); if (firstNonWhiteFwd != -1) { char chr = doc.getChars(firstNonWhiteFwd, 1)[0];
int[] block = sup.findMatchingBlock(ctx.getBufferStartOffset() + nwOffset, true); if (block != null) { int off = Utilities.getFirstNonWhiteFwd(ctx.getEditorUI().getDocument(), block[1]); if (off > -1) { if (bufferStartOffset + buffer.length > off) { int[] block = sup.findMatchingBlock(off, true); if (block != null) { off = Utilities.getFirstNonWhiteFwd(ctx.getEditorUI().getDocument(), block[1]); if (off > -1) resolvedValue = (ctx.getEditorUI().getDocument().getChars(off, 1)[0] == '(') && isGenericType(sup, off);