diff --git a/java/java-impl/src/com/intellij/refactoring/invertBoolean/JavaInvertBooleanDelegate.java b/java/java-impl/src/com/intellij/refactoring/invertBoolean/JavaInvertBooleanDelegate.java index 8b09aec1f867..98189b3a4881 100644 --- a/java/java-impl/src/com/intellij/refactoring/invertBoolean/JavaInvertBooleanDelegate.java +++ b/java/java-impl/src/com/intellij/refactoring/invertBoolean/JavaInvertBooleanDelegate.java @@ -66,13 +66,22 @@ public class JavaInvertBooleanDelegate extends InvertBooleanDelegate { return null; } - if (var instanceof PsiParameter && ((PsiParameter)var).getDeclarationScope() instanceof PsiMethod) { - final PsiMethod method = (PsiMethod)((PsiParameter)var).getDeclarationScope(); - final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor")); - if (superMethod == null) { + if (var instanceof PsiParameter) { + final PsiElement declarationScope = ((PsiParameter)var).getDeclarationScope(); + if (declarationScope instanceof PsiMethod) { + final PsiMethod method = (PsiMethod)declarationScope; + final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor")); + if (superMethod == null) { + return null; + } + var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex((PsiParameter)var)]; + } + else if (declarationScope instanceof PsiForeachStatement) { + CommonRefactoringUtil.showErrorHint(project, editor, + RefactoringBundle.message("invert.boolean.foreach"), + InvertBooleanHandler.REFACTORING_NAME, InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID); return null; } - var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex((PsiParameter)var)]; } return var; } diff --git a/platform/platform-resources-en/src/messages/RefactoringBundle.properties b/platform/platform-resources-en/src/messages/RefactoringBundle.properties index b998aecd1dca..3f810b29548a 100644 --- a/platform/platform-resources-en/src/messages/RefactoringBundle.properties +++ b/platform/platform-resources-en/src/messages/RefactoringBundle.properties @@ -713,6 +713,7 @@ invert.boolean.elements.header={0} to invert please.enter.a.valid.name.for.inverted.element=Please enter a valid name for inverted {0} invert.boolean.name.of.inverted.element=&Name of inverted {0}: invert.0.1=Invert {0} {1} and its usages +invert.boolean.foreach=Foreach parameter initializer can't be inverted 0.is.a.part.of.method.hierarchy.do.you.want.to.delete.multiple.parameters={0} is a part of method hierarchy. Do you want to delete multiple parameters? 0.is.a.part.of.method.hierarchy.do.you.want.to.delete.multiple.type.parameters={0} is a part of method hierarchy. Do you want to delete multiple type parameters? move.inner.class.to.be.moved=Class to be moved