001: /*
002: * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package javax.lang.model.util;
027:
028: import java.util.List;
029: import java.util.Map;
030:
031: import javax.lang.model.element.*;
032: import javax.lang.model.type.*;
033:
034: /**
035: * Utility methods for operating on program elements.
036: *
037: * <p><b>Compatibility Note:</b> Methods may be added to this interface
038: * in future releases of the platform.
039: *
040: * @author Joseph D. Darcy
041: * @author Scott Seligman
042: * @author Peter von der Ahé
043: * @version 1.17 07/05/05
044: * @see javax.annotation.processing.ProcessingEnvironment#getElementUtils
045: * @since 1.6
046: */
047: public interface Elements {
048:
049: /**
050: * Returns a package given its fully qualified name.
051: *
052: * @param name fully qualified package name, or "" for an unnamed package
053: * @return the named package, or {@code null} if it cannot be found
054: */
055: PackageElement getPackageElement(CharSequence name);
056:
057: /**
058: * Returns a type element given its canonical name.
059: *
060: * @param name the canonical name
061: * @return the named type element, or {@code null} if it cannot be found
062: */
063: TypeElement getTypeElement(CharSequence name);
064:
065: /**
066: * Returns the values of an annotation's elements, including defaults.
067: *
068: * @see AnnotationMirror#getElementValues()
069: * @param a annotation to examine
070: * @return the values of the annotation's elements, including defaults
071: */
072: Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValuesWithDefaults(
073: AnnotationMirror a);
074:
075: /**
076: * Returns the text of the documentation ("Javadoc")
077: * comment of an element.
078: *
079: * @param e the element being examined
080: * @return the documentation comment of the element, or {@code null}
081: * if there is none
082: */
083: String getDocComment(Element e);
084:
085: /**
086: * Returns {@code true} if the element is deprecated, {@code false} otherwise.
087: *
088: * @param e the element being examined
089: * @return {@code true} if the element is deprecated, {@code false} otherwise
090: */
091: boolean isDeprecated(Element e);
092:
093: /**
094: * Returns the <i>binary name</i> of a type element.
095: *
096: * @param type the type element being examined
097: * @return the binary name
098: *
099: * @see TypeElement#getQualifiedName
100: * @jls3 13.1 The Form of a Binary
101: */
102: Name getBinaryName(TypeElement type);
103:
104: /**
105: * Returns the package of an element. The package of a package is
106: * itself.
107: *
108: * @param type the element being examined
109: * @return the package of an element
110: */
111: PackageElement getPackageOf(Element type);
112:
113: /**
114: * Returns all members of a type element, whether inherited or
115: * declared directly. For a class the result also includes its
116: * constructors, but not local or anonymous classes.
117: *
118: * <p>Note that elements of certain kinds can be isolated using
119: * methods in {@link ElementFilter}.
120: *
121: * @param type the type being examined
122: * @return all members of the type
123: * @see Element#getEnclosedElements
124: */
125: List<? extends Element> getAllMembers(TypeElement type);
126:
127: /**
128: * Returns all annotations of an element, whether
129: * inherited or directly present.
130: *
131: * @param e the element being examined
132: * @return all annotations of the element
133: * @see Element#getAnnotationMirrors
134: */
135: List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e);
136:
137: /**
138: * Tests whether one type, method, or field hides another.
139: *
140: * @param hider the first element
141: * @param hidden the second element
142: * @return {@code true} if and only if the first element hides
143: * the second
144: */
145: boolean hides(Element hider, Element hidden);
146:
147: /**
148: * Tests whether one method, as a member of a given type,
149: * overrides another method.
150: * When a non-abstract method overrides an abstract one, the
151: * former is also said to <i>implement</i> the latter.
152: *
153: * <p> In the simplest and most typical usage, the value of the
154: * {@code type} parameter will simply be the class or interface
155: * directly enclosing {@code overrider} (the possibly-overriding
156: * method). For example, suppose {@code m1} represents the method
157: * {@code String.hashCode} and {@code m2} represents {@code
158: * Object.hashCode}. We can then ask whether {@code m1} overrides
159: * {@code m2} within the class {@code String} (it does):
160: *
161: * <blockquote>
162: * {@code assert elements.overrides(m1, m2,
163: * elements.getTypeElement("java.lang.String")); }
164: * </blockquote>
165: *
166: * A more interesting case can be illustrated by the following example
167: * in which a method in type {@code A} does not override a
168: * like-named method in type {@code B}:
169: *
170: * <blockquote>
171: * {@code class A { public void m() {} } }<br>
172: * {@code interface B { void m(); } }<br>
173: * ...<br>
174: * {@code m1 = ...; // A.m }<br>
175: * {@code m2 = ...; // B.m }<br>
176: * {@code assert ! elements.overrides(m1, m2,
177: * elements.getTypeElement("A")); }
178: * </blockquote>
179: *
180: * When viewed as a member of a third type {@code C}, however,
181: * the method in {@code A} does override the one in {@code B}:
182: *
183: * <blockquote>
184: * {@code class C extends A implements B {} }<br>
185: * ...<br>
186: * {@code assert elements.overrides(m1, m2,
187: * elements.getTypeElement("C")); }
188: * </blockquote>
189: *
190: * @param overrider the first method, possible overrider
191: * @param overridden the second method, possibly being overridden
192: * @param type the type of which the first method is a member
193: * @return {@code true} if and only if the first method overrides
194: * the second
195: * @jls3 8.4.8 Inheritance, Overriding, and Hiding
196: * @jls3 9.4.1 Inheritance and Overriding
197: */
198: boolean overrides(ExecutableElement overrider,
199: ExecutableElement overridden, TypeElement type);
200:
201: /**
202: * Returns the text of a <i>constant expression</i> representing a
203: * primitive value or a string.
204: * The text returned is in a form suitable for representing the value
205: * in source code.
206: *
207: * @param value a primitive value or string
208: * @return the text of a constant expression
209: * @throws IllegalArgumentException if the argument is not a primitive
210: * value or string
211: *
212: * @see VariableElement#getConstantValue()
213: */
214: String getConstantExpression(Object value);
215:
216: /**
217: * Prints a representation of the elements to the given writer in
218: * the specified order. The main purpose of this method is for
219: * diagnostics. The exact format of the output is <em>not</em>
220: * specified and is subject to change.
221: *
222: * @param w the writer to print the output to
223: * @param elements the elements to print
224: */
225: void printElements(java.io.Writer w, Element... elements);
226:
227: /**
228: * Return a name with the same sequence of characters as the
229: * argument.
230: *
231: * @param cs the character sequence to return as a name
232: */
233: Name getName(CharSequence cs);
234: }
|