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