1 /*
2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.tools.javadoc.main;
27 
28 import com.sun.javadoc.*;
29 
30 import com.sun.source.util.TreePath;
31 import com.sun.tools.javac.code.Symbol;
32 import com.sun.tools.javac.code.Symbol.*;
33 import com.sun.tools.javac.util.List;
34 
35 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
36 
37 import static com.sun.tools.javac.code.Kinds.Kind.*;
38 
39 /**
40  * Represents an annotation type.
41  *
42  *  <p><b>This is NOT part of any supported API.
43  *  If you write code that depends on this, you do so at your own risk.
44  *  This code and its internal interfaces are subject to change or
45  *  deletion without notice.</b>
46  *
47  * @author Scott Seligman
48  * @since 1.5
49  */
50 
51 @Deprecated(since="9", forRemoval=true)
52 @SuppressWarnings("removal")
53 public class AnnotationTypeDocImpl
54         extends ClassDocImpl implements AnnotationTypeDoc {
55 
AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym)56     public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) {
57         this(env, sym, null);
58     }
59 
AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath)60     public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
61         super(env, sym, treePath);
62     }
63 
64     /**
65      * Returns true, as this is an annotation type.
66      * (For legacy doclets, return false.)
67      */
isAnnotationType()68     public boolean isAnnotationType() {
69         return !isInterface();
70     }
71 
72     /**
73      * Returns false.  Though technically an interface, an annotation
74      * type is not considered an interface for this purpose.
75      * (For legacy doclets, returns true.)
76      */
isInterface()77     public boolean isInterface() {
78         return env.legacyDoclet;
79     }
80 
81     /**
82      * Returns an empty array, as all methods are annotation type elements.
83      * (For legacy doclets, returns the elements.)
84      * @see #elements()
85      */
methods(boolean filter)86     public MethodDoc[] methods(boolean filter) {
87         return env.legacyDoclet
88                 ? (MethodDoc[])elements()
89                 : new MethodDoc[0];
90     }
91 
92     /**
93      * Returns the elements of this annotation type.
94      * Returns an empty array if there are none.
95      * Elements are always public, so no need to filter them.
96      */
elements()97     public AnnotationTypeElementDoc[] elements() {
98         List<AnnotationTypeElementDoc> elements = List.nil();
99         for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) {
100             if (sym != null && sym.kind == MTH) {
101                 MethodSymbol s = (MethodSymbol)sym;
102                 elements = elements.prepend(env.getAnnotationTypeElementDoc(s));
103             }
104         }
105         return
106             elements.toArray(new AnnotationTypeElementDoc[elements.length()]);
107     }
108 }
109