Search in sources :

Example 1 with SourcePosition

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

the class RunToCursorBreakpoint method getXBreakpointType.

@Nullable
@Override
protected JavaLineBreakpointType getXBreakpointType() {
    SourcePosition position = getSourcePosition();
    VirtualFile file = position.getFile().getVirtualFile();
    int line = position.getLine();
    for (XLineBreakpointType<?> type : XDebuggerUtil.getInstance().getLineBreakpointTypes()) {
        if (type instanceof JavaLineBreakpointType && type.canPutAt(file, line, myProject)) {
            return ((JavaLineBreakpointType) type);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with SourcePosition

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

the class StepIntoBreakpoint method create.

@Nullable
protected static StepIntoBreakpoint create(@NotNull Project project, @NotNull BreakpointStepMethodFilter filter) {
    final SourcePosition pos = filter.getBreakpointPosition();
    if (pos != null) {
        final StepIntoBreakpoint breakpoint = new StepIntoBreakpoint(project, pos, filter);
        breakpoint.init();
        return breakpoint;
    }
    return null;
}
Also used : SourcePosition(com.intellij.debugger.SourcePosition) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with SourcePosition

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

the class JavaLineBreakpointType method getContainingMethod.

@Nullable
public PsiElement getContainingMethod(@NotNull LineBreakpoint<?> breakpoint) {
    SourcePosition position = breakpoint.getSourcePosition();
    if (position == null)
        return null;
    JavaBreakpointProperties properties = breakpoint.getProperties();
    if (properties instanceof JavaLineBreakpointProperties && !(breakpoint instanceof RunToCursorBreakpoint)) {
        Integer ordinal = ((JavaLineBreakpointProperties) properties).getLambdaOrdinal();
        if (ordinal > -1) {
            List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(position, true);
            if (ordinal < lambdas.size()) {
                return lambdas.get(ordinal);
            }
        }
    }
    return DebuggerUtilsEx.getContainingMethod(position);
}
Also used : XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) JavaLineBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties) JavaBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with SourcePosition

use of com.intellij.debugger.SourcePosition 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 5 with SourcePosition

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

the class LineBreakpoint method acceptLocation.

protected boolean acceptLocation(final DebugProcessImpl debugProcess, ReferenceType classType, final Location loc) {
    Method method = loc.method();
    // if (DebuggerUtils.isSynthetic(method)) { return false; }
    if (isAnonymousClass(classType)) {
        if ((method.isConstructor() && loc.codeIndex() == 0) || method.isBridge())
            return false;
    }
    SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
    if (position == null)
        return false;
    return ReadAction.compute(() -> {
        JavaLineBreakpointType type = getXBreakpointType();
        if (type == null)
            return true;
        return type.matchesPosition(this, position);
    });
}
Also used : XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition)

Aggregations

SourcePosition (com.intellij.debugger.SourcePosition)36 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)11 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 XSourcePosition (com.intellij.xdebugger.XSourcePosition)7 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)6 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)6 Document (com.intellij.openapi.editor.Document)6 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)5 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)4 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)4 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)4 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)4 Location (com.sun.jdi.Location)4 NotNull (org.jetbrains.annotations.NotNull)4 PsiElement (com.intellij.psi.PsiElement)3 DebuggerBundle (com.intellij.debugger.DebuggerBundle)2 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)2 NoDataException (com.intellij.debugger.NoDataException)2