<commit_before>package cml.language.features;

import cml.language.foundation.ScopeBase;
import cml.language.generated.Expression;
import cml.language.generated.Type;
import cml.language.types.TypeParameter;
import org.jetbrains.annotations.Nullable;
import org.jooq.lambda.Seq;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static java.lang.String.format;
import static java.util.Collections.unmodifiableList;
import static org.jooq.lambda.Seq.*;

public class Function extends ScopeBase
{
    private String name;
    private Type type;
    private List<TypeParameter> typeParams;

    public Function(final String name, final Type type, final Stream<FunctionParameter> parameters)
    {
        this(null, name, type, parameters);
    }

    public Function(@Nullable final TempModule module, final String name, final Type type, final Stream<FunctionParameter> parameters)
    {
        this(module, name, type, parameters, empty(), null);
    }

    public Function(@Nullable final TempModule module, final String name, final Type type, final Stream<FunctionParameter> parameters, final Seq<TypeParameter> typeParams, final @Nullable Expression expression)
    {
        super(module, seq(concat(seq(parameters), seq(Optional.ofNullable(expression)))).toList());

        this.name = name;
        this.type = type;
        this.typeParams = typeParams.toList();
    }

    public String getName()
    {
        return name;
    }

    public Type getType()
    {
        return type;
    }

    public List<FunctionParameter> getParameters()
    {
        return seq(getMembers()).filter(m -> m instanceof FunctionParameter)
                                .cast(FunctionParameter.class)
                                .toList();
    }

    public List<TypeParameter> getTypeParams()
    {
        return unmodifiableList(typeParams);
    }

    public Optional<Expression> getExpression()<commit_msg>Inferring result type of functions defined by expressions.<commit_after>package cml.language.features;

import cml.language.foundation.ScopeBase;
import cml.language.generated.Expression;
import cml.language.generated.Type;
import cml.language.types.TypeParameter;
import org.jetbrains.annotations.Nullable;
import org.jooq.lambda.Seq;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static cml.language.generated.UndefinedType.createUndefinedType;
import static java.lang.String.format;
import static java.util.Collections.unmodifiableList;
import static org.jooq.lambda.Seq.*;

public class Function extends ScopeBase
{
    private String name;
    private Type type;
    private List<TypeParameter> typeParams;

    public Function(final String name, final Type type, final Stream<FunctionParameter> parameters)
    {
        this(null, name, type, parameters);
    }

    public Function(@Nullable final TempModule module, final String name, final Type type, final Stream<FunctionParameter> parameters)
    {
        this(module, name, type, parameters, empty(), null);
    }

    public Function(@Nullable final TempModule module, final String name, final Type type, final Stream<FunctionParameter> parameters, final Seq<TypeParameter> typeParams, final @Nullable Expression expression)
    {
        super(module, seq(concat(seq(parameters), seq(Optional.ofNullable(expression)))).toList());

        this.name = name;
        this.type = type;
        this.typeParams = typeParams.toList();
    }

    public String getName()
    {
        return name;
    }

    public Type getType()
    {
        return type == null && getExpression().isPresent() ? getExpression().get().getType() : (type == null ? createUndefinedType("Unable to find type of function: " + getDiagnosticId()) : type);
    }

    public List<FunctionParameter> getParameters()
    {
        return seq(getMembers()).filter(m -> m instanceof FunctionParameter)
                                .cast(FunctionParameter.class)
                                .toList();
    }

    public List<TypeParameter> getTypeParams()
    {
        return unmodifiableList(typeParams);
    }

    public Optional<Expression> getExpression()
{'fraction_non_alphanumeric': 0.09792709077912795, 'fraction_numerical': 0.0, 'mean_word_length': 3.38662486938349, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4742765', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1087, 'n_words': 292}