PsiElement (PsiElement element, Project project, Editor editor) { if (element instanceof PsiVariable var) { final PsiType returnType = var.getType(); if (!PsiTypes.booleanType().equals(returnType)) { CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle .getCannotRefactorMessage(JavaRefactoringBundle.message("invert.boolean.wrong.type")), InvertBooleanHandler.getRefactoringName(), InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID); return null; } if (var instanceof PsiParameter parameter) { final PsiElement declarationScope = parameter.getDeclarationScope(); if (declarationScope instanceof PsiMethod method) { final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method); if (superMethod == null) { return null; } var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex(parameter)]; } else if (declarationScope instanceof PsiForeachStatement) { CommonRefactoringUtil.showErrorHint(project, editor, JavaRefactoringBundle.message("invert.boolean.foreach"), InvertBooleanHandler.getRefactoringName(), InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID); return null; } } return var; } else if (element instanceof PsiMethod) { final PsiMethod method = (PsiMethod)element; final PsiType returnType = method.getReturnType(); if (!PsiTypes.booleanType().equals(returnType)) { CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(JavaRefactoringBundle.message("invert.boolean.wrong.type")), InvertBooleanHandler.getRefactoringName(), InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID); return null; } return SuperMethodWarningUtil.checkSuperMethod(method); } return null; }