src/share/classes/com/sun/mirror/declaration/Declaration.java

Tue, 16 Sep 2008 18:35:18 -0700

author
jjg
date
Tue, 16 Sep 2008 18:35:18 -0700
changeset 113
eff38cc97183
parent 1
9a66ca7c79fa
child 331
d043adadc8b6
permissions
-rw-r--r--

6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
Reviewed-by: darcy, mcimadamore

duke@1 1 /*
duke@1 2 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.mirror.declaration;
duke@1 27
duke@1 28
duke@1 29 import java.lang.annotation.Annotation;
duke@1 30 import java.util.Collection;
duke@1 31
duke@1 32 import com.sun.mirror.type.*;
duke@1 33 import com.sun.mirror.util.*;
duke@1 34
duke@1 35
duke@1 36 /**
duke@1 37 * Represents the declaration of a program element such as a package,
duke@1 38 * class, or method. Each declaration represents a static, language-level
duke@1 39 * construct (and not, for example, a runtime construct of the virtual
duke@1 40 * machine), and typically corresponds one-to-one with a particular
duke@1 41 * fragment of source code.
duke@1 42 *
duke@1 43 * <p> Declarations should be compared using the {@link #equals(Object)}
duke@1 44 * method. There is no guarantee that any particular declaration will
duke@1 45 * always be represented by the same object.
duke@1 46 *
duke@1 47 * @author Joseph D. Darcy
duke@1 48 * @author Scott Seligman
duke@1 49 *
duke@1 50 * @see Declarations
duke@1 51 * @see TypeMirror
duke@1 52 * @since 1.5
duke@1 53 */
duke@1 54
duke@1 55 public interface Declaration {
duke@1 56
duke@1 57 /**
duke@1 58 * Tests whether an object represents the same declaration as this.
duke@1 59 *
duke@1 60 * @param obj the object to be compared with this declaration
duke@1 61 * @return <tt>true</tt> if the specified object represents the same
duke@1 62 * declaration as this
duke@1 63 */
duke@1 64 boolean equals(Object obj);
duke@1 65
duke@1 66 /**
duke@1 67 * Returns the text of the documentation ("javadoc") comment of
duke@1 68 * this declaration.
duke@1 69 *
duke@1 70 * @return the documentation comment of this declaration, or <tt>null</tt>
duke@1 71 * if there is none
duke@1 72 */
duke@1 73 String getDocComment();
duke@1 74
duke@1 75 /**
duke@1 76 * Returns the annotations that are directly present on this declaration.
duke@1 77 *
duke@1 78 * @return the annotations directly present on this declaration;
duke@1 79 * an empty collection if there are none
duke@1 80 */
duke@1 81 Collection<AnnotationMirror> getAnnotationMirrors();
duke@1 82
duke@1 83 /**
duke@1 84 * Returns the annotation of this declaration having the specified
duke@1 85 * type. The annotation may be either inherited or directly
duke@1 86 * present on this declaration.
duke@1 87 *
duke@1 88 * <p> The annotation returned by this method could contain an element
duke@1 89 * whose value is of type <tt>Class</tt>.
duke@1 90 * This value cannot be returned directly: information necessary to
duke@1 91 * locate and load a class (such as the class loader to use) is
duke@1 92 * not available, and the class might not be loadable at all.
duke@1 93 * Attempting to read a <tt>Class</tt> object by invoking the relevant
duke@1 94 * method on the returned annotation
duke@1 95 * will result in a {@link MirroredTypeException},
duke@1 96 * from which the corresponding {@link TypeMirror} may be extracted.
duke@1 97 * Similarly, attempting to read a <tt>Class[]</tt>-valued element
duke@1 98 * will result in a {@link MirroredTypesException}.
duke@1 99 *
duke@1 100 * <blockquote>
duke@1 101 * <i>Note:</i> This method is unlike
duke@1 102 * others in this and related interfaces. It operates on run-time
duke@1 103 * reflective information -- representations of annotation types
duke@1 104 * currently loaded into the VM -- rather than on the mirrored
duke@1 105 * representations defined by and used throughout these
duke@1 106 * interfaces. It is intended for callers that are written to
duke@1 107 * operate on a known, fixed set of annotation types.
duke@1 108 * </blockquote>
duke@1 109 *
duke@1 110 * @param <A> the annotation type
duke@1 111 * @param annotationType the <tt>Class</tt> object corresponding to
duke@1 112 * the annotation type
duke@1 113 * @return the annotation of this declaration having the specified type
duke@1 114 *
duke@1 115 * @see #getAnnotationMirrors()
duke@1 116 */
duke@1 117 <A extends Annotation> A getAnnotation(Class<A> annotationType);
duke@1 118
duke@1 119 /**
duke@1 120 * Returns the modifiers of this declaration, excluding annotations.
duke@1 121 * Implicit modifiers, such as the <tt>public</tt> and <tt>static</tt>
duke@1 122 * modifiers of interface members, are included.
duke@1 123 *
duke@1 124 * @return the modifiers of this declaration in undefined order;
duke@1 125 * an empty collection if there are none
duke@1 126 */
duke@1 127 Collection<Modifier> getModifiers();
duke@1 128
duke@1 129 /**
duke@1 130 * Returns the simple (unqualified) name of this declaration.
duke@1 131 * The name of a generic type does not include any reference
duke@1 132 * to its formal type parameters.
duke@1 133 * For example, the simple name of the interface declaration
duke@1 134 * {@code java.util.Set<E>} is <tt>"Set"</tt>.
duke@1 135 * If this declaration represents the empty package, an empty
duke@1 136 * string is returned.
duke@1 137 * If it represents a constructor, the simple name of its
duke@1 138 * declaring class is returned.
duke@1 139 *
duke@1 140 * @return the simple name of this declaration
duke@1 141 */
duke@1 142 String getSimpleName();
duke@1 143
duke@1 144 /**
duke@1 145 * Returns the source position of the beginning of this declaration.
duke@1 146 * Returns <tt>null</tt> if the position is unknown or not applicable.
duke@1 147 *
duke@1 148 * <p> This source position is intended for use in providing
duke@1 149 * diagnostics, and indicates only approximately where a declaration
duke@1 150 * begins.
duke@1 151 *
duke@1 152 * @return the source position of the beginning of this declaration,
duke@1 153 * or null if the position is unknown or not applicable
duke@1 154 */
duke@1 155 SourcePosition getPosition();
duke@1 156
duke@1 157 /**
duke@1 158 * Applies a visitor to this declaration.
duke@1 159 *
duke@1 160 * @param v the visitor operating on this declaration
duke@1 161 */
duke@1 162 void accept(DeclarationVisitor v);
duke@1 163 }

mercurial