Allow resource variables in-place rename; Java in-place rename tests updated

This commit is contained in:
Roman Shevchenko
2011-03-01 11:42:09 +01:00
parent beab19875d
commit 8f62093a5c
11 changed files with 70 additions and 43 deletions
@@ -111,8 +111,9 @@ public class JavaRefactoringSupportProvider extends RefactoringSupportProvider {
SearchScope useScope = elementToRename.getManager().getSearchHelper().getUseScope(elementToRename);
if (!(useScope instanceof LocalSearchScope)) return false;
PsiElement[] scopeElements = ((LocalSearchScope) useScope).getScope();
if (scopeElements.length > 1 && // assume there are no elements with use scopes with holes in'em
!isElementWithComment(scopeElements)) return false; // except a case of element and it's doc comment
if (scopeElements.length > 1 && // assume there are no elements with use scopes with holes in them
!isElementWithComment(scopeElements) && // ... except a case of element and it's doc comment
!isResourceVariable(scopeElements)) return false; // ... and badly scoped resource variables
PsiFile containingFile = elementToRename.getContainingFile();
return PsiTreeUtil.isAncestor(containingFile, scopeElements[0], false);
}
@@ -129,4 +130,10 @@ public class JavaRefactoringSupportProvider extends RefactoringSupportProvider {
return comment != null && comment.getOwner() == owner;
}
private static boolean isResourceVariable(final PsiElement[] scopeElements) {
return scopeElements.length == 2 &&
scopeElements[0] instanceof PsiResourceList &&
scopeElements[1] instanceof PsiCodeBlock;
}
}