001: /*
002: * @(#)Declaration.java 1.6 04/07/16
003: *
004: * Copyright (c) 2004, Sun Microsystems, Inc.
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: * * Neither the name of the Sun Microsystems, Inc. nor the names of
016: * its contributors may be used to endorse or promote products derived from
017: * this software without specific prior written permission.
018: *
019: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
020: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
021: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
022: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
023: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
024: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
025: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
026: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
027: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
028: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: */
031:
032: package com.sun.mirror.declaration;
033:
034: import java.lang.annotation.Annotation;
035: import java.util.Collection;
036:
037: import com.sun.mirror.type.*;
038: import com.sun.mirror.util.*;
039:
040: /**
041: * Represents the declaration of a program element such as a package,
042: * class, or method. Each declaration represents a static, language-level
043: * construct (and not, for example, a runtime construct of the virtual
044: * machine), and typically corresponds one-to-one with a particular
045: * fragment of source code.
046: *
047: * <p> Declarations should be compared using the {@link #equals(Object)}
048: * method. There is no guarantee that any particular declaration will
049: * always be represented by the same object.
050: *
051: * @author Joseph D. Darcy
052: * @author Scott Seligman
053: * @version 1.6 04/07/16
054: *
055: * @see Declarations
056: * @see TypeMirror
057: * @since 1.5
058: */
059:
060: public interface Declaration {
061:
062: /**
063: * Tests whether an object represents the same declaration as this.
064: *
065: * @param obj the object to be compared with this declaration
066: * @return <tt>true</tt> if the specified object represents the same
067: * declaration as this
068: */
069: boolean equals(Object obj);
070:
071: /**
072: * Returns the text of the documentation ("javadoc") comment of
073: * this declaration.
074: *
075: * @return the documentation comment of this declaration, or <tt>null</tt>
076: * if there is none
077: */
078: String getDocComment();
079:
080: /**
081: * Returns the annotations that are directly present on this declaration.
082: *
083: * @return the annotations directly present on this declaration;
084: * an empty collection if there are none
085: */
086: Collection<AnnotationMirror> getAnnotationMirrors();
087:
088: /**
089: * Returns the annotation of this declaration having the specified
090: * type. The annotation may be either inherited or directly
091: * present on this declaration.
092: *
093: * <p> The annotation returned by this method could contain an element
094: * whose value is of type <tt>Class</tt>.
095: * This value cannot be returned directly: information necessary to
096: * locate and load a class (such as the class loader to use) is
097: * not available, and the class might not be loadable at all.
098: * Attempting to read a <tt>Class</tt> object by invoking the relevant
099: * method on the returned annotation
100: * will result in a {@link MirroredTypeException},
101: * from which the corresponding {@link TypeMirror} may be extracted.
102: * Similarly, attempting to read a <tt>Class[]</tt>-valued element
103: * will result in a {@link MirroredTypesException}.
104: *
105: * <blockquote>
106: * <i>Note:</i> This method is unlike
107: * others in this and related interfaces. It operates on run-time
108: * reflective information -- representations of annotation types
109: * currently loaded into the VM -- rather than on the mirrored
110: * representations defined by and used throughout these
111: * interfaces. It is intended for callers that are written to
112: * operate on a known, fixed set of annotation types.
113: * </blockquote>
114: *
115: * @param <A> the annotation type
116: * @param annotationType the <tt>Class</tt> object corresponding to
117: * the annotation type
118: * @return the annotation of this declaration having the specified type
119: *
120: * @see #getAnnotationMirrors()
121: */
122: <A extends Annotation> A getAnnotation(Class<A> annotationType);
123:
124: /**
125: * Returns the modifiers of this declaration, excluding annotations.
126: * Implicit modifiers, such as the <tt>public</tt> and <tt>static</tt>
127: * modifiers of interface members, are included.
128: *
129: * @return the modifiers of this declaration in undefined order;
130: * an empty collection if there are none
131: */
132: Collection<Modifier> getModifiers();
133:
134: /**
135: * Returns the simple (unqualified) name of this declaration.
136: * The name of a generic type does not include any reference
137: * to its formal type parameters.
138: * For example, the simple name of the interface declaration
139: * {@code java.util.Set<E>} is <tt>"Set"</tt>.
140: * If this declaration represents the empty package, an empty
141: * string is returned.
142: * If it represents a constructor, the simple name of its
143: * declaring class is returned.
144: *
145: * @return the simple name of this declaration
146: */
147: String getSimpleName();
148:
149: /**
150: * Returns the source position of the beginning of this declaration.
151: * Returns <tt>null</tt> if the position is unknown or not applicable.
152: *
153: * <p> This source position is intended for use in providing
154: * diagnostics, and indicates only approximately where a declaration
155: * begins.
156: *
157: * @return the source position of the beginning of this declaration,
158: * or null if the position is unknown or not applicable
159: */
160: SourcePosition getPosition();
161:
162: /**
163: * Applies a visitor to this declaration.
164: *
165: * @param v the visitor operating on this declaration
166: */
167: void accept(DeclarationVisitor v);
168: }
|