Search in sources :

Example 1 with JavaStackFrame

use of com.intellij.debugger.engine.JavaStackFrame in project intellij-community by JetBrains.

the class AlternativeSourceNotificationProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (!DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE) {
        return null;
    }
    XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession();
    if (session == null) {
        FILE_PROCESSED_KEY.set(file, null);
        return null;
    }
    XSourcePosition position = session.getCurrentPosition();
    if (position == null || !file.equals(position.getFile())) {
        FILE_PROCESSED_KEY.set(file, null);
        return null;
    }
    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
    if (psiFile == null)
        return null;
    if (!(psiFile instanceof PsiJavaFile))
        return null;
    PsiClass[] classes = ((PsiJavaFile) psiFile).getClasses();
    if (classes.length == 0)
        return null;
    PsiClass baseClass = classes[0];
    String name = baseClass.getQualifiedName();
    if (name == null)
        return null;
    if (DumbService.getInstance(myProject).isDumb())
        return null;
    ArrayList<PsiClass> alts = ContainerUtil.newArrayList(JavaPsiFacade.getInstance(myProject).findClasses(name, GlobalSearchScope.allScope(myProject)));
    ContainerUtil.removeDuplicates(alts);
    FILE_PROCESSED_KEY.set(file, true);
    if (alts.size() > 1) {
        for (PsiClass cls : alts) {
            if (cls.equals(baseClass) || cls.getNavigationElement().equals(baseClass)) {
                alts.remove(cls);
                break;
            }
        }
        alts.add(0, baseClass);
        ComboBoxClassElement[] elems = ContainerUtil.map2Array(alts, ComboBoxClassElement.class, psiClass -> new ComboBoxClassElement((PsiClass) psiClass.getNavigationElement()));
        String locationDeclName = null;
        XStackFrame frame = session.getCurrentStackFrame();
        if (frame instanceof JavaStackFrame) {
            Location location = ((JavaStackFrame) frame).getDescriptor().getLocation();
            if (location != null) {
                locationDeclName = location.declaringType().name();
            }
        }
        return new AlternativeSourceNotificationPanel(elems, baseClass, myProject, file, locationDeclName);
    }
    return null;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JavaStackFrame

use of com.intellij.debugger.engine.JavaStackFrame in project intellij-community by JetBrains.

the class PopFrameAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final JavaStackFrame stackFrame = getStackFrame(e);
    if (stackFrame == null || stackFrame.getStackFrameProxy().isBottom()) {
        return;
    }
    try {
        final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext());
        final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess == null) {
            return;
        }
        debugProcess.getSession().setSteppingThrough(stackFrame.getStackFrameProxy().threadProxy());
        if (evaluateFinallyBlocks(project, UIUtil.removeMnemonic(ActionsBundle.actionText(DebuggerActions.POP_FRAME)), stackFrame, new XDebuggerEvaluator.XEvaluationCallback() {

            @Override
            public void evaluated(@NotNull XValue result) {
                popFrame(debugProcess, debuggerContext, stackFrame);
            }

            @Override
            public void errorOccurred(@NotNull final String errorMessage) {
                ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(project, DebuggerBundle.message("error.executing.finally", errorMessage), UIUtil.removeMnemonic(ActionsBundle.actionText(DebuggerActions.POP_FRAME)), Messages.getErrorIcon()));
            }
        }))
            return;
        popFrame(debugProcess, debuggerContext, stackFrame);
    } catch (NativeMethodException e2) {
        Messages.showMessageDialog(project, DebuggerBundle.message("error.native.method.exception"), UIUtil.removeMnemonic(ActionsBundle.actionText(DebuggerActions.POP_FRAME)), Messages.getErrorIcon());
    } catch (InvalidStackFrameException | VMDisconnectedException ignored) {
    }
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) XValue(com.intellij.xdebugger.frame.XValue) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) Project(com.intellij.openapi.project.Project) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Example 3 with JavaStackFrame

use of com.intellij.debugger.engine.JavaStackFrame in project intellij-community by JetBrains.

the class ForceEarlyReturnAction method update.

public void update(@NotNull AnActionEvent e) {
    boolean enable = false;
    JavaStackFrame stackFrame = PopFrameAction.getStackFrame(e);
    if (stackFrame != null && stackFrame.getDescriptor().getUiIndex() == 0) {
        enable = stackFrame.getStackFrameProxy().getVirtualMachine().canForceEarlyReturn();
    }
    if (ActionPlaces.isMainMenuOrActionSearch(e.getPlace()) || ActionPlaces.DEBUGGER_TOOLBAR.equals(e.getPlace())) {
        e.getPresentation().setEnabled(enable);
    } else {
        e.getPresentation().setVisible(enable);
    }
}
Also used : JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame)

Example 4 with JavaStackFrame

use of com.intellij.debugger.engine.JavaStackFrame in project intellij-community by JetBrains.

the class ForceEarlyReturnAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getProject();
    final JavaStackFrame stackFrame = PopFrameAction.getStackFrame(e);
    if (stackFrame == null || project == null) {
        return;
    }
    final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext());
    final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
    if (debugProcess == null) {
        return;
    }
    final StackFrameProxyImpl proxy = stackFrame.getStackFrameProxy();
    final ThreadReferenceProxyImpl thread = proxy.threadProxy();
    debugProcess.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext, thread) {

        @Override
        public void threadAction() {
            Method method;
            try {
                method = proxy.location().method();
            } catch (EvaluateException e) {
                showError(project, DebuggerBundle.message("error.early.return", e.getLocalizedMessage()));
                return;
            }
            if ("void".equals(method.returnTypeName())) {
                forceEarlyReturnWithFinally(thread.getVirtualMachine().mirrorOfVoid(), stackFrame, debugProcess, null);
            } else {
                ApplicationManager.getApplication().invokeLater(() -> new ReturnExpressionDialog(project, debugProcess.getXdebugProcess().getEditorsProvider(), debugProcess, stackFrame).show());
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) Method(com.sun.jdi.Method) ThreadReferenceProxyImpl(com.intellij.debugger.jdi.ThreadReferenceProxyImpl) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Aggregations

JavaStackFrame (com.intellij.debugger.engine.JavaStackFrame)4 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)2 Project (com.intellij.openapi.project.Project)2 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)1 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 XSourcePosition (com.intellij.xdebugger.XSourcePosition)1 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)1 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)1 XValue (com.intellij.xdebugger.frame.XValue)1 InvalidStackFrameException (com.sun.jdi.InvalidStackFrameException)1 Location (com.sun.jdi.Location)1 Method (com.sun.jdi.Method)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 VMDisconnectedException (com.sun.jdi.VMDisconnectedException)1 Nullable (org.jetbrains.annotations.Nullable)1