public char[] getChars(int[] block) throws BadLocationException { return getChars(block[0], block[1] - block[0]); }
private static boolean isEscapeSequence(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos <= 0) { return false; } char previousChar = doc.getChars(dotPos - 1, 1)[0]; return previousChar == '\\'; }
private static boolean isEscapeSequence(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos <= 0) { return false; } char previousChar = doc.getChars(dotPos - 1, 1)[0]; return previousChar == '\\'; }
private boolean isEscapeSequence(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos <= 0) { return false; } char previousChar = doc.getChars(dotPos - 1, 1)[0]; return previousChar == '\\'; }
/** * @param pos position of the first character to get. * @param len number of characters to obtain. * @return array with the requested characters. */ public char[] getChars(int pos, int len) throws BadLocationException { char[] chars = new char[len]; getChars(pos, chars, 0, len); return chars; }
/** * @param block two-element array with starting and ending offset * @return array with the requested characters. */ public char[] getChars(int[] block) throws BadLocationException { return getChars(block[0], block[1] - block[0]); }
private boolean isEscapeSequence(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos <= 0) { return false; } char previousChar = doc.getChars(dotPos - 1, 1)[0]; return previousChar == '\\'; }
private boolean isEscapeSequence(BaseDocument doc, int dotPos) throws BadLocationException { if (dotPos <= 0) { return false; } char previousChar = doc.getChars(dotPos - 1, 1)[0]; return previousChar == '\\'; }
/** * Get the word at given position. */ public static String getWord(BaseDocument doc, int offset) throws BadLocationException { int wordEnd = getWordEnd(doc, offset); if (wordEnd != -1) { return new String(doc.getChars(offset, wordEnd - offset), 0, wordEnd - offset); } return null; }
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; }
/** Get the word at given position. */ public static String getWord(BaseDocument doc, int offset) throws BadLocationException { int wordEnd = getWordEnd(doc, offset); if (wordEnd != -1) { return new String(doc.getChars(offset, wordEnd - offset), 0, wordEnd - offset); } return null; }
private boolean isRhtmlStartTag(BaseDocument doc, int offset, char[] origin) throws BadLocationException { int length = doc.getText().length(); if (length < offset + 1) { return false; } if (origin[0] == '<' && length >= offset + 1 && doc.getChars(offset + 1, 1)[0] == '%') { return true; } if (origin[0] == '%' && offset - 1 > 0) { return doc.getChars(offset - 1, 1)[0] == '<'; } return false; }
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; }
/** * Checks whether dotPos is a position at which bracket and quote * completion is performed. Brackets and quotes are not completed * everywhere but just at suitable places . * @param doc the document * @param dotPos position to be tested */ private boolean isCompletablePosition(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 ' char chr = doc.getChars(dotPos, 1)[0]; return ((chr == ')') || (chr == ',') || (chr == '\"') || (chr == '\'') || (chr == ' ') || (chr == ']') || (chr == '}') || (chr == '\n') || (chr == '\t') || (chr == ';')); } }
public static String getLine(final JTextComponent component, final int offset) { final BaseDocument workingDocument = org.netbeans.editor.Utilities.getDocument(component); try { final int lineStartOffset = org.netbeans.editor.Utilities.getRowStart(workingDocument, offset); final int lineEndOffset = org.netbeans.editor.Utilities.getRowEnd(workingDocument, offset); return String.valueOf(workingDocument.getChars(lineStartOffset, lineEndOffset - lineStartOffset)); } catch (BadLocationException ble) { return ""; } }
public static String getLine(final JTextComponent component, final int offset) { final BaseDocument workingDocument=org.netbeans.editor.Utilities.getDocument(component); try { final int lineStartOffset = org.netbeans.editor.Utilities.getRowStart(workingDocument, offset); final int lineEndOffset = org.netbeans.editor.Utilities.getRowEnd(workingDocument, offset); return String.valueOf(workingDocument.getChars(lineStartOffset, lineEndOffset - lineStartOffset)); } catch (BadLocationException ble) { return ""; } } }
/** * Get the identifier before the given position (ending at given offset) or * null if there's no identifier */ public static String getIdentifierBefore(BaseDocument doc, int offset) throws BadLocationException { int wordStart = getWordStart(doc, offset); if (wordStart != -1) { String word = new String(doc.getChars(wordStart, offset - wordStart), 0, offset - wordStart); if (doc.getSyntaxSupport().isIdentifier(word)) { return word; } } return null; }
/** Get the identifier before the given position (ending at given offset) * or null if there's no identifier */ public static String getIdentifierBefore(BaseDocument doc, int offset) throws BadLocationException { int wordStart = getWordStart(doc, offset); if (wordStart != -1) { String word = new String(doc.getChars(wordStart, offset - wordStart), 0, offset - wordStart); if (doc.getSyntaxSupport().isIdentifier(word)) { return word; } } 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 == ']')); } }