src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolEnvironment.java
author jlahoda
Fri, 09 Mar 2018 09:42:10 +0100
changeset 49197 cc2673fa8c20
parent 47216 71c04702a3d5
permissions -rw-r--r--
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure. Summary: Catching CompletionFailures that would be thrown to API clients, and re-completing the symbols again when javac itself needs it. Reviewed-by: cushon, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 42277
diff changeset
     2
 * Copyright (c) 2000, 2017, 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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    26
package jdk.javadoc.internal.tool;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    27
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    31
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    32
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    33
import javax.lang.model.util.Elements;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    34
import javax.tools.JavaFileManager;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    35
import javax.tools.JavaFileObject;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
    36
import javax.tools.JavaFileObject.Kind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    38
import com.sun.source.util.DocTrees;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
    39
import com.sun.source.util.TreePath;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    40
import com.sun.tools.javac.api.JavacTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    41
import com.sun.tools.javac.code.ClassFinder;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    42
import com.sun.tools.javac.code.Flags;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    43
import com.sun.tools.javac.code.Source;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    44
import com.sun.tools.javac.code.Symbol;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    45
import com.sun.tools.javac.code.Symbol.ClassSymbol;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    46
import com.sun.tools.javac.code.Symbol.CompletionFailure;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
    47
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    48
import com.sun.tools.javac.code.Symtab;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    49
import com.sun.tools.javac.comp.AttrContext;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import com.sun.tools.javac.comp.Check;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    51
import com.sun.tools.javac.comp.Enter;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    52
import com.sun.tools.javac.comp.Env;
21891
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
    53
import com.sun.tools.javac.file.JavacFileManager;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    54
import com.sun.tools.javac.model.JavacElements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    55
import com.sun.tools.javac.model.JavacTypes;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
    56
import com.sun.tools.javac.tree.JCTree;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    57
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    58
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    59
import com.sun.tools.javac.tree.JCTree.JCPackageDecl;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
import com.sun.tools.javac.util.Context;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
    61
import com.sun.tools.javac.util.Convert;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
    62
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
    63
import com.sun.tools.javac.util.Names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 * Holds the environment for a run of javadoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * Holds only the information needed throughout the
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * run and not the compiler info that could be GC'ed
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * or ported.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    71
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    72
 *  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
    73
 *  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
    74
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 10189
diff changeset
    75
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 * @author Scott Seligman (generics)
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 */
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
    80
