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