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