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