Search in sources :

Example 1 with XSourcePositionImpl

use of com.intellij.xdebugger.impl.XSourcePositionImpl 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)

Aggregations

SourcePosition (com.intellij.debugger.SourcePosition)1 Document (com.intellij.openapi.editor.Document)1 SmartList (com.intellij.util.SmartList)1 XSourcePosition (com.intellij.xdebugger.XSourcePosition)1 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)1 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)1 XSourcePositionImpl (com.intellij.xdebugger.impl.XSourcePositionImpl)1 NotNull (org.jetbrains.annotations.NotNull)1