Search in sources :

Example 1 with XSourcePosition

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

the class XsltBreakpointType method getEditorsProvider.

@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;
    }
    final XsltChecker.LanguageLevel level = XsltSupport.getXsltLanguageLevel(file);
    if (level == XsltChecker.LanguageLevel.V1) {
        return myMyEditorsProvider1;
    } else if (level == XsltChecker.LanguageLevel.V2) {
        return myMyEditorsProvider2;
    }
    return null;
}
Also used : PsiFile(com.intellij.psi.PsiFile) XsltChecker(org.intellij.lang.xpath.xslt.impl.XsltChecker) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Example 2 with XSourcePosition

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

the class JavaLineBreakpointType method computeVariants.

@NotNull
@Override
public List<JavaBreakpointVariant> computeVariants(@NotNull Project project, @NotNull XSourcePosition position) {
    PsiFile file = PsiManager.getInstance(project).findFile(position.getFile());
    if (file == null) {
        return Collections.emptyList();
    }
    SourcePosition pos = SourcePosition.createFromLine(file, position.getLine());
    List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(pos, true);
    if (lambdas.isEmpty()) {
        return Collections.emptyList();
    }
    PsiElement startMethod = DebuggerUtilsEx.getContainingMethod(pos);
    //noinspection SuspiciousMethodCalls
    if (lambdas.contains(startMethod) && lambdas.size() == 1) {
        return Collections.emptyList();
    }
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null) {
        return Collections.emptyList();
    }
    List<JavaBreakpointVariant> res = new SmartList<>();
    if (!(startMethod instanceof PsiLambdaExpression)) {
        // base method
        res.add(new LineJavaBreakpointVariant(position, startMethod, -1));
    }
    int ordinal = 0;
    for (PsiLambdaExpression lambda : lambdas) {
        //lambdas
        PsiElement firstElem = DebuggerUtilsEx.getFirstElementOnTheLine(lambda, document, position.getLine());
        XSourcePositionImpl elementPosition = XSourcePositionImpl.createByElement(firstElem);
        if (elementPosition != null) {
            if (lambda == startMethod) {
                res.add(0, new LineJavaBreakpointVariant(elementPosition, lambda, ordinal++));
            } else {
                res.add(new LambdaJavaBreakpointVariant(elementPosition, lambda, ordinal++));
            }
        }
    }
    //all
    res.add(new JavaBreakpointVariant(position));
    return res;
}
Also used : Document(com.intellij.openapi.editor.Document) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XSourcePositionImpl(com.intellij.xdebugger.impl.XSourcePositionImpl) XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition 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 4 with XSourcePosition

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

the class BreakpointWithHighlighter method isAt.

public boolean isAt(@NotNull Document document, int offset) {
    final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
    int line = document.getLineNumber(offset);
    XSourcePosition position = myXBreakpoint.getSourcePosition();
    return position != null && position.getLine() == line && position.getFile().equals(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 5 with XSourcePosition

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

the class ElixirSourcePosition method create.

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

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