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

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1777
3bd22f99d408
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.lang.model.util;
aoqi@0 27
aoqi@0 28
aoqi@0 29 import java.util.List;
aoqi@0 30 import java.util.Map;
aoqi@0 31
aoqi@0 32 import javax.lang.model.element.*;
aoqi@0 33 import javax.lang.model.type.*;
aoqi@0 34
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Utility methods for operating on program elements.
aoqi@0 38 *
aoqi@0 39 * <p><b>Compatibility Note:</b> Methods may be added to this interface
aoqi@0 40 * in future releases of the platform.
aoqi@0 41 *
aoqi@0 42 * @author Joseph D. Darcy
aoqi@0 43 * @author Scott Seligman
aoqi@0 44 * @author Peter von der Ah&eacute;
aoqi@0 45 * @see javax.annotation.processing.ProcessingEnvironment#getElementUtils
aoqi@0 46 * @since 1.6
aoqi@0 47 */
aoqi@0 48 public interface Elements {
aoqi@0 49
aoqi@0 50 /**
aoqi@0 51 * Returns a package given its fully qualified name.
aoqi@0 52 *
aoqi@0 53 * @param name fully qualified package name, or "" for an unnamed package
aoqi@0 54 * @return the named package, or {@code null} if it cannot be found
aoqi@0 55 */
aoqi@0 56 PackageElement getPackageElement(CharSequence name);
aoqi@0 57
aoqi@0 58 /**
aoqi@0 59 * Returns a type element given its canonical name.
aoqi@0 60 *
aoqi@0 61 * @param name the canonical name
aoqi@0 62 * @return the named type element, or {@code null} if it cannot be found
aoqi@0 63 */
aoqi@0 64 TypeElement getTypeElement(CharSequence name);
aoqi@0 65
aoqi@0 66 /**
aoqi@0 67 * Returns the values of an annotation's elements, including defaults.
aoqi@0 68 *
aoqi@0 69 * @see AnnotationMirror#getElementValues()
aoqi@0 70 * @param a annotation to examine
aoqi@0 71 * @return the values of the annotation's elements, including defaults
aoqi@0 72 */
aoqi@0 73 Map<? extends ExecutableElement, ? extends AnnotationValue>
aoqi@0 74 getElementValuesWithDefaults(AnnotationMirror a);
aoqi@0 75
aoqi@0 76 /**
aoqi@0 77 * Returns the text of the documentation (&quot;Javadoc&quot;)
aoqi@0 78 * comment of an element.
aoqi@0 79 *
aoqi@0 80 * <p> A documentation comment of an element is a comment that
aoqi@0 81 * begins with "{@code /**}" , ends with a separate
aoqi@0 82 * "<code>*&#47;</code>", and immediately precedes the element,
aoqi@0 83 * ignoring white space. Therefore, a documentation comment
aoqi@0 84 * contains at least three"{@code *}" characters. The text
aoqi@0 85 * returned for the documentation comment is a processed form of
aoqi@0 86 * the comment as it appears in source code. The leading "{@code
aoqi@0 87 * /**}" and trailing "<code>*&#47;</code>" are removed. For lines
aoqi@0 88 * of the comment starting after the initial "{@code /**}",
aoqi@0 89 * leading white space characters are discarded as are any
aoqi@0 90 * consecutive "{@code *}" characters appearing after the white
aoqi@0 91 * space or starting the line. The processed lines are then
aoqi@0 92 * concatenated together (including line terminators) and
aoqi@0 93 * returned.
aoqi@0 94 *
aoqi@0 95 * @param e the element being examined
aoqi@0 96 * @return the documentation comment of the element, or {@code null}
aoqi@0 97 * if there is none
aoqi@0 98 * @jls 3.6 White Space
aoqi@0 99 */
aoqi@0 100 String getDocComment(Element e);
aoqi@0 101
aoqi@0 102 /**
aoqi@0 103 * Returns {@code true} if the element is deprecated, {@code false} otherwise.
aoqi@0 104 *
aoqi@0 105 * @param e the element being examined
aoqi@0 106 * @return {@code true} if the element is deprecated, {@code false} otherwise
aoqi@0 107 */
aoqi@0 108 boolean isDeprecated(Element e);
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Returns the <i>binary name</i> of a type element.
aoqi@0 112 *
aoqi@0 113 * @param type the type element being examined
aoqi@0 114 * @return the binary name
aoqi@0 115 *
aoqi@0 116 * @see TypeElement#getQualifiedName
aoqi@0 117 * @jls 13.1 The Form of a Binary
aoqi@0 118 */
aoqi@0 119 Name getBinaryName(TypeElement type);
aoqi@0 120
aoqi@0 121
aoqi@0 122 /**
aoqi@0 123 * Returns the package of an element. The package of a package is
aoqi@0 124 * itself.
aoqi@0 125 *
aoqi@0 126 * @param type the element being examined
aoqi@0 127 * @return the package of an element
aoqi@0 128 */
aoqi@0 129 PackageElement getPackageOf(Element type);
aoqi@0 130
aoqi@0 131 /**
aoqi@0 132 * Returns all members of a type element, whether inherited or
aoqi@0 133 * declared directly. For a class the result also includes its
aoqi@0 134 * constructors, but not local or anonymous classes.
aoqi@0 135 *
aoqi@0 136 * <p>Note that elements of certain kinds can be isolated using
aoqi@0 137 * methods in {@link ElementFilter}.
aoqi@0 138 *
aoqi@0 139 * @param type the type being examined
aoqi@0 140 * @return all members of the type
aoqi@0 141 * @see Element#getEnclosedElements
aoqi@0 142 */
aoqi@0 143 List<? extends Element> getAllMembers(TypeElement type);
aoqi@0 144
aoqi@0 145 /**
aoqi@0 146 * Returns all annotations <i>present</i> on an element, whether
aoqi@0 147 * directly present or present via inheritance.
aoqi@0 148 *
aoqi@0 149 * @param e the element being examined
aoqi@0 150 * @return all annotations of the element
aoqi@0 151 * @see Element#getAnnotationMirrors
aoqi@0 152 * @see javax.lang.model.AnnotatedConstruct
aoqi@0 153 */
aoqi@0 154 List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e);
aoqi@0 155
aoqi@0 156 /**
aoqi@0 157 * Tests whether one type, method, or field hides another.
aoqi@0 158 *
aoqi@0 159 * @param hider the first element
aoqi@0 160 * @param hidden the second element
aoqi@0 161 * @return {@code true} if and only if the first element hides
aoqi@0 162 * the second
aoqi@0 163 */
aoqi@0 164 boolean hides(Element hider, Element hidden);
aoqi@0 165
aoqi@0 166 /**
aoqi@0 167 * Tests whether one method, as a member of a given type,
aoqi@0 168 * overrides another method.
aoqi@0 169 * When a non-abstract method overrides an abstract one, the
aoqi@0 170 * former is also said to <i>implement</i> the latter.
aoqi@0 171 *
aoqi@0 172 * <p> In the simplest and most typical usage, the value of the
aoqi@0 173 * {@code type} parameter will simply be the class or interface
aoqi@0 174 * directly enclosing {@code overrider} (the possibly-overriding
aoqi@0 175 * method). For example, suppose {@code m1} represents the method
aoqi@0 176 * {@code String.hashCode} and {@code m2} represents {@code
aoqi@0 177 * Object.hashCode}. We can then ask whether {@code m1} overrides
aoqi@0 178 * {@code m2} within the class {@code String} (it does):
aoqi@0 179 *
aoqi@0 180 * <blockquote>
aoqi@0 181 * {@code assert elements.overrides(m1, m2,
aoqi@0 182 * elements.getTypeElement("java.lang.String")); }
aoqi@0 183 * </blockquote>
aoqi@0 184 *
aoqi@0 185 * A more interesting case can be illustrated by the following example
aoqi@0 186 * in which a method in type {@code A} does not override a
aoqi@0 187 * like-named method in type {@code B}:
aoqi@0 188 *
aoqi@0 189 * <blockquote>
aoqi@0 190 * {@code class A { public void m() {} } }<br>
aoqi@0 191 * {@code interface B { void m(); } }<br>
aoqi@0 192 * ...<br>
aoqi@0 193 * {@code m1 = ...; // A.m }<br>
aoqi@0 194 * {@code m2 = ...; // B.m }<br>
aoqi@0 195 * {@code assert ! elements.overrides(m1, m2,
aoqi@0 196 * elements.getTypeElement("A")); }
aoqi@0 197 * </blockquote>
aoqi@0 198 *
aoqi@0 199 * When viewed as a member of a third type {@code C}, however,
aoqi@0 200 * the method in {@code A} does override the one in {@code B}:
aoqi@0 201 *
aoqi@0 202 * <blockquote>
aoqi@0 203 * {@code class C extends A implements B {} }<br>
aoqi@0 204 * ...<br>
aoqi@0 205 * {@code assert elements.overrides(m1, m2,
aoqi@0 206 * elements.getTypeElement("C")); }
aoqi@0 207 * </blockquote>
aoqi@0 208 *
aoqi@0 209 * @param overrider the first method, possible overrider
aoqi@0 210 * @param overridden the second method, possibly being overridden
aoqi@0 211 * @param type the type of which the first method is a member
aoqi@0 212 * @return {@code true} if and only if the first method overrides
aoqi@0 213 * the second
aoqi@0 214 * @jls 8.4.8 Inheritance, Overriding, and Hiding
aoqi@0 215 * @jls 9.4.1 Inheritance and Overriding
aoqi@0 216 */
aoqi@0 217 boolean overrides(ExecutableElement overrider, ExecutableElement overridden,
aoqi@0 218 TypeElement type);
aoqi@0 219
aoqi@0 220 /**
aoqi@0 221 * Returns the text of a <i>constant expression</i> representing a
aoqi@0 222 * primitive value or a string.
aoqi@0 223 * The text returned is in a form suitable for representing the value
aoqi@0 224 * in source code.
aoqi@0 225 *
aoqi@0 226 * @param value a primitive value or string
aoqi@0 227 * @return the text of a constant expression
aoqi@0 228 * @throws IllegalArgumentException if the argument is not a primitive
aoqi@0 229 * value or string
aoqi@0 230 *
aoqi@0 231 * @see VariableElement#getConstantValue()
aoqi@0 232 */
aoqi@0 233 String getConstantExpression(Object value);
aoqi@0 234
aoqi@0 235 /**
aoqi@0 236 * Prints a representation of the elements to the given writer in
aoqi@0 237 * the specified order. The main purpose of this method is for
aoqi@0 238 * diagnostics. The exact format of the output is <em>not</em>
aoqi@0 239 * specified and is subject to change.
aoqi@0 240 *
aoqi@0 241 * @param w the writer to print the output to
aoqi@0 242 * @param elements the elements to print
aoqi@0 243 */
aoqi@0 244 void printElements(java.io.Writer w, Element... elements);
aoqi@0 245
aoqi@0 246 /**
aoqi@0 247 * Return a name with the same sequence of characters as the
aoqi@0 248 * argument.
aoqi@0 249 *
aoqi@0 250 * @param cs the character sequence to return as a name
aoqi@0 251 * @return a name with the same sequence of characters as the argument
aoqi@0 252 */
aoqi@0 253 Name getName(CharSequence cs);
aoqi@0 254
aoqi@0 255 /**
aoqi@0 256 * Returns {@code true} if the type element is a functional interface, {@code false} otherwise.
aoqi@0 257 *
aoqi@0 258 * @param type the type element being examined
aoqi@0 259 * @return {@code true} if the element is a functional interface, {@code false} otherwise
aoqi@0 260 * @jls 9.8 Functional Interfaces
aoqi@0 261 * @since 1.8
aoqi@0 262 */
aoqi@0 263 boolean isFunctionalInterface(TypeElement type);
aoqi@0 264 }

mercurial