8004893: the javadoc/doclet needs to be updated to accommodate lambda changes

Reviewed-by: jjg
This commit is contained in:
Bhavesh Patel 2012-12-25 17:23:59 -08:00
parent 1d3157ac87
commit 8a40619e4d
12 changed files with 227 additions and 8 deletions

View File

@ -239,7 +239,14 @@ public abstract class AbstractMemberWriter {
if ((member.isField() || member.isMethod()) &&
writer instanceof ClassWriterImpl &&
((ClassWriterImpl) writer).getClassDoc().isInterface()) {
mod = Util.replaceText(mod, "public", "").trim();
// This check for isDefault() and the default modifier needs to be
// added for it to appear on the method details section. Once the
// default modifier is added to the Modifier list on DocEnv and once
// it is updated to use the javax.lang.model.element.Modifier, we
// will need to remove this.
mod = (member.isMethod() && ((MethodDoc)member).isDefault()) ?
Util.replaceText(mod, "public", "default").trim() :
Util.replaceText(mod, "public", "").trim();
}
if(mod.length() > 0) {
htmltree.addContent(mod);
@ -313,8 +320,18 @@ public abstract class AbstractMemberWriter {
code.addContent(configuration.getText("doclet.Package_private"));
code.addContent(" ");
}
if (member.isMethod() && ((MethodDoc)member).isAbstract()) {
code.addContent("abstract ");
if (member.isMethod()) {
if (((MethodDoc)member).isAbstract()) {
code.addContent("abstract ");
}
// This check for isDefault() and the default modifier needs to be
// added for it to appear on the "Modifier and Type" column in the
// method summary section. Once the default modifier is added
// to the Modifier list on DocEnv and once it is updated to use the
// javax.lang.model.element.Modifier, we will need to remove this.
else if (((MethodDoc)member).isDefault()) {
code.addContent("default ");
}
}
if (member.isStatic()) {
code.addContent("static ");
@ -547,6 +564,9 @@ public abstract class AbstractMemberWriter {
methodType = (classdoc.isInterface() || ((MethodDoc)member).isAbstract()) ?
methodType | MethodTypes.ABSTRACT.value() :
methodType | MethodTypes.CONCRETE.value();
if (((MethodDoc)member).isDefault()) {
methodType = methodType | MethodTypes.DEFAULT.value();
}
if (Util.isDeprecated(member) || Util.isDeprecated(classdoc)) {
methodType = methodType | MethodTypes.DEPRECATED.value();
}

View File

@ -513,6 +513,20 @@ public class ClassWriterImpl extends SubWriterHolderWriter
}
}
/**
* {@inheritDoc}
*/
public void addFunctionalInterfaceInfo (Content classInfoTree) {
if (classDoc.isFunctionalInterface()) {
Content dt = HtmlTree.DT(getResource("doclet.Functional_Interface"));
Content dl = HtmlTree.DL(dt);
Content dd = new HtmlTree(HtmlTag.DD);
dd.addContent(getResource("doclet.Functional_Interface_Message"));
dl.addContent(dd);
classInfoTree.addContent(dl);
}
}
/**
* {@inheritDoc}
*/

View File

@ -90,6 +90,8 @@ doclet.in_interface=in interface
doclet.Subclasses=Direct Known Subclasses:
doclet.Subinterfaces=All Known Subinterfaces:
doclet.Implementing_Classes=All Known Implementing Classes:
doclet.Functional_Interface=Functional Interface:
doclet.Functional_Interface_Message=This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
doclet.also=also
doclet.Frames=Frames
doclet.No_Frames=No Frames

View File

@ -116,6 +116,13 @@ public interface ClassWriter {
*/
public void addInterfaceUsageInfo(Content classInfoTree);
/**
* If this is an functional interface, display appropriate message.
*
* @param classInfoTree content tree to which the documentation will be added
*/
public void addFunctionalInterfaceInfo(Content classInfoTree);
/**
* If this is an inner class or interface, add the enclosing class or
* interface.

View File

@ -235,6 +235,16 @@ public class ClassBuilder extends AbstractBuilder {
writer.addInterfaceUsageInfo(classInfoTree);
}
/**
* If this is an functional interface, display appropriate message.
*
* @param node the XML element that specifies which components to document
* @param classInfoTree the content tree to which the documentation will be added
*/
public void buildFunctionalInterfaceInfo(XMLNode node, Content classInfoTree) {
writer.addFunctionalInterfaceInfo(classInfoTree);
}
/**
* If this class is deprecated, build the appropriate information.
*

View File

@ -85,6 +85,7 @@
<SubInterfacesInfo/>
<InterfaceUsageInfo/>
<NestedClassInfo/>
<FunctionalInterfaceInfo/>
<DeprecationInfo/>
<ClassSignature/>
<ClassDescription/>

View File

@ -36,7 +36,8 @@ public enum MethodTypes {
INSTANCE(0x2, "Instance Methods", "t2", false),
ABSTRACT(0x4, "Abstract Methods", "t3", false),
CONCRETE(0x8, "Concrete Methods", "t4", false),
DEPRECATED(0x10, "Deprecated Methods", "t5", false);
DEFAULT(0x10, "Default Methods", "t5", false),
DEPRECATED(0x20, "Deprecated Methods", "t6", false);
private final int value;
private final String text;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -207,7 +207,7 @@ public class TestHtmlTableTags extends JavadocTester {
"Instance Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t4\" class=\"tableTab\"><span><a href=\"javascript:show(8);\">" +
"Concrete Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t5\" class=\"tableTab\"><span><a href=\"javascript:show(16);\">" +
"<span id=\"t6\" class=\"tableTab\"><span><a href=\"javascript:show(32);\">" +
"Deprecated Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"</caption>"
},

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8004893
* @summary Make sure that the lambda feature changes work fine in
* javadoc.
* @author bpatel
* @library ../lib/
* @build JavadocTester TestLambdaFeature
* @run main TestLambdaFeature
*/
public class TestLambdaFeature extends JavadocTester {
//Test information.
private static final String BUG_ID = "8004893";
//Javadoc arguments.
private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg"
};
//Input for string search tests.
private static final String[][] TEST = {
{BUG_ID + FS + "pkg" + FS + "A.html",
"<td class=\"colFirst\"><code>default void</code></td>"},
{BUG_ID + FS + "pkg" + FS + "A.html",
"<pre>default&nbsp;void&nbsp;defaultMethod()</pre>"},
{BUG_ID + FS + "pkg" + FS + "A.html",
"<caption><span id=\"t0\" class=\"activeTableTab\"><span>" +
"All Methods</span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t2\" class=\"tableTab\"><span>" +
"<a href=\"javascript:show(2);\">Instance Methods</a></span>" +
"<span class=\"tabEnd\">&nbsp;</span></span><span id=\"t3\" " +
"class=\"tableTab\"><span><a href=\"javascript:show(4);\">" +
"Abstract Methods</a></span><span class=\"tabEnd\">&nbsp;</span>" +
"</span><span id=\"t5\" class=\"tableTab\"><span>" +
"<a href=\"javascript:show(16);\">Default Methods</a></span>" +
"<span class=\"tabEnd\">&nbsp;</span></span></caption>"},
{BUG_ID + FS + "pkg" + FS + "A.html",
"<dl>" + NL + "<dt>Functional Interface:</dt>" + NL +
"<dd>This is a functional interface and can therefore be used as " +
"the assignment target for a lambda expression or method " +
"reference. </dd>" + NL + "</dl>"}
};
private static final String[][] NEGATED_TEST = {
{BUG_ID + FS + "pkg" + FS + "A.html",
"<td class=\"colFirst\"><code>default default void</code></td>"},
{BUG_ID + FS + "pkg" + FS + "A.html",
"<pre>default&nbsp;default&nbsp;void&nbsp;defaultMethod()</pre>"},
{BUG_ID + FS + "pkg" + FS + "B.html",
"<td class=\"colFirst\"><code>default void</code></td>"},
{BUG_ID + FS + "pkg" + FS + "B.html",
"<dl>" + NL + "<dt>Functional Interface:</dt>"}
};
/**
* The entry point of the test.
* @param args the array of command line arguments.
*/
public static void main(String[] args) {
TestLambdaFeature tester = new TestLambdaFeature();
run(tester, ARGS, TEST, NEGATED_TEST);
tester.printSummary();
}
/**
* {@inheritDoc}
*/
public String getBugId() {
return BUG_ID;
}
/**
* {@inheritDoc}
*/
public String getBugName() {
return getClass().getName();
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg;
public interface A {
public void method1();
public default void defaultMethod() { }
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg;
public abstract class B {
public abstract void method1();
public void method2() { }
}

View File

@ -55,7 +55,7 @@ public class TestMethodTypes extends JavadocTester {
"Instance Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t4\" class=\"tableTab\"><span><a href=\"javascript:show(8);\">" +
"Concrete Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t5\" class=\"tableTab\"><span><a href=\"javascript:show(16);\">" +
"<span id=\"t6\" class=\"tableTab\"><span><a href=\"javascript:show(32);\">" +
"Deprecated Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"</caption>"
},
@ -87,7 +87,7 @@ public class TestMethodTypes extends JavadocTester {
"Abstract Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t4\" class=\"tableTab\"><span><a href=\"javascript:show(8);\">" +
"Concrete Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"<span id=\"t5\" class=\"tableTab\"><span><a href=\"javascript:show(16);\">" +
"<span id=\"t6\" class=\"tableTab\"><span><a href=\"javascript:show(32);\">" +
"Deprecated Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
"</caption>"
},