void (PsiLambdaExpression lambda) { PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 1) return; PsiParameter parameter = parameters[0]; PsiType type = PsiUtil.substituteTypeParameter(parameter.getType(), JAVA_UTIL_MAP_ENTRY, 1, true); PsiElement body = lambda.getBody(); if (body == null) return; List<PsiMethodCallExpression> calls = new ArrayList<>(); PsiLocalVariable declaration = null; for (PsiReferenceExpression ref : VariableAccessUtils.getVariableReferences(parameter, body)) { PsiMethodCallExpression call = ExpressionUtils.getCallForQualifier(ref); if (call != null) { calls.add(call); if (declaration == null) { PsiLocalVariable var = tryCast(PsiUtil.skipParenthesizedExprUp(call.getParent()), PsiLocalVariable.class); if (var != null && var.getParent() instanceof PsiDeclarationStatement && var.getParent().getParent() == body) { declaration = var; } } } } String name = declaration == null ? null : declaration.getName(); if (name == null) { name = new VariableNameGenerator(lambda, VariableKind.PARAMETER).byType(type).byName(myNames).generate(false); } for (PsiMethodCallExpression call : calls) { PsiElement result = new CommentTracker().replaceAndRestoreComments(call, name); if (call == body) { body = result; } } if (declaration != null) { new CommentTracker().deleteAndRestoreComments(declaration); } CommentTracker ct = new CommentTracker(); ct.replaceAndRestoreComments(lambda, name + "->" + ct.text(body)); }