src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/DocEnv.java
author ksrini
Fri, 09 Feb 2018 13:58:17 -0800
changeset 48840 5e2d2067da48
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194651: javadoc: mark the com.sun.javadoc API for removal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
37938
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 36526
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    28
import java.lang.reflect.Modifier;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.*;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
    30
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    31
import javax.tools.JavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.javadoc.*;
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
    34
import com.sun.source.tree.CompilationUnitTree;
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
    35
import com.sun.source.util.JavacTask;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
    36
import com.sun.source.util.TreePath;
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
    37
import com.sun.tools.doclint.DocLint;
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
    38
import com.sun.tools.javac.api.BasicJavacTask;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.code.Symbol.*;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    41
import com.sun.tools.javac.code.Symbol.ClassSymbol;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    42
import com.sun.tools.javac.code.Symbol.CompletionFailure;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    43
import com.sun.tools.javac.code.Symbol.MethodSymbol;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    44
import com.sun.tools.javac.code.Symbol.PackageSymbol;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    45
import com.sun.tools.javac.code.Symbol.VarSymbol;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import com.sun.tools.javac.code.Type.ClassType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import com.sun.tools.javac.comp.Check;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    48
import com.sun.tools.javac.comp.Enter;
21891
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
    49
import com.sun.tools.javac.file.JavacFileManager;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
    50
import com.sun.tools.javac.tree.JCTree;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    51
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    52
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    53
import com.sun.tools.javac.tree.JCTree.JCPackageDecl;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.javac.util.Context;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
    55
import com.sun.tools.javac.util.Convert;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
    56
