diff options
author | Scott Main <smain@google.com> | 2018-03-01 19:37:43 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-03-01 19:37:43 +0000 |
commit | cbdd3b49a2ade97fa5df36b2eb3f042570e9bb13 (patch) | |
tree | 9ea01f1c630ab1c890da7066c90549d41492f9b2 | |
parent | c5ccbb3f8644fd6eb9418a602d99b31146328354 (diff) | |
parent | 8999bdc8171eb632858feeab69023c0cebcc3d07 (diff) | |
download | platform_external_doclava-cbdd3b49a2ade97fa5df36b2eb3f042570e9bb13.tar.gz platform_external_doclava-cbdd3b49a2ade97fa5df36b2eb3f042570e9bb13.tar.bz2 platform_external_doclava-cbdd3b49a2ade97fa5df36b2eb3f042570e9bb13.zip |
Add support to build a full _book.yaml file for DAC reference. This creates a new version of writeYamlTree() to reproduce the nav structure used on d.android.com with all API links. am: 5880fe8bc7
am: 8999bdc817
Change-Id: Ia2e3dfe345310ac314d7e8a2a5275eba2dac740c
-rw-r--r-- | res/assets/templates-sdk/yaml_navtree2.cs | 15 | ||||
-rw-r--r-- | src/com/google/doclava/Doclava.java | 12 | ||||
-rw-r--r-- | src/com/google/doclava/NavTree.java | 105 |
3 files changed, 131 insertions, 1 deletions
diff --git a/res/assets/templates-sdk/yaml_navtree2.cs b/res/assets/templates-sdk/yaml_navtree2.cs new file mode 100644 index 0000000..a8ec241 --- /dev/null +++ b/res/assets/templates-sdk/yaml_navtree2.cs @@ -0,0 +1,15 @@ +toc: +<?cs +if:docs.packages.link ?> +- title: Class Index + path: /<?cs var:docs.classes.link ?><?cs + if:dac ?> + status_text: no-toggle<?cs + /if?> +- title: Package Index + path: /<?cs var:docs.packages.link ?><?cs + if:dac ?> + status_text: no-toggle<?cs + /if?><?cs +/if ?> +<?cs var:reference_tree ?>
\ No newline at end of file diff --git a/src/com/google/doclava/Doclava.java b/src/com/google/doclava/Doclava.java index 2241098..b059a64 100644 --- a/src/com/google/doclava/Doclava.java +++ b/src/com/google/doclava/Doclava.java @@ -120,6 +120,7 @@ public class Doclava { public static Map<String, String> annotationDocumentationMap = null; public static boolean referenceOnly = false; public static boolean staticOnly = false; + public static boolean yamlV2 = false; /* whether to build the new version of the yaml file */ public static AuxSource auxSource = new EmptyAuxSource(); public static Linter linter = new EmptyLinter(); public static boolean android = false; @@ -365,6 +366,8 @@ public class Doclava { NAVTREE_ONLY = true; } else if (a[0].equals("-atLinksNavtree")) { AT_LINKS_NAVTREE = true; + } else if (a[0].equals("-yamlV2")) { + yamlV2 = true; } else if (a[0].equals("-devsite")) { // Don't copy any assets to devsite output includeAssets = false; @@ -512,6 +515,12 @@ public class Doclava { // Write yaml tree. if (yamlNavFile != null){ NavTree.writeYamlTree(javadocDir, yamlNavFile); + if (yamlV2) { + // Generate both for good measure, to make transitions easier, but change the filename + // for the new one so there's yet another explicit opt-in required by fixing the name. + yamlNavFile = "_NEW" + yamlNavFile; + NavTree.writeYamlTree2(javadocDir, yamlNavFile); + } } // Packages Pages @@ -742,6 +751,9 @@ public class Doclava { if (option.equals("-devsite")) { return 1; } + if (option.equals("-yamlV2")) { + return 1; + } if (option.equals("-dac_libraryroot")) { return 2; } diff --git a/src/com/google/doclava/NavTree.java b/src/com/google/doclava/NavTree.java index de9dd4e..72a396c 100644 --- a/src/com/google/doclava/NavTree.java +++ b/src/com/google/doclava/NavTree.java @@ -60,6 +60,40 @@ public class NavTree { /** * Write the YAML formatted navigation tree. + * This is intended to replace writeYamlTree(), but for now requires an explicit opt-in via + * the yamlV2 flag in the doclava command. This version creates a yaml file with all classes, + * interface, exceptions, etc. separated into collapsible groups. + */ + public static void writeYamlTree2(String dir, String fileName){ + List<Node> children = new ArrayList<Node>(); + for (PackageInfo pkg : Doclava.choosePackages()) { + children.add(makePackageNode(pkg)); + } + Node node = new Node("Reference", Doclava.ensureSlash(dir) + "packages.html", children, null); + StringBuilder buf = new StringBuilder(); + + node.renderChildrenYaml(buf, 0); + + Data data = Doclava.makeHDF(); + data.setValue("reference_tree", buf.toString()); + + if (Doclava.USE_DEVSITE_LOCALE_OUTPUT_PATHS && (Doclava.libraryRoot != null)) { + dir = Doclava.ensureSlash(dir) + Doclava.libraryRoot; + } + + data.setValue("docs.classes.link", Doclava.ensureSlash(dir) + "classes.html"); + data.setValue("docs.packages.link", Doclava.ensureSlash(dir) + "packages.html"); + + ClearPage.write(data, "yaml_navtree2.cs", Doclava.ensureSlash(dir) + fileName); + + } + + + /** + * Write the YAML formatted navigation tree (legacy version). + * This creates a yaml file with package names followed by all + * classes, interfaces, exceptions, etc. But they are not separated by classes, interfaces, etc. + * It also nests any nested classes under the parent class, instead of listing them as siblings. * @see "http://yaml.org/" */ public static void writeYamlTree(String dir, String fileName){ @@ -254,5 +288,74 @@ public class NavTree { renderString(buf, mArtifact); buf.append(" ]"); } + + + // YAML VERSION + + + static void renderStringYaml(StringBuilder buf, String s) { + if (s != null) { + final int N = s.length(); + for (int i = 0; i < N; i++) { + char c = s.charAt(i); + if (c >= ' ' && c <= '~' && c != '"' && c != '\\') { + buf.append(c); + } else { + buf.append("\\u"); + for (int j = 0; i < 4; i++) { + char x = (char) (c & 0x000f); + if (x >= 10) { + x = (char) (x - 10 + 'a'); + } else { + x = (char) (x + '0'); + } + buf.append(x); + c >>= 4; + } + } + } + } + } + void renderChildrenYaml(StringBuilder buf, int depth) { + List<Node> list = mChildren; + if (list != null && list.size() > 0) { + if (depth > 0) { + buf.append("\n\n" + getIndent(depth)); + buf.append("section:"); + } + final int N = list.size(); + for (int i = 0; i < N; i++) { + // get each child Node and render it + list.get(i).renderYaml(buf, depth); + } + // Extra line break after each "section" + buf.append("\n"); + } + } + void renderYaml(StringBuilder buf, int depth) { + buf.append("\n" + getIndent(depth)); + buf.append("- title: \""); + renderStringYaml(buf, mLabel); + buf.append("\""); + // Add link path, if it exists (the class/interface toggles don't have links) + if (mLink != null) { + buf.append("\n" + getIndent(depth)); + buf.append(" path: "); + renderStringYaml(buf, "/" + mLink); + // and the API level also only makes sense if there's a link + buf.append("\n" + getIndent(depth)); + buf.append(" version_added: "); + renderStringYaml(buf, mSince); + } + // try rendering child Nodes + renderChildrenYaml(buf, depth + 1); + } + String getIndent(int depth) { + String spaces = ""; + for (int i = 0; i < depth; i++) { + spaces += " "; + } + return spaces; + } } -} +}
\ No newline at end of file |