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