langtools/src/share/classes/com/sun/tools/doclint/DocLint.java
author pgovereau
Tue, 22 Apr 2014 17:07:54 -0400
changeset 24069 dfb8f11542fc
parent 22163 3651128c74eb
permissions -rw-r--r--
8034245: Refactor TopLevel tree node. Summary: Added JCPackageDecl to JCTree to store package-level information. Reviewed-by: jjg, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     1
/*
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
     2
 * Copyright (c) 2012, 2013, 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.HashSet;
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
    33
import java.util.LinkedList;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    34
import java.util.List;
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
    35
import java.util.Queue;
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
    36
import java.util.Set;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    37
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    38
import javax.lang.model.element.Name;
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
    39
import javax.tools.JavaFileObject;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    40
import javax.tools.StandardLocation;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    41
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    42
import com.sun.source.doctree.DocCommentTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    43
import com.sun.source.tree.ClassTree;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    44
import com.sun.source.tree.CompilationUnitTree;
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;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    60
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    61
/**
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    62
 * Multi-function entry point for the doc check utility.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    63
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    64
 * This class can be invoked in the following ways:
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    65
 * <ul>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    66
 * <li>From the command line
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    67
 * <li>From javac, as a plugin
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    68
 * <li>Directly, via a simple API
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    69
 * </ul>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    70
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    71
 * <p><b>This is NOT part of any supported API.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    72
 * If you write code that depends on this, you do so at your own
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    73
 * risk.  This code and its internal interfaces are subject to change
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    74
 * or deletion without notice.</b></p>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    75
 */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    76
