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

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 554
9d9f26857129
child 972
694ff82ca68e
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

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

mercurial