diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-03 10:47:59 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-01-31 14:28:08 +0100 |
commit | 198464a0ef18b3d394a2fd456b98f53c3e95d2e1 (patch) | |
tree | f165ec3010e4c71f8e0df1a288af2d95b8fc3582 /doc-tool | |
parent | 25fde7896d27f31d2c1c0adfbff8e2b3e390ceaa (diff) | |
download | dotty-198464a0ef18b3d394a2fd456b98f53c3e95d2e1.tar.gz dotty-198464a0ef18b3d394a2fd456b98f53c3e95d2e1.tar.bz2 dotty-198464a0ef18b3d394a2fd456b98f53c3e95d2e1.zip |
Split Dottydoc.scala into separate files
Diffstat (limited to 'doc-tool')
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala | 35 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/DocDriver.scala | 50 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/DocFrontEnd.scala | 17 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/DottyDoc.scala | 85 | ||||
-rw-r--r-- | doc-tool/test/GenDocs.scala | 10 |
5 files changed, 107 insertions, 90 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala b/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala new file mode 100644 index 000000000..af4aaae4f --- /dev/null +++ b/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala @@ -0,0 +1,35 @@ +package dotty.tools +package dottydoc + +import core._ +import core.transform._ +import dotc.core.Phases.Phase +import dotc.Compiler + +/** Custom Compiler with phases for the documentation tool + * + * The idea here is to structure `dottydoc` around the new infrastructure. As + * such, dottydoc will itself be a compiler. It will, however, produce a format + * that can be used by other tools or web-browsers. + * + * Example: + * 1. Use the existing FrontEnd to typecheck the code being fed to dottydoc, + * wihtout discarding AnyVal interfaces + * 2. Create an AST that is serializable + * 3. Serialize to JS object + */ +class DocCompiler extends Compiler { + override def phases: List[List[Phase]] = List( + List(new DocFrontEnd), + List(new DocImplicitsPhase), + List(new DocASTPhase), + List(DocMiniTransformations(new UsecasePhase, + new DocstringPhase, + new LinkReturnTypes, + new LinkParamListTypes, + new LinkImplicitlyAddedTypes, + new LinkSuperTypes, + new AlternateConstructors, + new SortMembers)) + ) +} diff --git a/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala b/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala new file mode 100644 index 000000000..430fb8083 --- /dev/null +++ b/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala @@ -0,0 +1,50 @@ +package dotty.tools +package dottydoc + +import dotty.tools.dottydoc.util.syntax._ +import core.ContextDottydoc +import dotc.core.Contexts._ +import dotc.{ Compiler, Driver } +import model.Package +import model.json._ +import dotc.config._ +import dotc.core.Comments.ContextDoc + +/** `DocDriver` implements the main entry point to the Dotty documentation + * tool. It's methods are used by the external scala and java APIs. + */ +class DocDriver extends Driver { + import _root_.java.util.{ Map => JMap } + import scala.collection.JavaConverters._ + + override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = { + val ctx = rootCtx.fresh + val summary = CompilerCommand.distill(args)(ctx) + + ctx.setSettings(summary.sstate) + ctx.setSetting(ctx.settings.YkeepComments, true) + ctx.setSetting(ctx.settings.YnoInline, true) + ctx.setProperty(ContextDoc, new ContextDottydoc) + + val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx) + (fileNames, ctx) + } + + override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler + + def compiledDocs(args: Array[String]): collection.Map[String, Package] = { + val (fileNames, ctx) = setup(args, initCtx.fresh) + doCompile(newCompiler(ctx), fileNames)(ctx) + + ctx.docbase.packages + } + + def compiledDocsJava(args: Array[String]): JMap[String, Package] = + compiledDocs(args).asJava + + def indexToJson(index: collection.Map[String, Package]): String = + index.json + + def indexToJsonJava(index: JMap[String, Package]): String = + indexToJson(index.asScala) +} diff --git a/doc-tool/src/dotty/tools/dottydoc/DocFrontEnd.scala b/doc-tool/src/dotty/tools/dottydoc/DocFrontEnd.scala new file mode 100644 index 000000000..30c5e3e87 --- /dev/null +++ b/doc-tool/src/dotty/tools/dottydoc/DocFrontEnd.scala @@ -0,0 +1,17 @@ +package dotty.tools +package dottydoc + +import dotc.typer.FrontEnd +import dotc.core.Contexts.Context +import dotc.CompilationUnit + +/** `DocFrontEnd` uses the Dotty `FrontEnd` without discarding the AnyVal + * interfaces for Boolean, Int, Char, Long, Byte etc. + * + * It currently still throws away Java sources by overriding + * `discardAfterTyper`. + */ +class DocFrontEnd extends FrontEnd { + override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) = + unit.isJava +} diff --git a/doc-tool/src/dotty/tools/dottydoc/DottyDoc.scala b/doc-tool/src/dotty/tools/dottydoc/DottyDoc.scala deleted file mode 100644 index e6aaddb48..000000000 --- a/doc-tool/src/dotty/tools/dottydoc/DottyDoc.scala +++ /dev/null @@ -1,85 +0,0 @@ -package dotty.tools -package dottydoc - -import dotty.tools.dottydoc.util.syntax._ -import core._ -import core.transform._ -import dotc.config.CompilerCommand -import dotc.config.Printers.dottydoc -import dotc.core.Contexts._ -import dotc.core.Comments.ContextDoc -import dotc.core.Phases.Phase -import dotc.typer.FrontEnd -import dotc.{ CompilationUnit, Compiler, Driver, Run } -import io.PlainFile -import model.Package -import model.json._ - -import _root_.java.util.{ Map => JMap } - -/** Custom Compiler with phases for the documentation tool - * - * The idea here is to structure `dottydoc` around the new infrastructure. As - * such, dottydoc will itself be a compiler. It will, however, produce a format - * that can be used by other tools or web-browsers. - * - * Example: - * 1. Use the existing FrontEnd to typecheck the code being fed to dottydoc - * 2. Create an AST that is serializable - * 3. Serialize to JS object - */ -class DocCompiler extends Compiler { - override def phases: List[List[Phase]] = List( - List(new DocFrontEnd), - List(new DocImplicitsPhase), - List(new DocASTPhase), - List(DocMiniTransformations(new UsecasePhase, - new DocstringPhase, - new LinkReturnTypes, - new LinkParamListTypes, - new LinkImplicitlyAddedTypes, - new LinkSuperTypes, - new AlternateConstructors, - new SortMembers)) - ) -} - -class DocFrontEnd extends FrontEnd { - override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) = - unit.isJava -} - -class DocDriver extends Driver { - import scala.collection.JavaConverters._ - - override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = { - val ctx = rootCtx.fresh - val summary = CompilerCommand.distill(args)(ctx) - - ctx.setSettings(summary.sstate) - ctx.setSetting(ctx.settings.YkeepComments, true) - ctx.setSetting(ctx.settings.YnoInline, true) - ctx.setProperty(ContextDoc, new ContextDottydoc) - - val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx) - (fileNames, ctx) - } - - override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler - - def compiledDocs(args: Array[String]): collection.Map[String, Package] = { - val (fileNames, ctx) = setup(args, initCtx.fresh) - doCompile(newCompiler(ctx), fileNames)(ctx) - - ctx.docbase.packages - } - - def compiledDocsJava(args: Array[String]): JMap[String, Package] = - compiledDocs(args).asJava - - def indexToJson(index: collection.Map[String, Package]): String = - index.json - - def indexToJsonJava(index: JMap[String, Package]): String = - indexToJson(index.asScala) -} diff --git a/doc-tool/test/GenDocs.scala b/doc-tool/test/GenDocs.scala index 770904016..358e52fdf 100644 --- a/doc-tool/test/GenDocs.scala +++ b/doc-tool/test/GenDocs.scala @@ -19,6 +19,11 @@ trait LocalResources extends api.scala.Dottydoc { sys.env.get("DOC_RESOURCES").getOrElse("../../dottydoc-client/resources/") ).listFiles + def getFiles(file: JFile): Array[JFile] = + if (file.isDirectory) file.listFiles.flatMap(getFiles) + else if (file.getAbsolutePath.endsWith(".scala")) Array(file) + else Array() + assert(template.exists, "please specify a template.html file using DOC_TEMPLATE env var") assert(resources.forall(_.exists), "please specify a resource dir using DOC_RESOURCES env var") @@ -43,11 +48,6 @@ object GenCollections extends LocalResources { object GenDottyDocs extends LocalResources { import Files._ - def getFiles(file: JFile): Array[JFile] = - if (file.isDirectory) file.listFiles.flatMap(getFiles) - else if (file.getAbsolutePath.endsWith(".scala")) Array(file) - else Array() - val dottyFiles = new JFile("../compiler/src/dotty").listFiles.flatMap(getFiles).map(_.getAbsolutePath) override def main(args: Array[String]): Unit = buildDocs( |