langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/PackageDocImpl.java
author jjg
Mon, 09 May 2016 16:52:15 -0700
changeset 37938 42baa89d2156
parent 36526 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/PackageDocImpl.java@3b41f1c69604
child 38617 d93a7f64e231
permissions -rw-r--r--
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API. Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
     2
 * Copyright (c) 1997, 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: 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
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
public class PackageDocImpl extends DocImpl implements PackageDoc {
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
    67
    public final PackageSymbol sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private JCCompilationUnit tree = null;    // for source position
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
    70
    public FileObject docPath = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private boolean foundDoc;   // found a doc comment in either
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                                // package.html or package-info.java
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    boolean isIncluded = false;  // Set in RootDocImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public boolean setDocPath = false;  //Flag to avoid setting doc path multiple times.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public PackageDocImpl(DocEnv env, PackageSymbol sym) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    81
        this(env, sym, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    87
    public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    88
        super(env, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        this.sym = sym;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    90
        this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        foundDoc = (documentation != null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    void setTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        this.tree = (JCCompilationUnit) tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    98
    public void setTreePath(TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14260
diff changeset
    99
        super.setTreePath(treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        checkDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * Do lazy initialization of "documentation" string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     */
10189
57268b86d4da 7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents: 5520
diff changeset
   106
    protected String documentation() {
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   107
        if (documentation != null)
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   108
            return documentation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        if (docPath != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            // read from file
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            try {
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   112
                InputStream s = docPath.openInputStream();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
                documentation = readHTMLDocumentation(s, docPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                documentation = "";
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   116
                env.error(null, "javadoc.File_Read_Error", docPath.getName());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            // no doc file to be had
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            documentation = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        return documentation;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * Cache of all classes contained in this package, including
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * member classes of those classes, and their member classes, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * Includes only those classes at the specified protection level
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * and weaker.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    private List<ClassDocImpl> allClassesFiltered = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * Cache of all classes contained in this package, including
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * member classes of those classes, and their member classes, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    private List<ClassDocImpl> allClasses = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * Return a list of all classes contained in this package, including
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * member classes of those classes, and their member classes, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    private List<ClassDocImpl> getClasses(boolean filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        if (allClasses != null && !filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            return allClasses;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        if (allClassesFiltered != null && filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            return allClassesFiltered;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   150
        ListBuffer<ClassDocImpl> classes = new ListBuffer<>();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
   151
        for (Symbol enumerated : sym.members().getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
   152
            if (enumerated != null) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 22163
diff changeset
   153
                ClassSymbol s = (ClassSymbol)enumerated;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                ClassDocImpl c = env.getClassDoc(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                if (c != null && !c.isSynthetic())
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                    c.addAllClasses(classes, filtered);
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        if (filtered)
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            return allClassesFiltered = classes.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            return allClasses = classes.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * Add all included classes (including Exceptions and Errors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * and interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public void addAllClassesTo(ListBuffer<ClassDocImpl> list) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        list.appendList(getClasses(true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * Get all classes (including Exceptions and Errors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * and interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * @since J2SE1.4.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * @return all classes and interfaces in this package, filtered to include
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * only the included classes if filter==true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public ClassDoc[] allClasses(boolean filter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
        List<ClassDocImpl> classes = getClasses(filter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        return classes.toArray(new ClassDocImpl[classes.length()]);
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
     * Get all included classes (including Exceptions and Errors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * and interfaces.  Same as allClasses(true).
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @return all included classes and interfaces in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    public ClassDoc[] allClasses() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        return allClasses(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * Get ordinary classes (that is, exclude exceptions, errors,
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * enums, interfaces, and annotation types) in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * @return included ordinary classes in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    public ClassDoc[] ordinaryClasses() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   203
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            if (c.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * Get Exception classes in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * @return included Exceptions in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    public ClassDoc[] exceptions() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   218
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            if (c.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * Get Error classes in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * @return included Errors in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    public ClassDoc[] errors() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   233
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
            if (c.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        return ret.toArray(new ClassDocImpl[ret.length()]);
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
     * Get included enum types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * @return included enum types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    public ClassDoc[] enums() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   248
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            if (c.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     * Get included interfaces in this package, omitting annotation types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * @return included interfaces in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    public ClassDoc[] interfaces() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   263
        ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
            if (c.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                ret.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        return ret.toArray(new ClassDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * Get included annotation types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     * @return included annotation types in this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    public AnnotationTypeDoc[] annotationTypes() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17275
diff changeset
   278
        ListBuffer<AnnotationTypeDocImpl> ret = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        for (ClassDocImpl c : getClasses(true)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            if (c.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                ret.append((AnnotationTypeDocImpl)c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        return ret.toArray(new AnnotationTypeDocImpl[ret.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     * Get the annotations of this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     * Return an empty array if there are none.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    public AnnotationDesc[] annotations() {
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14802
diff changeset
   292
        AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        int i = 0;
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14802
diff changeset
   294
        for (Attribute.Compound a : sym.getRawAttributes()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            res[i++] = new AnnotationDescImpl(env, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        return res;
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     * Lookup for a class within this package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * @return ClassDocImpl of found class, or null if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    public ClassDoc findClass(String className) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        final boolean filtered = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        for (ClassDocImpl c : getClasses(filtered)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
            if (c.name().equals(className)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     * Return true if this package is included in the active set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    public boolean isIncluded() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
        return isIncluded;
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * Get package name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     * Note that we do not provide a means of obtaining the simple
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     * name of a package -- package names are always returned in their
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
     * uniquely qualified form.
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    public String name() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        return qualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     * Get package name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    public String qualifiedName() {
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   338
        if (qualifiedName == null) {
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   339
            Name fullname = sym.getQualifiedName();
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   340
            // Some bogus tests depend on the interned "" being returned.
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   341
            // See 6457276.
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   342
            qualifiedName = fullname.isEmpty() ? "" : fullname.toString();
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   343
        }
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   344
        return qualifiedName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   347
    private String qualifiedName;
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 14961
diff changeset
   348
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
     * set doc path for an unzipped directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
     */
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   352
    public void setDocPath(FileObject path) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        setDocPath = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            return;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   356
        if (!path.equals(docPath)) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   357
            docPath = path;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            checkDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    // Has checkDoc() sounded off yet?
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
    private boolean checkDocWarningEmitted = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
     * Invoked when a source of package doc comments is located.
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     * Emits a diagnostic if this is the second one.
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    private void checkDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        if (foundDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
            if (!checkDocWarningEmitted) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
                env.warning(null, "javadoc.Multiple_package_comments", name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                checkDocWarningEmitted = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            foundDoc = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     * Return the source position of the entity, or null if
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
     * no position is available.
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    public SourcePosition position() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        return (tree != null)
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 10
diff changeset
   386
                ? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                : SourcePositionImpl.make(docPath, Position.NOPOS, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
}