mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8006346: doclint should make allowance for headers generated by standard doclet
Reviewed-by: mcimadamore
This commit is contained in:
parent
059c4839bc
commit
84a50dc114
7 changed files with 102 additions and 4 deletions
|
@ -122,12 +122,15 @@ public class Checker extends DocTreeScanner<Void, Void> {
|
|||
private Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well
|
||||
private HtmlTag currHeaderTag;
|
||||
|
||||
private final int implicitHeaderLevel;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Top level">
|
||||
|
||||
Checker(Env env) {
|
||||
env.getClass();
|
||||
this.env = env;
|
||||
tagStack = new LinkedList<TagStackItem>();
|
||||
implicitHeaderLevel = env.implicitHeaderLevel;
|
||||
}
|
||||
|
||||
public Void scan(DocCommentTree tree, TreePath p) {
|
||||
|
@ -386,7 +389,7 @@ public class Checker extends DocTreeScanner<Void, Void> {
|
|||
|
||||
private int getHeaderLevel(HtmlTag tag) {
|
||||
if (tag == null)
|
||||
return 0;
|
||||
return implicitHeaderLevel;
|
||||
switch (tag) {
|
||||
case H1: return 1;
|
||||
case H2: return 2;
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.io.IOException;
|
|||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.tools.StandardLocation;
|
||||
|
@ -72,6 +73,7 @@ public class DocLint implements Plugin {
|
|||
public static final String XMSGS_OPTION = "-Xmsgs";
|
||||
public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:";
|
||||
private static final String STATS = "-stats";
|
||||
public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:";
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Command-line entry point">
|
||||
public static void main(String... args) {
|
||||
|
@ -289,6 +291,9 @@ public class DocLint implements Plugin {
|
|||
env.messages.setOptions(null);
|
||||
} else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
|
||||
env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
|
||||
} else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) {
|
||||
char ch = arg.charAt(arg.length() - 1);
|
||||
env.setImplicitHeaders(Character.digit(ch, 10));
|
||||
} else
|
||||
throw new IllegalArgumentException(arg);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2013, 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
|
||||
|
@ -83,6 +83,8 @@ public class Env {
|
|||
/** Message handler. */
|
||||
final Messages messages;
|
||||
|
||||
int implicitHeaderLevel = 0;
|
||||
|
||||
// Utility classes
|
||||
DocTrees trees;
|
||||
Elements elements;
|
||||
|
@ -102,7 +104,7 @@ public class Env {
|
|||
DocCommentTree currDocComment;
|
||||
/**
|
||||
* The access kind of the declaration containing the comment currently being analyzed.
|
||||
* This is the minimum (most restrictive) access kind of the declaration iteself
|
||||
* This is the minimum (most restrictive) access kind of the declaration itself
|
||||
* and that of its containers. For example, a public method in a private class is
|
||||
* noted as private.
|
||||
*/
|
||||
|
@ -128,6 +130,10 @@ public class Env {
|
|||
java_lang_Void = elements.getTypeElement("java.lang.Void").asType();
|
||||
}
|
||||
|
||||
void setImplicitHeaders(int n) {
|
||||
implicitHeaderLevel = n;
|
||||
}
|
||||
|
||||
/** Set the current declaration and its doc comment. */
|
||||
void setCurrent(TreePath path, DocCommentTree comment) {
|
||||
currPath = path;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2013, 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
|
||||
|
@ -497,6 +497,8 @@ public class Main {
|
|||
if (!(doclintOpts.size() == 1
|
||||
&& doclintOpts.iterator().next().equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) {
|
||||
JavacTask t = BasicJavacTask.instance(context);
|
||||
// standard doclet normally generates H1, H2
|
||||
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
|
||||
new DocLint().init(t, doclintOpts.toArray(new String[doclintOpts.size()]));
|
||||
comp.keepComments = true;
|
||||
}
|
||||
|
|
|
@ -810,6 +810,8 @@ public class DocEnv {
|
|||
|
||||
JavacTask t = BasicJavacTask.instance(context);
|
||||
doclint = new DocLint();
|
||||
// standard doclet normally generates H1, H2
|
||||
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
|
||||
doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
|
||||
}
|
||||
|
||||
|
|
35
langtools/test/tools/javac/doclint/ImplicitHeadersTest.java
Normal file
35
langtools/test/tools/javac/doclint/ImplicitHeadersTest.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 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 8006346
|
||||
* @summary doclint should make allowance for headers generated by standard doclet
|
||||
* @compile -Xdoclint:all/public ImplicitHeadersTest.java
|
||||
*/
|
||||
|
||||
/**
|
||||
* <h3> Header </h3>
|
||||
*/
|
||||
public class ImplicitHeadersTest { }
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 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 8006346
|
||||
* @summary doclint should make allowance for headers generated by standard doclet
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <h3> Header </h3>
|
||||
*/
|
||||
public class ImplicitHeadersTest {
|
||||
public static void main(String... args) {
|
||||
File testSrc = new File(System.getProperty("test.src"));
|
||||
File testFile = new File(testSrc, ImplicitHeadersTest.class.getSimpleName() + ".java");
|
||||
String[] javadocArgs = { "-d", "out", testFile.getPath() };
|
||||
int rc = com.sun.tools.javadoc.Main.execute(javadocArgs);
|
||||
if (rc != 0)
|
||||
throw new Error("unexpected exit: rc=" + rc);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue