IDEA-141772 Debugger: Smart Step Into inside lambda suggests method calls outside of this lambda

This commit is contained in:
Egor.Ushakov
2015-06-24 13:30:19 +03:00
parent 09c17458b8
commit 152e100b1b
@@ -24,9 +24,9 @@ import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.util.DocumentUtil;
import com.intellij.util.Range;
import com.intellij.util.containers.OrderedSet;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -65,10 +65,15 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
if (line >= doc.getLineCount()) {
return Collections.emptyList(); // the document has been changed
}
final int startOffset = doc.getLineStartOffset(line);
final TextRange lineRange = new TextRange(startOffset, doc.getLineEndOffset(line));
final int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), startOffset, " \t");
PsiElement element = DebuggerUtilsEx.findElementAt(file, offset);
TextRange curLineRange = DocumentUtil.getLineTextRange(doc, line);
PsiElement element = position.getElementAt();
PsiElement method = getBody(DebuggerUtilsEx.getContainingMethod(element));
final TextRange lineRange = (method != null) ? curLineRange.intersection(method.getTextRange()) : curLineRange;
if (lineRange == null || lineRange.isEmpty()) {
return Collections.emptyList();
}
if (element != null && !(element instanceof PsiCompiledElement)) {
do {
final PsiElement parent = element.getParent();
@@ -202,4 +207,13 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
return Collections.emptyList();
}
private static PsiElement getBody(@Nullable PsiElement containingMethod) {
if (containingMethod instanceof PsiMethod) {
return ((PsiMethod)containingMethod).getBody();
}
else if (containingMethod instanceof PsiLambdaExpression) {
return ((PsiLambdaExpression)containingMethod).getBody();
}
return null;
}
}