Thu, 24 Oct 2013 11:22:50 -0700
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Thu Oct 24 01:27:10 2013 -0400 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Thu Oct 24 11:22:50 2013 -0700 1.3 @@ -284,7 +284,7 @@ 1.4 setTopFile(root); 1.5 1.6 if (root instanceof RootDocImpl) { 1.7 - ((RootDocImpl) root).initDocLint(doclintOpts); 1.8 + ((RootDocImpl) root).initDocLint(doclintOpts, tagletManager.getCustomTagNames()); 1.9 } 1.10 } 1.11
2.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java Thu Oct 24 01:27:10 2013 -0400 2.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java Thu Oct 24 11:22:50 2013 -0700 2.3 @@ -205,6 +205,10 @@ 2.4 } 2.5 } 2.6 2.7 + public Set<String> getCustomTagNames() { 2.8 + return customTags.keySet(); 2.9 + } 2.10 + 2.11 /** 2.12 * Add a new <code>Taglet</code>. Print a message to indicate whether or not 2.13 * the Taglet was registered properly.
3.1 --- a/src/share/classes/com/sun/tools/doclint/Checker.java Thu Oct 24 01:27:10 2013 -0400 3.2 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Thu Oct 24 11:22:50 2013 -0700 3.3 @@ -71,6 +71,8 @@ 3.4 import com.sun.source.doctree.StartElementTree; 3.5 import com.sun.source.doctree.TextTree; 3.6 import com.sun.source.doctree.ThrowsTree; 3.7 +import com.sun.source.doctree.UnknownBlockTagTree; 3.8 +import com.sun.source.doctree.UnknownInlineTagTree; 3.9 import com.sun.source.doctree.ValueTree; 3.10 import com.sun.source.doctree.VersionTree; 3.11 import com.sun.source.util.DocTreePath; 3.12 @@ -842,6 +844,23 @@ 3.13 } 3.14 3.15 @Override 3.16 + public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void ignore) { 3.17 + checkUnknownTag(tree, tree.getTagName()); 3.18 + return super.visitUnknownBlockTag(tree, ignore); 3.19 + } 3.20 + 3.21 + @Override 3.22 + public Void visitUnknownInlineTag(UnknownInlineTagTree tree, Void ignore) { 3.23 + checkUnknownTag(tree, tree.getTagName()); 3.24 + return super.visitUnknownInlineTag(tree, ignore); 3.25 + } 3.26 + 3.27 + private void checkUnknownTag(DocTree tree, String tagName) { 3.28 + if (env.customTags != null && !env.customTags.contains(tagName)) 3.29 + env.messages.error(SYNTAX, tree, "dc.tag.unknown", tagName); 3.30 + } 3.31 + 3.32 + @Override 3.33 public Void visitValue(ValueTree tree, Void ignore) { 3.34 ReferenceTree ref = tree.getReference(); 3.35 if (ref == null || ref.getSignature().isEmpty()) {
4.1 --- a/src/share/classes/com/sun/tools/doclint/DocLint.java Thu Oct 24 01:27:10 2013 -0400 4.2 +++ b/src/share/classes/com/sun/tools/doclint/DocLint.java Thu Oct 24 11:22:50 2013 -0700 4.3 @@ -78,6 +78,8 @@ 4.4 public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:"; 4.5 private static final String STATS = "-stats"; 4.6 public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:"; 4.7 + public static final String XCUSTOM_TAGS_PREFIX = "-XcustomTags:"; 4.8 + public static final String TAGS_SEPARATOR = ","; 4.9 4.10 // <editor-fold defaultstate="collapsed" desc="Command-line entry point"> 4.11 public static void main(String... args) { 4.12 @@ -199,6 +201,8 @@ 4.13 env.messages.setOptions(null); 4.14 } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) { 4.15 env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); 4.16 + } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) { 4.17 + env.setCustomTags(arg.substring(arg.indexOf(":") + 1)); 4.18 } else if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help") 4.19 || arg.equals("-?") || arg.equals("-usage")) { 4.20 needHelp = true; 4.21 @@ -262,6 +266,8 @@ 4.22 } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) { 4.23 char ch = arg.charAt(arg.length() - 1); 4.24 env.setImplicitHeaders(Character.digit(ch, 10)); 4.25 + } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) { 4.26 + env.setCustomTags(arg.substring(arg.indexOf(":") + 1)); 4.27 } else 4.28 throw new IllegalArgumentException(arg); 4.29 }
5.1 --- a/src/share/classes/com/sun/tools/doclint/Env.java Thu Oct 24 01:27:10 2013 -0400 5.2 +++ b/src/share/classes/com/sun/tools/doclint/Env.java Thu Oct 24 11:22:50 2013 -0700 5.3 @@ -27,6 +27,7 @@ 5.4 5.5 5.6 import java.util.Set; 5.7 +import java.util.LinkedHashSet; 5.8 5.9 import javax.lang.model.element.Element; 5.10 import javax.lang.model.element.ElementKind; 5.11 @@ -86,6 +87,8 @@ 5.12 5.13 int implicitHeaderLevel = 0; 5.14 5.15 + Set<String> customTags; 5.16 + 5.17 // Utility classes 5.18 DocTrees trees; 5.19 Elements elements; 5.20 @@ -135,6 +138,14 @@ 5.21 implicitHeaderLevel = n; 5.22 } 5.23 5.24 + void setCustomTags(String cTags) { 5.25 + customTags = new LinkedHashSet<String>(); 5.26 + for (String s : cTags.split(DocLint.TAGS_SEPARATOR)) { 5.27 + if (!s.isEmpty()) 5.28 + customTags.add(s); 5.29 + } 5.30 + } 5.31 + 5.32 /** Set the current declaration and its doc comment. */ 5.33 void setCurrent(TreePath path, DocCommentTree comment) { 5.34 currPath = path;
6.1 --- a/src/share/classes/com/sun/tools/javadoc/DocEnv.java Thu Oct 24 01:27:10 2013 -0400 6.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocEnv.java Thu Oct 24 11:22:50 2013 -0700 6.3 @@ -800,7 +800,7 @@ 6.4 return result; 6.5 } 6.6 6.7 - void initDoclint(Collection<String> opts) { 6.8 + void initDoclint(Collection<String> opts, Collection<String> customTagNames) { 6.9 ArrayList<String> doclintOpts = new ArrayList<String>(); 6.10 6.11 for (String opt: opts) { 6.12 @@ -814,6 +814,15 @@ 6.13 return; 6.14 } 6.15 6.16 + String sep = ""; 6.17 + StringBuilder customTags = new StringBuilder(); 6.18 + for (String customTag : customTagNames) { 6.19 + customTags.append(sep); 6.20 + customTags.append(customTag); 6.21 + sep = DocLint.TAGS_SEPARATOR; 6.22 + } 6.23 + doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString()); 6.24 + 6.25 JavacTask t = BasicJavacTask.instance(context); 6.26 doclint = new DocLint(); 6.27 // standard doclet normally generates H1, H2
7.1 --- a/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java Thu Oct 24 01:27:10 2013 -0400 7.2 +++ b/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java Thu Oct 24 11:22:50 2013 -0700 7.3 @@ -377,8 +377,8 @@ 7.4 return env.fileManager; 7.5 } 7.6 7.7 - public void initDocLint(Collection<String> opts) { 7.8 - env.initDoclint(opts); 7.9 + public void initDocLint(Collection<String> opts, Collection<String> customTagNames) { 7.10 + env.initDoclint(opts, customTagNames); 7.11 } 7.12 7.13 public boolean showTagMessages() {
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/com/sun/javadoc/testCustomTag/TagTestClass.java Thu Oct 24 11:22:50 2013 -0700 8.3 @@ -0,0 +1,31 @@ 8.4 +/* 8.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +/** 8.28 + * @customTag A custom tag. 8.29 + * @unknownTag An unknown tag 8.30 + */ 8.31 +public class TagTestClass { 8.32 + 8.33 + public void method(){} 8.34 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/com/sun/javadoc/testCustomTag/TestCustomTag.java Thu Oct 24 11:22:50 2013 -0700 9.3 @@ -0,0 +1,109 @@ 9.4 +/* 9.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/* 9.28 + * @test 9.29 + * @bug 8006248 9.30 + * @summary Test custom tag. Verify that an unknown tag generates appropriate warnings. 9.31 + * @author Bhavesh Patel 9.32 + * @library ../lib/ 9.33 + * @build JavadocTester taglets.CustomTag TestCustomTag 9.34 + * @run main TestCustomTag 9.35 + */ 9.36 + 9.37 +public class TestCustomTag extends JavadocTester { 9.38 + 9.39 + //Test information. 9.40 + private static final String BUG_ID = "8006248"; 9.41 + 9.42 + //Javadoc arguments. 9.43 + private static final String[] ARGS = new String[] { 9.44 + "-Xdoclint:none", "-d", BUG_ID, "-tagletpath", SRC_DIR, 9.45 + "-taglet", "taglets.CustomTag", "-sourcepath", 9.46 + SRC_DIR, SRC_DIR + FS + "TagTestClass.java" 9.47 + }; 9.48 + 9.49 + private static final String[] ARGS1 = new String[] { 9.50 + "-d", BUG_ID + "-1", "-tagletpath", SRC_DIR, "-taglet", "taglets.CustomTag", 9.51 + "-sourcepath", SRC_DIR, SRC_DIR + FS + "TagTestClass.java" 9.52 + }; 9.53 + private static final String[] ARGS2 = new String[] { 9.54 + "-Xdoclint:none", "-d", BUG_ID + "-2", "-sourcepath", 9.55 + SRC_DIR, SRC_DIR + FS + "TagTestClass.java" 9.56 + }; 9.57 + 9.58 + private static final String[] ARGS3 = new String[] { 9.59 + "-d", BUG_ID + "-3", "-sourcepath", SRC_DIR, SRC_DIR + FS + "TagTestClass.java" 9.60 + }; 9.61 + 9.62 + //Input for string search tests. 9.63 + private static final String[][] TEST = new String[][] { 9.64 + {WARNING_OUTPUT, "warning - @unknownTag is an unknown tag." 9.65 + } 9.66 + }; 9.67 + 9.68 + private static final String[][] TEST1 = new String[][] { 9.69 + {ERROR_OUTPUT, "error: unknown tag: unknownTag" 9.70 + } 9.71 + }; 9.72 + private static final String[][] TEST2 = new String[][] { 9.73 + {WARNING_OUTPUT, "warning - @customTag is an unknown tag." 9.74 + }, 9.75 + {WARNING_OUTPUT, "warning - @unknownTag is an unknown tag." 9.76 + } 9.77 + }; 9.78 + 9.79 + private static final String[][] TEST3 = new String[][] { 9.80 + {ERROR_OUTPUT, "error: unknown tag: customTag" 9.81 + }, 9.82 + {ERROR_OUTPUT, "error: unknown tag: unknownTag" 9.83 + } 9.84 + }; 9.85 + 9.86 + /** 9.87 + * The entry point of the test. 9.88 + * @param args the array of command line arguments. 9.89 + */ 9.90 + public static void main(String[] args) { 9.91 + TestCustomTag tester = new TestCustomTag(); 9.92 + run(tester, ARGS, TEST, NO_TEST); 9.93 + run(tester, ARGS1, TEST1, NO_TEST); 9.94 + run(tester, ARGS2, TEST2, NO_TEST); 9.95 + run(tester, ARGS3, TEST3, NO_TEST); 9.96 + tester.printSummary(); 9.97 + } 9.98 + 9.99 + /** 9.100 + * {@inheritDoc} 9.101 + */ 9.102 + public String getBugId() { 9.103 + return BUG_ID; 9.104 + } 9.105 + 9.106 + /** 9.107 + * {@inheritDoc} 9.108 + */ 9.109 + public String getBugName() { 9.110 + return getClass().getName(); 9.111 + } 9.112 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/com/sun/javadoc/testCustomTag/taglets/CustomTag.java Thu Oct 24 11:22:50 2013 -0700 10.3 @@ -0,0 +1,59 @@ 10.4 +/* 10.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.23 + * or visit www.oracle.com if you need additional information or have any 10.24 + * questions. 10.25 + */ 10.26 + 10.27 +package taglets; 10.28 + 10.29 +import com.sun.tools.doclets.internal.toolkit.*; 10.30 +import com.sun.tools.doclets.internal.toolkit.taglets.*; 10.31 +import com.sun.tools.doclets.internal.toolkit.util.*; 10.32 + 10.33 +import com.sun.javadoc.*; 10.34 +import java.util.*; 10.35 + 10.36 +public class CustomTag extends BaseTaglet { 10.37 + 10.38 + public CustomTag() { 10.39 + name = "customTag"; 10.40 + } 10.41 + 10.42 + public static void register(Map tagletMap) { 10.43 + CustomTag tag = new CustomTag(); 10.44 + Taglet t = (Taglet) tagletMap.get(tag.getName()); 10.45 + if (t != null) { 10.46 + tagletMap.remove(tag.getName()); 10.47 + } 10.48 + tagletMap.put(tag.getName(), tag); 10.49 + } 10.50 + 10.51 + /** 10.52 + * {@inheritDoc} 10.53 + */ 10.54 + public Content getTagletOutput(Tag tag, TagletWriter writer) { 10.55 + ArrayList inlineTags = new ArrayList(); 10.56 + inlineTags.add(new TextTag(tag.holder(), "<dt><span class=\"simpleTagLabel\">Custom Tag:</span></dt><dd>")); 10.57 + inlineTags.addAll(Arrays.asList(tag.inlineTags())); 10.58 + inlineTags.add(new TextTag(tag.holder(), "</dd>")); 10.59 + return writer.commentTagsToOutput(tag, 10.60 + (Tag[]) inlineTags.toArray(new Tag[] {})); 10.61 + } 10.62 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/doclint/CustomTagTest.java Thu Oct 24 11:22:50 2013 -0700 11.3 @@ -0,0 +1,19 @@ 11.4 +/* 11.5 + * @test /nodynamiccopyright/ 11.6 + * @bug 8006248 11.7 + * @summary DocLint should report unknown tags 11.8 + * @build DocLintTester 11.9 + * @run main DocLintTester CustomTagTest.java 11.10 + * @run main DocLintTester -XcustomTags: -ref CustomTagTest.out CustomTagTest.java 11.11 + * @run main DocLintTester -XcustomTags:customTag -ref CustomTagTestWithOption.out CustomTagTest.java 11.12 + * @run main DocLintTester -XcustomTags:customTag,anotherCustomTag -ref CustomTagTestWithOption.out CustomTagTest.java 11.13 + * @author bpatel 11.14 + */ 11.15 + 11.16 +/** 11.17 + * @customTag Text for a custom tag. 11.18 + * @unknownTag Text for an unknown tag. 11.19 + */ 11.20 +public class CustomTagTest { 11.21 +} 11.22 +
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/doclint/CustomTagTest.out Thu Oct 24 11:22:50 2013 -0700 12.3 @@ -0,0 +1,8 @@ 12.4 +CustomTagTest.java:14: error: unknown tag: customTag 12.5 + * @customTag Text for a custom tag. 12.6 + ^ 12.7 +CustomTagTest.java:15: error: unknown tag: unknownTag 12.8 + * @unknownTag Text for an unknown tag. 12.9 + ^ 12.10 +2 errors 12.11 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/doclint/CustomTagTestWithOption.out Thu Oct 24 11:22:50 2013 -0700 13.3 @@ -0,0 +1,5 @@ 13.4 +CustomTagTest.java:15: error: unknown tag: unknownTag 13.5 + * @unknownTag Text for an unknown tag. 13.6 + ^ 13.7 +1 error 13.8 +
14.1 --- a/test/tools/doclint/DocLintTester.java Thu Oct 24 01:27:10 2013 -0400 14.2 +++ b/test/tools/doclint/DocLintTester.java Thu Oct 24 11:22:50 2013 -0700 14.3 @@ -58,6 +58,8 @@ 14.4 badArgs = true; 14.5 } else if (arg.startsWith("-Xmsgs")) { 14.6 opts.add(arg); 14.7 + } else if (arg.startsWith("-XcustomTags")) { 14.8 + opts.add(arg); 14.9 } else if (arg.startsWith("-")) { 14.10 opts.add(arg); 14.11 if (i < args.length - 1 && !args[i+1].startsWith("-"))