<commit_before>package org.smoothbuild.lang.expr;

import static org.smoothbuild.lang.base.Scope.scope;
import static org.smoothbuild.lang.type.GenericTypeMap.inferMapping;
import static org.smoothbuild.task.base.Evaluator.identityEvaluator;

import java.util.List;

import org.smoothbuild.db.values.ValuesDb;
import org.smoothbuild.lang.base.DefinedFunction;
import org.smoothbuild.lang.base.Location;
import org.smoothbuild.lang.base.Scope;
import org.smoothbuild.lang.type.ConcreteType;
import org.smoothbuild.lang.type.GenericTypeMap;
import org.smoothbuild.task.base.Evaluator;

public class DefinedCallExpression extends Expression {
  private final DefinedFunction function;

  public DefinedCallExpression(DefinedFunction definedFunction,
      List<? extends Expression> arguments, Location location) {
    super(arguments, location);
    this.function = definedFunction;
  }

  @Override
  public Evaluator createEvaluator(ValuesDb valuesDb, Scope<Evaluator> scope) {
    List<Evaluator> arguments = childrenEvaluators(valuesDb, scope);
    GenericTypeMap<ConcreteType> mapping =
        inferMapping(function.parameterTypes(), evaluatorTypes(arguments));
    ConcreteType actualResultType = mapping.applyTo(function.signature().type());
    Evaluator evaluator = function.body().createEvaluator(valuesDb, functionScope(arguments))
        .convertIfNeeded(actualResultType);
    return namedEvaluator(actualResultType, function.name(), evaluator);
  }

  private Scope<Evaluator> functionScope(List<Evaluator> arguments) {
    Scope<Evaluator> functionScope = scope();
    for (int i = 0; i < arguments.size(); i++) {
      functionScope.add(function.parameters().get(i).name(), arguments.get(i));
    }
    return functionScope;
  }

  private Evaluator namedEvaluator(ConcreteType type, String name, Evaluator evaluator) {
    return identityEvaluator(type, name, false, evaluator, location());
  }
}<commit_msg>refactored DefinedCallExpression<commit_after>package org.smoothbuild.lang.expr;

import static org.smoothbuild.lang.base.Scope.scope;
import static org.smoothbuild.lang.type.GenericTypeMap.inferMapping;
import static org.smoothbuild.task.base.Evaluator.identityEvaluator;

import java.util.List;

import org.smoothbuild.db.values.ValuesDb;
import org.smoothbuild.lang.base.DefinedFunction;
import org.smoothbuild.lang.base.Location;
import org.smoothbuild.lang.base.Scope;
import org.smoothbuild.lang.type.ConcreteType;
import org.smoothbuild.task.base.Evaluator;

public class DefinedCallExpression extends Expression {
  private final DefinedFunction function;

  public DefinedCallExpression(DefinedFunction definedFunction,
      List<? extends Expression> arguments, Location location) {
    super(arguments, location);
    this.function = definedFunction;
  }

  @Override
  public Evaluator createEvaluator(ValuesDb valuesDb, Scope<Evaluator> scope) {
    List<Evaluator> arguments = childrenEvaluators(valuesDb, scope);
    ConcreteType actualResultType =
        inferMapping(function.parameterTypes(), evaluatorTypes(arguments))
            .applyTo(function.signature().type());
    Evaluator evaluator = function
        .body()
        .createEvaluator(valuesDb, functionScope(arguments))
        .convertIfNeeded(actualResultType);
    return namedEvaluator(actualResultType, function.name(), evaluator);
  }

  private Scope<Evaluator> functionScope(List<Evaluator> arguments) {
    Scope<Evaluator> functionScope = scope();
    for (int i = 0; i < arguments.size(); i++) {
      functionScope.add(function.parameters().get(i).name(), arguments.get(i));
    }
    return functionScope;
  }

  private Evaluator namedEvaluator(ConcreteType type, String name, Evaluator evaluator) {
    return identityEvaluator(type, name, false, evaluator, location());
  }
}
{'fraction_non_alphanumeric': 0.10397473019215583, 'fraction_numerical': 0.0005264543300868649, 'mean_word_length': 5.260296540362439, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, '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': '5107515', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1078, 'n_words': 215}