Search in sources :

Example 16 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-elixir by KronicDeth.

the class SourcePosition method create.

@Nullable
public static SourcePosition create(@NotNull String filePath, int line) {
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath(filePath);
    XSourcePosition sourcePosition = XDebuggerUtil.getInstance().createPosition(file, line);
    if (sourcePosition != null) {
        return new SourcePosition(sourcePosition);
    } else {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-plugins by JetBrains.

the class FlexSuspendContext method createStackFrame.

private static FlexStackFrame createStackFrame(final FlexDebugProcess flexDebugProcess, final String frameText) {
    // #0   global$init() at Some4Class.as#42:6
    // #0   FlexSprite() at FlexSprite.as:59
    // #2   Some4Class() at Singleton.as#16:0
    // #2   UIComponent() at <null>:0\r\nNo active session
    // #0   global/publicFun() at publicFun.as#41:5
    // #0   HelloFlex4/button1_clickHandler(event=[Object 181591585, class='flash.events::MouseEvent']) at HelloFlex4.mxml#40:11
    // #0   NameUtil$/createUniqueName(object=[Object 172624937, class='mx.controls::TextInput']) at NameUtil.as#29:65
    // #0   EventDispatcher/dispatchEvent(_arg1=null) at <null>:0\r\nNo active session
    // #0   FlexEvent(type="valueCommit", bubbles=false, cancelable=false) at FlexEvent.as#18:1178
    // #0   HelloFlex4/get abc() at HelloFlex4.mxml#40:18
    // #0   HelloFlex4/set abc(value="Asd") at HelloFlex4.mxml#40:22
    // #0   this = [Object 94314641, class='BackWorker'].BackWorker/onProgress(event=[Object 246336977, class='flash.events::ProgressEvent']) at BackWorker.as:36
    // #1   EventDispatcher/dispatchEventFunction() at <null>:0
    // #2   this = [Object 106360769, class='fr.kikko.lab::ShineMP3Encoder'].EventDispatcher/dispatchEvent(_arg1=[Object 246336977, class='flash.events::ProgressEvent']) at <null>:0
    // #3   this = [Object 106360769, class='fr.kikko.lab::ShineMP3Encoder'].ShineMP3Encoder/update(event=[Object 246068457, class='flash.events::TimerEvent']) at ShineMP3Encoder.as:63
    // #4   Timer/_timerDispatch() at <null>:0
    // #5   this = [Object 152354881, class='flash.utils::Timer'].Timer/tick() at <null>:0
    VirtualFile file = null;
    final Trinity<String, String, Integer> fileNameAndIndexAndLine = getFileNameAndIdAndLine(frameText);
    final String fileName = fileNameAndIndexAndLine.first;
    final String fileId = fileNameAndIndexAndLine.second;
    final int line = fileNameAndIndexAndLine.third;
    if (!StringUtil.isEmpty(fileName)) {
        file = flexDebugProcess.findFileByNameOrId(fileName, getPackageFromFrameText(frameText), fileId);
        if (file == null) {
        // todo find position in decompiled code
        }
    }
    final VirtualFile finalFile = file;
    final XSourcePosition sourcePosition = file == null ? null : ReadAction.compute(() -> XDebuggerUtil.getInstance().createPosition(finalFile, line > 0 ? line - 1 : line));
    return sourcePosition != null ? new FlexStackFrame(flexDebugProcess, sourcePosition) : new FlexStackFrame(flexDebugProcess, fileName, line);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Example 18 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-plugins by JetBrains.

the class FlexValue method computeSourcePosition.

@Override
public void computeSourcePosition(@NotNull final XNavigatable navigatable) {
    if (mySourcePosition == null) {
        navigatable.setSourcePosition(null);
        return;
    }
    XSourcePosition result = null;
    final Project project = myDebugProcess.getSession().getProject();
    if (myValueType == ValueType.Variable) {
        final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
        final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
        if (jsFunction != null) {
            final Ref<JSVariable> varRef = new Ref<>();
            jsFunction.accept(new JSElementVisitor() {

                @Override
                public void visitJSElement(final JSElement node) {
                    if (varRef.isNull()) {
                        node.acceptChildren(this);
                    }
                }

                @Override
                public void visitJSVariable(final JSVariable node) {
                    if (myName.equals(node.getName())) {
                        varRef.set(node);
                    }
                    super.visitJSVariable(node);
                }
            });
            if (!varRef.isNull()) {
                result = DebuggerSupportUtils.calcSourcePosition(varRef.get());
            }
        }
    } else if (myValueType == ValueType.Parameter) {
        final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
        final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
        final JSParameter[] parameters = jsFunction == null ? JSParameter.EMPTY_ARRAY : jsFunction.getParameterVariables();
        for (final JSParameter parameter : parameters) {
            if (myName.equals(parameter.getName())) {
                result = DebuggerSupportUtils.calcSourcePosition(parameter);
                break;
            }
        }
    } else if (myValueType == ValueType.Field && myParentResult != null) {
        final String typeFromFlexValueResult = getTypeAndAdditionalInfo(myParentResult).first;
        final JSClass jsClass = findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
        if (jsClass != null) {
            final Ref<PsiElement> fieldRef = new Ref<>();
            fieldRef.set(JSInheritanceUtil.findMember(myName, jsClass, JSInheritanceUtil.SearchedMemberType.FieldsAndMethods, JSFunction.FunctionKind.GETTER, true));
            if (fieldRef.isNull() && jsClass instanceof MxmlJSClass) {
                final PsiFile file = jsClass.getContainingFile();
                final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
                final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
                if (rootTag != null) {
                    NodeClassInfo.processSubtagsRecursively(rootTag, tag -> {
                        final XmlAttribute idAttr = tag.getAttribute("id");
                        final String id = idAttr == null ? null : idAttr.getValue();
                        if (id != null && id.equals(myName)) {
                            fieldRef.set(idAttr);
                        }
                        return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
                    });
                }
            }
            result = DebuggerSupportUtils.calcSourcePosition(fieldRef.get());
        }
    }
    navigatable.setSourcePosition(result);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) PsiFile(com.intellij.psi.PsiFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 19 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-plugins by JetBrains.

the class DartVmServiceListener method onIsolatePaused.

void onIsolatePaused(@NotNull final IsolateRef isolateRef, @Nullable final ElementList<Breakpoint> vmBreakpoints, @Nullable final InstanceRef exception, @Nullable final Frame vmTopFrame, boolean atAsyncSuspension) {
    if (vmTopFrame == null) {
        myDebugProcess.getSession().positionReached(new XSuspendContext() {
        });
        return;
    }
    final DartVmServiceSuspendContext suspendContext = new DartVmServiceSuspendContext(myDebugProcess, isolateRef, vmTopFrame, exception, atAsyncSuspension);
    final XStackFrame xTopFrame = suspendContext.getActiveExecutionStack().getTopFrame();
    final XSourcePosition sourcePosition = xTopFrame == null ? null : xTopFrame.getSourcePosition();
    if (vmBreakpoints == null || vmBreakpoints.isEmpty()) {
        final StepOption latestStep = myDebugProcess.getVmServiceWrapper().getLatestStep();
        if (latestStep == StepOption.Over && equalSourcePositions(myLatestSourcePosition, sourcePosition)) {
            // continue stepping to change current line
            myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), latestStep);
        } else {
            myLatestSourcePosition = sourcePosition;
            myDebugProcess.getSession().positionReached(suspendContext);
        }
    } else {
        if (vmBreakpoints.size() > 1) {
            // Shouldn't happen. IDE doesn't allow to set 2 breakpoints on one line.
            LOG.error(vmBreakpoints.size() + " breakpoints hit in one shot.");
        }
        // Remove any temporary (run to cursor) breakpoints.
        myBreakpointHandler.removeTemporaryBreakpoints(isolateRef.getId());
        final XLineBreakpoint<XBreakpointProperties> xBreakpoint = myBreakpointHandler.getXBreakpoint(vmBreakpoints.get(0));
        if (xBreakpoint == null) {
            // breakpoint could be set in the Observatory
            myLatestSourcePosition = sourcePosition;
            myDebugProcess.getSession().positionReached(suspendContext);
            return;
        }
        if ("false".equals(evaluateExpression(isolateRef.getId(), vmTopFrame, xBreakpoint.getConditionExpression()))) {
            myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), null);
            return;
        }
        myLatestSourcePosition = sourcePosition;
        final String logExpression = evaluateExpression(isolateRef.getId(), vmTopFrame, xBreakpoint.getLogExpressionObject());
        final boolean suspend = myDebugProcess.getSession().breakpointReached(xBreakpoint, logExpression, suspendContext);
        if (!suspend) {
            myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), null);
        }
    }
}
Also used : XBreakpointProperties(com.intellij.xdebugger.breakpoints.XBreakpointProperties) DartVmServiceSuspendContext(com.jetbrains.lang.dart.ide.runner.server.vmService.frame.DartVmServiceSuspendContext) XSuspendContext(com.intellij.xdebugger.frame.XSuspendContext) XSourcePosition(com.intellij.xdebugger.XSourcePosition) XStackFrame(com.intellij.xdebugger.frame.XStackFrame)

Example 20 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-plugins by JetBrains.

the class DartVmServiceValue method reportSourcePosition.

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));
    });
}
Also used : XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Aggregations

XSourcePosition (com.intellij.xdebugger.XSourcePosition)40 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 Project (com.intellij.openapi.project.Project)9 Nullable (org.jetbrains.annotations.Nullable)8 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)6 PsiFile (com.intellij.psi.PsiFile)5 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 XDebugSession (com.intellij.xdebugger.XDebugSession)4 PsiElement (com.intellij.psi.PsiElement)3 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)3 Editor (com.intellij.openapi.editor.Editor)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 FileEditorManagerImpl (com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl)2 Ref (com.intellij.openapi.util.Ref)2 TextRange (com.intellij.openapi.util.TextRange)2 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)2 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)2 XValue (com.intellij.xdebugger.frame.XValue)2 VMPausedException (org.intellij.plugins.xsltDebugger.VMPausedException)2