Skip to content

Commit 0abcfd4

Browse files
committed
Add documentation to dottydoc API
1 parent 16c63b5 commit 0abcfd4

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ abstract class DocDriver extends Driver {
7070
def compiledDocsJava(args: Array[String]): JMap[String, Package] =
7171
compiledDocs(args).asJava
7272

73-
def indexToJson(index: JMap[String, Package]): String =
74-
index.asScala.json
73+
def indexToJson(index: collection.Map[String, Package]): String =
74+
index.json
75+
76+
def indexToJsonJava(index: JMap[String, Package]): String =
77+
indexToJson(index.asScala)
7578
}

dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,46 @@
77
import java.util.List;
88
import java.net.URL;
99

10-
/** FIXME: document me! */
10+
/**
11+
* The Dottydoc API is fairly simple. The tool creates an index by calling:
12+
* "createIndex" with the same argument list as you would the compiler - e.g:
13+
*
14+
* {{{
15+
* String[] array = {
16+
* "-language:Scala2"
17+
* };
18+
*
19+
* Map<String, Package> index = createIndex(array);
20+
* }}}
21+
*
22+
* Once the index has been generated, the tool can also build a documentation
23+
* API given a Mustache template and a flat resources structure (i.e. absolute
24+
* paths to each resource, which will be put in the same directory).
25+
*
26+
* {{{
27+
* buildDocs("path/to/output/dir", templateURL, resources, index);
28+
* }}}
29+
*
30+
* The tool can also generate JSON from the created index using "toJson(index)"
31+
* or directly using "createJsonIndex"
32+
*/
1133
public class Dottydoc extends DocDriver {
34+
35+
/** Creates index from compiler arguments */
1236
public Map<String, Package> createIndex(String[] args) {
1337
return compiledDocsJava(args);
1438
}
1539

40+
/** Creates JSON from compiler arguments */
1641
public String createJsonIndex(String[] args) {
17-
return indexToJson(createIndex(args));
42+
return indexToJsonJava(createIndex(args));
43+
}
44+
45+
public String toJson(Map<String, Package> index) {
46+
return indexToJsonJava(index);
1847
}
1948

49+
/** Creates a documentation from the given parameters */
2050
public void buildDocs(
2151
String outputDir,
2252
URL template,
@@ -26,6 +56,7 @@ public void buildDocs(
2656
new OutputWriter().writeJava(index, outputDir, template, resources);
2757
}
2858

59+
/** Writes JSON to an output directory as "index.json" */
2960
public void writeJson(Map<String, Package> index, String outputDir) {
3061
new OutputWriter().writeJsonJava(index, outputDir);
3162
}

dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,43 @@ import dotty.tools.dottydoc.util.OutputWriter
77
import scala.collection.Map
88
import java.net.URL
99

10-
/** FIXME: document this class plz */
10+
/**
11+
* The Dottydoc API is fairly simple. The tool creates an index by calling:
12+
* "createIndex" with the same argument list as you would the compiler - e.g:
13+
*
14+
* {{{
15+
* val array: Array[String] = Array(
16+
* "-language:Scala2"
17+
* )
18+
*
19+
* val index: Map[String, Package] = createIndex(array)
20+
* }}}
21+
*
22+
* Once the index has been generated, the tool can also build a documentation
23+
* API given a Mustache template and a flat resources structure (i.e. absolute
24+
* paths to each resource, which will be put in the same directory).
25+
*
26+
* {{{
27+
* buildDocs("path/to/output/dir", templateURL, resources, index)
28+
* }}}
29+
*
30+
* The tool can also generate JSON from the created index using "indexToJson"
31+
* or directly using "createJsonIndex"
32+
*/
1133
trait Dottydoc extends DocDriver {
34+
/** Creates index from compiler arguments */
1235
def createIndex(args: Array[String]): Map[String, Package] =
1336
compiledDocs(args)
1437

38+
/** Creates JSON from compiler arguments */
39+
def createJsonIndex(args: Array[String]): String =
40+
indexToJson(compiledDocs(args))
41+
42+
/** Creates a documentation from the given parameters */
1543
def buildDocs(outDir: String, template: URL, resources: List[URL], index: Map[String, Package]) =
1644
new OutputWriter().write(index, outDir, template, resources)
1745

46+
/** Writes JSON to an output directory as "index.json" */
1847
def writeJson(index: Map[String, Package], outputDir: String) =
1948
new OutputWriter().writeJson(index, outputDir)
2049
}

dottydoc/src/dotty/tools/dottydoc/model/comment/CommentParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ trait CommentParser extends util.MemberLookup {
347347

348348
/** listStyle ::= '-' spc | '1.' spc | 'I.' spc | 'i.' spc | 'A.' spc | 'a.' spc
349349
* Characters used to build lists and their constructors */
350-
protected val listStyles = Map[String, (Seq[Block] => Block)]( // TODO Should this be defined at some list companion?
350+
protected val listStyles = Map[String, (Seq[Block] => Block)](
351351
"- " -> ( UnorderedList(_) ),
352352
"1. " -> ( OrderedList(_,"decimal") ),
353353
"I. " -> ( OrderedList(_,"upperRoman") ),

0 commit comments

Comments
 (0)