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;
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();
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;
+ }
}