下面列出了com.intellij.psi.search.GlobalSearchScopes#com.intellij.xdebugger.XSourcePosition 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public XDebuggerEditorsProvider getEditorsProvider(@NotNull XLineBreakpoint<XBreakpointProperties> breakpoint, @NotNull Project project)
{
final XSourcePosition position = breakpoint.getSourcePosition();
if (position == null)
{
return null;
}
final PsiFile file = PsiManager.getInstance(project).findFile(position.getFile());
if (file == null)
{
return null;
}
return new MuleDebuggerEditorsProvider();
}
/**
* Returns the local position (to display to the user) corresponding to a token position in Observatory.
*/
@Nullable
private XSourcePosition getSourcePosition(@NotNull final String isolateId, @NotNull final String scriptId,
@NotNull final String scriptUri, int tokenPos) {
if (scriptProvider == null) {
FlutterUtils.warn(LOG, "attempted to get source position before connected to observatory");
return null;
}
final VirtualFile local = findLocalFile(scriptUri);
final ObservatoryFile.Cache cache =
fileCache.computeIfAbsent(isolateId, (id) -> new ObservatoryFile.Cache(id, scriptProvider));
final ObservatoryFile remote = cache.downloadOrGet(scriptId, local == null);
if (remote == null) return null;
return remote.createPosition(local, tokenPos);
}
@Override
public void customizePresentation(ColoredTextContainer component) {
XSourcePosition position = getSourcePosition();
component.append(myScope, SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.append(" in ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
if (position != null) {
component.append(position.getFile().getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.append(":" + position.getLine(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
else {
component.append("<file name is not available>", SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
component.setIcon(AllIcons.Debugger.StackFrame);
}
public XInspectDialog(@Nonnull Project project,
XDebuggerEditorsProvider editorsProvider,
XSourcePosition sourcePosition,
@Nonnull String name,
@Nonnull XValue value,
XValueMarkers<?, ?> markers) {
super(project, false);
setTitle(XDebuggerBundle.message("inspect.value.dialog.title", name));
setModal(false);
Pair<XValue, String> initialItem = Pair.create(value, name);
XDebuggerTreeCreator creator = new XDebuggerTreeCreator(project, editorsProvider, sourcePosition, markers);
myDebuggerTreePanel = new DebuggerTreeWithHistoryPanel<Pair<XValue, String>>(initialItem, creator, project);
init();
}
/**
* Given a token id, returns the source position to display to the user.
* <p>
* If no local file was provided, uses the snapshot if available. (However, in that
* case, breakpoints won't work.)
*/
@Nullable
XSourcePosition createPosition(@Nullable VirtualFile local, int tokenPos) {
final VirtualFile fileToUse = local == null ? snapshot : local;
if (fileToUse == null) return null;
if (positionMap == null) {
return null;
}
final Position pos = positionMap.get(tokenPos);
if (pos == null) {
return XDebuggerUtil.getInstance().createPositionByOffset(fileToUse, 0);
}
return XDebuggerUtil.getInstance().createPosition(fileToUse, pos.line, pos.column);
}
@Test
public void shouldGetPositionInFileUnderRemoteBaseUri() throws Exception {
tmp.writeFile("root/pubspec.yaml", "");
tmp.ensureDir("root/lib");
final VirtualFile main = tmp.writeFile("root/lib/main.dart", "");
final VirtualFile hello = tmp.writeFile("root/lib/hello.dart", "");
final FlutterPositionMapper mapper = setUpMapper(main, "remote:root");
scripts.addScript("1", "2", "remote:root/lib/hello.dart", ImmutableList.of(new Line(10, 123, 1)));
final XSourcePosition pos = mapper.getSourcePosition("1", makeScriptRef("2", "remote:root/lib/hello.dart"), 123);
assertNotNull(pos);
assertEquals(pos.getFile(), hello);
assertEquals(pos.getLine(), 9); // zero-based
}
@Override
public Document createDocument(
Project project,
String expression,
@Nullable XSourcePosition sourcePosition,
EvaluationMode mode) {
PsiElement context = null;
if (sourcePosition != null) {
context = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project);
}
PsiFile codeFragment =
createExpressionCodeFragment(project, expression, sourcePosition, context);
Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
assert document != null;
return document;
}
public XDebuggerTreePanel(final @Nonnull Project project,
final @Nonnull XDebuggerEditorsProvider editorsProvider,
@Nonnull Disposable parentDisposable,
final @Nullable XSourcePosition sourcePosition,
@Nonnull @NonNls final String popupActionGroupId,
@Nullable XValueMarkers<?, ?> markers) {
myTree = new XDebuggerTree(project, editorsProvider, sourcePosition, popupActionGroupId, markers);
myMainPanel = new JPanel(new BorderLayout());
myMainPanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
Disposer.register(parentDisposable, myTree);
Disposer.register(parentDisposable, myMainPanel::removeAll);
}
@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition xSourcePosition, @NotNull EvaluationMode evaluationMode)
{
final PsiFile psiFile = PsiFileFactory.getInstance(project)
.createFileFromText("muleExpr." + getFileType().getDefaultExtension(), getFileType(), text, LocalTimeCounter.currentTime(), true);
return PsiDocumentManager.getInstance(project).getDocument(psiFile);
}
@Override
public void evaluate(@NotNull String script, @NotNull final XEvaluationCallback xEvaluationCallback, @Nullable XSourcePosition xSourcePosition) {
final String melExpression = MuleConfigUtils.asMelScript(script);
session.eval(melExpression, new ScriptEvaluationCallback() {
@Override
public void onScriptEvaluationException(RemoteDebugException exception) {
xEvaluationCallback.evaluated(new ObjectFieldDefinitionValue(session, exception.getException(), AllIcons.General.Error));
}
@Override
public void onScriptEvaluation(ScriptResultInfo info) {
xEvaluationCallback.evaluated(new ObjectFieldDefinitionValue(session, info.getResult(), AllIcons.Nodes.Function));
}
});
}
@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode evaluationMode) {
final PsiFile psiFile = PsiFileFactory.getInstance(project)
.createFileFromText("MelExpr." + getFileType().getDefaultExtension(), getFileType(), text, LocalTimeCounter.currentTime(), true);
final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
assert document != null;
return document;
}
@Nonnull
public static OpenFileDescriptor createOpenFileDescriptor(@Nonnull Project project, @Nonnull XSourcePosition position) {
Navigatable navigatable = position.createNavigatable(project);
if (navigatable instanceof OpenFileDescriptor) {
return (OpenFileDescriptor)navigatable;
}
else {
return doCreateOpenFileDescriptor(project, position);
}
}
private void updateBreakpointInFile(final VirtualFile file) {
ApplicationManager.getApplication().invokeLater(() -> {
for (XBreakpointBase breakpoint : getAllBreakpoints()) {
XSourcePosition position = breakpoint.getSourcePosition();
if (position != null && Comparing.equal(position.getFile(), file)) {
fireBreakpointChanged(breakpoint);
}
}
});
}
@Nullable
protected VirtualFile getCurrentFile(@Nonnull Component component) {
XDebugSession session = getSession(component);
if (session != null) {
XSourcePosition position = session.getCurrentPosition();
if (position != null) {
return position.getFile();
}
}
return null;
}
/**
* Customize presentation of the stack frame in frames list
* @param component component
*/
public void customizePresentation(ColoredTextContainer component) {
XSourcePosition position = getSourcePosition();
if (position != null) {
component.append(position.getFile().getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.append(":" + (position.getLine() + 1), SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.setIcon(AllIcons.Debugger.StackFrame);
}
else {
component.append(XDebuggerBundle.message("invalid.frame"), SimpleTextAttributes.ERROR_ATTRIBUTES);
}
}
@Override
public XDebuggerEditorsProvider getEditorsProvider(@NotNull XLineBreakpoint<XBreakpointProperties> breakpoint, @NotNull Project project) {
final XSourcePosition position = breakpoint.getSourcePosition();
if (position == null) {
return null;
}
final PsiFile file = PsiManager.getInstance(project).findFile(position.getFile());
if (file == null) {
return null;
}
return new XQueryEditorsProvider();
}
@Nonnull
@Override
public final Document createDocument(@Nonnull Project project, @Nonnull String text, @Nullable XSourcePosition sourcePosition, @Nonnull EvaluationMode mode) {
PsiElement context = null;
if (sourcePosition != null) {
context = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project);
}
PsiFile codeFragment = createExpressionCodeFragment(project, text, context, true);
Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
assert document != null;
return document;
}
@Nonnull
@Override
public Document createDocument(@Nonnull Project project,
@Nonnull XExpression expression,
@javax.annotation.Nullable XSourcePosition sourcePosition,
@Nonnull EvaluationMode mode) {
PsiElement context = null;
if (sourcePosition != null) {
context = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project);
}
return createDocument(project, expression, context, mode);
}
@Nonnull
public Document createDocument(@Nonnull Project project,
@Nonnull XExpression expression,
@Nullable XSourcePosition sourcePosition,
@Nonnull EvaluationMode mode) {
return createDocument(project, expression.getExpression(), sourcePosition, mode);
}
@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text,
@Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode mode) {
final PsiFile psiFile = PsiFileFactory.getInstance(project)
.createFileFromText("XQueryExpr." + fileType.getDefaultExtension(), fileType, text,
LocalTimeCounter.currentTime(), true);
final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
assert document != null;
return document;
}
@Override
public void customizePresentation(@NotNull ColoredTextContainer component) {
XSourcePosition position = this.getSourcePosition();
if(position != null) {
component.append(where != null && !"".equals(where) ? where + "()" : "<main>()", SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.append(":" + (lineNumber) +", ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.append(position.getFile().getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
component.append("(" + position.getFile().getPath() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
component.setIcon(AllIcons.Debugger.StackFrame);
} else {
component.append(XDebuggerBundle.message("invalid.frame", new Object[0]), SimpleTextAttributes.ERROR_ATTRIBUTES);
}
}
@Override
protected void perform(@Nonnull XDebugSession session, DataContext dataContext) {
XSmartStepIntoHandler<?> handler = session.getDebugProcess().getSmartStepIntoHandler();
XSourcePosition position = session.getTopFramePosition();
if (position == null || handler == null) return;
FileEditor editor = FileEditorManager.getInstance(session.getProject()).getSelectedEditor(position.getFile());
if (editor instanceof TextEditor) {
doSmartStepInto(handler, position, session, ((TextEditor)editor).getEditor());
}
}
private static void reportSourcePosition(@NotNull final DartVmServiceDebugProcess debugProcess,
@NotNull final XNavigatable navigatable,
@NotNull final String isolateId,
@Nullable final ScriptRef script,
final int tokenPos) {
if (script == null || tokenPos <= 0) {
navigatable.setSourcePosition(null);
return;
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final XSourcePosition sourcePosition = debugProcess.getSourcePosition(isolateId, script, tokenPos);
ApplicationManager.getApplication().runReadAction(() -> navigatable.setSourcePosition(sourcePosition));
});
}
private CompletableFuture<String> createPropertyDocFuture() {
final DiagnosticsNode parent = getParent();
if (parent != null) {
return inspectorService.thenComposeAsync((service) -> service.toDartVmServiceValueForSourceLocation(parent.getValueRef())
.thenComposeAsync((DartVmServiceValue vmValue) -> {
if (vmValue == null) {
return CompletableFuture.completedFuture(null);
}
return inspectorService.getNow(null).getPropertyLocation(vmValue.getInstanceRef(), getName())
.thenApplyAsync((XSourcePosition sourcePosition) -> {
if (sourcePosition != null) {
final VirtualFile file = sourcePosition.getFile();
final int offset = sourcePosition.getOffset();
final Project project = getProject(file);
if (project != null) {
final List<HoverInformation> hovers =
DartAnalysisServerService.getInstance(project).analysis_getHover(file, offset);
if (!hovers.isEmpty()) {
return hovers.get(0).getDartdoc();
}
}
}
return "Unable to find property source";
});
})).exceptionally(t -> {
LOG.info("ignoring exception from toObjectForSourceLocation: " + t.toString());
return null;
});
}
return CompletableFuture.completedFuture("Unable to find property source");
}
public XSourcePosition getXSourcePosition() {
final VirtualFile file = getFile();
if (file == null) {
return null;
}
final int line = getLine();
final int column = getColumn();
if (line < 0 || column < 0) {
return null;
}
return XSourcePositionImpl.create(file, line - 1, column - 1);
}
@Override
public void doUpdateDetailView(DetailView panel, boolean editorOnly) {
XBreakpointBase breakpoint = (XBreakpointBase)myBreakpoint;
Project project = breakpoint.getProject();
//saveState();
if (myPropertiesPanel != null) {
myPropertiesPanel.dispose();
myPropertiesPanel = null;
}
if (!editorOnly) {
myPropertiesPanel = new XLightBreakpointPropertiesPanel(project, getManager(), breakpoint, true);
panel.setPropertiesPanel(myPropertiesPanel.getMainPanel());
}
XSourcePosition sourcePosition = myBreakpoint.getSourcePosition();
if (sourcePosition != null && sourcePosition.getFile().isValid()) {
showInEditor(panel, sourcePosition.getFile(), sourcePosition.getLine());
}
else {
panel.clearEditor();
}
if (myPropertiesPanel != null) {
myPropertiesPanel.setDetailView(panel);
myPropertiesPanel.loadProperties();
myPropertiesPanel.getMainPanel().revalidate();
}
}
@Override
protected XSourcePosition getSourcePosition(DiagnosticsNode node) {
if (!node.hasCreationLocation()) {
return null;
}
return node.getCreationLocation().getXSourcePosition();
}
@NotNull
public CompletableFuture<XSourcePosition> getSourcePosition(DartVmServiceDebugProcess debugProcess,
ScriptRef script,
int tokenPos,
InspectorService.ObjectGroup isAlive) {
return addRequest(isAlive, "getSourcePosition",
() -> CompletableFuture.completedFuture(debugProcess.getSourcePosition(isolateId, script, tokenPos)));
}
public XDebuggerExpressionComboBox(@Nonnull Project project, @Nonnull XDebuggerEditorsProvider debuggerEditorsProvider, @Nullable @NonNls String historyId,
@Nullable XSourcePosition sourcePosition, boolean showEditor) {
super(project, debuggerEditorsProvider, EvaluationMode.EXPRESSION, historyId, sourcePosition);
myComboBox = new ComboBox<>(100);
myComboBox.setEditable(true);
myExpression = XExpressionImpl.EMPTY_EXPRESSION;
Dimension minimumSize = new Dimension(myComboBox.getMinimumSize());
minimumSize.width = 100;
myComboBox.setMinimumSize(minimumSize);
initEditor();
fillComboBox();
myComponent = showEditor ? addMultilineButton(myComboBox) : myComboBox;
}
private void navigateToStatsEntry(SlidingWindowStatsSummary stats) {
if (stats == null) {
return;
}
final Location location = stats.getLocation();
final XSourcePosition position = location.getXSourcePosition();
if (position != null) {
AsyncUtils.invokeLater(() -> {
position.createNavigatable(app.getProject()).navigate(false);
});
}
}