public static String getJavaIdentifier(StyledDocument doc, JEditorPane ep, int offset) { String t = null; if ( (ep.getSelectionStart() <= offset) && (offset <= ep.getSelectionEnd())) { t = ep.getSelectedText(); int line = NbDocument.findLineNumber(doc, offset); int col = NbDocument.findLineColumn(doc, offset); try { javax.swing.text.Element lineElem = org.openide.text.NbDocument.findLineRootElement(doc). getElement(line); if (lineElem == null) { return null; int lineStartOffset = lineElem.getStartOffset(); int lineLen = lineElem.getEndOffset() - lineStartOffset; t = doc.getText (lineStartOffset, lineLen); int identStart = col; while (identStart > 0 &&
private static boolean openFileAtOffset(DataObject dataObject, int offset) throws IOException { EditorCookie ec = dataObject.getCookie(EditorCookie.class); LineCookie lc = dataObject.getCookie(LineCookie.class); if (ec != null && lc != null) { StyledDocument doc = ec.openDocument(); if (doc != null) { int lineNumber = NbDocument.findLineNumber(doc, offset); if (lineNumber != -1) { Line line = lc.getLineSet().getCurrent(lineNumber); if (line != null) { int lineOffset = NbDocument.findLineOffset(doc, lineNumber); int column = offset - lineOffset; line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column); return true; } } } } return false; }
public void updateUserCodesFromEditor (final StyledDocument document, final DesignDocument designDocument) { NbDocument.runAtomic (document, new Runnable() { public void run () { updateUserCodesFromEditorCore (document, designDocument); } }); }
public String getHighlightTestData() { int lineStart = NbDocument.findLineNumber((StyledDocument) doc, start); int columnStart = NbDocument.findLineColumn((StyledDocument) doc, start); int lineEnd = NbDocument.findLineNumber((StyledDocument) doc, end); int columnEnd = NbDocument.findLineColumn((StyledDocument) doc, end); return coloringsToString() + ", " + lineStart + ":" + columnStart + "-" + lineEnd + ":" + columnEnd; }
public void run() { // Part of #33165 - the following code is wrapped by doc.render() int lineNumber = getLineNumber(); int lineStart = NbDocument.findLineOffset(doc, lineNumber); // #24434: Check whether the next line exists // (the current one could be the last one). int lineEnd; if ((lineNumber + 1) >= NbDocument.findLineRootElement(doc).getElementCount()) { lineEnd = doc.getLength(); } else { lineEnd = NbDocument.findLineOffset(doc, lineNumber + 1); } try { retStringArray[0] = doc.getText(lineStart, lineEnd - lineStart); } catch (BadLocationException ex) { Logger.getLogger(DocumentLine.class.getName()).log(Level.WARNING, null, ex); retStringArray[0] = null; } // End of the code wrapped by doc.render() } }
public static boolean isScriptlet(StyledDocument doc, JEditorPane ep, int offset) { String t; int line = NbDocument.findLineNumber(doc, offset); int col = NbDocument.findLineColumn(doc, offset); try { while (line > 0) { javax.swing.text.Element lineElem = org.openide.text.NbDocument.findLineRootElement(doc).getElement(line); if (lineElem == null) { continue; int lineStartOffset = lineElem.getStartOffset(); int lineLen = lineElem.getEndOffset() - lineStartOffset; t = doc.getText (lineStartOffset, lineLen); if ((t != null) && (t.length() > 1)) { int identStart; if (line == NbDocument.findLineNumber(doc, offset)) { identStart = col; } else {
return ""; StyledDocument doc = (StyledDocument) ep.getDocument(); if (doc == null) { return ""; int offset = ep.getCaret().getDot(); String t = null; int line = NbDocument.findLineNumber( doc, offset); int col = NbDocument.findLineColumn( doc, offset); try { javax.swing.text.Element lineElem = org.openide.text.NbDocument.findLineRootElement(doc). getElement(line); int lineStartOffset = lineElem.getStartOffset(); int lineLen = lineElem.getEndOffset() - lineStartOffset; t = doc.getText(lineStartOffset, lineLen);
int line = argKind.getLine(); int col = argKind.getColumn(); Element lineRoot = NbDocument.findLineRootElement(mgr.getDoc()); p = NbDocument.createPosition( mgr.getDoc(), offset, argInsertAfter ? Position.Bias.Backward : Position.Bias.Forward ); } catch (BadLocationException e) { p = mgr.getDoc().getEndPosition(); retInt = NbDocument.findLineNumber(mgr.getDoc(), argKind.getOffset()); retInt = NbDocument.findLineColumn(mgr.getDoc(), argKind.getOffset()); retInt = NbDocument.findLineNumber(mgr.getCloneableEditorSupport().openDocument(), argInt); retInt = NbDocument.findLineColumn(mgr.getCloneableEditorSupport().openDocument(), argInt); retInt = NbDocument.findLineOffset(argDoc, argLine) + argColumn; retObject = NbDocument.createPosition( mgr.getDoc(), NbDocument.findLineOffset(mgr.getDoc(), argLine) + argColumn, argInsertAfter ? Position.Bias.Backward : Position.Bias.Forward ); } catch (BadLocationException e) { retObject = mgr.getDoc().getEndPosition(); } catch (IndexOutOfBoundsException e) { retObject = mgr.getDoc().getEndPosition();
public void run () { int definitionOffset = definition.getOffset (); try { DataObject dobj = DataObject.find (fo); EditorCookie ec = dobj.getCookie (EditorCookie.class); StyledDocument doc2 = ec.openDocument (); LineCookie lc = dobj.getCookie (LineCookie.class); Line.Set lineSet = lc.getLineSet (); Line line = lineSet.getCurrent (NbDocument.findLineNumber (doc2, definitionOffset)); int column = NbDocument.findLineColumn (doc2, definitionOffset); line.show (ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column); } catch (IOException ex) { ex.printStackTrace (); } } };
DataObject dobj = lineLookup.lookup(DataObject.class); final EditorCookie ec = dobj.getCookie(EditorCookie.class); final StyledDocument doc = ec.openDocument(); final int offset = NbDocument.findLineOffset(doc, line.getLineNumber()) + pos; if (expr == null && DebuggerOption.BALLOON_EVAL.isEnabled(NativeDebuggerManager.get().globalOptions())) { Element lineElem = NbDocument.findLineRootElement(doc). getElement(line.getLineNumber()); int lineStartOffset = lineElem.getStartOffset(); int lineLen = lineElem.getEndOffset() - lineStartOffset; expr = doc.getText(lineStartOffset, lineLen); doc.render(new Runnable() { @Override public void run() {
public void run() { // XXX: why is this not done by LineParser ? final OffsetsBag bag = new OffsetsBag(document, true); Element root = NbDocument.findLineRootElement((StyledDocument) document); int count = root.getElementCount(); try { for (int i = 0; i < count; i++) { Element elm = root.getElement(i); if (BLOCK_HEADER_PATTERN.matcher(document.getText(elm.getStartOffset(), elm.getEndOffset() - elm.getStartOffset()).trim()).find()) { bag.addHighlight(elm.getStartOffset(), elm.getEndOffset(), commandHighlight); } } } catch (BadLocationException ex) { //ignore return; } headersBag.setHighlights(bag); } });
private static int findNumLines(String url) { FileObject file; try { file = URLMapper.findFileObject (new URL(url)); } catch (MalformedURLException e) { return 0; } if (file == null) return 0; DataObject dataObject; try { dataObject = DataObject.find (file); } catch (DataObjectNotFoundException ex) { return 0; } EditorCookie ec = (EditorCookie) dataObject.getCookie(EditorCookie.class); if (ec == null) return 0; ec.prepareDocument().waitFinished(); Document d = ec.getDocument(); if (!(d instanceof StyledDocument)) return 0; StyledDocument sd = (StyledDocument) d; return NbDocument.findLineNumber(sd, sd.getLength()); }
public void run() { switch (opCode) { case FIND_LINE_NUMBER: { Element paragraphsParent = findLineRootElement (doc); retInt = paragraphsParent.getElementIndex (argInt); // argInt is offset break; } case FIND_LINE_COLUMN: { Element paragraphsParent = findLineRootElement (doc); int indx = paragraphsParent.getElementIndex (argInt); // argInt is offset retInt = argInt - paragraphsParent.getElement (indx).getStartOffset (); break; } case FIND_LINE_OFFSET: { Element paragraphsParent = findLineRootElement (doc); Element line = paragraphsParent.getElement (argInt); // argInt is lineNumber if(line == null) { throw new IndexOutOfBoundsException( "Index=" + argInt + " is out of bounds."); // NOI18N } retInt = line.getStartOffset (); break; } default: throw new IllegalStateException(); } } }
final DataObject dataObject; try { dataObject = DataObject.find(fileObject); } catch (DataObjectNotFoundException e) { getLogger().log(Level.INFO, null, e); final EditorCookie editorCookie = dataObject.getCookie(EditorCookie.class); if (editorCookie != null) { doc = editorCookie.openDocument(); } catch (IOException ex) { String msg = ex.getLocalizedMessage(); editorCookie.open(); ||(currentPos >= elementPositionBounds[1]))) { int startPos = elementPositionBounds[0]; int lineNum = NbDocument.findLineNumber(doc, startPos); if (lineNum != -1) { Line line = lineCookie.getLineSet().getCurrent(lineNum); try { int lineOffset = NbDocument.findLineOffset(doc, lineNum); int column = startPos - lineOffset;
/*package*/ static void navigateToOccurrence(boolean next) { final Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes(); // check whether current file is C/C++ DataObject dobj = activatedNodes[0].getLookup().lookup(DataObject.class); FileObject fo = (dobj == null) ? null : dobj.getPrimaryFile(); String mime = (fo == null) ? "" : fo.getMIMEType(); if (MIMENames.isHeaderOrCppOrC(mime)) { EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); Document doc = ec.getDocument(); int position = CaretAwareCsmFileTaskFactory.getLastPosition(dobj.getPrimaryFile()); int goTo = findOccurrencePosition(next, doc, position); if (goTo > 0) { JEditorPane pane = NbDocument.findRecentEditorPane(ec); pane.setCaretPosition(goTo); } else { StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(SemanticUtils.class, "cpp-no-marked-occurrence")); } } } }
DataObject od = DataObject.find(javaClass.getFileObject()); EditorCookie ec = od.getCookie(EditorCookie.class); if (ec != null && offset != -1) { StyledDocument doc = ec.getDocument(); if (doc != null) { int line = NbDocument.findLineNumber(doc, (int)offset); int col = NbDocument.findLineColumn(doc, (int)offset);
final Element lineRootElement = NbDocument.findLineRootElement(document); final Element lineElem = lineRootElement.getElement(line-1); if (lineElem != null) { final AtomicInteger prevOffset = new AtomicInteger(lineElem.getEndOffset()); document.render(new Runnable() { @Override public void run() { int prevLine = NbDocument.findLineNumber(document, prevOffset.get()); addAutos(csmFile, lineRootElement, prevLine, document, autos);
/** Add the line offset into the jump history */ private void addPositionToJumpList(String url, Line l, int column) { DataObject dataObject = getDataObject (url); if (dataObject != null) { EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class); if (ec != null) { try { StyledDocument doc = ec.openDocument(); JEditorPane[] eps = ec.getOpenedPanes(); if (eps != null && eps.length > 0) { JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column); } } catch (java.io.IOException ioex) { ErrorManager.getDefault().notify(ioex); } } } }
doc = ec.openDocument(); } catch (IOException ex) { return ; if (ep == null || ep.getDocument() != doc) { return ; final int offset = NbDocument.findLineOffset(doc, lineNo) + column; boolean[] isFunctionPtr = new boolean[] { false }; final String expression = getIdentifier (
private static int getOffset(Frame frame, StyledDocument doc) { try { int lineNumber = Integer.valueOf(frame.getLineNo()); if (lineNumber >= 0 && doc != null) { return NbDocument.findLineOffset(doc, lineNumber-1); } } catch(NumberFormatException ex) { Exceptions.printStackTrace(ex); } catch (IndexOutOfBoundsException ex) { return doc.getLength(); } return -1; } }