diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-05-05 15:22:29 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-08-19 15:37:22 +0200 |
commit | 8e39b71b29afd7951745dbaf957eade0e9f51434 (patch) | |
tree | 720ab08f15936a8c0cd4cf5da5f792fcdab3150b /dottydoc/jvm/test/BaseTest.scala | |
parent | bc594c81c6ce8c696dde2f7668132952e83b383a (diff) | |
download | dotty-8e39b71b29afd7951745dbaf957eade0e9f51434.tar.gz dotty-8e39b71b29afd7951745dbaf957eade0e9f51434.tar.bz2 dotty-8e39b71b29afd7951745dbaf957eade0e9f51434.zip |
Fix repeated traversal of packages when generating docs (5x speedup)
Diffstat (limited to 'dottydoc/jvm/test/BaseTest.scala')
-rw-r--r-- | dottydoc/jvm/test/BaseTest.scala | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/dottydoc/jvm/test/BaseTest.scala b/dottydoc/jvm/test/BaseTest.scala new file mode 100644 index 000000000..2703f8169 --- /dev/null +++ b/dottydoc/jvm/test/BaseTest.scala @@ -0,0 +1,58 @@ +package dotty.tools +package dottydoc + +import dotc.core.Contexts +import Contexts.{ Context, ContextBase, FreshContext } +import dotc.util.SourceFile +import dotc.core.Phases.Phase +import dotc.typer.FrontEnd +import dottydoc.core.Phases.DocPhase + +trait DottyTest { + dotty.tools.dotc.parsing.Scanners // initialize keywords + + implicit var ctx: FreshContext = { + val base = new ContextBase + import base.settings._ + val ctx = base.initialCtx.fresh + ctx.setSetting(ctx.settings.language, List("Scala2")) + ctx.setSetting(ctx.settings.YkeepComments, true) + ctx.setSetting(ctx.settings.YDocNoWrite, true) + base.initialize()(ctx) + ctx + } + + private def compilerWithChecker(assertion: DocPhase => Unit) = new DottyDocCompiler { + private[this] val docPhase = new DocPhase + + override def phases = + List(new FrontEnd) :: + List(docPhase) :: + List(new Phase { + def phaseName = "assertionPhase" + override def run(implicit ctx: Context): Unit = assertion(docPhase) + }) :: + Nil + } + + def checkSource(source: String)(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compile(source) + } + + def checkFiles(sources: List[String])(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compile(sources) + } + + def checkSources(sourceFiles: List[SourceFile])(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compileSources(sourceFiles) + } +} |