public class DocLint implements Plugin {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    77
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    78
    public static final String XMSGS_OPTION = "-Xmsgs";
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    79
    public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:";
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    80
    private static final String STATS = "-stats";
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15370
diff changeset
    81
    public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:";
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
    82
    public static final String XCUSTOM_TAGS_PREFIX = "-XcustomTags:";
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
    83
    public static final String TAGS_SEPARATOR = ",";
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    84
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    85
    // <editor-fold defaultstate="collapsed" desc="Command-line entry point">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    86
    public static void main(String... args) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
    87
        DocLint dl = new DocLint();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    88
        try {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
    89
            dl.run(args);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    90
        } catch (BadArgs e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    91
            System.err.println(e.getMessage());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    92
            System.exit(1);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    93
        } catch (IOException e) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
    94
            System.err.println(dl.localize("dc.main.ioerror", e.getLocalizedMessage()));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    95
            System.exit(2);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    96
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    97
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    98
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    99
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   100
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   101
    // <editor-fold defaultstate="collapsed" desc="Simple API">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   102
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   103
    public class BadArgs extends Exception {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   104
        private static final long serialVersionUID = 0;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   105
        BadArgs(String code, Object... args) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   106
            super(localize(code, args));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   107
            this.code = code;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   108
            this.args = args;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   109
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   110
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   111
        final String code;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   112
        final Object[] 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
    /**
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   116
     * Simple API entry point.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   117
     */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   118
    public void run(String... args) throws BadArgs, IOException {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   119
        PrintWriter out = new PrintWriter(System.out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   120
        try {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   121
            run(out, args);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   122
        } finally {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   123
            out.flush();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   124
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   125
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   126
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   127
    public void run(PrintWriter out, String... args) throws BadArgs, IOException {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   128
        env = new Env();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   129
        processArgs(args);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   130
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   131
        if (needHelp)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   132
            showHelp(out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   133
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   134
        if (javacFiles.isEmpty()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   135
            if (!needHelp)
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   136
                out.println(localize("dc.main.no.files.given"));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   137
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   138
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   139
        JavacTool tool = JavacTool.create();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   140
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   141
        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   142
        fm.setSymbolFileEnabled(false);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   143
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, javacBootClassPath);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   144
        fm.setLocation(StandardLocation.CLASS_PATH, javacClassPath);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   145
        fm.setLocation(StandardLocation.SOURCE_PATH, javacSourcePath);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   146
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   147
        JavacTask task = tool.getTask(out, fm, null, javacOpts, null,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   148
                fm.getJavaFileObjectsFromFiles(javacFiles));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   149
        Iterable<? extends CompilationUnitTree> units = task.parse();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   150
        ((JavacTaskImpl) task).enter();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   151
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   152
        env.init(task);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   153
        checker = new Checker(env);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   154
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   155
        DeclScanner ds = new DeclScanner() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   156
            @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   157
            void visitDecl(Tree tree, Name name) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   158
                TreePath p = getCurrentPath();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   159
                DocCommentTree dc = env.trees.getDocCommentTree(p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   160
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   161
                checker.scan(dc, p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   162
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   163
        };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   164
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   165
        ds.scan(units, null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   166
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   167
        reportStats(out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   168
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   169
        Context ctx = ((JavacTaskImpl) task).getContext();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   170
        JavaCompiler c = JavaCompiler.instance(ctx);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   171
        c.printCount("error", c.errorCount());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   172
        c.printCount("warn", c.warningCount());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   173
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   174
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   175
    void processArgs(String... args) throws BadArgs {
19121
c626ed0c6ab0 8020664: doclint gives incorrect warnings on normal package statements
jjg
parents: 18908
diff changeset
   176
        javacOpts = new ArrayList<>();
c626ed0c6ab0 8020664: doclint gives incorrect warnings on normal package statements
jjg
parents: 18908
diff changeset
   177
        javacFiles = new ArrayList<>();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   178
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   179
        if (args.length == 0)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   180
            needHelp = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   181
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   182
        for (int i = 0; i < args.length; i++) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   183
            String arg = args[i];
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   184
            if (arg.matches("-Xmax(errs|warns)") && i + 1 < args.length) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   185
                if (args[++i].matches("[0-9]+")) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   186
                    javacOpts.add(arg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   187
                    javacOpts.add(args[i]);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   188
                } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   189
                    throw new BadArgs("dc.bad.value.for.option", arg, args[i]);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   190
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   191
            } else if (arg.equals(STATS)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   192
                env.messages.setStatsEnabled(true);
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   193
            } else if (arg.equals("-bootclasspath") && i + 1 < args.length) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   194
                javacBootClassPath = splitPath(args[++i]);
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   195
            } else if (arg.equals("-classpath") && i + 1 < args.length) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   196
                javacClassPath = splitPath(args[++i]);
18898
0eab5f5e3d1d 8009924: some langtools tools do not accept -cp as an alias for -classpath
vromero
parents: 18004
diff changeset
   197
            } 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
   198
                javacClassPath = splitPath(args[++i]);
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   199
            } else if (arg.equals("-sourcepath") && i + 1 < args.length) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   200
                javacSourcePath = splitPath(args[++i]);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   201
            } else if (arg.equals(XMSGS_OPTION)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   202
                env.messages.setOptions(null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   203
            } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   204
                env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   205
            } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   206
                env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   207
            } else if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   208
                    || arg.equals("-?") || arg.equals("-usage")) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   209
                needHelp = true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   210
            } else if (arg.startsWith("-")) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   211
                throw new BadArgs("dc.bad.option", arg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   212
            } else {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   213
                while (i < args.length)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   214
                    javacFiles.add(new File(args[i++]));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   215
            }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   216
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   217
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   218
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   219
    void showHelp(PrintWriter out) {
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   220
        String msg = localize("dc.main.usage");
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   221
        for (String line: msg.split("\n"))
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   222
            out.println(line);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   223
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   224
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   225
    List<File> splitPath(String path) {
19121
c626ed0c6ab0 8020664: doclint gives incorrect warnings on normal package statements
jjg
parents: 18908
diff changeset
   226
        List<File> files = new ArrayList<>();
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents: 14955
diff changeset
   227
        for (String f: path.split(File.pathSeparator)) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   228
            if (f.length() > 0)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   229
                files.add(new File(f));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   230
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   231
        return files;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   232
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   233
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   234
    List<File> javacBootClassPath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   235
    List<File> javacClassPath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   236
    List<File> javacSourcePath;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   237
    List<String> javacOpts;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   238
    List<File> javacFiles;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   239
    boolean needHelp = false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   240
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   241
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   242
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   243
    // <editor-fold defaultstate="collapsed" desc="javac Plugin">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   244
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   245
    @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   246
    public String getName() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   247
        return "doclint";
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   248
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   249
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   250
    @Override
14955
8fe779a6d616 8005137: Rename DocLint.call to DocLint.init which overrides Plugin.init
mchung
parents: 14952
diff changeset
   251
    public void init(JavacTask task, String... args) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   252
        init(task, args, true);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   253
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   254
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   255
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   256
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   257
    // <editor-fold defaultstate="collapsed" desc="Embedding API">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   258
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   259
    public void init(JavacTask task, String[] args, boolean addTaskListener) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   260
        env = new Env();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21500
diff changeset
   261
        for (String arg : args) {
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   262
            if (arg.equals(XMSGS_OPTION)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   263
                env.messages.setOptions(null);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   264
            } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   265
                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
   266
            } 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
   267
                char ch = arg.charAt(arg.length() - 1);
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15370
diff changeset
   268
                env.setImplicitHeaders(Character.digit(ch, 10));
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   269
            } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 20235
diff changeset
   270
                env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   271
            } else
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   272
                throw new IllegalArgumentException(arg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   273
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   274
        env.init(task);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   275
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   276
        checker = new Checker(env);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   277
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   278
        if (addTaskListener) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   279
            final DeclScanner ds = new DeclScanner() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   280
                @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   281
                void visitDecl(Tree tree, Name name) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   282
                    TreePath p = getCurrentPath();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   283
                    DocCommentTree dc = env.trees.getDocCommentTree(p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   284
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   285
                    checker.scan(dc, p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   286
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   287
            };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   288
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   289
            TaskListener tl = new TaskListener() {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   290
                @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   291
                public void started(TaskEvent e) {
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   292
                    switch (e.getKind()) {
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   293
                        case ANALYZE:
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   294
                            CompilationUnitTree tree;
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   295
                            while ((tree = todo.poll()) != null)
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   296
                                ds.scan(tree, null);
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   297
                            break;
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   298
                    }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   299
                }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   300
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   301
                @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   302
                public void finished(TaskEvent e) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   303
                    switch (e.getKind()) {
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   304
                        case PARSE:
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   305
                            todo.add(e.getCompilationUnit());
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   306
                            break;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   307
                    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   308
                }
20235
7834123e35dc 8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents: 19123
diff changeset
   309
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   310
                Queue<CompilationUnitTree> todo = new LinkedList<>();
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   311
            };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   312
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   313
            task.addTaskListener(tl);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   314
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   315
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   316
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   317
    public void scan(TreePath p) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   318
        DocCommentTree dc = env.trees.getDocCommentTree(p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   319
        checker.scan(dc, p);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   320
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   321
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   322
    public void reportStats(PrintWriter out) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   323
        env.messages.reportStats(out);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   324
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   325
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   326
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   327
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   328
    Env env;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   329
    Checker checker;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   330
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   331
    public static boolean isValidOption(String opt) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   332
        if (opt.equals(XMSGS_OPTION))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   333
           return true;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   334
        if (opt.startsWith(XMSGS_CUSTOM_PREFIX))
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   335
           return Messages.Options.isValidOptions(opt.substring(XMSGS_CUSTOM_PREFIX.length()));
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   336
        return false;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   337
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   338
18004
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   339
    private String localize(String code, Object... args) {
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   340
        Messages m = (env != null) ? env.messages : new Messages(null);
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   341
        return m.localize(code, args);
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   342
    }
dcf9d59b1635 8006615: [doclint] move remaining messages into resource bundle
jjg
parents: 16799
diff changeset
   343
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   344
    // <editor-fold defaultstate="collapsed" desc="DeclScanner">
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   345
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   346
    static abstract class DeclScanner extends TreePathScanner<Void, Void> {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   347
        abstract void visitDecl(Tree tree, Name name);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   348
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   349
        @Override
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   350
        public Void visitPackage(PackageTree tree, Void ignore) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   351
            visitDecl(tree, null);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   352
            return super.visitPackage(tree, ignore);
18908
f76cab33bee3 8020278: NPE in javadoc
jjg
parents: 18898
diff changeset
   353
        }
f76cab33bee3 8020278: NPE in javadoc
jjg
parents: 18898
diff changeset
   354
        @Override
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   355
        public Void visitClass(ClassTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   356
            visitDecl(tree, tree.getSimpleName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   357
            return super.visitClass(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   358
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   359
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   360
        @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   361
        public Void visitMethod(MethodTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   362
            visitDecl(tree, tree.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   363
            //return super.visitMethod(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   364
            return null;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   365
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   366
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   367
        @Override
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   368
        public Void visitVariable(VariableTree tree, Void ignore) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   369
            visitDecl(tree, tree.getName());
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   370
            return super.visitVariable(tree, ignore);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   371
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   372
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   373
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   374
    // </editor-fold>
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   375
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
   376
}