/** Get the syntax-support class that belongs to the document of the given * component. Besides using directly this method, the <tt>SyntaxSupport</tt> * can be obtained by calling <tt>doc.getSyntaxSupport()</tt>. * The method can return null in case the document is not * an instance of the BaseDocument. * The method doesn't require any document locking. * @param target JTextComponent for which the syntax-support should be obtained * @return SyntaxSupport instance or null */ public static SyntaxSupport getSyntaxSupport(JTextComponent target) { Document doc = target.getDocument(); return (doc instanceof BaseDocument) ? ((BaseDocument)doc).getSyntaxSupport() : null; }
/** * Get the syntax-support class that belongs to the document of the given * component. Besides using directly this method, the <tt>SyntaxSupport</tt> * can be obtained by calling <tt>doc.getSyntaxSupport()</tt>. The method * can return null in case the document is not an instance of the * BaseDocument. The method doesn't require any document locking. * * @param target * JTextComponent for which the syntax-support should be obtained * @return SyntaxSupport instance or null */ public static SyntaxSupport getSyntaxSupport(JTextComponent target) { Document doc = target.getDocument(); return (doc instanceof BaseDocument) ? ((BaseDocument) doc).getSyntaxSupport() : null; }
public PropertyRefFinder(DocumentAccess docAccess, CompilationController cc, RenamedProperty renamedProperty) { this.docAccess = docAccess; BaseDocument document = (BaseDocument) docAccess.getDocument(); syntaxSupport = (XMLSyntaxSupport) document.getSyntaxSupport(); this.cc = cc; this.renamedProperty = renamedProperty; }
public JavaElementRefFinder(DocumentAccess docAccess) { this.docAccess = docAccess; BaseDocument document = (BaseDocument)docAccess.getDocument(); syntaxSupport = document.getSyntaxSupport(); }
DocumentContext(Document document) { this.document = document; try { this.syntaxSupport = (XMLSyntaxSupport) ((BaseDocument)document).getSyntaxSupport(); } catch (ClassCastException cce) { LOGGER.log(Level.FINE, cce.getMessage()); this.syntaxSupport = new XMLSyntaxSupport(((BaseDocument)document)); } }
private DocumentContext(Document document, int caretOffset) throws BadLocationException { this.document = document; this.syntaxSupport = (XMLSyntaxSupport) ((BaseDocument) document).getSyntaxSupport(); this.caretOffset = caretOffset; initialize(); }
protected abstract int[] findNextSpellSpan (SyntaxSupport ts, int offset) throws BadLocationException;
void updateSchemaLocation(Document doc, final int offset, final String namespace, final String schemaLocation) { BaseDocument baseDoc = (BaseDocument) doc; final XMLSyntaxSupport syntaxSupport = (XMLSyntaxSupport) baseDoc.getSyntaxSupport(); baseDoc.runAtomic(new Runnable() { @Override public void run() { try { SyntaxElement element = syntaxSupport.getElementChain(offset); if (element instanceof StartTag) { Attr attr = ((StartTag) element).getAttributeNode("xsi:schemaLocation"); //NOI18N if (attr != null) { String val = attr.getValue(); if (val.indexOf(namespace) == -1) { attr.setValue(val + "\n " + namespace + " " + schemaLocation); //NOI18N } } } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); }
public boolean isHyperlinkPoint(Document document, int offset) { if (!(document instanceof BaseDocument)) { return false; } BaseDocument doc = (BaseDocument) document; if (!(doc.getSyntaxSupport() instanceof XMLSyntaxSupport)) { return false; } HyperlinkEnv env = new HyperlinkEnv(document, offset); HyperlinkProcessor processor = locateProcessor(env); return processor != 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; }
public CompletionContext(Document doc, int caretOffset) { this.doc = doc; this.caretOffset = caretOffset; try { this.support = (XMLSyntaxSupport) ((BaseDocument)doc).getSyntaxSupport(); } catch (ClassCastException cce) { LOGGER.log(Level.FINE, cce.getMessage()); this.support = new XMLSyntaxSupport(((BaseDocument)doc)); } this.documentContext = EditorContextFactory.getDocumentContext(doc, caretOffset); this.lastTypedChar = support.lastTypedChar(); initContext(); }
/** 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; }
/** * Execute complegtion query subtask */ private void performQuery(final JTextComponent target) { BaseDocument doc = Utilities.getDocument(target); long start = System.currentTimeMillis(); try { lastResult = getQuery().query( target, caretPos, doc.getSyntaxSupport()); } finally { trace("performQuery took " + (System.currentTimeMillis() - start) + "ms"); // NOI18N setKeyPressed(false); } }
/** * Execute complegtion query subtask */ private void performQuery(final JTextComponent target) { BaseDocument doc = Utilities.getDocument(target); long start = System.currentTimeMillis(); try { lastResult = getQuery().query( target, caretPos, doc.getSyntaxSupport()); } finally { trace("performQuery took " + (System.currentTimeMillis() - start) + "ms"); // NOI18N setKeyPressed(false); } }
/** * Checks whether class is already imported * @param cls JCClass **/ protected boolean isAlreadyImported(JCClass cls){ BaseDocument doc = Utilities.getDocument(target); if (doc == null) return false; JavaSyntaxSupport sup = (JavaSyntaxSupport)doc.getSyntaxSupport().get(JavaSyntaxSupport.class); if (sup == null) return false; sup.refreshJavaImport(); return sup.isImported(cls); }
/** Get the identifier around the given position or null if there's no identifier * around the given position. The identifier must be * accepted by SyntaxSupport.isIdnetifier() otherwise null is returned. * @param doc document to work on * @param offset position in document - usually the caret.getDot() * @return the block (starting and ending position) enclosing the identifier * or null if no identifier was found */ public static int[] getIdentifierBlock(BaseDocument doc, int offset) throws BadLocationException { int[] ret = null; int idStart = getWordStart(doc, offset); if (idStart >= 0) { int idEnd = getWordEnd(doc, idStart); if (idEnd >= 0) { String id = doc.getText(idStart, idEnd - idStart); if (doc.getSyntaxSupport().isIdentifier(id)) { ret = new int[] { idStart, idEnd }; } else { // not identifier by syntax support id = getWord(doc, offset); // try right at offset if (doc.getSyntaxSupport().isIdentifier(id)) { ret = new int[] { offset, offset + id.length() }; } } } } return ret; }
public boolean gotoDeclaration(JTextComponent target) { try { Caret caret = target.getCaret(); int dotPos = caret.getDot(); BaseDocument doc = (BaseDocument) target.getDocument(); int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos); ExtSyntaxSupport extSup = (ExtSyntaxSupport) doc.getSyntaxSupport(); if (idBlk != null) { int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]); if (decPos >= 0) { caret.setDot(decPos); return true; } } } catch (BadLocationException e) { } return false; }
public boolean gotoDeclaration(JTextComponent target) { try { Caret caret = target.getCaret(); int dotPos = caret.getDot(); BaseDocument doc = (BaseDocument)target.getDocument(); int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos); ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport(); if (idBlk != null) { int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]); if (decPos >= 0) { caret.setDot(decPos); return true; } } } catch (BadLocationException e) { } return false; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int dotPos = caret.getDot(); ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport(); if (dotPos > 0) { int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false); if (matchBlk != null) { if (select) { caret.moveDot(matchBlk[1]); } else { caret.setDot(matchBlk[1]); } } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int dotPos = caret.getDot(); ExtSyntaxSupport sup = (ExtSyntaxSupport) doc.getSyntaxSupport(); if (dotPos > 0) { int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false); if (matchBlk != null) { if (select) { caret.moveDot(matchBlk[1]); } else { caret.setDot(matchBlk[1]); } } } } catch (BadLocationException e) { target.getToolkit().beep(); } } } }