本文整理汇总了Java中org.openide.text.Line类的典型用法代码示例。如果您正苦于以下问题:Java Line类的具体用法?Java Line怎么用?Java Line使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Line类属于org.openide.text包,在下文中一共展示了Line类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareLine
import org.openide.text.Line; //导入依赖的package包/类
private void prepareLine() {
if (dobj == null || !dobj.isValid()) {
lineObj = null;
} else if (lineObj == null) { // try to get Line from DataObject
LineCookie lineCookie = dobj.getLookup().lookup(LineCookie.class);
if (lineCookie != null) {
Line.Set lineSet = lineCookie.getLineSet();
try {
lineObj = lineSet.getOriginal(line - 1);
} catch (IndexOutOfBoundsException ioobex) {
// The line doesn't exist - go to the last line
lineObj = lineSet.getOriginal(findMaxLine(lineSet));
column = markLength = 0;
}
}
}
}
示例2: openDocument
import org.openide.text.Line; //导入依赖的package包/类
@Override
@NbBundle.Messages({"LBL_OpenDocument=Open Document",
"# {0} - to be opened documents path", "MSG_CannotOpen=Could not open document with path\n {0}",
"# {0} - to be found documents path", "MSG_CannotFind=Could not find document with path\n {0}"})
public void openDocument(final String path, final int offset) {
final FileObject fo = findFile(path);
if ( fo != null ) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
DataObject od = DataObject.find(fo);
boolean ret = NbDocument.openDocument(od, offset, -1, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
if(!ret) {
notifyError(Bundle.LBL_OpenDocument(), Bundle.MSG_CannotOpen(path));
}
} catch (DataObjectNotFoundException e) {
IDEServicesImpl.LOG.log(Level.SEVERE, null, e);
}
}
});
} else {
notifyError(Bundle.LBL_OpenDocument(), Bundle.MSG_CannotFind(path));
}
}
示例3: isValidLocation
import org.openide.text.Line; //导入依赖的package包/类
public static boolean isValidLocation(CodeProfilingPoint.Location location) {
// Fail if location not in method
String methodName = Utils.getMethodName(location);
if (methodName == null) return false;
// Succeed if location in method body
if (location.isLineStart()) return true;
else if (location.isLineEnd()) {
CodeProfilingPoint.Location startLocation = new CodeProfilingPoint.Location(
location.getFile(), location.getLine(), CodeProfilingPoint.Location.OFFSET_START);
if (methodName.equals(Utils.getMethodName(startLocation))) return true;
}
Line line = getEditorLine(location);
if (line == null) return false;
// #211135, line.getText() returns null for closed documents
String lineText = line.getText();
if (lineText == null) return false;
// Fail if location immediately after method declaration - JUST A BEST GUESS!
lineText = lineText.trim();
if (lineText.endsWith("{") && lineText.indexOf('{') == lineText.lastIndexOf('{')) return false; // NOI18N
return true;
}
示例4: openFileAtOffset
import org.openide.text.Line; //导入依赖的package包/类
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;
}
示例5: create
import org.openide.text.Line; //导入依赖的package包/类
public static List<Task> create(TextlintJsonResult[] results, FileObject fileObject) {
List<Task> tasks = new ArrayList<>();
final DataObject dataObject = getDataObject(fileObject);
if (results != null && dataObject != null) {
Line.Set lineSet = getLineSet(dataObject);
if (lineSet != null) {
for (TextlintJsonResult result : results) {
result.getMessages().forEach((message) -> {
Line line = getCurrentLine(lineSet, message.getLine());
OpenAction defaultAction = line != null ? new OpenAction(line) : null;
Action[] popupActions = createPopupActions(dataObject, fileObject, message.getFix());
String description = String.format(MESSAGE_FORMAT,
message.getRuleId(),
message.getMessage(),
message.getLine(),
message.getIndex());
String groupName = message.getFix() != null ? TEXTLINT_FIXABLE_GROUP_NAME : TEXTLINT_GROUP_NAME;
tasks.add(Task.create(fileObject.toURL(), groupName, description, defaultAction, popupActions));
});
}
}
}
return tasks;
}
示例6: annotate
import org.openide.text.Line; //导入依赖的package包/类
private void annotate(final CodeProfilingPoint profilingPoint, final CodeProfilingPoint.Annotation[] annotations) {
ProfilerUtils.runInProfilerRequestProcessor(new Runnable() {
public void run() {
for (CodeProfilingPoint.Annotation cppa : annotations) {
// --- Code for saving dirty profiling points on document save instead of IDE closing ----------------
// DataObject dataObject = Utils.getDataObject(profilingPoint.getLocation(cppa));
// if (dataObject != null) dataObject.addPropertyChangeListener(ProfilingPointsManager.this);
// ---------------------------------------------------------------------------------------------------
Line editorLine = Utils.getEditorLine(profilingPoint, cppa);
if (editorLine != null) {
editorLine.addPropertyChangeListener(ProfilingPointsManager.getDefault());
cppa.attach(editorLine);
}
}
}
});
}
示例7: openErrorDescription
import org.openide.text.Line; //导入依赖的package包/类
@Messages("ERR_CannotOpen=Cannot open target file")
static void openErrorDescription(AnalyzerFactory analyzer, ErrorDescription ed) throws IndexOutOfBoundsException {
try {
DataObject od = DataObject.find(ed.getFile());
LineCookie lc = od.getLookup().lookup(LineCookie.class);
if (lc != null) {
Line line = lc.getLineSet().getCurrent(ed.getRange().getBegin().getLine());
line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
analyzer.warningOpened(ed);
}
} catch (IOException ex) {
Exceptions.printStackTrace(Exceptions.attachLocalizedMessage(Exceptions.attachSeverity(ex, Level.WARNING), Bundle.ERR_CannotOpen()));
}
}
示例8: openAtSource
import org.openide.text.Line; //导入依赖的package包/类
/**
* Opens a pom file at location defined in InputLocation parameter
* @since 2.77
* @param location
*/
public static void openAtSource(InputLocation location) {
InputSource source = location.getSource();
if (source != null && source.getLocation() != null) {
FileObject fobj = FileUtilities.convertStringToFileObject(source.getLocation());
if (fobj != null) {
try {
DataObject dobj = DataObject.find(NodeUtils.readOnlyLocalRepositoryFile(fobj));
EditCookie edit = dobj.getLookup().lookup(EditCookie.class);
if (edit != null) {
edit.edit();
}
LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
lc.getLineSet().getOriginal(location.getLineNumber() - 1).show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS, location.getColumnNumber() - 1);
} catch (DataObjectNotFoundException ex) {
LOG.log(Level.FINE, "dataobject not found", ex);
}
}
}
}
示例9: startDebugger
import org.openide.text.Line; //导入依赖的package包/类
/** Starts the debugger. The method stops the current debugging (if any)
* and takes information from the provided info (containing the class to start and
* arguments to pass it and name of class to stop debugging in) and starts
* new debugging session.
*
* @param info debugger info about class to start
* @exception DebuggerException if an error occures during the start of the debugger
*/
public void startDebugger (DebuggerInfo info) throws DebuggerException {
boolean stopOnMain = info.getStopClassName () != null;
super.startDebugger (info);
setState (Debugger.DEBUGGER_RUNNING);
String stopClassName = info.getClassName ();
Line l = Utils.getLine (stopClassName, 1);
stack = new Stack ();
stack.push (l);
isOnStack = new HashSet ();
isOnStack.add (l.getDataObject ());
// stop on main
if (stopOnMain) {
setState (DEBUGGER_STOPPED);
setCurrentLine (l);
refreshWatches ();
} else
go ();
}
示例10: getLine
import org.openide.text.Line; //导入依赖的package包/类
/** Get the line object from the given position.
* @param doc document for which the line is being retrieved
* @param offset position in the document
* @param original whether to retrieve the original line (true) before
* the modifications were done or the current line (false)
* @return the line object
*/
public static Line getLine(Document doc, int offset, boolean original) {
DataObject dob = getDataObject(doc);
if (dob != null) {
LineCookie lc = (LineCookie)dob.getCookie(LineCookie.class);
if (lc != null) {
Line.Set lineSet = lc.getLineSet();
if (lineSet != null) {
Element lineRoot = (doc instanceof AbstractDocument)
? ((AbstractDocument)doc).getParagraphElement(0).getParentElement()
: doc.getDefaultRootElement();
int lineIndex = lineRoot.getElementIndex(offset);
return original
? lineSet.getOriginal(lineIndex)
: lineSet.getCurrent(lineIndex);
}
}
}
return null;
}
示例11: traceOver
import org.openide.text.Line; //导入依赖的package包/类
/**
* Trace over.
*/
synchronized public void traceOver () throws DebuggerException {
setState (DEBUGGER_RUNNING);
Stack stack = getStack ();
int d = stack.size ();
Line l = null;
do {
l = step ();
if (l == null) {
finishDebugger ();
refreshWatches ();
return;
}
} while (stack.size () > d);
setCurrentLine (l);
setState (DEBUGGER_STOPPED);
setLastAction (ACTION_TRACE_OVER);
refreshWatches ();
}
示例12: getLineSet
import org.openide.text.Line; //导入依赖的package包/类
Line.Set getLineSet (String url, Object timeStamp) {
DataObject dataObject = getDataObject (url);
if (dataObject == null) {
return null;
}
if (timeStamp != null) {
// get original
synchronized (this) {
Registry registry = timeStampToRegistry.get (timeStamp);
if (registry != null) {
Line.Set ls = registry.getLineSet (dataObject);
if (ls != null) {
return ls;
}
}
}
}
// get current
LineCookie lineCookie = dataObject.getLookup().lookup(LineCookie.class);
if (lineCookie == null) {
return null;
}
return lineCookie.getLineSet ();
}
示例13: showSourceLine
import org.openide.text.Line; //导入依赖的package包/类
static Line showSourceLine (String url, int lineNumber, Object timeStamp) {
Line l = LineTranslations.getTranslations().getLine (url, lineNumber, timeStamp); // false = use original ln
if (l == null) {
ErrorManager.getDefault().log(ErrorManager.WARNING,
"Show Source: Have no line for URL = "+url+", line number = "+lineNumber);
return null;
}
Properties p = Properties.getDefault().getProperties("debugger.options.JPDA");
boolean reuseEditorTabs = p.getBoolean("ReuseEditorTabs", true);
if ("true".equalsIgnoreCase(fronting)) {
if (reuseEditorTabs) {
l.show (ShowOpenType.REUSE, ShowVisibilityType.FOCUS);
} else {
l.show (ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
}
l.show (ShowOpenType.OPEN, ShowVisibilityType.FRONT); //FIX 47825
} else {
if (reuseEditorTabs) {
l.show (ShowOpenType.REUSE, ShowVisibilityType.FOCUS);
} else {
l.show (ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
}
}
return l;
}
示例14: addPositionToJumpList
import org.openide.text.Line; //导入依赖的package包/类
/** 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);
}
}
}
}
示例15: doAction
import org.openide.text.Line; //导入依赖的package包/类
/**
* Called when the action is called (action button is pressed).
*
* @param action an action which has been called
*/
@Override
public void doAction (Object action) {
Line line = getCurrentLine ();
if (line == null) return ;
Breakpoint[] breakpoints = DebuggerManager.getDebuggerManager ().
getBreakpoints ();
int i, k = breakpoints.length;
for (i = 0; i < k; i++)
if ( breakpoints [i] instanceof AntBreakpoint &&
((AntBreakpoint) breakpoints [i]).getLine ().equals (line)
) {
DebuggerManager.getDebuggerManager ().removeBreakpoint
(breakpoints [i]);
break;
}
if (i == k)
DebuggerManager.getDebuggerManager ().addBreakpoint (
new AntBreakpoint (line)
);
//S ystem.out.println("toggle");
}