Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/javax/lang/model/util/Elements.java
38899 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.lang.model.util;262728import java.util.List;29import java.util.Map;3031import javax.lang.model.element.*;32import javax.lang.model.type.*;333435/**36* Utility methods for operating on program elements.37*38* <p><b>Compatibility Note:</b> Methods may be added to this interface39* in future releases of the platform.40*41* @author Joseph D. Darcy42* @author Scott Seligman43* @author Peter von der Ahé44* @see javax.annotation.processing.ProcessingEnvironment#getElementUtils45* @since 1.646*/47public interface Elements {4849/**50* Returns a package given its fully qualified name.51*52* @param name fully qualified package name, or "" for an unnamed package53* @return the named package, or {@code null} if it cannot be found54*/55PackageElement getPackageElement(CharSequence name);5657/**58* Returns a type element given its canonical name.59*60* @param name the canonical name61* @return the named type element, or {@code null} if it cannot be found62*/63TypeElement getTypeElement(CharSequence name);6465/**66* Returns the values of an annotation's elements, including defaults.67*68* @see AnnotationMirror#getElementValues()69* @param a annotation to examine70* @return the values of the annotation's elements, including defaults71*/72Map<? extends ExecutableElement, ? extends AnnotationValue>73getElementValuesWithDefaults(AnnotationMirror a);7475/**76* Returns the text of the documentation ("Javadoc")77* comment of an element.78*79* <p> A documentation comment of an element is a comment that80* begins with "{@code /**}" , ends with a separate81* "<code>*/</code>", and immediately precedes the element,82* ignoring white space. Therefore, a documentation comment83* contains at least three"{@code *}" characters. The text84* returned for the documentation comment is a processed form of85* the comment as it appears in source code. The leading "{@code86* /**}" and trailing "<code>*/</code>" are removed. For lines87* of the comment starting after the initial "{@code /**}",88* leading white space characters are discarded as are any89* consecutive "{@code *}" characters appearing after the white90* space or starting the line. The processed lines are then91* concatenated together (including line terminators) and92* returned.93*94* @param e the element being examined95* @return the documentation comment of the element, or {@code null}96* if there is none97* @jls 3.6 White Space98*/99String getDocComment(Element e);100101/**102* Returns {@code true} if the element is deprecated, {@code false} otherwise.103*104* @param e the element being examined105* @return {@code true} if the element is deprecated, {@code false} otherwise106*/107boolean isDeprecated(Element e);108109/**110* Returns the <i>binary name</i> of a type element.111*112* @param type the type element being examined113* @return the binary name114*115* @see TypeElement#getQualifiedName116* @jls 13.1 The Form of a Binary117*/118Name getBinaryName(TypeElement type);119120121/**122* Returns the package of an element. The package of a package is123* itself.124*125* @param type the element being examined126* @return the package of an element127*/128PackageElement getPackageOf(Element type);129130/**131* Returns all members of a type element, whether inherited or132* declared directly. For a class the result also includes its133* constructors, but not local or anonymous classes.134*135* <p>Note that elements of certain kinds can be isolated using136* methods in {@link ElementFilter}.137*138* @param type the type being examined139* @return all members of the type140* @see Element#getEnclosedElements141*/142List<? extends Element> getAllMembers(TypeElement type);143144/**145* Returns all annotations <i>present</i> on an element, whether146* directly present or present via inheritance.147*148* @param e the element being examined149* @return all annotations of the element150* @see Element#getAnnotationMirrors151* @see javax.lang.model.AnnotatedConstruct152*/153List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e);154155/**156* Tests whether one type, method, or field hides another.157*158* @param hider the first element159* @param hidden the second element160* @return {@code true} if and only if the first element hides161* the second162*/163boolean hides(Element hider, Element hidden);164165/**166* Tests whether one method, as a member of a given type,167* overrides another method.168* When a non-abstract method overrides an abstract one, the169* former is also said to <i>implement</i> the latter.170*171* <p> In the simplest and most typical usage, the value of the172* {@code type} parameter will simply be the class or interface173* directly enclosing {@code overrider} (the possibly-overriding174* method). For example, suppose {@code m1} represents the method175* {@code String.hashCode} and {@code m2} represents {@code176* Object.hashCode}. We can then ask whether {@code m1} overrides177* {@code m2} within the class {@code String} (it does):178*179* <blockquote>180* {@code assert elements.overrides(m1, m2,181* elements.getTypeElement("java.lang.String")); }182* </blockquote>183*184* A more interesting case can be illustrated by the following example185* in which a method in type {@code A} does not override a186* like-named method in type {@code B}:187*188* <blockquote>189* {@code class A { public void m() {} } }<br>190* {@code interface B { void m(); } }<br>191* ...<br>192* {@code m1 = ...; // A.m }<br>193* {@code m2 = ...; // B.m }<br>194* {@code assert ! elements.overrides(m1, m2,195* elements.getTypeElement("A")); }196* </blockquote>197*198* When viewed as a member of a third type {@code C}, however,199* the method in {@code A} does override the one in {@code B}:200*201* <blockquote>202* {@code class C extends A implements B {} }<br>203* ...<br>204* {@code assert elements.overrides(m1, m2,205* elements.getTypeElement("C")); }206* </blockquote>207*208* @param overrider the first method, possible overrider209* @param overridden the second method, possibly being overridden210* @param type the type of which the first method is a member211* @return {@code true} if and only if the first method overrides212* the second213* @jls 8.4.8 Inheritance, Overriding, and Hiding214* @jls 9.4.1 Inheritance and Overriding215*/216boolean overrides(ExecutableElement overrider, ExecutableElement overridden,217TypeElement type);218219/**220* Returns the text of a <i>constant expression</i> representing a221* primitive value or a string.222* The text returned is in a form suitable for representing the value223* in source code.224*225* @param value a primitive value or string226* @return the text of a constant expression227* @throws IllegalArgumentException if the argument is not a primitive228* value or string229*230* @see VariableElement#getConstantValue()231*/232String getConstantExpression(Object value);233234/**235* Prints a representation of the elements to the given writer in236* the specified order. The main purpose of this method is for237* diagnostics. The exact format of the output is <em>not</em>238* specified and is subject to change.239*240* @param w the writer to print the output to241* @param elements the elements to print242*/243void printElements(java.io.Writer w, Element... elements);244245/**246* Return a name with the same sequence of characters as the247* argument.248*249* @param cs the character sequence to return as a name250* @return a name with the same sequence of characters as the argument251*/252Name getName(CharSequence cs);253254/**255* Returns {@code true} if the type element is a functional interface, {@code false} otherwise.256*257* @param type the type element being examined258* @return {@code true} if the element is a functional interface, {@code false} otherwise259* @jls 9.8 Functional Interfaces260* @since 1.8261*/262boolean isFunctionalInterface(TypeElement type);263}264265266