src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/PackageDocImpl.java
author ksrini
Fri, 09 Feb 2018 13:58:17 -0800
changeset 48840 5e2d2067da48
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194651: javadoc: mark the com.sun.javadoc API for removal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
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: 2212
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: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
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
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 10189
diff changeset
    28
import java.io.IOException;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    29
import java.io.InputStream;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 10189
diff changeset
    30
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    31
import javax.tools.FileObject;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    33
import com.sun.javadoc.*;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    34
import com.sun.source.util.TreePath;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.code.Attribute;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
    36
import com.sun.tools.javac.code.Symbol;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol.ClassSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.code.Symbol.PackageSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.tree.JCTree;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    40
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.util.ListBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.util.Name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.tools.javac.util.Position;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
    46
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
    47
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * Represents a java package.  Provides access to information
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * about the package, the package's comment and tags, and the
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * classes in the package.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    53
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    54
 *  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: 14258
diff changeset
    55
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    56
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    57
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 * @since 1.2
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 * @author Kaiyang Liu (original)
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * @author Robert Field (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * @author Scott Seligman (package-info.java)
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    65
@Deprecated(since="9", forRemoval=true)
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    66
@SuppressWarnings("removal")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
public class PackageDocImpl extends DocImpl implements PackageDoc {
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
    69
    public final PackageSymbol sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    private JCCompilationUnit tree = null;    // for source position
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    72
    public FileObject docPath = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private boolean foundDoc;   // found a doc comment in either
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                                // package.html or package-info.java
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    boolean isIncluded = false;  // Set in RootDocImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    public boolean setDocPath = false;  //Flag to avoid setting doc path multiple times.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    public PackageDocImpl(DocEnv env, PackageSymbol sym) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    83
        this(env, sym, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    89
    public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    90
        super(env, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        this.sym = sym;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    92
        this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        foundDoc = (documentation != null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    void setTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        this.tree = (JCCompilationUnit) tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   100
    public void setTreePath(TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
   101
        super.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        checkDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * Do lazy initialization of "documentation" string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 5520
diff changeset
   108
    protected String documentation() {
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   109
        if (documentation != null)
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   110
            return documentation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        if (docPath != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            // read from file
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            try {
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   114
                InputStream s = docPath.openInputStream();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                documentation = readHTMLDocumentation(s, docPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                documentation = "";
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   118
                env.error(null, "javadoc.File_Read_Error", docPath.getName());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            // no doc file to be had
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            documentation = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return documentation;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * Cache of all classes contained in this package, including
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * member classes of those classes, and their member classes, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * Includes only those classes at the specified protection level
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * and weaker.
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    private List<ClassDocImpl> allClassesFiltered = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * Cache of all classes contained in this package, including
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * member classes of those classes, and their member classes, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    private List<ClassDocImpl> allClasses = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * Return a list of all classes contained in this package, including
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * member classes of those classes, and their member classes, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    private List<ClassDocImpl> getClasses(boolean filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        if (allClasses != null && !filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            return allClasses;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        if (allClassesFiltered != null && filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
            return allClassesFiltered;
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   152
        ListBuffer<ClassDocImpl> classes = new ListBuffer<>();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
   153
        for (Symbol enumerated : sym.members().getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
   154
            if (enumerated != null) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
   155
                ClassSymbol s = (ClassSymbol)enumerated;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                ClassDocImpl c = env.getClassDoc(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                if (c != null && !c.isSynthetic())
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                    c.addAllClasses(classes, filtered);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        if (filtered)
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            return allClassesFiltered = classes.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            return allClasses = classes.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * Add all included classes (including Exceptions and Errors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * and interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    public void addAllClassesTo(ListBuffer<ClassDocImpl> list) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        list.appendList(getClasses(true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * Get all classes (including Exceptions and Errors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * and interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * @since J2SE1.4.
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * @return all classes and interfaces in this package, filtered to include
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * only the included classes if filter==true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public ClassDoc[] allClasses(boolean filter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        List<ClassDocImpl> classes = getClasses(filter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        return classes.toArray(new ClassDocImpl[classes.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * Get all included classes (including Exceptions and Errors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * and interfaces.  Same as allClasses(true).
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * @return all included classes and interfaces in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    public ClassDoc[] allClasses() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        return allClasses(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * Get ordinary classes (that is, exclude exceptions, errors,
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * enums, interfaces, and annotation types) in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * @return included ordinary classes in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    public ClassDoc[] ordinaryClasses() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   205
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            if (c.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * Get Exception classes in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * @return included Exceptions in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    public ClassDoc[] exceptions() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   220
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            if (c.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * Get Error classes in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * @return included Errors in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    public ClassDoc[] errors() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   235
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            if (c.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * Get included enum types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     * @return included enum types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public ClassDoc[] enums() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   250
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            if (c.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * Get included interfaces in this package, omitting annotation types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * @return included interfaces in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    public ClassDoc[] interfaces() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   265
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            if (c.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                ret.append(c);
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 ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     * Get included annotation types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * @return included annotation types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    public AnnotationTypeDoc[] annotationTypes() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   280
        ListBuffer<AnnotationTypeDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            if (c.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                ret.append((AnnotationTypeDocImpl)c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        return ret.toArray(new AnnotationTypeDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     * Get the annotations of this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     * Return an empty array if there are none.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    public AnnotationDesc[] annotations() {
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14802
diff changeset
   294
        AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        int i = 0;
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14802
diff changeset
   296
        for (Attribute.Compound a : sym.getRawAttributes()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            res[i++] = new AnnotationDescImpl(env, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        return res;
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * Lookup for a class within this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     * @return ClassDocImpl of found class, or null if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    public ClassDoc findClass(String className) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        final boolean filtered = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        for (ClassDocImpl c : getClasses(filtered)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            if (c.name().equals(className)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     * Return true if this package is included in the active set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    public boolean isIncluded() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        return isIncluded;
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     * Get package name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
     * Note that we do not provide a means of obtaining the simple
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
     * name of a package -- package names are always returned in their
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
     * uniquely qualified form.
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    public String name() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        return qualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
     * Get package name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    public String qualifiedName() {
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   340
        if (qualifiedName == null) {
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   341
            Name fullname = sym.getQualifiedName();
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   342
            // Some bogus tests depend on the interned "" being returned.
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   343
            // See 6457276.
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   344
            qualifiedName = fullname.isEmpty() ? "" : fullname.toString();
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   345
        }
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   346
        return qualifiedName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   349
    private String qualifiedName;
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   350
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
     * set doc path for an unzipped directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
     */
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   354
    public void setDocPath(FileObject path) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        setDocPath = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            return;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   358
        if (!path.equals(docPath)) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   359
            docPath = path;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            checkDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    // Has checkDoc() sounded off yet?
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    private boolean checkDocWarningEmitted = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     * Invoked when a source of package doc comments is located.
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     * Emits a diagnostic if this is the second one.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    private void checkDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        if (foundDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            if (!checkDocWarningEmitted) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                env.warning(null, "javadoc.Multiple_package_comments", name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                checkDocWarningEmitted = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            foundDoc = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     * Return the source position of the entity, or null if
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     * no position is available.
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    public SourcePosition position() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        return (tree != null)
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   388
                ? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
                : SourcePositionImpl.make(docPath, Position.NOPOS, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
}