inplace -> dialog: accept second call as same element if there was local variable with same name as introduced field (IDEA-153747)

This commit is contained in:
Anna.Kozlova
2016-04-01 11:38:39 +02:00
parent 43e3e4f6bb
commit 1449ccff22
@@ -23,6 +23,7 @@ import com.intellij.psi.*;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.RefactoringActionHandler;
import com.intellij.refactoring.introduceParameter.AbstractJavaInplaceIntroducer;
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
import com.intellij.refactoring.util.occurrences.OccurrenceManager;
@@ -81,6 +82,14 @@ public abstract class AbstractInplaceIntroduceFieldPopup extends AbstractJavaInp
return new LocalSearchScope(myParentClass);
}
@Override
protected boolean startsOnTheSameElement(RefactoringActionHandler handler, PsiElement element) {
return super.startsOnTheSameElement(handler, element) ||
myParentClass != null &&
element instanceof PsiLocalVariable &&
myParentClass.findFieldByName(((PsiLocalVariable)element).getName(), false) != null;
}
protected PsiElement getAnchorElement() {
if (myAnchorIdx != -1 && myOccurrences[myAnchorIdx] != null) {
return myOccurrences[myAnchorIdx].getParent();