@Override public int getElementIndex(int offset) { if (offset == 0) { // Optimization of a frequent pattern in NB sources: // LineRootElement root = styledDocument.getParagraphElement(0).getParentElement() return 0; } return super.getElementIndex(offset); }
/** Does the CppFile record need updating? */ public boolean needsUpdate(final Document doc) { final long documentTimestamp = org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentTimestamp(doc); return documentTimestamp != version; }
private boolean isIn(MutablePositionRegion region, int caretOffset) { return region.getStartOffset() <= caretOffset && caretOffset <= region.getEndOffset(); }
private static boolean isWhitespace(Document document, int startOffset, int endOffset) throws BadLocationException { CharSequence chars = DocumentUtilities.getText(document, startOffset, endOffset - startOffset); for(int i = 0; i < chars.length(); i++) { if (!Character.isWhitespace(chars.charAt(i))) { return false; } } return true; }
/** * Gets the mime type of a document. If the mime type can't be determined * this method will return <code>null</code>. This method should work reliably * for Netbeans documents that have their mime type stored in a special * property. For any other documents it will probably just return <code>null</code>. * * @param doc The document to get the mime type for. * * @return The mime type of the document or <code>null</code>. * @see NbEditorDocument#MIME_TYPE_PROP */ public static String getMimeType(Document doc) { return DocumentUtilities.getMimeType(doc); }
public int getFirstRegionStartOffset() { return getRegion(0).getStartOffset(); }
public int getFirstRegionEndOffset() { return getRegion(0).getEndOffset(); }
@Override public Element getElement(int index) { if (index < 0) { throw new IndexOutOfBoundsException("Invalid line index=" + index + " < 0"); // NOI18N } int elementCount = getElementCount(); if (index >= elementCount) { throw new IndexOutOfBoundsException("Invalid line index=" + index // NOI18N + " >= lineCount=" + elementCount); // NOI18N } return super.getElement(index); }
public ModRootElement(Document doc) { super(doc); docText = DocumentUtilities.getText(doc); doc.putProperty(NAME, this); }
protected void init(Document doc){ String mimeType = DocumentUtilities.getMimeType(doc); CsmFontColorManager.instance().addListener(mimeType, this); }
private boolean isIn(MutablePositionRegion region, int caretOffset) { return region.getStartOffset() <= caretOffset && caretOffset <= region.getEndOffset(); }
private boolean resetLastModified() { final long documentTimestamp = org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentTimestamp(doc); if (documentTimestamp != lastModified) { lastModified = documentTimestamp; clearLineCache(); return true; } return false; }
public int getFirstRegionStartOffset() { return getRegion(0).getStartOffset(); }
public int getFirstRegionEndOffset() { return getRegion(0).getEndOffset(); }
@Override public int getIdentifierEnd(Document doc, int offset, boolean backward) { DocumentCharacterAcceptor characterAcceptor = DocumentCharacterAcceptor.get(doc); CharSequence docText = DocumentUtilities.getText(doc); if (backward) { while (--offset >= 0 && characterAcceptor.isIdentifier(docText.charAt(offset))) { } return offset + 1; } else { int docTextLen = docText.length(); while (offset < docTextLen && characterAcceptor.isIdentifier(docText.charAt(offset))) { offset++; } return offset; } }
@Override public void run() { try { version = org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentTimestamp(doc); final int length = doc.getLength(); char[] buf = new char[length]; DocumentUtilities.copyText(doc, 0, length, buf, 0); res[0] = buf; } catch( BadLocationException e ) { res[1] = e; } } });
private boolean isInComment(Document doc, int offset) { CharSequence text = DocumentUtilities.getText(doc); //shared instance, low cost int lastCommentStartIndex = CharSequenceUtilities.lastIndexOf(text, commentHandler.getCommentStartDelimiter(), offset); int lastCommentEndIndex = CharSequenceUtilities.lastIndexOf(text, commentHandler.getCommentEndDelimiter(), offset); return lastCommentStartIndex > -1 && (lastCommentStartIndex > lastCommentEndIndex || lastCommentEndIndex == -1); }
public static int getWordStart(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getWordStart(docText, classifier, offset); }
public static int getNextWordStart(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getNextWordStart(docText, classifier, offset); }
public static int getWordEnd(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getWordEnd(docText, classifier, offset); }