public class ToolEnvironment {
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
    81
    protected static final Context.Key<ToolEnvironment> ToolEnvKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
    83
    public static ToolEnvironment instance(Context context) {
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
    84
        ToolEnvironment instance = context.get(ToolEnvKey);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        if (instance == null)
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
    86
            instance = new ToolEnvironment(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40508
diff changeset
    90
    final Messager messager;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    91
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /** Predefined symbols known to the compiler. */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
    93
    public final Symtab syms;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /** Referenced directly in RootDocImpl. */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    96
    private final ClassFinder finder;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    /** Javadoc's own version of the compiler's enter phase. */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
    99
    final Enter enter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /** The name table. */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
   102
    private Names names;
10
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
44287
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 43265
diff changeset
   106
    /** If true, prevent printing of any notifications. */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    boolean quiet = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
44287
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 43265
diff changeset
   109
    /** If true, ignore all errors encountered during Enter. */
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 43265
diff changeset
   110
    boolean ignoreSourceErrors = false;
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 43265
diff changeset
   111
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    Check chk;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   113
    com.sun.tools.javac.code.Types types;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   114
    JavaFileManager fileManager;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   115
    public final Context context;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21891
diff changeset
   117
    WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<>();
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   118
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** Allow documenting from class files? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    boolean docClasses = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    /**
19912
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   123
     * The source language version.
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   124
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   125
    public final Source source;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   126
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   127
    public final Elements elements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   128
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   129
    public final JavacTypes typeutils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   130
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
   131
    protected DocEnvImpl docEnv;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   132
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   133
    public final DocTrees docTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   134
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   135
    public final Map<Element, TreePath> elementToTreePath;
19912
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   136
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   137
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * @param context      Context for this javadoc instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
   142
    protected ToolEnvironment(Context context) {
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 37750
diff changeset
   143
        context.put(ToolEnvKey, this);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14260
diff changeset
   144
        this.context = context;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        messager = Messager.instance0(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        syms = Symtab.instance(context);
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
   148
        finder = JavadocClassFinder.instance(context);
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24069
diff changeset
   149
        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
   150
        names = Names.instance(context);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
   151
        externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        chk = Check.instance(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   153
        types = com.sun.tools.javac.code.Types.instance(context);
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   154
        fileManager = context.get(JavaFileManager.class);
21891
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
   155
        if (fileManager instanceof JavacFileManager) {
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
   156
            ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
42435b2c96cf 8027977: javadoc dies on NumberFormat/DateFormat subclass
bpatel
parents: 21500
diff changeset
   157
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   158
        docTrees = JavacTrees.instance(context);
19912
4b1a79163f9c 8022738: doclet should only generate functional interface text if source >= 8
bpatel
parents: 16799
diff changeset
   159
        source = Source.instance(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   160
        elements =  JavacElements.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   161
        typeutils = JavacTypes.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   162
        elementToTreePath = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 39364
diff changeset
   165
    public void initialize(Map<ToolOption, Object> toolOpts) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 39364
diff changeset
   166
        this.quiet = (boolean)toolOpts.getOrDefault(ToolOption.QUIET, false);
44287
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 43265
diff changeset
   167
        this.ignoreSourceErrors = (boolean)toolOpts.getOrDefault(ToolOption.IGNORE_SOURCE_ERRORS, false);
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
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   171
     * Load a class by qualified name.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   173
    public TypeElement loadClass(String name) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        try {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
   175
            Name nameImpl = names.fromString(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
   176
            ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36042
diff changeset
   177
            ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   178
            return c;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            chk.completionError(null, ex);
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
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 39364
diff changeset
   185
    boolean isSynthetic(Symbol sym) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 39364
diff changeset
   186
        return (sym.flags() & Flags.SYNTHETIC) != 0;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   187
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   189
    void setElementToTreePath(Element e, TreePath tree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   190
        if (e == null || tree == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   191
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   192
        elementToTreePath.put(e, tree);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   193
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   194
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   195
    public Kind getFileKind(TypeElement te) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   196
        JavaFileObject jfo = ((ClassSymbol)te).outermostClass().classfile;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   197
        return jfo == null ? Kind.SOURCE : jfo.getKind();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   198
    }
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 42277
diff changeset
   199
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    /**
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40508
diff changeset
   201
     * Print a notice, iff <em>quiet</em> is not specified.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    public void notice(String key) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   206
        if (quiet) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            return;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   208
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        messager.notice(key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    /**
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40508
diff changeset
   213
     * Print a notice, iff <em>quiet</em> is not specified.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    public void notice(String key, String a1) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   219
        if (quiet) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            return;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   221
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        messager.notice(key, a1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   225
    TreePath getTreePath(JCCompilationUnit tree) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   226
        TreePath p = treePaths.get(tree);
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   227
        if (p == null)
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   228
            treePaths.put(tree, p = new TreePath(tree));
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   229
        return p;
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   230
    }
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   231
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   232
    TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   233
        TreePath p = treePaths.get(tree);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   234
        if (p == null)
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   235
            treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   236
        return p;
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   237
    }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22442
diff changeset
   238
15354
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   239
    TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) {
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   240
        TreePath p = treePaths.get(tree);
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   241
        if (p == null)
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   242
            treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   243
        return p;
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   244
    }
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   245
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   246
    TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) {
52a04c670c05 8004834: Add doclint support into javadoc
jjg
parents: 14802
diff changeset
   247
        return new TreePath(getTreePath(toplevel, cdecl), tree);
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   248
    }
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14543
diff changeset
   249
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   250
    public com.sun.tools.javac.code.Types getTypes() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   251
        return types;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   252
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   253
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   254
    public Env<AttrContext> getEnv(ClassSymbol tsym) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   255
        return enter.getEnv(tsym);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   256
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   257
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   258
    public boolean isQuiet() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   259
        return quiet;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31752
diff changeset
   260
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
}