com.intellij.xdebugger.XSourcePosition Java Examples

The following examples show how to use com.intellij.xdebugger.XSourcePosition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MuleBreakpointType.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: SkylarkDebuggerEditorsProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: FlutterPositionMapper.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: CppStackFrame.java    From CppTools with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: FlutterPositionMapperTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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
}
 
Example #6
Source File: ObservatoryFile.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: XInspectDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #8
Source File: UnityScriptDebuggerProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(@Nonnull DotNetStackFrameProxy stackFrameMirror,
		@Nonnull DotNetDebugContext context,
		@Nonnull String s,
		@Nullable PsiElement element,
		@Nonnull XDebuggerEvaluator.XEvaluationCallback callback,
		@Nullable XSourcePosition sourcePosition)
{
	callback.errorOccurred("UnityScript evaluation is not supported");
}
 
Example #9
Source File: VmServiceWrapper.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addTemporaryBreakpoint(@NotNull final XSourcePosition position, @NotNull final String isolateId) {
  addBreakpoint(isolateId, position, new VmServiceConsumers.BreakpointsConsumer() {
    @Override
    void sourcePositionNotApplicable() {
    }

    @Override
    void received(List<Breakpoint> breakpointResponses, List<RPCError> errorResponses) {
      for (Breakpoint breakpoint : breakpointResponses) {
        myBreakpointHandler.temporaryBreakpointAdded(isolateId, breakpoint);
      }
    }
  });
}
 
Example #10
Source File: DebuggerEvaluator.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(
    String expression,
    XEvaluationCallback callback,
    @Nullable XSourcePosition expressionPosition) {
  ApplicationManager.getApplication()
      .executeOnPooledThread(
          () -> {
            debugProcess.evaluate(expression, callback);
          });
}
 
Example #11
Source File: SkylarkDebuggerEditorsProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
private PsiFile createExpressionCodeFragment(
    Project project,
    String text,
    @Nullable XSourcePosition sourcePosition,
    @Nullable PsiElement context) {
  text = text.trim();
  SkylarkExpressionCodeFragment fragment =
      new SkylarkExpressionCodeFragment(
          project, codeFragmentFileName(context), text, /* isPhysical= */ true);
  // inject the debug frame context into the file
  if (sourcePosition instanceof SkylarkSourcePosition) {
    fragment.setDebugEvaluationContext((SkylarkSourcePosition) sourcePosition);
  }
  return fragment;
}
 
Example #12
Source File: XQueryBreakpointHandler.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public void registerBreakpoint(@NotNull XLineBreakpoint<XBreakpointProperties> breakpoint) {
    final XSourcePosition sourcePosition = breakpoint.getSourcePosition();
    if (isSourcePositionInvalid(sourcePosition)) return;

    final int lineNumber = getActualLineNumber(breakpoint.getLine());
    if (handleInvalidLine(breakpoint, lineNumber)) return;
    debugProcess.setBreakpoint(getFileUrl(sourcePosition), lineNumber, breakpoint.getConditionExpression());
}
 
Example #13
Source File: XDebuggerExpressionEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public XDebuggerExpressionEditor(Project project,
                                 @Nonnull XDebuggerEditorsProvider debuggerEditorsProvider,
                                 @Nullable @NonNls String historyId,
                                 @Nullable XSourcePosition sourcePosition,
                                 @Nonnull XExpression text,
                                 final boolean multiline,
                                 boolean editorFont,
                                 boolean showEditor) {
  super(project, debuggerEditorsProvider, multiline ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION, historyId, sourcePosition);
  myExpression = XExpressionImpl.changeMode(text, getMode());
  myEditorTextField =
          new EditorTextField(createDocument(myExpression), project, debuggerEditorsProvider.getFileType(), false, !multiline) {
            @Override
            protected EditorEx createEditor() {
              final EditorEx editor = super.createEditor();
              editor.setVerticalScrollbarVisible(multiline);
              editor.getColorsScheme().setEditorFontName(getFont().getFontName());
              editor.getColorsScheme().setEditorFontSize(getFont().getSize());
              return editor;
            }

            @Override
            public Object getData(@Nonnull Key dataId) {
              if (LangDataKeys.CONTEXT_LANGUAGES == dataId) {
                return new Language[]{myExpression.getLanguage()};
              } else if (CommonDataKeys.PSI_FILE == dataId) {
                return PsiDocumentManager.getInstance(getProject()).getPsiFile(getDocument());
              }
              return super.getData(dataId);
            }
          };
  if (editorFont) {
    myEditorTextField.setFontInheritedFromLAF(false);
    myEditorTextField.setFont(EditorUtil.getEditorFont());
  }
  myComponent = decorate(myEditorTextField, multiline, showEditor);
}
 
Example #14
Source File: XLineBreakpointImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public XSourcePosition getSourcePosition() {
  if (mySourcePosition != null) {
    return mySourcePosition;
  }
  mySourcePosition = super.getSourcePosition();
  if (mySourcePosition == null) {
    mySourcePosition = XDebuggerUtil.getInstance().createPosition(getFile(), getLine());
  }
  return mySourcePosition;
}
 
