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