PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { @SuppressWarnings("unchecked") Class<? extends UMethod>[] hint = new Class[]{UMethod.class}; return UastHintedVisitorAdapter.create(holder.getFile().getLanguage(), new AbstractUastNonRecursiveVisitor() { @Override public boolean visitMethod(@NotNull UMethod method) { UElement anchor = method.getUastAnchor(); if (anchor == null) return true; PsiElement psiAnchor = anchor.getSourcePsi(); if (psiAnchor == null) return true; PsiMethod javaMethod = method.getJavaPsi(); final PsiType returnType = javaMethod.getReturnType(); if (returnType == null || returnType.equalsToText(CommonClassNames.JAVA_LANG_VOID)) { return true; } if (javaMethod.findSuperMethods().length != 0 || PsiUtil.canBeOverridden(javaMethod)) { return true; } List<UExpression> returnExpressions = new SmartList<>(); final UExpression body = method.getUastBody(); if (body == null) return true; body.accept(new AbstractUastVisitor() { @Override public boolean visitReturnExpression(@NotNull UReturnExpression node) { if (node.getJumpTarget() == method) { UExpression returnExpression = node.getReturnExpression(); if (returnExpression != null) { StreamEx.of(UastUtils.nonStructuralChildren(returnExpression)).into(returnExpressions); } } return super.visitReturnExpression(node); } }); if (returnExpressions.size() < 2) return true; String returnValue = RefMethodImpl.createReturnValueTemplate(returnExpressions.get(0)); if (returnValue != null && ContainerUtil.all(returnExpressions, returnExpression -> returnValue.equals(RefMethodImpl.createReturnValueTemplate(returnExpression)))) { String message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor", returnValue); holder.registerProblem(psiAnchor, message); } return true; } }, hint); }