/** Runs the runnable under read lock. */ public void render(Runnable r) { readLock(); try { r.run(); } finally { readUnlock(); } }
public Indentation count(int caretOffset) { Indentation result = Indentation.NONE; doc.readLock(); try { result = countUnderReadLock(caretOffset); } finally { doc.readUnlock(); } return result; }
/** Runs the runnable under read lock. */ public void render(Runnable r) { readLock(); assert incrementThreadLocalLockDepth(); try { r.run(); } finally { assert decrementThreadLocalLockDepth(); readUnlock(); } }
private boolean copyDocument(final BaseDocument src, final BaseDocument dest) { final boolean[] retVal = new boolean[]{true}; src.readLock(); try{ dest.runAtomic(new Runnable() { @Override public void run() { try { String docText = src.getText(0, src.getLength()); dest.insertString(0, docText, null); } catch(BadLocationException ble) { Exceptions.printStackTrace(ble); retVal[0] = false; } } }); } finally { src.readUnlock(); } return retVal[0]; }
/** Find the Groovy token sequence (in case it's embedded in something else at the top level. */ @SuppressWarnings("unchecked") public static TokenSequence<GroovyTokenId> getGroovyTokenSequence(Document doc, int offset) { final BaseDocument baseDocument = (BaseDocument) doc; try { baseDocument.readLock(); return getGroovyTokenSequence(TokenHierarchy.get(doc), offset); } finally { baseDocument.readUnlock(); } }
public HyperlinkEnv(Document document, int offset) { this.baseDocument = (BaseDocument) document; this.fileObject = NbEditorUtilities.getFileObject(baseDocument); this.offset = offset; baseDocument.readLock(); try { initialize(); } finally { baseDocument.readUnlock(); } }
private String getPosition(TokenItem<TokenId> offset, CsmFile file) { BaseDocument document = CsmReferenceRepository.getDocument(file); StringBuilder out = new StringBuilder(); out.append("offset=").append(offset.offset()); // NOI18N if (document instanceof StyledDocument) { int line = NbDocument.findLineNumber((StyledDocument) document, offset.offset()) + 1; out.append(", line=").append(line); // NOI18N int col = NbDocument.findLineColumn((StyledDocument) document, offset.offset()) + 1; out.append(", column=").append(col); // NOI18N TokenItem<TokenId> jumpToken; document.readLock(); try { jumpToken = CndTokenUtilities.getTokenCheckPrev(document, offset.offset()); } finally { document.readUnlock(); } out.append(", tok=").append(jumpToken); // NOI18N } return out.toString(); }
public void run() { JTextComponent c2 = component; if (c2 != null) { BaseDocument doc = Utilities.getDocument(c2); if (doc != null) { doc.readLock(); try { update(scrollRect, scrollPolicy); } finally { doc.readUnlock(); } } } } }
public void run() { JTextComponent c2 = component; if (c2 != null) { BaseDocument doc = Utilities.getDocument(c2); if (doc != null) { doc.readLock(); try { update(scrollRect, scrollPolicy); } finally { doc.readUnlock(); } } } } });
/** Write part of the document into specified writer. * @param writer writer into which data will be written. * @param pos from which position get the data * @param len how many characters write */ public void write(Writer writer, int pos, int len) throws IOException, BadLocationException { readLock(); try { if ((pos < 0) || ((pos + len) > getLength())) { throw new BadLocationException("BaseDocument.write()", pos); // NOI18N } Analyzer.write(this, writer, pos, len); writer.flush(); } finally { readUnlock(); } }
private List<CsmReferenceContext> getIdentifierReferences(CsmFile csmFile, final BaseDocument doc, final int start, final int end, Set<CsmReferenceKind> kinds, FileReferencesContext fileReferncesContext, Interrupter canceled) { ExpandedReferencesProcessor merp = ExpandedReferencesProcessor.create(doc, csmFile, kinds, fileReferncesContext, canceled); doc.readLock(); try { CndTokenUtilities.processTokens(merp, doc, start, end); } finally { doc.readUnlock(); } return merp.getReferences(); }
/** * Write part of the document into specified writer. * * @param writer * writer into which data will be written. * @param pos * from which position get the data * @param len * how many characters write */ public void write(Writer writer, int pos, int len) throws IOException, BadLocationException { readLock(); try { if ((pos < 0) || ((pos + len) > getLength())) { throw new BadLocationException("BaseDocument.write()", pos); // NOI18N } Analyzer.write(this, writer, pos, len); writer.flush(); } finally { readUnlock(); } }
/*package*/ static ReferenceImpl createReferenceImpl(final CsmFile file, final BaseDocument doc, final int offset) { ReferenceImpl ref = null; doc.readLock(); try { TokenItem<TokenId> token = CndTokenUtilities.getTokenCheckPrev(doc, offset); if (isSupportedToken(token)) { ref = createReferenceImpl(file, doc, offset, token, null); } } finally { doc.readUnlock(); } return ref; }
private void highlightExits( final MethodDefNode node, final Map<OffsetRange, ColoringAttributes> highlights, final Result info) { BaseDocument doc = RubyUtils.getDocument(info); if (doc == null) { return; } try { doc.readLock(); Set<Node> exits = new HashSet<Node>(); AstUtilities.findExitPoints(node, exits); for (Node exit : exits) { if (exit.isInvisible()) { continue; } highlightExitPoint(exit, highlights, info); } } finally { doc.readUnlock(); } }
/** * Causes the portion of the view responsible for the given part of the * model to be repainted. * * @param p0 * the beginning of the range >= 0 * @param p1 * the end of the range >= p0 */ public void damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias) { BaseDocument doc = Utilities.getDocument(component); if (t == component && doc != null) { doc.readLock(); try { Rectangle r = (Rectangle) rootView.modelToView(p0, p0Bias, p1, p1Bias, null); component.repaint(r.x, r.y, r.width, r.height); } catch (BadLocationException e) { } finally { doc.readUnlock(); } } }
private void doParse(FileObject fo, boolean updateTask) throws IOException { assert ExclusiveAccess.getInstance().isCurrentThreadAccess(); BaseDocument document = (BaseDocument)getEditorCookie(fo).openDocument(); document.readLock(); try { doParse(fo, document, updateTask); } finally { document.readUnlock(); } }
public void print(PrintContainer container) { readLock(); try { EditorUI editorUI = BaseKit.getKit(kitClass).createPrintEditorUI(this); DrawGraphics.PrintDG printDG = new DrawGraphics.PrintDG(container); DrawEngine.getDrawEngine().draw(printDG, editorUI, 0, getLength(), 0, 0, Integer.MAX_VALUE); } catch (BadLocationException e) { e.printStackTrace(); } finally { readUnlock(); } }
private int getOffsetWithoutLeadingWhitespaces(final int startOffset) { int result = startOffset; baseDocument.readLock(); try { TokenSequence<PHPTokenId> ts = LexUtilities.getPHPTokenSequence(baseDocument, startOffset); if (ts != null) { ts.move(startOffset); while (ts.movePrevious() && ts.token().id().equals(PHPTokenId.WHITESPACE)) { result = ts.offset(); } } } finally { baseDocument.readUnlock(); } return result; }
/** Create a new element holder representing the given node in the same context as the given existing context */ public JsElementCtx(JsElementCtx ctx, Node node) { BaseDocument doc = GsfUtilities.getDocument(ctx.getFileObject(), true); try { if (doc != null) { doc.readLock(); } Element e = AstElement.getElement(ctx.getInfo(), node); initialize(ctx.getRoot(), node, e, ctx.getFileObject(), ctx.getInfo()); } finally { if (doc != null) { doc.readUnlock(); } } }
private static int getOffsetAfterNextTokenId(BaseDocument doc, int offset, PHPTokenId tokenId) throws BadLocationException { int retval = offset; doc.readLock(); try { TokenSequence<? extends PHPTokenId> ts = LexUtilities.getPHPTokenSequence(doc, retval); if (ts != null) { ts.move(retval); while (ts.moveNext()) { Token t = ts.token(); if (t.id() == tokenId) { ts.moveNext(); retval = ts.offset(); break; } } } } finally { doc.readUnlock(); } return retval; }