boolean (PsiCodeBlock body, PsiMethod method, PsiMethod superMethod) { final PsiStatement[] statements = body.getStatements(); if (statements.length != 1) { return false; } final PsiStatement statement = statements[0]; final PsiExpression expression; if (PsiTypes.voidType().equals(method.getReturnType())) { if (statement instanceof PsiExpressionStatement expressionStatement) { expression = expressionStatement.getExpression(); } else { return false; } } else { if (statement instanceof PsiReturnStatement returnStatement) { expression = PsiUtil.skipParenthesizedExprDown(returnStatement.getReturnValue()); } else { return false; } } if (!(expression instanceof PsiMethodCallExpression methodCallExpression)) { return false; } if (!MethodCallUtils.isSuperMethodCall(methodCallExpression, method)) { return false; } final PsiMethod targetMethod = methodCallExpression.resolveMethod(); if (targetMethod != superMethod) { return false; } if (!collectCommentText(method).isEmpty()) { return false; } if (superMethod.hasModifierProperty(PsiModifier.PROTECTED)) { final PsiJavaFile file = (PsiJavaFile)method.getContainingFile(); // implementing a protected method in another package makes it available to that package. PsiPackage aPackage = JavaPsiFacade.getInstance(method.getProject()).findPackage(file.getPackageName()); if (aPackage == null) { return false; // when package statement is incorrect } final PackageScope scope = new PackageScope(aPackage, false, false); if (isOnTheFly()) { final PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(method.getProject()); final PsiSearchHelper.SearchCostResult cost = searchHelper.isCheapEnoughToSearch(method.getName(), scope, null, null); if (cost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES) { return true; } if (cost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) { return false; } } final Query<PsiReference> search = ReferencesSearch.search(method, scope); final PsiClass containingClass = method.getContainingClass(); for (PsiReference reference : search) { if (!PsiTreeUtil.isAncestor(containingClass, reference.getElement(), true)) { return false; } } } return areSameArguments(methodCallExpression, method); }