8221991: Improve the HTML for the inheritance tree for a type

Reviewed-by: hannesw
This commit is contained in:
Priya Lakshmi Muthuswamy 2019-04-30 11:58:30 +05:30
parent 61f35bf898
commit a722889681
8 changed files with 39 additions and 74 deletions

View File

@ -40,7 +40,9 @@ import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleElementVisitor8;
import com.sun.source.doctree.DocTree;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
@ -295,26 +297,17 @@ public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWrite
*/
private Content getClassInheritenceTree(TypeMirror type) {
TypeMirror sup;
HtmlTree classTreeUl = new HtmlTree(HtmlTag.UL);
classTreeUl.setStyle(HtmlStyle.inheritance);
Content liTree = null;
HtmlTree classTree = null;
do {
sup = utils.getFirstVisibleSuperClass(type);
if (sup != null) {
HtmlTree ul = new HtmlTree(HtmlTag.UL);
ul.setStyle(HtmlStyle.inheritance);
ul.add(getTreeForClassHelper(type));
if (liTree != null)
ul.add(liTree);
Content li = HtmlTree.LI(ul);
liTree = li;
type = sup;
} else
classTreeUl.add(getTreeForClassHelper(type));
HtmlTree htmlElement = HtmlTree.DIV(HtmlStyle.inheritance, getTreeForClassHelper(type));
if (classTree != null)
htmlElement.add(classTree);
classTree = htmlElement;
type = sup;
} while (sup != null);
if (liTree != null)
classTreeUl.add(liTree);
return classTreeUl;
classTree.put(HtmlAttr.TITLE, contents.getContent("doclet.Inheritance_Tree").toString());
return classTree;
}
/**
@ -324,25 +317,25 @@ public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWrite
* @return a content tree for class helper
*/
private Content getTreeForClassHelper(TypeMirror type) {
Content li = new HtmlTree(HtmlTag.LI);
Content content = new ContentBuilder();
if (type.equals(typeElement.asType())) {
Content typeParameters = getTypeParameterLinks(
new LinkInfoImpl(configuration, LinkInfoImpl.Kind.TREE,
typeElement));
if (configuration.shouldExcludeQualifier(utils.containingPackage(typeElement).toString())) {
li.add(utils.asTypeElement(type).getSimpleName());
li.add(typeParameters);
content.add(utils.asTypeElement(type).getSimpleName());
content.add(typeParameters);
} else {
li.add(utils.asTypeElement(type).getQualifiedName());
li.add(typeParameters);
content.add(utils.asTypeElement(type).getQualifiedName());
content.add(typeParameters);
}
} else {
Content link = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_TREE_PARENT, type)
.label(configuration.getClassName(utils.asTypeElement(type))));
li.add(link);
content.add(link);
}
return li;
return content;
}
/**

View File

@ -94,6 +94,7 @@ doclet.No_Non_Deprecated_Classes_To_Document=No non-deprecated classes found to
doclet.Interfaces=Interfaces
doclet.Enclosing_Class=Enclosing class:
doclet.Enclosing_Interface=Enclosing interface:
doclet.Inheritance_Tree=Inheritance Tree
doclet.System_Property=System Property
doclet.Window_Source_title=Source code
doclet.Window_Help_title=API Help

View File

@ -364,18 +364,12 @@ ul.horizontal li {
display:inline;
font-size:0.9em;
}
ul.inheritance {
div.inheritance {
margin:0;
padding:0;
}
ul.inheritance li {
display:inline;
list-style:none;
}
ul.inheritance li ul.inheritance {
margin-left:15px;
padding-left:15px;
padding-top:1px;
div.inheritance div.inheritance {
margin-left:2em;
}
ul.blockList, ul.blockListLast {
margin:10px 0 10px 0;

View File

@ -50,10 +50,10 @@ public class AccessAsciiArt extends JavadocTester {
checkOutput("p1/subpkg/SSC.html", true,
// Test the top line of the class tree
"<li><a href=\"../C.html\" title=\"class in p1\">p1.C</a></li>",
"<div class=\"inheritance\"><a href=\"../C.html\" title=\"class in p1\">p1.C</a>",
// Test the second line of the class tree
"<li><a href=\"../SC.html\" title=\"class in p1\">p1.SC</a></li>",
"<div class=\"inheritance\"><a href=\"../SC.html\" title=\"class in p1\">p1.SC</a>",
// Test the third line of the class tree
"<li>p1.subpkg.SSC</li>");
"<div class=\"inheritance\">p1.subpkg.SSC</div>\n</div>\n</div>");
}
}

View File

@ -85,20 +85,11 @@ public class TestInterface extends JavadocTester {
+ "Interface</a>&lt;CE&gt;</code></dd>\n"
+ "</dl>",
//Make sure Class Tree has substituted type parameters.
"<ul class=\"inheritance\">\n"
+ "<li>java.lang.Object</li>\n"
+ "<li>\n"
+ "<ul class=\"inheritance\">\n"
+ "<li><a href=\"Parent.html\" title=\"class in pkg\">"
+ "pkg.Parent</a>&lt;CE&gt;</li>\n"
+ "<li>\n"
+ "<ul class=\"inheritance\">\n"
+ "<li>pkg.Child&lt;CE&gt;</li>\n"
+ "</ul>\n"
+ "</li>\n"
+ "</ul>\n"
+ "</li>\n"
+ "</ul>",
"<div class=\"inheritance\" title=\"Inheritance Tree\">java.lang.Object\n"
+ "<div class=\"inheritance\"><a href=\"Parent.html\""
+ " title=\"class in pkg\">pkg.Parent</a>&lt;CE&gt;\n"
+ "<div class=\"inheritance\">pkg.Child&lt;CE&gt;</div>\n"
+ "</div>\n</div>",
//Make sure "Specified By" has substituted type parameters.
"<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n"
+ "<dd><code><a href=\"Interface.html#method()\">method</a>"

View File

@ -268,9 +268,9 @@ public class TestOptions extends JavadocTester {
checkExit(Exit.OK);
checkOutput("pkg/Foo.html", true,
"<li>Foo</li>");
"<div class=\"inheritance\">Foo</div>");
checkOutput("deprecated/Foo.html", true,
"<li>deprecated.Foo</li>");
"<div class=\"inheritance\">deprecated.Foo</div>");
javadoc("-d", "out-10a",
"-noqualifier", "all",
@ -279,8 +279,8 @@ public class TestOptions extends JavadocTester {
checkExit(Exit.OK);
checkOutput("pkg/Foo.html", true,
"<li>Foo</li>");
"<div class=\"inheritance\">Foo</div>");
checkOutput("deprecated/Foo.html", true,
"<li>Foo</li>");
"<div class=\"inheritance\">Foo</div>");
}
}

View File

@ -66,14 +66,9 @@ public class TestPrivateClasses extends JavadocTester {
"<a href=\"#methodInheritedFromParent(int)\">"
+ "methodInheritedFromParent</a>",
// private class does not show up in tree
"<ul class=\"inheritance\">\n"
+ "<li>java.lang.Object</li>\n"
+ "<li>\n"
+ "<ul class=\"inheritance\">\n"
+ "<li>pkg.PublicChild</li>\n"
+ "</ul>\n"
+ "</li>\n"
+ "</ul>",
"<div class=\"inheritance\" title=\"Inheritance Tree\">java.lang.Object\n"
+ "<div class=\"inheritance\">pkg.PublicChild</div>\n"
+ "</div>",
// Method is documented as though it is declared in the inheriting method.
"<pre class=\"methodSignature\">public&nbsp;void&nbsp;methodInheritedFromParent&#8203;(int&nbsp;p1)",
"<dl>\n"

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8219998
* @bug 8219998 8221991
* @summary Eliminate inherently singleton lists
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -275,10 +275,6 @@ public class TestSingletonLists extends JavadocTester {
case "ul": case "ol": case "dl":
counts.push(new TreeMap<>());
if (!attrs.isEmpty() && attrs.containsKey("class")
&& attrs.containsValue("inheritance")) {
inheritanceClass = true;
}
break;
case "li": case "dd": case "dt": {
@ -297,11 +293,7 @@ public class TestSingletonLists extends JavadocTester {
if (c.get("li") == 0) {
error(currFile, getLineNumber(), "empty list");
} else if (c.get("li") == 1 && fileName != null && !excludeFiles.contains(fileName)) {
if (!inheritanceClass) {
error(currFile, getLineNumber(), "singleton list");
} else {
inheritanceClass = false;
}
error(currFile, getLineNumber(), "singleton list");
}
break;
}
@ -319,5 +311,4 @@ public class TestSingletonLists extends JavadocTester {
}
}
}
}
}