001: /*
002: * Copyright 2004 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.mirror.declaration;
027:
028: import java.lang.annotation.Annotation;
029: import java.util.Collection;
030:
031: import com.sun.mirror.type.*;
032: import com.sun.mirror.util.*;
033:
034: /**
035: * Represents the declaration of a program element such as a package,
036: * class, or method. Each declaration represents a static, language-level
037: * construct (and not, for example, a runtime construct of the virtual
038: * machine), and typically corresponds one-to-one with a particular
039: * fragment of source code.
040: *
041: * <p> Declarations should be compared using the {@link #equals(Object)}
042: * method. There is no guarantee that any particular declaration will
043: * always be represented by the same object.
044: *
045: * @author Joseph D. Darcy
046: * @author Scott Seligman
047: * @version 1.13 07/05/05
048: *
049: * @see Declarations
050: * @see TypeMirror
051: * @since 1.5
052: */
053:
054: public interface Declaration {
055:
056: /**
057: * Tests whether an object represents the same declaration as this.
058: *
059: * @param obj the object to be compared with this declaration
060: * @return <tt>true</tt> if the specified object represents the same
061: * declaration as this
062: */
063: boolean equals(Object obj);
064:
065: /**
066: * Returns the text of the documentation ("javadoc") comment of
067: * this declaration.
068: *
069: * @return the documentation comment of this declaration, or <tt>null</tt>
070: * if there is none
071: */
072: String getDocComment();
073:
074: /**
075: * Returns the annotations that are directly present on this declaration.
076: *
077: * @return the annotations directly present on this declaration;
078: * an empty collection if there are none
079: */
080: Collection<AnnotationMirror> getAnnotationMirrors();
081:
082: /**
083: * Returns the annotation of this declaration having the specified
084: * type. The annotation may be either inherited or directly
085: * present on this declaration.
086: *
087: * <p> The annotation returned by this method could contain an element
088: * whose value is of type <tt>Class</tt>.
089: * This value cannot be returned directly: information necessary to
090: * locate and load a class (such as the class loader to use) is
091: * not available, and the class might not be loadable at all.
092: * Attempting to read a <tt>Class</tt> object by invoking the relevant
093: * method on the returned annotation
094: * will result in a {@link MirroredTypeException},
095: * from which the corresponding {@link TypeMirror} may be extracted.
096: * Similarly, attempting to read a <tt>Class[]</tt>-valued element
097: * will result in a {@link MirroredTypesException}.
098: *
099: * <blockquote>
100: * <i>Note:</i> This method is unlike
101: * others in this and related interfaces. It operates on run-time
102: * reflective information -- representations of annotation types
103: * currently loaded into the VM -- rather than on the mirrored
104: * representations defined by and used throughout these
105: * interfaces. It is intended for callers that are written to
106: * operate on a known, fixed set of annotation types.
107: * </blockquote>
108: *
109: * @param <A> the annotation type
110: * @param annotationType the <tt>Class</tt> object corresponding to
111: * the annotation type
112: * @return the annotation of this declaration having the specified type
113: *
114: * @see #getAnnotationMirrors()
115: */
116: <A extends Annotation> A getAnnotation(Class<A> annotationType);
117:
118: /**
119: * Returns the modifiers of this declaration, excluding annotations.
120: * Implicit modifiers, such as the <tt>public</tt> and <tt>static</tt>
121: * modifiers of interface members, are included.
122: *
123: * @return the modifiers of this declaration in undefined order;
124: * an empty collection if there are none
125: */
126: Collection<Modifier> getModifiers();
127:
128: /**
129: * Returns the simple (unqualified) name of this declaration.
130: * The name of a generic type does not include any reference
131: * to its formal type parameters.
132: * For example, the simple name of the interface declaration
133: * {@code java.util.Set<E>} is <tt>"Set"</tt>.
134: * If this declaration represents the empty package, an empty
135: * string is returned.
136: * If it represents a constructor, the simple name of its
137: * declaring class is returned.
138: *
139: * @return the simple name of this declaration
140: */
141: String getSimpleName();
142:
143: /**
144: * Returns the source position of the beginning of this declaration.
145: * Returns <tt>null</tt> if the position is unknown or not applicable.
146: *
147: * <p> This source position is intended for use in providing
148: * diagnostics, and indicates only approximately where a declaration
149: * begins.
150: *
151: * @return the source position of the beginning of this declaration,
152: * or null if the position is unknown or not applicable
153: */
154: SourcePosition getPosition();
155:
156: /**
157: * Applies a visitor to this declaration.
158: *
159: * @param v the visitor operating on this declaration
160: */
161: void accept(DeclarationVisitor v);
162: }
|