inline to anonymous: do not try on refs inside the class (IDEA-89293)

This commit is contained in:
anna
2012-07-31 21:09:15 +02:00
parent f9f6c29c3a
commit e9cfb7c993
@@ -87,7 +87,13 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler {
public boolean canInlineElementInEditor(PsiElement element, Editor editor) {
if (canInlineElement(element)) {
PsiReference reference = editor != null ? TargetElementUtilBase.findReference(editor, editor.getCaretModel().getOffset()) : null;
return !InlineMethodHandler.isThisReference(reference);
if (!InlineMethodHandler.isThisReference(reference)) {
if (element instanceof PsiMethod && reference != null) {
final PsiElement referenceElement = reference.getElement();
return referenceElement != null && !PsiTreeUtil.isAncestor(((PsiMethod)element).getContainingClass(), referenceElement, false);
}
return true;
}
}
return false;
}