KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mirror > declaration > Declaration


1 /*
2  * @(#)Declaration.java 1.6 04/07/16
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.mirror.declaration;
9
10
11 import java.lang.annotation.Annotation JavaDoc;
12 import java.util.Collection JavaDoc;
13
14 import com.sun.mirror.type.*;
15 import com.sun.mirror.util.*;
16
17
18 /**
19  * Represents the declaration of a program element such as a package,
20  * class, or method. Each declaration represents a static, language-level
21  * construct (and not, for example, a runtime construct of the virtual
22  * machine), and typically corresponds one-to-one with a particular
23  * fragment of source code.
24  *
25  * <p> Declarations should be compared using the {@link #equals(Object)}
26  * method. There is no guarantee that any particular declaration will
27  * always be represented by the same object.
28  *
29  * @author Joseph D. Darcy
30  * @author Scott Seligman
31  * @version 1.6 04/07/16
32  *
33  * @see Declarations
34  * @see TypeMirror
35  * @since 1.5
36  */

37
38 public interface Declaration {
39
40     /**
41      * Tests whether an object represents the same declaration as this.
42      *
43      * @param obj the object to be compared with this declaration
44      * @return <tt>true</tt> if the specified object represents the same
45      * declaration as this
46      */

47     boolean equals(Object JavaDoc obj);
48
49     /**
50      * Returns the text of the documentation ("javadoc") comment of
51      * this declaration.
52      *
53      * @return the documentation comment of this declaration, or <tt>null</tt>
54      * if there is none
55      */

56     String JavaDoc getDocComment();
57
58     /**
59      * Returns the annotations that are directly present on this declaration.
60      *
61      * @return the annotations directly present on this declaration;
62      * an empty collection if there are none
63      */

64     Collection JavaDoc<AnnotationMirror> getAnnotationMirrors();
65
66     /**
67      * Returns the annotation of this declaration having the specified
68      * type. The annotation may be either inherited or directly
69      * present on this declaration.
70      *
71      * <p> The annotation returned by this method could contain an element
72      * whose value is of type <tt>Class</tt>.
73      * This value cannot be returned directly: information necessary to
74      * locate and load a class (such as the class loader to use) is
75      * not available, and the class might not be loadable at all.
76      * Attempting to read a <tt>Class</tt> object by invoking the relevant
77      * method on the returned annotation
78      * will result in a {@link MirroredTypeException},
79      * from which the corresponding {@link TypeMirror} may be extracted.
80      * Similarly, attempting to read a <tt>Class[]</tt>-valued element
81      * will result in a {@link MirroredTypesException}.
82      *
83      * <blockquote>
84      * <i>Note:</i> This method is unlike
85      * others in this and related interfaces. It operates on run-time
86      * reflective information -- representations of annotation types
87      * currently loaded into the VM -- rather than on the mirrored
88      * representations defined by and used throughout these
89      * interfaces. It is intended for callers that are written to
90      * operate on a known, fixed set of annotation types.
91      * </blockquote>
92      *
93      * @param <A> the annotation type
94      * @param annotationType the <tt>Class</tt> object corresponding to
95      * the annotation type
96      * @return the annotation of this declaration having the specified type
97      *
98      * @see #getAnnotationMirrors()
99      */

100     <A extends Annotation JavaDoc> A getAnnotation(Class JavaDoc<A> annotationType);
101
102     /**
103      * Returns the modifiers of this declaration, excluding annotations.
104      * Implicit modifiers, such as the <tt>public</tt> and <tt>static</tt>
105      * modifiers of interface members, are included.
106      *
107      * @return the modifiers of this declaration in undefined order;
108      * an empty collection if there are none
109      */

110     Collection JavaDoc<Modifier> getModifiers();
111
112     /**
113      * Returns the simple (unqualified) name of this declaration.
114      * The name of a generic type does not include any reference
115      * to its formal type parameters.
116      * For example, the simple name of the interface declaration
117      * {@code java.util.Set<E>} is <tt>"Set"</tt>.
118      * If this declaration represents the empty package, an empty
119      * string is returned.
120      * If it represents a constructor, the simple name of its
121      * declaring class is returned.
122      *
123      * @return the simple name of this declaration
124      */

125     String JavaDoc getSimpleName();
126
127     /**
128      * Returns the source position of the beginning of this declaration.
129      * Returns <tt>null</tt> if the position is unknown or not applicable.
130      *
131      * <p> This source position is intended for use in providing
132      * diagnostics, and indicates only approximately where a declaration
133      * begins.
134      *
135      * @return the source position of the beginning of this declaration,
136      * or null if the position is unknown or not applicable
137      */

138     SourcePosition getPosition();
139
140     /**
141      * Applies a visitor to this declaration.
142      *
143      * @param v the visitor operating on this declaration
144      */

145     void accept(DeclarationVisitor v);
146 }
147
Popular Tags