void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { if (!(element instanceof PsiLambdaExpression lambda)) return; PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 2) return; boolean keepParameterTypes = parameters[0].getTypeElement() != null; if (lambda.getBody() instanceof PsiCodeBlock) { PsiStatement[] statements = ((PsiCodeBlock)lambda.getBody()).getStatements(); if(statements.length > 1) { List<ComparisonBlock> chain = extractComparisonChain(statements, parameters[0], parameters[1]); if (chain == null) return; String code = generateChainCombinator(chain, parameters[0], parameters[1]); if (code == null) return; PsiElement result = new CommentTracker().replaceAndRestoreComments(lambda, code); RemoveRedundantTypeArgumentsUtil.removeRedundantTypeArguments(result); LambdaCanBeMethodReferenceInspection.replaceAllLambdasWithMethodReferences(result); CodeStyleManager.getInstance(project).reformat(JavaCodeStyleManager.getInstance(project).shortenClassReferences(result)); return; } } String text = generateSimpleCombinator(lambda, parameters[0], parameters[1]); if (text == null) return; PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiExpression replacement = factory.createExpressionFromText(text, element); PsiMethodCallExpression result = (PsiMethodCallExpression)lambda.replace(replacement); normalizeLambda(ArrayUtil.getFirstElement(result.getArgumentList().getExpressions()), factory, keepParameterTypes); CodeStyleManager.getInstance(project).reformat(JavaCodeStyleManager.getInstance(project).shortenClassReferences(result)); }