src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java
author rkennke
Fri, 12 Oct 2018 16:25:24 +0200
changeset 52107 0c1e44da019c
parent 48441 9c37fbceb579
child 54135 67f72165dca5
permissions -rw-r--r--
8212053: A few more missing object equals barriers Reviewed-by: shade, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     1
/*
48441
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     4
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    10
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    15
 * accompanied this code).
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    16
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    20
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    23
 * questions.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    24
 */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    25
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    26
package com.sun.tools.doclint;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    27
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    28
import java.io.File;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    29
import java.io.IOException;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    30
import java.io.PrintWriter;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    31
import java.util.ArrayList;
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
    32
import java.util.LinkedList;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    33
import java.util.List;
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
    34
import java.util.Queue;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    35
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    36
import javax.lang.model.element.Name;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    37
import javax.tools.StandardLocation;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    38
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    39
import com.sun.source.doctree.DocCommentTree;
48441
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
    40
import com.sun.source.tree.BlockTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    41
import com.sun.source.tree.ClassTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    42
import com.sun.source.tree.CompilationUnitTree;
48441
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
    43
import com.sun.source.tree.LambdaExpressionTree;
40507
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
    44
import com.sun.source.tree.ModuleTree;
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
    45
import com.sun.source.tree.PackageTree;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    46
import com.sun.source.tree.MethodTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    47
import com.sun.source.tree.Tree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    48
import com.sun.source.tree.VariableTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    49
import com.sun.source.util.JavacTask;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    50
import com.sun.source.util.Plugin;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    51
import com.sun.source.util.TaskEvent;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    52
import com.sun.source.util.TaskListener;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    53
import com.sun.source.util.TreePath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    54
import com.sun.source.util.TreePathScanner;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    55
import com.sun.tools.javac.api.JavacTaskImpl;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    56
import com.sun.tools.javac.api.JavacTool;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    57
import com.sun.tools.javac.file.JavacFileManager;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    58
import com.sun.tools.javac.main.JavaCompiler;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    59
import com.sun.tools.javac.util.Context;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
    60
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
    61
import com.sun.tools.javac.util.DefinedBy.Api;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    62
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    63
/**
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    64
 * Multi-function entry point for the doc check utility.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    65
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    66
 * This class can be invoked in the following ways:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    67
 * <ul>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    68
 * <li>From the command line
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    69
 * <li>From javac, as a plugin
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    70
 * <li>Directly, via a simple API
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    71
 * </ul>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    72
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    73
 * <p><b>This is NOT part of any supported API.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    74
 * If you write code that depends on this, you do so at your own
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    75
 * risk.  This code and its internal interfaces are subject to change
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    76
 * or deletion without notice.</b></p>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    77
 */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    78
