<commit_before>package org.smoothbuild.parse;

import static org.smoothbuild.parse.DefinedFunctionsCreator.createDefinedFunctions;
import static org.smoothbuild.parse.DependencyCollector.collectDependencies;
import static org.smoothbuild.parse.DependencySorter.sortDependencies;
import static org.smoothbuild.parse.FunctionsCollector.collectFunctions;
import static org.smoothbuild.parse.ScriptParser.parseScript;
import static org.smoothbuild.parse.UndefinedFunctionsDetector.detectUndefinedFunctions;

import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;

import org.smoothbuild.antlr.SmoothParser.FunctionContext;
import org.smoothbuild.antlr.SmoothParser.ModuleContext;
import org.smoothbuild.function.base.Module;
import org.smoothbuild.function.base.Name;
import org.smoothbuild.function.def.DefinedFunction;
import org.smoothbuild.plugin.Path;
import org.smoothbuild.problem.DetectingErrorsProblemsListener;
import org.smoothbuild.problem.ProblemsListener;

public class ModuleParser {
  private final ImportedFunctions importedFunctions;

  @Inject
  public ModuleParser(ImportedFunctions importedFunctions) {
    this.importedFunctions = importedFunctions;
  }

  public Module createModule(ProblemsListener problemsListener, InputStream inputStream,
      Path scriptFile) {
    DetectingErrorsProblemsListener problems = new DetectingErrorsProblemsListener(problemsListener);
    ModuleContext module = parseScript(problemsListener, inputStream, scriptFile);
    if (problems.errorDetected()) {
      return null;
    }

    Map<String, FunctionContext> functions = collectFunctions(problemsListener, importedFunctions,
        module);
    if (problems.errorDetected()) {
      return null;
    }

    Map<String, Set<Dependency>> dependencies = collectDependencies(module);

    detectUndefinedFunctions(problems, importedFunctions, dependencies);
    if (problems.errorDetected()) {
      return null;
    }

    List<String> sorted = sortDependencies(problemsListener, importedFunctions, dependencies);
    if (problems.errorDetected()) {
      return null;
    }

    Map<Name, DefinedFunction> definedFunctions = createDefinedFunctions(problems,
        importedFunctions, functions, sorted);
    if (problems.errorDetected()) {
      return null;
    }

    return new Module(definedFunctions);<commit_msg>fixed ModuleParser to use correct ProblemsListener<commit_after>package org.smoothbuild.parse;

import static org.smoothbuild.parse.DefinedFunctionsCreator.createDefinedFunctions;
import static org.smoothbuild.parse.DependencyCollector.collectDependencies;
import static org.smoothbuild.parse.DependencySorter.sortDependencies;
import static org.smoothbuild.parse.FunctionsCollector.collectFunctions;
import static org.smoothbuild.parse.ScriptParser.parseScript;
import static org.smoothbuild.parse.UndefinedFunctionsDetector.detectUndefinedFunctions;

import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;

import org.smoothbuild.antlr.SmoothParser.FunctionContext;
import org.smoothbuild.antlr.SmoothParser.ModuleContext;
import org.smoothbuild.function.base.Module;
import org.smoothbuild.function.base.Name;
import org.smoothbuild.function.def.DefinedFunction;
import org.smoothbuild.plugin.Path;
import org.smoothbuild.problem.DetectingErrorsProblemsListener;
import org.smoothbuild.problem.ProblemsListener;

public class ModuleParser {
  private final ImportedFunctions importedFunctions;

  @Inject
  public ModuleParser(ImportedFunctions importedFunctions) {
    this.importedFunctions = importedFunctions;
  }

  public Module createModule(ProblemsListener problemsListener, InputStream inputStream,
      Path scriptFile) {
    DetectingErrorsProblemsListener problems = new DetectingErrorsProblemsListener(problemsListener);
    return createModule(problems, inputStream, scriptFile);
  }

  private Module createModule(DetectingErrorsProblemsListener problems, InputStream inputStream,
      Path scriptFile) {
    ModuleContext module = parseScript(problems, inputStream, scriptFile);
    if (problems.errorDetected()) {
      return null;
    }

    Map<String, FunctionContext> functions = collectFunctions(problems, importedFunctions, module);
    if (problems.errorDetected()) {
      return null;
    }

    Map<String, Set<Dependency>> dependencies = collectDependencies(module);

    detectUndefinedFunctions(problems, importedFunctions, dependencies);
    if (problems.errorDetected()) {
      return null;
    }

    List<String> sorted = sortDependencies(problems, importedFunctions, dependencies);
    if (problems.errorDetected()) {
      return null;
    }

    Map<Name, DefinedFunction> definedFunctions = createDefinedFunctions(problems,
        importedFunctions, functions, sorted);
    if (problems.errorDetected()) {
      return null;
    }

    return new Module(definedFunctions);
{'fraction_non_alphanumeric': 0.08129265355279004, 'fraction_numerical': 0.0, 'mean_word_length': 5.565217391304348, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6533747', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1281, 'n_words': 264}