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;
}
Aggregations