Example #15
Source File: XQueryDebugProcess.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public void runToPosition(@NotNull XSourcePosition position, XSuspendContext context) {
    String fileURL = XQueryBreakpointHandler.getFileUrl(position);
    int lineNumber = XQueryBreakpointHandler.getActualLineNumber(position.getLine());
    dbgpIde.breakpointSet(aLineBreakpoint(fileURL, lineNumber).withTemporary(true).build());
    dbgpIde.run();
}
 
Example #16
Source File: MuleDebuggerEditorsProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #17
Source File: DiagnosticsNode.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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");
}
 
Example #18
Source File: EvalOnDartLibrary.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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)));
}
 
Example #19
Source File: XQueryBreakpointHandler.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public void unregisterBreakpoint(@NotNull XLineBreakpoint<XBreakpointProperties> breakpoint, boolean temporary) {
    final XSourcePosition sourcePosition = breakpoint.getSourcePosition();
    if (isSourcePositionInvalid(sourcePosition)) return;

    final int lineNumber = getActualLineNumber(breakpoint.getLine());
    if (handleInvalidLine(breakpoint, lineNumber)) return;
    debugProcess.removeBreakpoint(getFileUrl(sourcePosition), lineNumber);
}
 
Example #20
Source File: BlazeAndroidNativeDebuggerLanguageSupport.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public Document createDocument(
    final Project project,
    final String text,
    @Nullable XSourcePosition sourcePosition,
    final EvaluationMode mode) {
  final PsiElement context = OCDebuggerTypesHelper.getContextElement(sourcePosition, project);
  if (context != null && context.getLanguage() == OCLanguage.getInstance()) {
    return new WriteAction<Document>() {
      @Override
      protected void run(Result<Document> result) {
        PsiFile fragment =
            mode == EvaluationMode.EXPRESSION
                ? OCElementFactory.expressionCodeFragment(text, project, context, true, false)
                : OCElementFactory.expressionOrStatementsCodeFragment(
                    text, project, context, true, false);
        //noinspection ConstantConditions
        result.setResult(PsiDocumentManager.getInstance(project).getDocument(fragment));
      }
    }.execute().getResultObject();
  } else {
    final LightVirtualFile plainTextFile =
        new LightVirtualFile("oc-debug-editor-when-no-source-position-available.txt", text);
    //noinspection ConstantConditions
    return FileDocumentManager.getInstance().getDocument(plainTextFile);
  }
}
 
Example #21
Source File: DartVmServiceValue.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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));
  });
}
 
Example #22
Source File: XDebuggerEditorLinePainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int getCurrentBreakPointLineInFile(@Nullable XDebugSession session, VirtualFile file) {
  try {
    if (session != null) {
      final XSourcePosition position = session.getCurrentPosition();
      if (position != null && position.getFile().equals(file)) {
        return position.getLine();
      }
    }
  }
  catch (Exception ignore) {
  }
  return -1;
}
 
Example #23
Source File: JumpToSourceAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected XSourcePosition getSourcePosition(DiagnosticsNode node) {
  if (!node.hasCreationLocation()) {
    return null;
  }
  return node.getCreationLocation().getXSourcePosition();
}
 
Example #24
Source File: VmServiceWrapper.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addBreakpoint(@NotNull final String isolateId,
                          @Nullable final XSourcePosition position,
                          @NotNull final VmServiceConsumers.BreakpointsConsumer consumer) {
  if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) {
    consumer.sourcePositionNotApplicable();
    return;
  }

  addRequest(() -> {
    final int line = position.getLine() + 1;

    final Collection<String> scriptUris = myDebugProcess.getUrisForFile(position.getFile());
    final List<Breakpoint> breakpointResponses = new ArrayList<>();
    final List<RPCError> errorResponses = new ArrayList<>();

    for (String uri : scriptUris) {
      myVmService.addBreakpointWithScriptUri(isolateId, uri, line, new BreakpointConsumer() {
        @Override
        public void received(Breakpoint response) {
          breakpointResponses.add(response);

          checkDone();
        }

        @Override
        public void onError(RPCError error) {
          errorResponses.add(error);

          checkDone();
        }

        private void checkDone() {
          if (scriptUris.size() == breakpointResponses.size() + errorResponses.size()) {
            consumer.received(breakpointResponses, errorResponses);
          }
        }
      });
    }
  });
}
 
Example #25
Source File: HaxeDebuggerEditorsProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@NotNull
public Document createDocument(@NotNull final Project project,
                               @NotNull final String text, @Nullable final XSourcePosition position, @NotNull EvaluationMode mode) {
  return HaxeDebuggerSupportUtils.createDocument(
    text,
    project,
    position != null ? position.getFile() : null, position != null ? position.getOffset() : -1
  );
}
 
Example #26
Source File: WidgetPerfTable.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
    });
  }
}
 
Example #27
Source File: XDebuggerExpressionComboBox.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #28
Source File: EvalOnDartLibrary.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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)));
}
 
Example #29
Source File: JumpToSourceAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected XSourcePosition getSourcePosition(DiagnosticsNode node) {
  if (!node.hasCreationLocation()) {
    return null;
  }
  return node.getCreationLocation().getXSourcePosition();
}
 
Example #30
Source File: XBreakpointItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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();

  }

}