public class DocLint implements Plugin {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    79
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    80
    public static final String XMSGS_OPTION = "-Xmsgs";
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    81
    public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:";
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    82
    private static final String STATS = "-stats";
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15370
diff changeset
    83
    public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:";
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
    84
    public static final String XCUSTOM_TAGS_PREFIX = "-XcustomTags:";
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
    85
    public static final String XHTML_VERSION_PREFIX = "-XhtmlVersion:";
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
    86
    public static final String XCHECK_PACKAGE = "-XcheckPackage:";
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
    87
    public static final String SEPARATOR = ",";
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    88
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    89
    // <editor-fold defaultstate="collapsed" desc="Command-line entry point">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    90
    public static void main(String... args) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
    91
        DocLint dl = new DocLint();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    92
        try {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
    93
            dl.run(args);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    94
        } catch (BadArgs e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    95
            System.err.println(e.getMessage());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    96
            System.exit(1);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    97
        } catch (IOException e) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
    98
            System.err.println(dl.localize("dc.main.ioerror", e.getLocalizedMessage()));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    99
            System.exit(2);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   100
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   101
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   102
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   103
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   104
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   105
    // <editor-fold defaultstate="collapsed" desc="Simple API">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   106
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   107
    public class BadArgs extends Exception {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   108
        private static final long serialVersionUID = 0;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   109
        BadArgs(String code, Object... args) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   110
            super(localize(code, args));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   111
            this.code = code;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   112
            this.args = args;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   113
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   114
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   115
        final String code;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   116
        final Object[] args;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   117
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   118
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   119
    /**
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   120
     * Simple API entry point.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   121
     * @param args Options and operands for doclint
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   122
     * @throws BadArgs if an error is detected in any args
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   123
     * @throws IOException if there are problems with any of the file arguments
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   124
     */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   125
    public void run(String... args) throws BadArgs, IOException {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   126
        PrintWriter out = new PrintWriter(System.out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   127
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   128
            run(out, args);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   129
        } finally {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   130
            out.flush();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   131
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   132
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   133
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   134
    public void run(PrintWriter out, String... args) throws BadArgs, IOException {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   135
        env = new Env();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   136
        processArgs(args);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   137
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   138
        boolean noFiles = javacFiles.isEmpty();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   139
        if (needHelp) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   140
            showHelp(out);
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   141
            if (noFiles)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   142
                return;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   143
        } else if (noFiles) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   144
            out.println(localize("dc.main.no.files.given"));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   145
            return;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   146
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   147
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   148
        JavacTool tool = JavacTool.create();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   149
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   150
        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   151
        fm.setSymbolFileEnabled(false);
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   152
        if (javacBootClassPath != null) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   153
            fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, javacBootClassPath);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   154
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   155
        if (javacClassPath != null) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   156
            fm.setLocation(StandardLocation.CLASS_PATH, javacClassPath);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   157
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   158
        if (javacSourcePath != null) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   159
            fm.setLocation(StandardLocation.SOURCE_PATH, javacSourcePath);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 40507
diff changeset
   160
        }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   161
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   162
        JavacTask task = tool.getTask(out, fm, null, javacOpts, null,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   163
                fm.getJavaFileObjectsFromFiles(javacFiles));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   164
        Iterable<? extends CompilationUnitTree> units = task.parse();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   165
        ((JavacTaskImpl) task).enter();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   166
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   167
        env.init(task);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   168
        checker = new Checker(env);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   169
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   170
        DeclScanner ds = new DeclScanner(env) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   171
            @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   172
            void visitDecl(Tree tree, Name name) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   173
                TreePath p = getCurrentPath();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   174
                DocCommentTree dc = env.trees.getDocCommentTree(p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   175
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   176
                checker.scan(dc, p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   177
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   178
        };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   179
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   180
        ds.scan(units, null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   181
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   182
        reportStats(out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   183
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   184
        Context ctx = ((JavacTaskImpl) task).getContext();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   185
        JavaCompiler c = JavaCompiler.instance(ctx);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   186
        c.printCount("error", c.errorCount());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   187
        c.printCount("warn", c.warningCount());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   188
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   189
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   190
    void processArgs(String... args) throws BadArgs {
19121
c626ed0c6ab0 8020664: doclint gives incorrect warnings on normal package statements
jjg
parents: 18908
diff changeset
   191
        javacOpts = new ArrayList<>();
c626ed0c6ab0 8020664: doclint gives incorrect warnings on normal package statements
jjg
parents: 18908
diff changeset
   192
        javacFiles = new ArrayList<>();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   193
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   194
        if (args.length == 0)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   195
            needHelp = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   196
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   197
        for (int i = 0; i < args.length; i++) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   198
            String arg = args[i];
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   199
            if (arg.matches("-Xmax(errs|warns)") && i + 1 < args.length) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   200
                if (args[++i].matches("[0-9]+")) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   201
                    javacOpts.add(arg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   202
                    javacOpts.add(args[i]);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   203
                } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   204
                    throw new BadArgs("dc.bad.value.for.option", arg, args[i]);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   205
                }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   206
            } else if ((arg.equals("-target") || arg.equals("-source")) && i + 1 < args.length) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   207
                javacOpts.add(arg);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   208
                javacOpts.add(args[++i]);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   209
            } else if (arg.equals(STATS)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   210
                env.messages.setStatsEnabled(true);
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   211
            } else if (arg.equals("-bootclasspath") && i + 1 < args.length) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   212
                javacBootClassPath = splitPath(args[++i]);
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   213
            } else if (arg.equals("-classpath") && i + 1 < args.length) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   214
                javacClassPath = splitPath(args[++i]);
18898
0eab5f5e3d1d 8009924: some langtools tools do not accept -cp as an alias for -classpath
vromero
parents: 18004
diff changeset
   215
            } else if (arg.equals("-cp") && i + 1 < args.length) {
0eab5f5e3d1d 8009924: some langtools tools do not accept -cp as an alias for -classpath
vromero
parents: 18004
diff changeset
   216
                javacClassPath = splitPath(args[++i]);
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   217
            } else if (arg.equals("-sourcepath") && i + 1 < args.length) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   218
                javacSourcePath = splitPath(args[++i]);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   219
            } else if (arg.equals(XMSGS_OPTION)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   220
                env.messages.setOptions(null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   221
            } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   222
                env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   223
            } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   224
                env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   225
            } else if (arg.startsWith(XHTML_VERSION_PREFIX)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   226
                String argsVersion = arg.substring(arg.indexOf(":") + 1);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   227
                HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   228
                if (htmlVersion != null) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   229
                    env.setHtmlVersion(htmlVersion);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   230
                } else {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   231
                    throw new BadArgs("dc.bad.value.for.option", arg, argsVersion);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   232
                }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   233
            } else if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   234
                    || arg.equals("-?") || arg.equals("-usage")) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   235
                needHelp = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   236
            } else if (arg.startsWith("-")) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   237
                throw new BadArgs("dc.bad.option", arg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   238
            } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   239
                while (i < args.length)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   240
                    javacFiles.add(new File(args[i++]));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   241
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   242
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   243
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   244
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   245
    void showHelp(PrintWriter out) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   246
        String msg = localize("dc.main.usage");
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   247
        for (String line: msg.split("\n"))
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   248
            out.println(line);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   249
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   250
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   251
    List<File> splitPath(String path) {
19121
c626ed0c6ab0 8020664: doclint gives incorrect warnings on normal package statements
jjg
parents: 18908
diff changeset
   252
        List<File> files = new ArrayList<>();
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   253
        for (String f: path.split(File.pathSeparator)) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   254
            if (f.length() > 0)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   255
                files.add(new File(f));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   256
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   257
        return files;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   258
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   259
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   260
    List<File> javacBootClassPath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   261
    List<File> javacClassPath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   262
    List<File> javacSourcePath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   263
    List<String> javacOpts;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   264
    List<File> javacFiles;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   265
    boolean needHelp = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   266
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   267
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   268
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   269
    // <editor-fold defaultstate="collapsed" desc="javac Plugin">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   270
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   271
    @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   272
    public String getName() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   273
        return "doclint";
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   274
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   275
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   276
    @Override @DefinedBy(Api.COMPILER_TREE)
14955
8fe779a6d616 8005137: Rename DocLint.call to DocLint.init which overrides Plugin.init
mchung
parents: 14952
diff changeset
   277
    public void init(JavacTask task, String... args) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   278
        init(task, args, true);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   279
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   280
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   281
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   282
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   283
    // <editor-fold defaultstate="collapsed" desc="Embedding API">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   284
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   285
    public void init(JavacTask task, String[] args, boolean addTaskListener) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   286
        env = new Env();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21500
diff changeset
   287
        for (String arg : args) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   288
            if (arg.equals(XMSGS_OPTION)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   289
                env.messages.setOptions(null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   290
            } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   291
                env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15370
diff changeset
   292
            } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) {
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15370
diff changeset
   293
                char ch = arg.charAt(arg.length() - 1);
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15370
diff changeset
   294
                env.setImplicitHeaders(Character.digit(ch, 10));
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   295
            } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   296
                env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   297
            } else if (arg.startsWith(XHTML_VERSION_PREFIX)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   298
                String argsVersion = arg.substring(arg.indexOf(":") + 1);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   299
                HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   300
                if (htmlVersion != null) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   301
                    env.setHtmlVersion(htmlVersion);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   302
                } else {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   303
                    throw new IllegalArgumentException(argsVersion);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   304
                }
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   305
            } else if (arg.startsWith(XCHECK_PACKAGE)) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   306
                env.setCheckPackages(arg.substring(arg.indexOf(":") + 1));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   307
            } else
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   308
                throw new IllegalArgumentException(arg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   309
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   310
        env.init(task);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   311
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   312
        checker = new Checker(env);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   313
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   314
        if (addTaskListener) {
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   315
            final DeclScanner ds = new DeclScanner(env) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   316
                @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   317
                void visitDecl(Tree tree, Name name) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   318
                    TreePath p = getCurrentPath();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   319
                    DocCommentTree dc = env.trees.getDocCommentTree(p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   320
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   321
                    checker.scan(dc, p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   322
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   323
            };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   324
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   325
            TaskListener tl = new TaskListener() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   326
                @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   327
                public void started(TaskEvent e) {
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   328
                    switch (e.getKind()) {
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   329
                        case ANALYZE:
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   330
                            CompilationUnitTree tree;
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   331
                            while ((tree = todo.poll()) != null)
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   332
                                ds.scan(tree, null);
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   333
                            break;
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   334
                    }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   335
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   336
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   337
                @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   338
                public void finished(TaskEvent e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   339
                    switch (e.getKind()) {
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   340
                        case PARSE:
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   341
                            todo.add(e.getCompilationUnit());
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   342
                            break;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   343
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   344
                }
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   345
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   346
                Queue<CompilationUnitTree> todo = new LinkedList<>();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   347
            };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   348
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   349
            task.addTaskListener(tl);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   350
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   351
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   352
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   353
    public void scan(TreePath p) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   354
        DocCommentTree dc = env.trees.getDocCommentTree(p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   355
        checker.scan(dc, p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   356
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   357
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   358
    public boolean shouldCheck(CompilationUnitTree unit) {
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   359
        return env.shouldCheck(unit);
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   360
    }
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   361
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   362
    public void reportStats(PrintWriter out) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   363
        env.messages.reportStats(out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   364
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   365
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   366
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   367
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   368
    Env env;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   369
    Checker checker;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   370
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   371
    public static boolean isValidOption(String opt) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   372
        if (opt.equals(XMSGS_OPTION))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   373
           return true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   374
        if (opt.startsWith(XMSGS_CUSTOM_PREFIX))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   375
           return Messages.Options.isValidOptions(opt.substring(XMSGS_CUSTOM_PREFIX.length()));
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   376
        if (opt.startsWith(XCHECK_PACKAGE)) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   377
            return Env.validatePackages(opt.substring(opt.indexOf(":") + 1));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   378
        }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   379
        return false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   380
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   381
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   382
    private String localize(String code, Object... args) {
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   383
        Messages m = (env != null) ? env.messages : new Messages(null);
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   384
        return m.localize(code, args);
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   385
    }
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   386
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   387
    // <editor-fold defaultstate="collapsed" desc="DeclScanner">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   388
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   389
    static abstract class DeclScanner extends TreePathScanner<Void, Void> {
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   390
        final Env env;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   391
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   392
        public DeclScanner(Env env) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   393
            this.env = env;
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   394
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   395
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   396
        abstract void visitDecl(Tree tree, Name name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   397
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   398
        @Override @DefinedBy(Api.COMPILER_TREE)
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   399
        public Void visitPackage(PackageTree tree, Void ignore) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   400
            visitDecl(tree, null);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   401
            return super.visitPackage(tree, ignore);
18908
f76cab33bee3 8020278: NPE in javadoc
jjg
parents: 18898
diff changeset
   402
        }
48441
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   403
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   404
        @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   405
        public Void visitClass(ClassTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   406
            visitDecl(tree, tree.getSimpleName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   407
            return super.visitClass(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   408
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   409
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   410
        @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   411
        public Void visitMethod(MethodTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   412
            visitDecl(tree, tree.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   413
            return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   414
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   415
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   416
        @Override @DefinedBy(Api.COMPILER_TREE)
40507
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
   417
        public Void visitModule(ModuleTree tree, Void ignore) {
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
   418
            visitDecl(tree, null);
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
   419
            return super.visitModule(tree, ignore);
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
   420
        }
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
   421
4413083331c7 8162576: Missing doclint check missing for modules
sadayapalam
parents: 36526
diff changeset
   422
        @Override @DefinedBy(Api.COMPILER_TREE)
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   423
        public Void visitVariable(VariableTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   424
            visitDecl(tree, tree.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   425
            return super.visitVariable(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   426
        }
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   428
        @Override @DefinedBy(Api.COMPILER_TREE)
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   429
        public Void visitCompilationUnit(CompilationUnitTree node, Void p) {
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   430
            if (!env.shouldCheck(node)) {
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   431
                return null;
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   432
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   433
            return super.visitCompilationUnit(node, p);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   434
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26266
diff changeset
   435
48441
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   436
        @Override @DefinedBy(Api.COMPILER_TREE)
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   437
        public Void visitBlock(BlockTree tree, Void ignore) {
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   438
            return null;
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   439
        }
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   440
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   441
        @Override @DefinedBy(Api.COMPILER_TREE)
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   442
        public Void visitLambdaExpression(LambdaExpressionTree tree, Void ignore) {
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   443
            return null;
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   444
        }
9c37fbceb579 8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents: 47216
diff changeset
   445
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   446
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   447
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   448
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   449
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   450
}