Tue, 28 Dec 2010 15:54:52 -0800
6962318: Update copyright year
Reviewed-by: xdono
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2005, 2006, Oracle and/or its affiliates. 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 |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle 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 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * 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é |
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 ("Javadoc") |
duke@1 | 78 | * comment of an element. |
duke@1 | 79 | * |
darcy@425 | 80 | * <p> A documentation comment of an element is a comment that |
darcy@425 | 81 | * begins with "{@code /**}" , ends with a separate |
darcy@425 | 82 | * "<code>*/</code>", and immediately precedes the element, |
darcy@425 | 83 | * ignoring white space. Therefore, a documentation comment |
darcy@425 | 84 | * contains at least three"{@code *}" characters. The text |
darcy@425 | 85 | * returned for the documentation comment is a processed form of |
darcy@425 | 86 | * the comment as it appears in source code. The leading "{@code |
darcy@425 | 87 | * /**}" and trailing "<code>*/</code>" are removed. For lines |
darcy@425 | 88 | * of the comment starting after the initial "{@code /**}", |
darcy@425 | 89 | * leading white space characters are discarded as are any |
darcy@425 | 90 | * consecutive "{@code *}" characters appearing after the white |
darcy@425 | 91 | * space or starting the line. The processed lines are then |
darcy@425 | 92 | * concatenated together (including line terminators) and |
darcy@425 | 93 | * returned. |
darcy@425 | 94 | * |
duke@1 | 95 | * @param e the element being examined |
duke@1 | 96 | * @return the documentation comment of the element, or {@code null} |
duke@1 | 97 | * if there is none |
darcy@425 | 98 | * @jls3 3.6 White Space |
duke@1 | 99 | */ |
duke@1 | 100 | String getDocComment(Element e); |
duke@1 | 101 | |
duke@1 | 102 | /** |
duke@1 | 103 | * Returns {@code true} if the element is deprecated, {@code false} otherwise. |
duke@1 | 104 | * |
duke@1 | 105 | * @param e the element being examined |
duke@1 | 106 | * @return {@code true} if the element is deprecated, {@code false} otherwise |
duke@1 | 107 | */ |
duke@1 | 108 | boolean isDeprecated(Element e); |
duke@1 | 109 | |
duke@1 | 110 | /** |
duke@1 | 111 | * Returns the <i>binary name</i> of a type element. |
duke@1 | 112 | * |
duke@1 | 113 | * @param type the type element being examined |
duke@1 | 114 | * @return the binary name |
duke@1 | 115 | * |
duke@1 | 116 | * @see TypeElement#getQualifiedName |
duke@1 | 117 | * @jls3 13.1 The Form of a Binary |
duke@1 | 118 | */ |
duke@1 | 119 | Name getBinaryName(TypeElement type); |
duke@1 | 120 | |
duke@1 | 121 | |
duke@1 | 122 | /** |
duke@1 | 123 | * Returns the package of an element. The package of a package is |
duke@1 | 124 | * itself. |
duke@1 | 125 | * |
duke@1 | 126 | * @param type the element being examined |
duke@1 | 127 | * @return the package of an element |
duke@1 | 128 | */ |
duke@1 | 129 | PackageElement getPackageOf(Element type); |
duke@1 | 130 | |
duke@1 | 131 | /** |
duke@1 | 132 | * Returns all members of a type element, whether inherited or |
duke@1 | 133 | * declared directly. For a class the result also includes its |
duke@1 | 134 | * constructors, but not local or anonymous classes. |
duke@1 | 135 | * |
duke@1 | 136 | * <p>Note that elements of certain kinds can be isolated using |
duke@1 | 137 | * methods in {@link ElementFilter}. |
duke@1 | 138 | * |
duke@1 | 139 | * @param type the type being examined |
duke@1 | 140 | * @return all members of the type |
duke@1 | 141 | * @see Element#getEnclosedElements |
duke@1 | 142 | */ |
duke@1 | 143 | List<? extends Element> getAllMembers(TypeElement type); |
duke@1 | 144 | |
duke@1 | 145 | /** |
duke@1 | 146 | * Returns all annotations of an element, whether |
duke@1 | 147 | * inherited or directly present. |
duke@1 | 148 | * |
duke@1 | 149 | * @param e the element being examined |
duke@1 | 150 | * @return all annotations of the element |
duke@1 | 151 | * @see Element#getAnnotationMirrors |
duke@1 | 152 | */ |
duke@1 | 153 | List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e); |
duke@1 | 154 | |
duke@1 | 155 | /** |
duke@1 | 156 | * Tests whether one type, method, or field hides another. |
duke@1 | 157 | * |
duke@1 | 158 | * @param hider the first element |
duke@1 | 159 | * @param hidden the second element |
duke@1 | 160 | * @return {@code true} if and only if the first element hides |
duke@1 | 161 | * the second |
duke@1 | 162 | */ |
duke@1 | 163 | boolean hides(Element hider, Element hidden); |
duke@1 | 164 | |
duke@1 | 165 | /** |
duke@1 | 166 | * Tests whether one method, as a member of a given type, |
duke@1 | 167 | * overrides another method. |
duke@1 | 168 | * When a non-abstract method overrides an abstract one, the |
duke@1 | 169 | * former is also said to <i>implement</i> the latter. |
duke@1 | 170 | * |
duke@1 | 171 | * <p> In the simplest and most typical usage, the value of the |
duke@1 | 172 | * {@code type} parameter will simply be the class or interface |
duke@1 | 173 | * directly enclosing {@code overrider} (the possibly-overriding |
duke@1 | 174 | * method). For example, suppose {@code m1} represents the method |
duke@1 | 175 | * {@code String.hashCode} and {@code m2} represents {@code |
duke@1 | 176 | * Object.hashCode}. We can then ask whether {@code m1} overrides |
duke@1 | 177 | * {@code m2} within the class {@code String} (it does): |
duke@1 | 178 | * |
duke@1 | 179 | * <blockquote> |
duke@1 | 180 | * {@code assert elements.overrides(m1, m2, |
duke@1 | 181 | * elements.getTypeElement("java.lang.String")); } |
duke@1 | 182 | * </blockquote> |
duke@1 | 183 | * |
duke@1 | 184 | * A more interesting case can be illustrated by the following example |
duke@1 | 185 | * in which a method in type {@code A} does not override a |
duke@1 | 186 | * like-named method in type {@code B}: |
duke@1 | 187 | * |
duke@1 | 188 | * <blockquote> |
duke@1 | 189 | * {@code class A { public void m() {} } }<br> |
duke@1 | 190 | * {@code interface B { void m(); } }<br> |
duke@1 | 191 | * ...<br> |
duke@1 | 192 | * {@code m1 = ...; // A.m }<br> |
duke@1 | 193 | * {@code m2 = ...; // B.m }<br> |
duke@1 | 194 | * {@code assert ! elements.overrides(m1, m2, |
duke@1 | 195 | * elements.getTypeElement("A")); } |
duke@1 | 196 | * </blockquote> |
duke@1 | 197 | * |
duke@1 | 198 | * When viewed as a member of a third type {@code C}, however, |
duke@1 | 199 | * the method in {@code A} does override the one in {@code B}: |
duke@1 | 200 | * |
duke@1 | 201 | * <blockquote> |
duke@1 | 202 | * {@code class C extends A implements B {} }<br> |
duke@1 | 203 | * ...<br> |
duke@1 | 204 | * {@code assert elements.overrides(m1, m2, |
duke@1 | 205 | * elements.getTypeElement("C")); } |
duke@1 | 206 | * </blockquote> |
duke@1 | 207 | * |
duke@1 | 208 | * @param overrider the first method, possible overrider |
duke@1 | 209 | * @param overridden the second method, possibly being overridden |
duke@1 | 210 | * @param type the type of which the first method is a member |
duke@1 | 211 | * @return {@code true} if and only if the first method overrides |
duke@1 | 212 | * the second |
duke@1 | 213 | * @jls3 8.4.8 Inheritance, Overriding, and Hiding |
duke@1 | 214 | * @jls3 9.4.1 Inheritance and Overriding |
duke@1 | 215 | */ |
duke@1 | 216 | boolean overrides(ExecutableElement overrider, ExecutableElement overridden, |
duke@1 | 217 | TypeElement type); |
duke@1 | 218 | |
duke@1 | 219 | /** |
duke@1 | 220 | * Returns the text of a <i>constant expression</i> representing a |
duke@1 | 221 | * primitive value or a string. |
duke@1 | 222 | * The text returned is in a form suitable for representing the value |
duke@1 | 223 | * in source code. |
duke@1 | 224 | * |
duke@1 | 225 | * @param value a primitive value or string |
duke@1 | 226 | * @return the text of a constant expression |
duke@1 | 227 | * @throws IllegalArgumentException if the argument is not a primitive |
duke@1 | 228 | * value or string |
duke@1 | 229 | * |
duke@1 | 230 | * @see VariableElement#getConstantValue() |
duke@1 | 231 | */ |
duke@1 | 232 | String getConstantExpression(Object value); |
duke@1 | 233 | |
duke@1 | 234 | /** |
duke@1 | 235 | * Prints a representation of the elements to the given writer in |
duke@1 | 236 | * the specified order. The main purpose of this method is for |
duke@1 | 237 | * diagnostics. The exact format of the output is <em>not</em> |
duke@1 | 238 | * specified and is subject to change. |
duke@1 | 239 | * |
duke@1 | 240 | * @param w the writer to print the output to |
duke@1 | 241 | * @param elements the elements to print |
duke@1 | 242 | */ |
duke@1 | 243 | void printElements(java.io.Writer w, Element... elements); |
duke@1 | 244 | |
duke@1 | 245 | /** |
duke@1 | 246 | * Return a name with the same sequence of characters as the |
duke@1 | 247 | * argument. |
duke@1 | 248 | * |
duke@1 | 249 | * @param cs the character sequence to return as a name |
duke@1 | 250 | */ |
duke@1 | 251 | Name getName(CharSequence cs); |
duke@1 | 252 | } |