boolean (@NotNull PsiParameterListOwner method) { if (!(method instanceof PsiLambdaExpression lambda)) return false; PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(lambda); if (returnType == null) return false; PsiCodeBlock body = ObjectUtils.tryCast(lambda.getBody(), PsiCodeBlock.class); if (body == null) return false; PsiStatement[] statements = body.getStatements(); if (statements.length != 1 || !(statements[0] instanceof PsiExpressionStatement expressionStatement)) return false; PsiExpression expression = expressionStatement.getExpression(); PsiType expressionType = expression.getType(); if (expressionType == null || !returnType.isAssignableFrom(expressionType)) return false; PsiElementFactory factory = JavaPsiFacade.getElementFactory(lambda.getProject()); PsiReturnStatement returnStatement = (PsiReturnStatement)factory.createStatementFromText("return 0;", lambda); Objects.requireNonNull(returnStatement.getReturnValue()).replace(expression); CommentTracker tracker = new CommentTracker(); tracker.markUnchanged(expression); tracker.replaceAndRestoreComments(expressionStatement, returnStatement); return true; }