src/share/classes/javax/lang/model/util/Elements.java

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 425
b8936a7930fe
permissions
-rw-r--r--

Initial load

duke@1 1 /*
duke@1 2 * Copyright 2005-2006 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 javax.lang.model.util;
duke@1 27
duke@1 28
duke@1 29 import java.util.List;
duke@1 30 import java.util.Map;
duke@1 31
duke@1 32 import javax.lang.model.element.*;
duke@1 33 import javax.lang.model.type.*;
duke@1 34
duke@1 35
duke@1 36 /**
duke@1 37 * Utility methods for operating on program elements.
duke@1 38 *
duke@1 39 * <p><b>Compatibility Note:</b> Methods may be added to this interface
duke@1 40 * in future releases of the platform.
duke@1 41 *
duke@1 42 * @author Joseph D. Darcy
duke@1 43 * @author Scott Seligman
duke@1 44 * @author Peter von der Ah&eacute;
duke@1 45 * @see javax.annotation.processing.ProcessingEnvironment#getElementUtils
duke@1 46 * @since 1.6
duke@1 47 */
duke@1 48 public interface Elements {
duke@1 49
duke@1 50 /**
duke@1 51 * Returns a package given its fully qualified name.
duke@1 52 *
duke@1 53 * @param name fully qualified package name, or "" for an unnamed package
duke@1 54 * @return the named package, or {@code null} if it cannot be found
duke@1 55 */
duke@1 56 PackageElement getPackageElement(CharSequence name);
duke@1 57
duke@1 58 /**
duke@1 59 * Returns a type element given its canonical name.
duke@1 60 *
duke@1 61 * @param name the canonical name
duke@1 62 * @return the named type element, or {@code null} if it cannot be found
duke@1 63 */
duke@1 64 TypeElement getTypeElement(CharSequence name);
duke@1 65
duke@1 66 /**
duke@1 67 * Returns the values of an annotation's elements, including defaults.
duke@1 68 *
duke@1 69 * @see AnnotationMirror#getElementValues()
duke@1 70 * @param a annotation to examine
duke@1 71 * @return the values of the annotation's elements, including defaults
duke@1 72 */
duke@1 73 Map<? extends ExecutableElement, ? extends AnnotationValue>
duke@1 74 getElementValuesWithDefaults(AnnotationMirror a);
duke@1 75
duke@1 76 /**
duke@1 77 * Returns the text of the documentation (&quot;Javadoc&quot;)
duke@1 78 * comment of an element.
duke@1 79 *
duke@1 80 * @param e the element being examined
duke@1 81 * @return the documentation comment of the element, or {@code null}
duke@1 82 * if there is none
duke@1 83 */
duke@1 84 String getDocComment(Element e);
duke@1 85
duke@1 86 /**
duke@1 87 * Returns {@code true} if the element is deprecated, {@code false} otherwise.
duke@1 88 *
duke@1 89 * @param e the element being examined
duke@1 90 * @return {@code true} if the element is deprecated, {@code false} otherwise
duke@1 91 */
duke@1 92 boolean isDeprecated(Element e);
duke@1 93
duke@1 94 /**
duke@1 95 * Returns the <i>binary name</i> of a type element.
duke@1 96 *
duke@1 97 * @param type the type element being examined
duke@1 98 * @return the binary name
duke@1 99 *
duke@1 100 * @see TypeElement#getQualifiedName
duke@1 101 * @jls3 13.1 The Form of a Binary
duke@1 102 */
duke@1 103 Name getBinaryName(TypeElement type);
duke@1 104
duke@1 105
duke@1 106 /**
duke@1 107 * Returns the package of an element. The package of a package is
duke@1 108 * itself.
duke@1 109 *
duke@1 110 * @param type the element being examined
duke@1 111 * @return the package of an element
duke@1 112 */
duke@1 113 PackageElement getPackageOf(Element type);
duke@1 114
duke@1 115 /**
duke@1 116 * Returns all members of a type element, whether inherited or
duke@1 117 * declared directly. For a class the result also includes its
duke@1 118 * constructors, but not local or anonymous classes.
duke@1 119 *
duke@1 120 * <p>Note that elements of certain kinds can be isolated using
duke@1 121 * methods in {@link ElementFilter}.
duke@1 122 *
duke@1 123 * @param type the type being examined
duke@1 124 * @return all members of the type
duke@1 125 * @see Element#getEnclosedElements
duke@1 126 */
duke@1 127 List<? extends Element> getAllMembers(TypeElement type);
duke@1 128
duke@1 129 /**
duke@1 130 * Returns all annotations of an element, whether
duke@1 131 * inherited or directly present.
duke@1 132 *
duke@1 133 * @param e the element being examined
duke@1 134 * @return all annotations of the element
duke@1 135 * @see Element#getAnnotationMirrors
duke@1 136 */
duke@1 137 List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e);
duke@1 138
duke@1 139 /**
duke@1 140 * Tests whether one type, method, or field hides another.
duke@1 141 *
duke@1 142 * @param hider the first element
duke@1 143 * @param hidden the second element
duke@1 144 * @return {@code true} if and only if the first element hides
duke@1 145 * the second
duke@1 146 */
duke@1 147 boolean hides(Element hider, Element hidden);
duke@1 148
duke@1 149 /**
duke@1 150 * Tests whether one method, as a member of a given type,
duke@1 151 * overrides another method.
duke@1 152 * When a non-abstract method overrides an abstract one, the
duke@1 153 * former is also said to <i>implement</i> the latter.
duke@1 154 *
duke@1 155 * <p> In the simplest and most typical usage, the value of the
duke@1 156 * {@code type} parameter will simply be the class or interface
duke@1 157 * directly enclosing {@code overrider} (the possibly-overriding
duke@1 158 * method). For example, suppose {@code m1} represents the method
duke@1 159 * {@code String.hashCode} and {@code m2} represents {@code
duke@1 160 * Object.hashCode}. We can then ask whether {@code m1} overrides
duke@1 161 * {@code m2} within the class {@code String} (it does):
duke@1 162 *
duke@1 163 * <blockquote>
duke@1 164 * {@code assert elements.overrides(m1, m2,
duke@1 165 * elements.getTypeElement("java.lang.String")); }
duke@1 166 * </blockquote>
duke@1 167 *
duke@1 168 * A more interesting case can be illustrated by the following example
duke@1 169 * in which a method in type {@code A} does not override a
duke@1 170 * like-named method in type {@code B}:
duke@1 171 *
duke@1 172 * <blockquote>
duke@1 173 * {@code class A { public void m() {} } }<br>
duke@1 174 * {@code interface B { void m(); } }<br>
duke@1 175 * ...<br>
duke@1 176 * {@code m1 = ...; // A.m }<br>
duke@1 177 * {@code m2 = ...; // B.m }<br>
duke@1 178 * {@code assert ! elements.overrides(m1, m2,
duke@1 179 * elements.getTypeElement("A")); }
duke@1 180 * </blockquote>
duke@1 181 *
duke@1 182 * When viewed as a member of a third type {@code C}, however,
duke@1 183 * the method in {@code A} does override the one in {@code B}:
duke@1 184 *
duke@1 185 * <blockquote>
duke@1 186 * {@code class C extends A implements B {} }<br>
duke@1 187 * ...<br>
duke@1 188 * {@code assert elements.overrides(m1, m2,
duke@1 189 * elements.getTypeElement("C")); }
duke@1 190 * </blockquote>
duke@1 191 *
duke@1 192 * @param overrider the first method, possible overrider
duke@1 193 * @param overridden the second method, possibly being overridden
duke@1 194 * @param type the type of which the first method is a member
duke@1 195 * @return {@code true} if and only if the first method overrides
duke@1 196 * the second
duke@1 197 * @jls3 8.4.8 Inheritance, Overriding, and Hiding
duke@1 198 * @jls3 9.4.1 Inheritance and Overriding
duke@1 199 */
duke@1 200 boolean overrides(ExecutableElement overrider, ExecutableElement overridden,
duke@1 201 TypeElement type);
duke@1 202
duke@1 203 /**
duke@1 204 * Returns the text of a <i>constant expression</i> representing a
duke@1 205 * primitive value or a string.
duke@1 206 * The text returned is in a form suitable for representing the value
duke@1 207 * in source code.
duke@1 208 *
duke@1 209 * @param value a primitive value or string
duke@1 210 * @return the text of a constant expression
duke@1 211 * @throws IllegalArgumentException if the argument is not a primitive
duke@1 212 * value or string
duke@1 213 *
duke@1 214 * @see VariableElement#getConstantValue()
duke@1 215 */
duke@1 216 String getConstantExpression(Object value);
duke@1 217
duke@1 218 /**
duke@1 219 * Prints a representation of the elements to the given writer in
duke@1 220 * the specified order. The main purpose of this method is for
duke@1 221 * diagnostics. The exact format of the output is <em>not</em>
duke@1 222 * specified and is subject to change.
duke@1 223 *
duke@1 224 * @param w the writer to print the output to
duke@1 225 * @param elements the elements to print
duke@1 226 */
duke@1 227 void printElements(java.io.Writer w, Element... elements);
duke@1 228
duke@1 229 /**
duke@1 230 * Return a name with the same sequence of characters as the
duke@1 231 * argument.
duke@1 232 *
duke@1 233 * @param cs the character sequence to return as a name
duke@1 234 */
duke@1 235 Name getName(CharSequence cs);
duke@1 236 }

mercurial