import com.sun.tools.javac.util.Name;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    57
import com.sun.tools.javac.util.Names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * Holds the environment for a run of javadoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * Holds only the information needed throughout the
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * run and not the compiler info that could be GC'ed
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 * or ported.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    65
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    66
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    67
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    68
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    69
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 * @since 1.4
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * @author Scott Seligman (generics)
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 */
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    75
@Deprecated(since="9", forRemoval=true)
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    76
@SuppressWarnings("removal")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
public class DocEnv {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
    78
    protected static final Context.Key<DocEnv> docEnvKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public static DocEnv instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        DocEnv instance = context.get(docEnvKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            instance = new DocEnv(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    DocLocale doclocale;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    89
    private final Messager messager;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    90
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /** Predefined symbols known to the compiler. */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    92
    final Symtab syms;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** Referenced directly in RootDocImpl. */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    95
    private final ClassFinder finder;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /** Javadoc's own version of the compiler's enter phase. */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    98
    final Enter enter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** The name table. */
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   101
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /** The encoding name. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    private String encoding;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    final Symbol externalizableSym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /** Access filter (public, protected, ...).  */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   109
    protected ModifierFilter showAccess;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /** True if we are using a sentence BreakIterator. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    boolean breakiterator;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * True if we do not want to print any notifications at all.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    boolean quiet = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    Types types;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   121
    JavaFileManager fileManager;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14260
diff changeset
   122
    Context context;
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   123
    DocLint doclint;
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   124
    JavaScriptScanner javaScriptScanner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   126
    WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<>();
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   127
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /** Allow documenting from class files? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    boolean docClasses = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /** Does the doclet only expect pre-1.5 doclet API? */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   132
    protected boolean legacyDoclet = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * Set this to true if you would like to not emit any errors, warnings and
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * notices.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    private boolean silent = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    /**
19912
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   141
     * The source language version.
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   142
     */
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   143
    protected Source source;
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   144
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   145
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @param context      Context for this javadoc instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   150
    protected DocEnv(Context context) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        context.put(docEnvKey, this);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14260
diff changeset
   152
        this.context = context;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        messager = Messager.instance0(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        syms = Symtab.instance(context);
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
   156
        finder = JavadocClassFinder.instance(context);
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
   157
        enter = JavadocEnter.instance(context);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   158
        names = Names.instance(context);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   159
        externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        types = Types.instance(context);
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   162
        fileManager = context.get(JavaFileManager.class);
21891
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
   163
        if (fileManager instanceof JavacFileManager) {
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
   164
            ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
   165
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        // Default.  Should normally be reset with setLocale.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        this.doclocale = new DocLocale(this, "", breakiterator);
19912
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   169
        source = Source.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public void setSilent(boolean silent) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        this.silent = silent;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * Look up ClassDoc by qualified name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    public ClassDocImpl lookupClass(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        ClassSymbol c = getClassSymbol(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        if (c != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            return getClassDoc(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * Load ClassDoc by qualified name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    public ClassDocImpl loadClass(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        try {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   193
            Name nameImpl = names.fromString(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   194
            ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   195
            ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            return getClassDoc(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            chk.completionError(null, ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * Look up PackageDoc by qualified name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    public PackageDocImpl lookupPackage(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        //### Jing alleges that class check is needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        //### to avoid a compiler bug.  Most likely
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        //### instead a dummy created for error recovery.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        //### Should investigate this.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   211
        Name nameImpl = names.fromString(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   212
        ModuleSymbol mod = syms.inferModule(nameImpl);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   213
        PackageSymbol p = mod != null ? syms.getPackage(mod, nameImpl) : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        ClassSymbol c = getClassSymbol(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        if (p != null && c == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            return getPackageDoc(p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        /** Retrieve class symbol by fully-qualified name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        ClassSymbol getClassSymbol(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
            // Name may contain nested class qualification.
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            // Generate candidate flatnames with successively shorter
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            // package qualifiers and longer nested class qualifiers.
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            int nameLen = name.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            char[] nameChars = name.toCharArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            int idx = name.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            for (;;) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   232
                Name nameImpl = names.fromChars(nameChars, 0, nameLen);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   233
                ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 31752
diff changeset
   234
                ClassSymbol s = mod != null ? syms.getClass(mod, nameImpl) : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                if (s != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    return s; // found it!
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                idx = name.substring(0, idx).lastIndexOf('.');
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                if (idx < 0) break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                nameChars[idx] = '$';
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * Set the locale.
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    public void setLocale(String localeName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        // create locale specifics
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        doclocale = new DocLocale(this, localeName, breakiterator);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14541
diff changeset
   250
        // update Messager if locale has changed.
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14541
diff changeset
   251
        messager.setLocale(doclocale.locale);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    /** Check whether this member should be documented. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    public boolean shouldDocument(VarSymbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        long mod = sym.flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        if ((mod & Flags.SYNTHETIC) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        return showAccess.checkModifier(translateModifiers(mod));
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    /** Check whether this member should be documented. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    public boolean shouldDocument(MethodSymbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        long mod = sym.flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        if ((mod & Flags.SYNTHETIC) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        return showAccess.checkModifier(translateModifiers(mod));
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    /** check whether this class should be documented. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    public boolean shouldDocument(ClassSymbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            (sym.flags_field&Flags.SYNTHETIC) == 0 && // no synthetics
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            (docClasses || getClassDoc(sym).tree != null) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            isVisible(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    //### Comment below is inaccurate wrt modifier filter testing
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     * Check the visibility if this is an nested class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     * if this is not a nested class, return true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     * if this is an static visible nested class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     *    return true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     * if this is an visible nested class
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     *    if the outer class is visible return true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     *    else return false.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     * IMPORTANT: This also allows, static nested classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * to be defined inside an nested class, which is not
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * allowed by the compiler. So such an test case will
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     * not reach upto this method itself, but if compiler
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * allows it, then that will go through.
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    protected boolean isVisible(ClassSymbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        long mod = sym.flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        if (!showAccess.checkModifier(translateModifiers(mod))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        ClassSymbol encl = sym.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        return (encl == null || (mod & Flags.STATIC) != 0 || isVisible(encl));
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    //---------------- print forwarders ----------------//
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     * @param msg message to print.
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    public void printError(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        messager.printError(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    public void error(DocImpl doc, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        messager.error(doc==null ? null : doc.position(), key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    public void error(SourcePosition pos, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        messager.error(pos, key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     * @param msg message to print.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    public void printError(SourcePosition pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        messager.printError(pos, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    public void error(DocImpl doc, String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        messager.error(doc==null ? null : doc.position(), key, a1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    public void error(DocImpl doc, String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        messager.error(doc==null ? null : doc.position(), key, a1, a2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    public void error(DocImpl doc, String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        messager.error(doc==null ? null : doc.position(), key, a1, a2, a3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     * @param msg message to print.
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    public void printWarning(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        messager.printWarning(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    public void warning(DocImpl doc, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        messager.warning(doc==null ? null : doc.position(), key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
     * @param msg message to print.
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    public void printWarning(SourcePosition pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        messager.printWarning(pos, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
    public void warning(DocImpl doc, String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
            return;
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   435
        // suppress messages that have (probably) been covered by doclint
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   436
        if (doclint != null && doc != null && key.startsWith("tag"))
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   437
            return;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        messager.warning(doc==null ? null : doc.position(), key, a1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    public void warning(DocImpl doc, String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        messager.warning(doc==null ? null : doc.position(), key, a1, a2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    public void warning(DocImpl doc, String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
    public void warning(DocImpl doc, String key, String a1, String a2, String a3,
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                        String a4) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        if (silent)
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3, a4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
     * @param msg message to print.
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
    public void printNotice(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        if (silent || quiet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        messager.printNotice(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
    public void notice(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        if (silent || quiet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        messager.notice(key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
     * @param msg message to print.
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
    public void printNotice(SourcePosition pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        if (silent || quiet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        messager.printNotice(pos, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
    public void notice(String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        if (silent || quiet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        messager.notice(key, a1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
    public void notice(String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        if (silent || quiet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        messager.notice(key, a1, a2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
    public void notice(String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        if (silent || quiet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        messager.notice(key, a1, a2, a3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
     * Exit, reporting errors and warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    public void exit() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        // Messager should be replaced by a more general
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        // compilation environment.  This can probably
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        // subsume DocEnv as well.
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        messager.exit();
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   566
    protected Map<PackageSymbol, PackageDocImpl> packageMap = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
     * Return the PackageDoc of this package symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    public PackageDocImpl getPackageDoc(PackageSymbol pack) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        PackageDocImpl result = packageMap.get(pack);
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
        result = new PackageDocImpl(this, pack);
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
        packageMap.put(pack, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
     * Create the PackageDoc (or a subtype) for a package symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   581
    void makePackageDoc(PackageSymbol pack, TreePath treePath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        PackageDocImpl result = packageMap.get(pack);
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        if (result != null) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   584
            if (treePath != null) result.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        } else {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   586
            result = new PackageDocImpl(this, pack, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            packageMap.put(pack, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   592
    protected Map<ClassSymbol, ClassDocImpl> classMap = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
     * Return the ClassDoc (or a subtype) of this class symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
     */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   596
    public ClassDocImpl getClassDoc(ClassSymbol clazz) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        ClassDocImpl result = classMap.get(clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        if (isAnnotationType(clazz)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            result = new AnnotationTypeDocImpl(this, clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
            result = new ClassDocImpl(this, clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        classMap.put(clazz, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
     * Create the ClassDoc (or a subtype) for a class symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   611
    protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        ClassDocImpl result = classMap.get(clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        if (result != null) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   614
            if (treePath != null) result.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        }
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   617
        if (isAnnotationType((JCClassDecl) treePath.getLeaf())) {   // flags of clazz may not yet be set
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   618
            result = new AnnotationTypeDocImpl(this, clazz, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
        } else {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   620
            result = new ClassDocImpl(this, clazz, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
        classMap.put(clazz, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   625
    protected static boolean isAnnotationType(ClassSymbol clazz) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        return ClassDocImpl.isAnnotationType(clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   629
    protected static boolean isAnnotationType(JCClassDecl tree) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        return (tree.mods.flags & Flags.ANNOTATION) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   633
    protected Map<VarSymbol, FieldDocImpl> fieldMap = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
     * Return the FieldDoc of this var symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
     */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 7681
diff changeset
   637
    public FieldDocImpl getFieldDoc(VarSymbol var) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
        FieldDocImpl result = fieldMap.get(var);
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
        result = new FieldDocImpl(this, var);
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        fieldMap.put(var, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
     * Create a FieldDoc for a var symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   647
    protected void makeFieldDoc(VarSymbol var, TreePath treePath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
        FieldDocImpl result = fieldMap.get(var);
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
        if (result != null) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   650
            if (treePath != null) result.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        } else {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   652
            result = new FieldDocImpl(this, var, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
            fieldMap.put(var, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   657
    protected Map<MethodSymbol, ExecutableMemberDocImpl> methodMap = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
     * Create a MethodDoc for this MethodSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
     * Should be called only on symbols representing methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   662
    protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
        if (result != null) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   665
            if (treePath != null) result.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
        } else {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   667
            result = new MethodDocImpl(this, meth, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
            methodMap.put(meth, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
     * Return the MethodDoc for a MethodSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
     * Should be called only on symbols representing methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
    public MethodDocImpl getMethodDoc(MethodSymbol meth) {
7071
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   677
        assert !meth.isConstructor() : "not expecting a constructor symbol";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        result = new MethodDocImpl(this, meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
        methodMap.put(meth, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
     * Create the ConstructorDoc for a MethodSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
     * Should be called only on symbols representing constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   689
    protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
        if (result != null) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   692
            if (treePath != null) result.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
        } else {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   694
            result = new ConstructorDocImpl(this, meth, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            methodMap.put(meth, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
     * Return the ConstructorDoc for a MethodSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
     * Should be called only on symbols representing constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
    public ConstructorDocImpl getConstructorDoc(MethodSymbol meth) {
7071
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   704
        assert meth.isConstructor() : "expecting a constructor symbol";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        result = new ConstructorDocImpl(this, meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        methodMap.put(meth, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
     * Create the AnnotationTypeElementDoc for a MethodSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
     * Should be called only on symbols representing annotation type elements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   716
    protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
        AnnotationTypeElementDocImpl result =
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
            (AnnotationTypeElementDocImpl)methodMap.get(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        if (result != null) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   720
            if (treePath != null) result.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
            result =
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   723
                new AnnotationTypeElementDocImpl(this, meth, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
            methodMap.put(meth, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     * Return the AnnotationTypeElementDoc for a MethodSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
     * Should be called only on symbols representing annotation type elements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
    public AnnotationTypeElementDocImpl getAnnotationTypeElementDoc(
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
            MethodSymbol meth) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        AnnotationTypeElementDocImpl result =
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            (AnnotationTypeElementDocImpl)methodMap.get(meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
        result = new AnnotationTypeElementDocImpl(this, meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        methodMap.put(meth, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
//  private Map<ClassType, ParameterizedTypeImpl> parameterizedTypeMap =
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
//          new HashMap<ClassType, ParameterizedTypeImpl>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
     * Return the ParameterizedType of this instantiation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
//   * ### Could use Type.sameTypeAs() instead of equality matching in hashmap
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
//   * ### to avoid some duplication.
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
    ParameterizedTypeImpl getParameterizedType(ClassType t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        return new ParameterizedTypeImpl(this, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
//      ParameterizedTypeImpl result = parameterizedTypeMap.get(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
//      if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
//      result = new ParameterizedTypeImpl(this, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
//      parameterizedTypeMap.put(t, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
//      return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   759
    TreePath getTreePath(JCCompilationUnit tree) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   760
        TreePath p = treePaths.get(tree);
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   761
        if (p == null)
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   762
            treePaths.put(tree, p = new TreePath(tree));
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   763
        return p;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   764
    }
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   765
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   766
    TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   767
        TreePath p = treePaths.get(tree);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   768
        if (p == null)
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   769
            treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   770
        return p;
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   771
    }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   772
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   773
    TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) {
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   774
        TreePath p = treePaths.get(tree);
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   775
        if (p == null)
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   776
            treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   777
        return p;
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   778
    }
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   779
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   780
    TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) {
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   781
        return new TreePath(getTreePath(toplevel, cdecl), tree);
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   782
    }
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   783
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
     * Set the encoding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
    public void setEncoding(String encoding) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
        this.encoding = encoding;
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
     * Get the encoding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
    public String getEncoding() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        return encoding;
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
     * Convert modifier bits from private coding used by
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
     * the compiler to that of java.lang.reflect.Modifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
    static int translateModifiers(long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        int result = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
        if ((flags & Flags.ABSTRACT) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            result |= Modifier.ABSTRACT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
        if ((flags & Flags.FINAL) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            result |= Modifier.FINAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        if ((flags & Flags.INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
            result |= Modifier.INTERFACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
        if ((flags & Flags.NATIVE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            result |= Modifier.NATIVE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        if ((flags & Flags.PRIVATE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
            result |= Modifier.PRIVATE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
        if ((flags & Flags.PROTECTED) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            result |= Modifier.PROTECTED;
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        if ((flags & Flags.PUBLIC) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
            result |= Modifier.PUBLIC;
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
        if ((flags & Flags.STATIC) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
            result |= Modifier.STATIC;
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        if ((flags & Flags.SYNCHRONIZED) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
            result |= Modifier.SYNCHRONIZED;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
        if ((flags & Flags.TRANSIENT) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
            result |= Modifier.TRANSIENT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
        if ((flags & Flags.VOLATILE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
            result |= Modifier.VOLATILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
    }
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   828
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   829
    void initDoclint(Collection<String> opts, Collection<String> customTagNames, String htmlVersion) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   830
        ArrayList<String> doclintOpts = new ArrayList<>();
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   831
        boolean msgOptionSeen = false;
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   832
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   833
        for (String opt : opts) {
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   834
            if (opt.startsWith(DocLint.XMSGS_OPTION)) {
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   835
                if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   836
                    return;
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   837
                msgOptionSeen = true;
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   838
            }
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   839
            doclintOpts.add(opt);
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   840
        }
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   841
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   842
        if (!msgOptionSeen) {
15713
55f55d4f5f9f 8007610: javadoc doclint does not work with -private
jjg
parents: 15354
diff changeset
   843
            doclintOpts.add(DocLint.XMSGS_OPTION);
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   844
        }
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   845
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   846
        String sep = "";
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   847
        StringBuilder customTags = new StringBuilder();
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   848
        for (String customTag : customTagNames) {
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   849
            customTags.append(sep);
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   850
            customTags.append(customTag);
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 25874
diff changeset
   851
            sep = DocLint.SEPARATOR;
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   852
        }
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   853
        doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 29427
diff changeset
   854
        doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + htmlVersion);
21500
475e59d3b40c 8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents: 19912
diff changeset
   855
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   856
        JavacTask t = BasicJavacTask.instance(context);
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   857
        doclint = new DocLint();
16799
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15713
diff changeset
   858
        // standard doclet normally generates H1, H2
fbe4d27b8791 8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents: 15713
diff changeset
   859
        doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   860
        doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   861
    }
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   862
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   863
    JavaScriptScanner initJavaScriptScanner(boolean allowScriptInComments) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   864
        if (allowScriptInComments) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   865
            javaScriptScanner = null;
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   866
        } else {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   867
            javaScriptScanner = new JavaScriptScanner();
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   868
        }
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   869
        return javaScriptScanner;
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   870
    }
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 38617
diff changeset
   871
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   872
    boolean showTagMessages() {
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   873
        return (doclint == null);
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   874
    }
31752
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   875
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   876
    Map<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>();
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   877
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   878
    boolean shouldCheck(CompilationUnitTree unit) {
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   879
        return shouldCheck.computeIfAbsent(unit, doclint :: shouldCheck);
a4ea4c9bce2f 8129909: Add -Xdoclint/package: to javadoc
jlahoda
parents: 29957
diff changeset
   880
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
}