return null;
}
- public static List<PsiLambdaExpression> collectLambdas(SourcePosition position, final boolean onlyOnTheLine) {
+ public static List<PsiLambdaExpression> collectLambdas(@NotNull SourcePosition position, final boolean onlyOnTheLine) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFile file = position.getFile();
int line = position.getLine();
return body;
}
+ public static boolean inTheMethod(@NotNull SourcePosition pos, @NotNull PsiElement method) {
+ PsiElement elem = pos.getElementAt();
+ if (elem == null) return false;
+ NavigatablePsiElement elemMethod = PsiTreeUtil.getParentOfType(elem, PsiMethod.class, PsiLambdaExpression.class);
+ return Comparing.equal(elemMethod, method);
+ }
+
public static boolean inTheSameMethod(@NotNull SourcePosition pos1, @NotNull SourcePosition pos2) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiElement elem1 = pos1.getElementAt();
res.add(new JavaBreakpointVariant(position)); //all
if (startMethod instanceof PsiMethod) {
- res.add(new ExactJavaBreakpointVariant(position, startMethod)); // base method
+ res.add(new ExactJavaBreakpointVariant(position, startMethod, -1)); // base method
}
+ int ordinal = 0;
for (PsiLambdaExpression lambda : lambdas) { //lambdas
PsiElement firstElem = DebuggerUtilsEx.getFirstElementOnTheLine(lambda, document, position.getLine());
- res.add(new ExactJavaBreakpointVariant(XSourcePositionImpl.createByElement(firstElem), lambda));
+ res.add(new ExactJavaBreakpointVariant(XSourcePositionImpl.createByElement(firstElem), lambda, ordinal++));
}
return res;
private class ExactJavaBreakpointVariant extends JavaBreakpointVariant {
private final PsiElement myElement;
+ private final Integer myLambdaOrdinal;
- public ExactJavaBreakpointVariant(XSourcePosition position, PsiElement element) {
+ public ExactJavaBreakpointVariant(XSourcePosition position, PsiElement element, Integer lambdaOrdinal) {
super(position);
myElement = element;
+ myLambdaOrdinal = lambdaOrdinal;
}
@Override
@Override
public JavaLineBreakpointProperties createProperties() {
JavaLineBreakpointProperties properties = super.createProperties();
- properties.setOffset(mySourcePosition.getOffset());
+ properties.setLambdaOrdinal(myLambdaOrdinal);
return properties;
}
}
@Nullable
@Override
- public TextRange getHighlightRange(JavaLineBreakpointProperties properties, Document document, Project project) {
- Integer offset = properties.getOffset();
- if (offset != null) {
- PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
- if (file != null) {
- PsiElement elem = file.findElementAt(offset);
- NavigatablePsiElement method = PsiTreeUtil.getParentOfType(elem, PsiMethod.class, PsiLambdaExpression.class);
- if (method != null) {
- return method.getTextRange();
+ public TextRange getHighlightRange(XLineBreakpoint<JavaLineBreakpointProperties> breakpoint) {
+ JavaLineBreakpointProperties properties = breakpoint.getProperties();
+ if (properties != null) {
+ Integer ordinal = properties.getLambdaOrdinal();
+ if (ordinal != null) {
+ Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
+ if (javaBreakpoint instanceof LineBreakpoint) {
+ PsiElement method = ((LineBreakpoint)javaBreakpoint).getContainingMethod();
+ if (method != null) {
+ return method.getTextRange();
+ }
}
}
}
@Override
public Boolean compute() {
if (getProperties() instanceof JavaLineBreakpointProperties) {
- Integer offset = ((JavaLineBreakpointProperties)getProperties()).getOffset();
- if (offset == null) return true;
- PsiFile file = getPsiFile();
- if (file != null) {
- SourcePosition exactPosition = SourcePosition.createFromOffset(file, offset);
- SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
- if (position == null) return false;
- return DebuggerUtilsEx.inTheSameMethod(exactPosition, position);
- }
+ Integer ordinal = ((JavaLineBreakpointProperties)getProperties()).getLambdaOrdinal();
+ if (ordinal == null) return true;
+ PsiElement containingMethod = getContainingMethod();
+ if (containingMethod == null) return false;
+ SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
+ if (position == null) return false;
+ return DebuggerUtilsEx.inTheMethod(position, containingMethod);
}
return true;
}
});
}
+ @Nullable
+ public PsiElement getContainingMethod() {
+ SourcePosition position = getSourcePosition();
+ if (position == null) return null;
+ if (getProperties() instanceof JavaLineBreakpointProperties) {
+ Integer ordinal = ((JavaLineBreakpointProperties)getProperties()).getLambdaOrdinal();
+ if (ordinal > -1) {
+ List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(position, true);
+ if (ordinal < lambdas.size()) {
+ return lambdas.get(ordinal);
+ }
+ }
+ }
+ return PsiTreeUtil.getParentOfType(position.getElementAt(), PsiMethod.class, PsiLambdaExpression.class);
+ }
+
private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
final SourcePosition position = getSourcePosition();
if (position != null) {
* @author egor
*/
public class JavaLineBreakpointProperties extends JavaBreakpointProperties<JavaLineBreakpointProperties> {
- private Integer myOffset = null;
+ // null - stop at all positions on the line
+ // -1 - stop only at the base position (first on the line)
+ // 0 or more - index of the lambda on the line to stop at
+ private Integer myLambdaOrdinal = null;
- @OptionTag("offset")
- public Integer getOffset() {
- return myOffset;
+ @OptionTag("lambda-ordinal")
+ public Integer getLambdaOrdinal() {
+ return myLambdaOrdinal;
}
- public void setOffset(Integer offset) {
- myOffset = offset;
+ public void setLambdaOrdinal(Integer lambdaOrdinal) {
+ myLambdaOrdinal = lambdaOrdinal;
}
}
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
* @return range to highlight on the line, null to highlight the whole line
*/
@Nullable
- public TextRange getHighlightRange(P properties, Document document, Project project) {
+ public TextRange getHighlightRange(XLineBreakpoint<P> breakpoint) {
return null;
}
MarkupModelEx markupModel;
if (highlighter == null) {
markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, getProject(), true);
- TextRange range = myType.getHighlightRange(getProperties(), document, getProject());
+ TextRange range = myType.getHighlightRange(this);
if (range != null && !range.isEmpty()) {
range = range.intersection(DocumentUtil.getLineTextRange(document, getLine()));
if (range != null && !range.isEmpty()) {