001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javadoc;
027:
028: import com.sun.javadoc.*;
029:
030: import static com.sun.javadoc.LanguageVersion.*;
031:
032: import com.sun.tools.javac.code.Flags;
033: import com.sun.tools.javac.code.Kinds;
034: import com.sun.tools.javac.code.Scope;
035: import com.sun.tools.javac.code.Symbol;
036: import com.sun.tools.javac.code.Symbol.*;
037: import com.sun.tools.javac.tree.JCTree.*;
038: import com.sun.tools.javac.util.List;
039: import com.sun.tools.javac.util.ListBuffer;
040: import com.sun.tools.javac.util.Name;
041: import com.sun.tools.javac.util.Position;
042:
043: /**
044: * Represents an annotation type.
045: *
046: * @author Scott Seligman
047: * @version 1.16 07/05/05
048: * @since 1.5
049: */
050:
051: public class AnnotationTypeDocImpl extends ClassDocImpl implements
052: AnnotationTypeDoc {
053:
054: AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) {
055: this (env, sym, null, null, null);
056: }
057:
058: AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, String doc,
059: JCClassDecl tree, Position.LineMap lineMap) {
060: super (env, sym, doc, tree, lineMap);
061: }
062:
063: /**
064: * Returns true, as this is an annotation type.
065: * (For legacy doclets, return false.)
066: */
067: public boolean isAnnotationType() {
068: return !isInterface();
069: }
070:
071: /**
072: * Returns false. Though technically an interface, an annotation
073: * type is not considered an interface for this purpose.
074: * (For legacy doclets, returns true.)
075: */
076: public boolean isInterface() {
077: return env.legacyDoclet;
078: }
079:
080: /**
081: * Returns an empty array, as all methods are annotation type elements.
082: * (For legacy doclets, returns the elements.)
083: * @see #elements()
084: */
085: public MethodDoc[] methods(boolean filter) {
086: return env.legacyDoclet ? (MethodDoc[]) elements()
087: : new MethodDoc[0];
088: }
089:
090: /**
091: * Returns the elements of this annotation type.
092: * Returns an empty array if there are none.
093: * Elements are always public, so no need to filter them.
094: */
095: public AnnotationTypeElementDoc[] elements() {
096: Name.Table names = tsym.name.table;
097: List<AnnotationTypeElementDoc> elements = List.nil();
098: for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
099: if (e.sym != null && e.sym.kind == Kinds.MTH) {
100: MethodSymbol s = (MethodSymbol) e.sym;
101: elements = elements.prepend(env
102: .getAnnotationTypeElementDoc(s));
103: }
104: }
105: return elements.toArray(new AnnotationTypeElementDoc[elements
106: .length()]);
107: }
108: }
|