<commit_before>package de.tuberlin.uebb.sl2.impl

import de.tuberlin.uebb.sl2.modules._
import java.io.File

trait ModuleResolverImpl extends ModuleResolver {
  this: Syntax with Errors with Configs with SignatureSerializer =>

  case class ImportError(what: String, where: Attribute) extends Error

  def inferDependencies(program: AST, config: Config) = program match {
    case Program(imports, _, _, _, _, attribute) =>
      //TODO: really deal with transitive imports and the like...
      errorMap(imports, resolveImport(config))
    case _ => throw new RuntimeException("")
  }

  def resolveImport(config: Config)(imp: Import): Either[Error, ResolvedImport] = imp match {
    case qi @ QualifiedImport(name, path, attr) =>
      for (
        file <- findImport(config, imp.path + ".signature", attr).right;
        signature <- importSignature(file).right
      ) yield ResolvedQualifiedImport(name, path, file, signature, qi)
    case ei @ ExternImport(path, attr) =>
      for (
        file <- findImport(config, imp.path + ".js", attr).right
      ) yield ResolvedExternImport(file, ei)
  }

  def findImport(config: Config, path: String, attr: Attribute): Either[Error, File] = {
    //TODO: look at places according to some defined classpath hierarchie etc.
    val files = List(new File(config.classpath, path), new File(path))
    files.find(_.canRead()).toRight(
      ImportError("Could not find " + quote(path) + " at " + files.map(_.getCanonicalPath()), attr))
  }

  def importSignature(file: File): Either[Error, Program] = {
    val signature = deserialize(file.getCanonicalPath())
    if (null == signature) {
      Left(ImportError("Failed to load signature " + file, EmptyAttribute))
    } else {
      Right(signature.asInstanceOf[Program])
    }
  }
}<commit_msg>fixed some path issues in moduleresolverimpl<commit_after>package de.tuberlin.uebb.sl2.impl

import de.tuberlin.uebb.sl2.modules._
import java.io.File

trait ModuleResolverImpl extends ModuleResolver {
  this: Syntax with Errors with Configs with SignatureSerializer =>

  case class ImportError(what: String, where: Attribute) extends Error

  def inferDependencies(program: AST, config: Config) = program match {
    case Program(imports, _, _, _, _, attribute) =>
      //TODO: really deal with transitive imports and the like...
      errorMap(imports, resolveImport(config))
    case _ => throw new RuntimeException("")
  }

  def resolveImport(config: Config)(imp: Import): Either[Error, ResolvedImport] = imp match {
    case qi @ QualifiedImport(name, path, attr) =>
      for (
        file <- findImport(config, imp.path + ".sl.signature", attr).right;
        signature <- importSignature(file).right
      ) yield ResolvedQualifiedImport(name, path, file, signature, qi)
    case ei @ ExternImport(path, attr) =>
      for (
        file <- findImport(config, imp.path + ".sl.js", attr).right
      ) yield ResolvedExternImport(file, ei)
  }

  def findImport(config: Config, path: String, attr: Attribute): Either[Error, File] = {
    //TODO: look at places according to some defined classpath hierarchie etc.
    val files = List(new File(config.classpath, path), new File(path))
    files.find(_.canRead()).toRight(
      ImportError("Could not find " + quote(path) + " at " + files.map(_.getCanonicalPath()), attr))
  }

  def importSignature(file: File): Either[Error, Program] = {
    val signature = deserialize(file.getCanonicalPath())
    if (null == signature) {
      Left(ImportError("Failed to load signature " + file, EmptyAttribute))
    } else {
      Right(signature.asInstanceOf[Program])
    }
  }
}
{'fraction_non_alphanumeric': 0.12144631520839083, 'fraction_numerical': 0.0011040574109853713, 'mean_word_length': 3.71875, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4627085', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1045, 'n_words': 295}