void (@NotNull PsiLambdaExpression lambda) { super.visitLambdaExpression(lambda); PsiType type = lambda.getFunctionalInterfaceType(); PsiElement parent = PsiUtil.skipParenthesizedExprUp(lambda.getParent()); if (parent instanceof PsiTypeCastExpression && ((PsiTypeCastExpression)parent).getType() instanceof PsiIntersectionType) { return; } PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 2 || !PsiTypesUtil.classNameEquals(type, CommonClassNames.JAVA_UTIL_COMPARATOR)) { return; } String replacementText = generateSimpleCombinator(lambda, parameters[0], parameters[1]); if (replacementText != null) { if (!LambdaUtil.isSafeLambdaReplacement(lambda, replacementText)) return; String qualifiedName = Objects.requireNonNull(StringUtil.substringBefore(replacementText, "(")); @NonNls String methodName = "Comparator." + StringUtil.getShortName(qualifiedName); final String problemMessage = InspectionGadgetsBundle.message("inspection.comparator.combinators.description2", methodName); holder.registerProblem(lambda, problemMessage, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new ReplaceWithComparatorFix(CommonQuickFixBundle.message("fix.replace.with.x", methodName))); return; } if (lambda.getBody() instanceof PsiCodeBlock) { PsiStatement[] statements = ((PsiCodeBlock)lambda.getBody()).getStatements(); List<ComparisonBlock> blocks = extractComparisonChain(statements, parameters[0], parameters[1]); if (blocks == null) return; String chainCombinator = generateChainCombinator(blocks, parameters[0], parameters[1]); if (chainCombinator == null) return; if (!LambdaUtil.isSafeLambdaReplacement(lambda, chainCombinator)) return; final String problemMessage = InspectionGadgetsBundle.message("inspection.comparator.combinators.description"); holder.registerProblem(lambda, problemMessage, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new ReplaceWithComparatorFix(InspectionGadgetsBundle.message("inspection.comparator.combinators.fix.chain"))); } }