forbid introduce refactorings on resource from try-with-resources (IDEA-66788 )

This commit is contained in:
anna
2011-03-21 16:45:28 +01:00
parent f50b2133cc
commit 7d96e45dfc
3 changed files with 20 additions and 0 deletions
@@ -70,6 +70,12 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler {
}
protected boolean invokeImpl(final Project project, final PsiLocalVariable localVariable, final Editor editor) {
final PsiElement parent = localVariable.getParent();
if (!(parent instanceof PsiDeclarationStatement)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.local.or.expression.name"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, getHelpID());
return false;
}
final LocalToFieldHandler localToFieldHandler = new LocalToFieldHandler(project, true){
@Override
protected Settings showRefactoringDialog(PsiClass aClass,
@@ -155,6 +155,12 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler {
}
protected boolean invokeImpl(final Project project, PsiLocalVariable localVariable, final Editor editor) {
final PsiElement parent = localVariable.getParent();
if (!(parent instanceof PsiDeclarationStatement)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.local.or.expression.name"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, getHelpID());
return false;
}
LocalToFieldHandler localToFieldHandler = new LocalToFieldHandler(project, false){
@Override
protected Settings showRefactoringDialog(PsiClass aClass,
@@ -127,6 +127,14 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R
return false;
}
if (localVar != null) {
final PsiElement parent = localVar.getParent();
if (!(parent instanceof PsiDeclarationStatement)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.local.or.expression.name"));
showErrorMessage(myProject, message, editor);
return false;
}
}
if (method == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME));