<commit_before>package org.smoothbuild.lang.base.define;

import static java.util.Objects.requireNonNull;
import static org.smoothbuild.lang.base.define.Item.toItemSignatures;
import static org.smoothbuild.lang.base.type.Side.LOWER;
import static org.smoothbuild.lang.base.type.Type.inferVariableBounds;
import static org.smoothbuild.lang.expr.Expression.toTypes;

import org.smoothbuild.lang.base.type.FunctionType;
import org.smoothbuild.lang.base.type.Type;
import org.smoothbuild.lang.expr.Expression;

import com.google.common.collect.ImmutableList;

/**
 * This class and all its subclasses are immutable.
 */
public abstract class Function extends Referencable {
  public static final String PARENTHESES = "()";
  private final Type resultType;
  private final ImmutableList<Item> parameters;

  public Function(Type resultType, ModulePath modulePath, String name,
      ImmutableList<Item> parameters, Location location) {
    super(functionType(resultType, parameters), modulePath, name, location);
    this.resultType = requireNonNull(resultType);
    this.parameters = requireNonNull(parameters);
  }

  private static FunctionType functionType(Type resultType, ImmutableList<Item> parameters) {
    return new FunctionType(resultType, toItemSignatures(parameters));
  }

  @Override
  public FunctionType type() {
    return (FunctionType) super.type();
  }

  @Override
  public String extendedName() {
    return name() + PARENTHESES;
  }

  public Type resultType() {
    return resultType;
  }

  public ImmutableList<Item> parameters() {
    return parameters;
  }

  public Type inferResultType(ImmutableList<Expression> arguments) {
    var variableToBounds =
        inferVariableBounds(type().parameterTypes(), toTypes(arguments), LOWER);
    return resultType().mapVariables(variableToBounds, LOWER);
  }

  public boolean canBeCalledArgless() {
    return parameters.stream()
        .allMatch(p -> p.defaultValue().isPresent());
  }
}
<commit_msg>refactored Function<commit_after>package org.smoothbuild.lang.base.define;

import static java.util.Objects.requireNonNull;
import static org.smoothbuild.lang.base.define.Item.toItemSignatures;
import static org.smoothbuild.lang.base.type.Side.LOWER;
import static org.smoothbuild.lang.base.type.Type.inferVariableBounds;
import static org.smoothbuild.lang.expr.Expression.toTypes;

import org.smoothbuild.lang.base.type.FunctionType;
import org.smoothbuild.lang.base.type.Type;
import org.smoothbuild.lang.expr.Expression;

import com.google.common.collect.ImmutableList;

/**
 * This class and all its subclasses are immutable.
 */
public abstract class Function extends Referencable {
  public static final String PARENTHESES = "()";
  private final ImmutableList<Item> parameters;

  public Function(Type resultType, ModulePath modulePath, String name,
      ImmutableList<Item> parameters, Location location) {
    super(functionType(resultType, parameters), modulePath, name, location);
    this.parameters = requireNonNull(parameters);
  }

  private static FunctionType functionType(Type resultType, ImmutableList<Item> parameters) {
    return new FunctionType(resultType, toItemSignatures(parameters));
  }

  @Override
  public FunctionType type() {
    return (FunctionType) super.type();
  }

  @Override
  public String extendedName() {
    return name() + PARENTHESES;
  }

  public Type resultType() {
    return type().resultType();
  }

  public ImmutableList<Item> parameters() {
    return parameters;
  }

  public Type inferResultType(ImmutableList<Expression> arguments) {
    var variableToBounds =
        inferVariableBounds(type().parameterTypes(), toTypes(arguments), LOWER);
    return resultType().mapVariables(variableToBounds, LOWER);
  }

  public boolean canBeCalledArgless() {
    return parameters.stream()
        .allMatch(p -> p.defaultValue().isPresent());
  }
}

{'fraction_non_alphanumeric': 0.10247805885389778, 'fraction_numerical': 0.0, 'mean_word_length': 4.844645550527903, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '7588186', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1081, 'n_words': 247}