<commit_before>import java.net._
import java.io.File
import scala.reflect.runtime.{universe => ru}
import scala.tools.reflect.ToolBox
import scala.meta._
import scala.meta.syntactic.parsers._
import scala.meta.syntactic.show._
import scala.meta.internal.hosts.scalacompiler.scalahost.Scalahost
import scala.meta.semantic.{Host => PalladiumHost}
import scala.meta.internal.hosts.scalacompiler.scalahost.{Host => OurHost}

trait ToolboxHarness {
  def typecheckConvertAndPrettyprint(code: String): String = {
    val pluginJar = System.getProperty("sbt.classpaths.package.plugin")
    val compilationClasspath = System.getProperty("sbt.classpaths.test.tests").split(File.pathSeparatorChar.toString).map(path => new URL("file://" + path))
    val classloader = new URLClassLoader(compilationClasspath)
    val mirror = ru.runtimeMirror(classloader)
    val tb = mirror.mkToolBox(options = "-Xplugin:" + pluginJar + " -Xplugin-require:scalahost")
    val tree = tb.parse(code)
    val result: String = null
    def cont(compilerApi: AnyRef): Unit = {
      val m_compiler = compilerApi.getClass.getDeclaredMethod("compiler")
      val compiler = m_compiler.invoke(compilerApi).asInstanceOf[scala.tools.nsc.Global]

      val m_importer = compilerApi.getClass.getDeclaredMethod("importer")
      val importer = m_importer.invoke(compilerApi).asInstanceOf[compiler.Importer { val from: ru.type }]
      val ctree: compiler.Tree = importer.importTree(tree)
      import compiler._
      import analyzer._
      val run = new Run
      phase = run.namerPhase
      globalPhase = run.namerPhase
      val namer = newNamer(rootContext(NoCompilationUnit))
      namer.enterSym(ctree)
      phase = run.typerPhase
      globalPhase = run.typerPhase
      val typer = newTyper(rootContext(NoCompilationUnit))
      val ttree = typer.typed(ctree).asInstanceOf[compiler.Tree]
      println(ttree)

      val h = Scalahost(compiler).asInstanceOf[PalladiumHost with OurHost[compiler.type]]
      val result = ttree match {
        case term: TermTree => h.toPalladium(term, classOf[Term])
        case member: MemberDef => h.toPalladium(member, classOf[Stmt.Template])
        case other => h.toPalladium(other, classOf[Stmt.TopLevel])
      }
      println(result.show[Code])
      println(result.show[Raw])
      ???
    }
    val m_withCompilerApi = tb.getClass.getDeclaredMethod("withCompilerApi")
    val o_withCompilerApi = m_withCompilerApi.invoke(tb)
    val m_apply = o_withCompilerApi.getClass.getDeclaredMethods.find(_.getName == "apply").get
    m_apply.invoke(o_withCompilerApi, cont _)
    result
  }
}<commit_msg>moving forward with the test infrastructure<commit_after>import java.net._
import java.io.File
import scala.reflect.runtime.{universe => ru}
import scala.tools.reflect.ToolBox
import scala.meta._
import scala.meta.syntactic.parsers._
import scala.meta.syntactic.show._
import scala.meta.internal.hosts.scalacompiler.scalahost.Scalahost
import scala.meta.semantic.{Host => PalladiumHost}
import scala.meta.internal.hosts.scalacompiler.scalahost.{Host => OurHost}

trait ToolboxHarness {
  def typecheckConvertAndPrettyprint(code: String): String = {
    val pluginJar = System.getProperty("sbt.classpaths.package.plugin")
    val compilationClasspath = System.getProperty("sbt.classpaths.test.tests").split(File.pathSeparatorChar.toString).map(path => new URL("file://" + path))
    val classloader = new URLClassLoader(compilationClasspath, getClass.getClassLoader)
    val mirror = ru.runtimeMirror(classloader)
    val tb = mirror.mkToolBox(options = "-Xplugin:" + pluginJar + " -Xplugin-require:scalahost")
    var result: String = null
    def cont(compilerApi: AnyRef): Unit = {
      val m_compiler = compilerApi.getClass.getDeclaredMethod("compiler")
      val compiler = m_compiler.invoke(compilerApi).asInstanceOf[scala.tools.nsc.Global]
      import compiler._
      import analyzer._

      val run = new Run
      phase = run.parserPhase
      globalPhase = run.parserPhase
      val unit = compiler.newCompilationUnit(code, "<memory>")
      unit.body = compiler.newUnitParser(unit).parse()
      phase = run.namerPhase
      globalPhase = run.namerPhase
      newNamer(rootContext(unit)).enterSym(unit.body)
      phase = run.phaseNamed("packageobjects")
      globalPhase = run.phaseNamed("packageobjects")
      val openPackageObjectsTraverser = new Traverser {
        override def traverse(tree: Tree): Unit = tree match {
          case ModuleDef(_, _, _) =>
            if (tree.symbol.name == nme.PACKAGEkw) {
              openPackageModule(tree.symbol, tree.symbol.owner)
            }
          case ClassDef(_, _, _, _) => () // make it fast
          case _ => super.traverse(tree)
        }
      }
      openPackageObjectsTraverser(unit.body)
      phase = run.typerPhase
      globalPhase = run.typerPhase
      unit.body = newTyper(rootContext(unit)).typed(unit.body).asInstanceOf[compiler.Tree]
      for (workItem <- unit.toCheck) workItem()

      val h = Scalahost(compiler).asInstanceOf[PalladiumHost with OurHost[compiler.type]]
      val ptree = h.toPalladium(unit.body, classOf[Aux.CompUnit])
      result = ptree.show[Code]
    }
    val m_withCompilerApi = tb.getClass.getDeclaredMethod("withCompilerApi")
    val o_withCompilerApi = m_withCompilerApi.invoke(tb)
    val m_apply = o_withCompilerApi.getClass.getDeclaredMethods.find(_.getName == "apply").get
    m_apply.invoke(o_withCompilerApi, cont _)
    result
  }
}
{'fraction_non_alphanumeric': 0.11058307439225004, 'fraction_numerical': 0.0, 'mean_word_length': 3.7957931638913234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '7047154', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1685, 'n_words': 304}