diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2013-02-03 15:55:00 +0100 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2013-02-03 15:55:00 +0100 |
commit | 21b497fa516b3997d9893ee0ddf81db75c71ef91 (patch) | |
tree | edd13103c39293e826d5b987d244f191a8dd72e1 /javax/lang/model/element | |
parent | f1ea0230edd3df0e98c737afb6820bf106519bc2 (diff) | |
parent | f45f5eea2eb5bed298a7372d6d2da827b0400e86 (diff) | |
download | classpath-21b497fa516b3997d9893ee0ddf81db75c71ef91.tar.gz |
Merge branch 'compiler-support'
Conflicts:
ChangeLog
Signed-off-by: Andrew John Hughes <gnu_andrew@member.fsf.org>
Diffstat (limited to 'javax/lang/model/element')
-rw-r--r-- | javax/lang/model/element/AnnotationMirror.java | 78 | ||||
-rw-r--r-- | javax/lang/model/element/AnnotationValue.java | 86 | ||||
-rw-r--r-- | javax/lang/model/element/AnnotationValueVisitor.java | 226 | ||||
-rw-r--r-- | javax/lang/model/element/Element.java | 213 | ||||
-rw-r--r-- | javax/lang/model/element/ElementKind.java | 119 | ||||
-rw-r--r-- | javax/lang/model/element/ElementVisitor.java | 143 | ||||
-rw-r--r-- | javax/lang/model/element/ExecutableElement.java | 113 | ||||
-rw-r--r-- | javax/lang/model/element/Modifier.java | 71 | ||||
-rw-r--r-- | javax/lang/model/element/Name.java | 90 | ||||
-rw-r--r-- | javax/lang/model/element/NestingKind.java | 65 | ||||
-rw-r--r-- | javax/lang/model/element/PackageElement.java | 72 | ||||
-rw-r--r-- | javax/lang/model/element/TypeElement.java | 126 | ||||
-rw-r--r-- | javax/lang/model/element/TypeParameterElement.java | 82 | ||||
-rw-r--r-- | javax/lang/model/element/UnknownAnnotationValueException.java | 106 | ||||
-rw-r--r-- | javax/lang/model/element/UnknownElementException.java | 105 | ||||
-rw-r--r-- | javax/lang/model/element/VariableElement.java | 63 |
16 files changed, 1758 insertions, 0 deletions
diff --git a/javax/lang/model/element/AnnotationMirror.java b/javax/lang/model/element/AnnotationMirror.java new file mode 100644 index 000000000..eeaf688e8 --- /dev/null +++ b/javax/lang/model/element/AnnotationMirror.java @@ -0,0 +1,78 @@ +/* AnnotationMirror.java -- Represents an annotation. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +import java.util.Map; + +import javax.lang.model.type.DeclaredType; + +/** + * Represents an annotation. An annotation associates values + * with the elements of an annotation type. Annotations should + * be compared using {@link #equals(Object)}. There is no guarantee + * that the same annotation is always represented by the same + * instance. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface AnnotationMirror +{ + + /** + * Returns the type of this annotation. + * + * @return the type of this annotation. + */ + DeclaredType getAnnotationType(); + + /** + * Returns a map of elements to their values. Only those + * elements explicitly set in the annotation are present; + * default values are not included. To obtain the default + * values as well, use + * {@link javax.lang.model.util.Elements#getElementValuesWithDefaults(AnnotationMirror)} + * A marker annotation, by definition, returns an empty map. + * The order of the elements in the map follows that of the + * source code. + * + * @return the map of elements to values. + */ + Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValues(); + +} diff --git a/javax/lang/model/element/AnnotationValue.java b/javax/lang/model/element/AnnotationValue.java new file mode 100644 index 000000000..d25ce4205 --- /dev/null +++ b/javax/lang/model/element/AnnotationValue.java @@ -0,0 +1,86 @@ +/* AnnotationValue.java -- Represents an annotation value. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * <p>Represents the value of an element in an annotation. This + * may be one of the following types:</p> + * <ul> + * <li>a wrapper class for a primitive type (e.g. {@code Integer} + * for {@code int}.</li> + * <li>{@code String}</li> + * <li>{@code TypeMirror}</li> + * <li>{@code VariableElement} (an enum constant)</li> + * <li>{@code AnnotationMirror}</li> + * <li>{@code List<? extends AnnotationValue>} (an array, + * with elements in the order they were declared)</li> + * </ol> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface AnnotationValue +{ + + /** + * Applies a visitor to this type. + * + * @param <R> the return type of the visitor's methods. + * @param <P> the type of the additional parameter used in the visitor's + * methods. + * @param visitor the visitor to apply to the element. + * @param param the additional parameter to be sent to the visitor. + * @return the return value from the visitor. + */ + <R,P> R accept(AnnotationValueVisitor<R,P> visitor, P param); + + /** + * Returns the value. + * + * @return the value. + */ + Object getValue(); + + /** + * Returns a textual representation of the value. + * + * @return a textual representation. + */ + String toString(); + +} diff --git a/javax/lang/model/element/AnnotationValueVisitor.java b/javax/lang/model/element/AnnotationValueVisitor.java new file mode 100644 index 000000000..74229eb55 --- /dev/null +++ b/javax/lang/model/element/AnnotationValueVisitor.java @@ -0,0 +1,226 @@ +/* AnnotationValueVisitor.java -- A visitor of annotation values. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +import java.util.List; + +import javax.lang.model.type.TypeMirror; + +/** + * <p>A visitor for annotation values. Unlike other visitors, such + * as {@link ElementVisitor} and {@link javax.lang.model.type.TypeVisitor}, + * which work on a concrete type hierarchy, this visitor dispatches based + * on the type of data stored in the annotation, some of which don't have + * distinct subclasses for storing them (e.g. primitives like {@code boolean} + * and {@code int}.</p> + * <p> The visitor is used when the specific type is not known at compile + * time. A visitor instance is passed to the + * {@link AnnotationValue#accept(AnnotationValueVisitor,P)} method of + * the type, which then calls the specific {@code visitN} method + * appropriate to that specific type.</p> + * <p>The additional parameter supplied to visitor methods may or + * may not be optional, and so the class is free to throw a + * {@code NullPointerException} if {@code null} is passed as the + * additional parameter.</p> + * <p>As this interface may be extended to accomodate future language + * versions, implementators are encouraged to extend one of the + * appropriate abstract classes rather than implementating this + * interface. However, this interface should be used as the type + * for parameters and return values.</p> + * + * @param <R> the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param <P> the type of the additional parameter supplied to the visitor's + * methods. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface AnnotationValueVisitor<R,P> +{ + + /** + * A convenience method for use when there is no additional + * parameter to pass. This is equivalent to {@code #visit(value, null)}. + * + * @param value the value to visit. + * @return the return value specific to the visitor. + */ + R visit(AnnotationValue value); + + /** + * Visits a value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visit(AnnotationValue value, P param); + + /** + * Visits an annotation value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitAnnotation(AnnotationMirror value, P param); + + /** + * Visits an array value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitArray(List<? extends AnnotationValue> value, P param); + + /** + * Visits a boolean value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitBoolean(boolean value, P param); + + /** + * Visits a byte value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitByte(byte value, P param); + + /** + * Visits a character value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitChar(char value, P param); + + /** + * Visits a double value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitDouble(double value, P param); + + /** + * Visits an enum value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitEnumConstant(VariableElement value, P param); + + /** + * Visits a float value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitFloat(float value, P param); + + /** + * Visits an int value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitInt(int value, P param); + + /** + * Visits a long value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitLong(long value, P param); + + /** + * Visits a short value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitShort(short value, P param); + + /** + * Visits a {@code String} value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitString(String value, P param); + + /** + * Visits a type value. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitType(TypeMirror value, P param); + + /** + * Visits an unknown type of value. This method is called if + * a new type is added to the hierarchy which isn't yet + * handled by the visitor. + * + * @param value the value to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + * @return the return value specific to the visitor. + * @throws UnknownAnnotationValueException if the implementation + * chooses to. + */ + R visitUnknown(AnnotationValue value, P param); + +} diff --git a/javax/lang/model/element/Element.java b/javax/lang/model/element/Element.java new file mode 100644 index 000000000..507547600 --- /dev/null +++ b/javax/lang/model/element/Element.java @@ -0,0 +1,213 @@ +/* Element.java -- Represents a program element at the language level. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +import java.lang.annotation.Annotation; + +import java.util.List; +import java.util.Set; + +import javax.lang.model.type.TypeMirror; + +/** + * <p> + * Represents a program element at the language level. For example, + * an {@code Element} may represent a package, a class or a type + * parameter. Types only present at runtime in the virtual machine + * are not represented. + * </p> + * <p>To compare two instances, use {@link #equals(Object)} as there + * is no guarantee that == will hold. To determine the subtype of + * {@code Element}, use {@link #getKind()} or a visitor, as + * implementations may use the same class to implement multiple + * subinterfaces.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface Element +{ + + /** + * Applies a visitor to this element. + * + * @param <R> the return type of the visitor's methods. + * @param <P> the type of the additional parameter used in the visitor's + * methods. + * @param visitor the visitor to apply to the element. + * @param param the additional parameter to be sent to the visitor. + * @return the return value from the visitor. + */ + <R,P> R accept(ElementVisitor<R,P> visitor, P param); + + /** + * <p>Returns {@code true} if this instance represents the same + * element as the one supplied.</p> + * <p>Please note that an element may not be equal to the same + * element provided by a different implementation of this framework, + * as the equivalence comparison may include the use of internal + * state which is inaccessible from the element's methods. This + * is similar to the way {@link Class} objects provided by different + * classloaders are not guaranteed to be equal.</p> + * + * @param obj the object to compare. + * @return {@code true} if {@code this} and {@code obj} represent + * the same element. + */ + boolean equals(Object obj); + + /** + * <p>Returns the element's annotation for the specified annotation type, + * if present, or {@code null} if not. The annotation may be directly + * present on the element or inherited.</p> + * <p>If the annotation contains an element of type {@code Class} or + * {@code Class[]}, attempts to read such an object will result in + * a {@link javax.lang.model.type.MirroredTypeException} or + * {@link javax.lang.model.type.MirroredTypesException} respectively. + * This is because information required to load the class (such as its + * class loader) is unavailable and so it may not be possible to load + * the class at all.</p> + * <p>Note that, unlike other methods in this framework, this method + * operates on runtime information obtained through reflection. + * As a result, the methods of the returned annotation object may + * throw exceptions relating to reflection failures.</p> + * + * @param <A> the type of annotation. + * @param annonType the {@code Class} object representing the annotation type. + * @return an annotation of the specified type, if present, or {@code null}. + * @see #getAnnotationMirrors() + * @see Elements#getAllAnnotationMirrors(Element) + * @see java.lang.reflect.AnnotatedElement#getAnnotation(Class) + * @see java.lang.annotation.AnnotationTypeMismatchException + * @see java.lang.annotation.IncompleteAnnotationException + * @see javax.lang.model.type.MirroredTypeException + * @see javax.lang.model.type.MirroredTypesException + */ + <A extends Annotation> A getAnnotation(Class<A> annonType); + + /** + * Returns the elements directly enclosed by this element. + * For example, a class element encloses constructor, method, + * field and further class elements. The returned list + * includes elements automatically generated by the compiler + * such as the default constructor and {@code values} and + * {@code valueOf} methods present in enumerations. Package + * elements contain class and interface elements, but not + * other packages. All other types of element do not contain + * other elements at this time. + * + * @return the enclosed elements, or an empty list if the + * element has none. + * @see Elements#getAllMembers(TypeElement) + */ + List<? extends Element> getEnclosedElements(); + + /** + * Returns the element that encloses this element. For a top-level + * type, its package is returned. Package and type parameter + * elements return {@code null}. + * + * @return the enclosing element or {@code null} if there isn't one. + * @see Elements#getPackageOf(Element) + */ + Element getEnclosingElement(); + + /** + * Returns the kind of this element. + * + * @return the kind of element. + */ + ElementKind getKind(); + + /** + * Obeys the general contract of {@link java.lang.Object#hashCode()}. + * + * @return a hash code for this element. + * @see #equals(Object) + */ + int hashCode(); + + /** + * Returns the type defined by this element. A generic + * element defines not one type, but a family of types. + * For such elements, a prototypical type is returned + * i.e. the element {@code Set<N extends Number>} will + * return the type {@code Set<N>}. The methods of + * {@link javax.lang.model.util.Types} should be used to + * obtain the full family of types. + * + * @return the type defined by this element. + * @see javax.lang.model.util.Types + */ + TypeMirror asType(); + + /** + * Returns the annotations directly present on this element. + * To obtain inherited annotations as well, call + * the {@link javax.lang.model.util.Elements#getAllAnnotationMirrors()} + * method of {@link javax.lang.model.util.Elements}. + * + * @return the annotations directly present on this element or + * an empty list if there are none. + * @see javax.lang.model.util.ElementFilter + */ + List<? extends AnnotationMirror> getAnnotationMirrors(); + + /** + * Returns the modifiers attached to this element, other than + * annotations e.g. {@code public} or {@code abstract}. If + * there are no modifiers, an empty set is returned. + * + * @return the modifiers of this element. + */ + Set<Modifier> getModifiers(); + + /** + * Returns the simple name of this element i.e. without any + * package prefix. The simple name of a generic type is the + * same as that of the raw variant i.e. {@code Set<E>}'s simple + * name is {@code "Set"}. Constructors are named {@code "<init>"} + * and static initializers {@code "<clinit>"}. Unnamed packages, + * anonymous classes and instance initializers all return the + * empty string, {@code ""}. + * + * @return the simple name of this element. + */ + Name getSimpleName(); + +} diff --git a/javax/lang/model/element/ElementKind.java b/javax/lang/model/element/ElementKind.java new file mode 100644 index 000000000..b1765c547 --- /dev/null +++ b/javax/lang/model/element/ElementKind.java @@ -0,0 +1,119 @@ +/* ElementKind.java -- Represents the kind of an element. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * <p>Represents the kind of an element, such as a class element + * or a field element. This enumeration may be extended with + * further kinds to represent future versions of the language.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public enum ElementKind +{ + /** An annotation type. */ + ANNOTATION_TYPE, + /** A normal class, not described by a more specific type. */ + CLASS, + /** A constructor */ + CONSTRUCTOR, + /** An enumeration */ + ENUM, + /** A constant field used in an enumeration. */ + ENUM_CONSTANT, + /** A parameter passed to an exception handler. */ + EXCEPTION_PARAMETER, + /** A normal field, not described by a more specific type. */ + FIELD, + /** An instance initializer. */ + INSTANCE_INIT, + /** A normal interface, not described by a more specific type. */ + INTERFACE, + /** A local variable. */ + LOCAL_VARIABLE, + /** A method. */ + METHOD, + /** An element reserved for implementation-specific usage. */ + OTHER, + /** A package. */ + PACKAGE, + /** A parameter passed to a method or constructor. */ + PARAMETER, + /** A static initializer. */ + STATIC_INIT, + /** A type parameter. */ + TYPE_PARAMETER; + + /** + * Returns true if this element is a class i.e. either a + * general {@code CLASS} or the specific {@code ENUM}. + * + * @return true if this kind is either {@code CLASS} or + * {@code ENUM}. + */ + public boolean isClass() + { + return this == CLASS || this == ENUM; + } + + /** + * Returns true if this element is a field i.e. either a + * general {@code FIELD} or the specific {@code ENUM_CONSTANT}. + * + * @return true if this kind is either {@code FIELD} or + * {@code ENUM_CONSTANT}. + */ + public boolean isField() + { + return this == FIELD || this == ENUM_CONSTANT; + } + + /** + * Returns true if this element is a interface i.e. either a + * general {@code INTERFACE} or the specific {@code ANNOTATION_TYPE}. + * + * @return true if this kind is either {@code INTERFACE} or + * {@code ANNOTATION_TYPE}. + */ + public boolean isInterface() + { + return this == INTERFACE || this == ANNOTATION_TYPE; + } + +} diff --git a/javax/lang/model/element/ElementVisitor.java b/javax/lang/model/element/ElementVisitor.java new file mode 100644 index 000000000..133ab5aa5 --- /dev/null +++ b/javax/lang/model/element/ElementVisitor.java @@ -0,0 +1,143 @@ +/* ElementVisitor.java -- A visitor of program elements. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * <p>A visitor for program elements. This is used when the specific + * type of element is not known at compile time. A visitor instance + * is passed to the {@link Element#accept(ElementVisitor,P)} method of + * the element, which then calls the specific {@code visitN} method + * appropriate to that specific element.</p> + * <p>The additional parameter supplied to visitor methods may or + * may not be optional, and so the class is free to throw a + * {@code NullPointerException} if {@code null} is passed as the + * additional parameter.</p> + * <p>As this interface may be extended to accomodate future language + * versions, implementators are encouraged to extend one of the + * appropriate abstract classes rather than implementating this + * interface. However, this interface should be used as the type + * for parameters and return values.</p> + * + * @param <R> the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param <P> the type of the additional parameter supplied to the visitor's + * methods. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface ElementVisitor<R,P> +{ + + /** + * A convenience method for use when there is no additional + * parameter to pass. This is equivalent to {@code #visit(element, null)}. + * + * @param element the element to visit. + * @return the return value specific to the visitor. + */ + R visit(Element element); + + /** + * Visits an element. + * + * @param element the element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visit(Element element, P param); + + /** + * Visits a type element. + * + * @param element the type element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitType(TypeElement element, P param); + + /** + * Visits an unknown element. This method is called if + * a new type of element is added to the hierarchy + * which isn't yet handled by the visitor. + * + * @param element the element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + * @return the return value specific to the visitor. + * @throws UnknownElementException if the implementation chooses to. + */ + R visitUnknown(Element element, P param); + + /** + * Visits an executable element. + * + * @param element the executable element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitExecutable(ExecutableElement element, P param); + + /** + * Visits a type parameter element. + * + * @param element the type parameter element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitTypeParameter(TypeParameterElement element, P param); + + /** + * Visits a variable element. + * + * @param element the variable element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitVariable(VariableElement element, P param); + + /** + * Visits a package element. + * + * @param element the package element to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visitPackage(PackageElement element, P param); + +} diff --git a/javax/lang/model/element/ExecutableElement.java b/javax/lang/model/element/ExecutableElement.java new file mode 100644 index 000000000..389eff07e --- /dev/null +++ b/javax/lang/model/element/ExecutableElement.java @@ -0,0 +1,113 @@ +/* ExecutableElement.java -- Represents a method, constructor or initialiser. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +import java.util.List; + +import javax.lang.model.type.TypeMirror; + +/** + * Represents a method, constructor or initialiser (static + * or instance) for a class or interface (including annotation + * types). + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.type.ExecutableType + */ +public interface ExecutableElement + extends Element +{ + + /** + * Returns the default value of this type if this is an + * annotation with a default, or {@code null} otherwise. + * + * @return the default value or {@code null}. + */ + AnnotationValue getDefaultValue(); + + /** + * Returns the formal parameters of this executable + * in the order they were declared. If there are no + * parameters, the list is empty. + * + * @return the formal parameters. + */ + List<? extends VariableElement> getParameters(); + + /** + * Returns the return type of this executable or + * an instance of {@link javax.lang.model.type.NoType} + * with the kind {@link javax.lang.model.type.TypeKind#VOID} + * if there is no return type or this is a + * constructor or initialiser. + * + * @return the return type of the executbale. + */ + TypeMirror getReturnType(); + + /** + * Returns the exceptions or other throwables listed + * in the {@code throws} clause in the order they + * are declared. The list is empty if there is no + * {@code throws} clause. + * + * @return the exceptions or other throwables listed + * as thrown by this executable. + */ + List<? extends TypeMirror> getThrownTypes(); + + /** + * Returns the formal type parameters of this executable + * in the order they were declared. The list is empty + * if there are no type parameters. + * + * @return the formal type parameters. + */ + List<? extends TypeParameterElement> getTypeParameters(); + + /** + * Returns {@code true} if this method or constructor accepts + * a variable number of arguments. + * + * @return true if this is a varargs method or constructor. + */ + boolean isVarArgs(); + +} diff --git a/javax/lang/model/element/Modifier.java b/javax/lang/model/element/Modifier.java new file mode 100644 index 000000000..20da02364 --- /dev/null +++ b/javax/lang/model/element/Modifier.java @@ -0,0 +1,71 @@ +/* Modifier.java -- Represents a modifier on an element such as a method. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * Represents a modifier on an element such as a class, method + * or field. Not all modifiers are applicable to all elements. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public enum Modifier +{ + /** Denotes an abstract class or method. */ + ABSTRACT, + /** Denotes a final class, method or field. */ + FINAL, + /** Denotes a native method. */ + NATIVE, + /** Denotes a private class, method or field. */ + PRIVATE, + /** Denotes a protected class, method or field. */ + PROTECTED, + /** Denotes a public class, method or field. */ + PUBLIC, + /** Denotes a static class, method or field. */ + STATIC, + /** Denotes a strictfp class or method. */ + STRICTFP, + /** Denotes a synchronized method. */ + SYNCHRONIZED, + /** Denotes a transient field. */ + TRANSIENT, + /** Denotes a volatile field. */ + VOLATILE; +} diff --git a/javax/lang/model/element/Name.java b/javax/lang/model/element/Name.java new file mode 100644 index 000000000..28da2cab6 --- /dev/null +++ b/javax/lang/model/element/Name.java @@ -0,0 +1,90 @@ +/* Name.java -- An immutable sequence of characters. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * <p>An immutable sequence of characters, representing a name. + * An empty name has a length of zero.</p> + * <p>Names created by the same implementation are comparable + * using {@link #equals(Object)} and thus usable in a collection. + * This guarantee as regards the "same implementation" also + * applies to successive annotation rounds in the context of + * annotation processing.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.util.Elements#getName(CharSequence) + */ +public interface Name + extends CharSequence +{ + + /** + * Returns true if the sequence of characters within this + * name is the same as the specified sequence of characters. + * + * @param chars the sequence of characters to compare. + * @return true if {@code chars} represents the same sequence + * of characters as this name. + * @see String#contentEquals(CharSequence) + */ + boolean contentEquals(CharSequence chars); + + /** + * Returns {@code true} if the specified object represents the + * same name as this instance. Name comparisons are not + * just reliant on the content of the name (see + * {@link #contentEquals(CharSequence)}) but also + * the implementation which created the name. + * + * @param obj the object to compare. + * @return {@code true} if {@code this} and {@code obj} represent + * the same element. + */ + boolean equals(Object obj); + + /** + * Obeys the general contract of {@link java.lang.Object#hashCode()}. + * + * @return a hash code for this element. + * @see #equals(Object) + */ + int hashCode(); + +} + diff --git a/javax/lang/model/element/NestingKind.java b/javax/lang/model/element/NestingKind.java new file mode 100644 index 000000000..d98e4d993 --- /dev/null +++ b/javax/lang/model/element/NestingKind.java @@ -0,0 +1,65 @@ +/* NestingKind.java -- Represents the nesting level of an element. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * Represents the level of nesting at which an element appears; + * top-level, member, local and anonymous. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public enum NestingKind +{ + ANONYMOUS, + LOCAL, + MEMBER, + TOP_LEVEL; + + /** + * Returns true if this constant represents an element + * that is nested inside another i.e. is not top-level. + * + * @return true if this is a constant for a nested level. + */ + public boolean isNested() + { + return this != TOP_LEVEL; + } + +} diff --git a/javax/lang/model/element/PackageElement.java b/javax/lang/model/element/PackageElement.java new file mode 100644 index 000000000..71a06bc94 --- /dev/null +++ b/javax/lang/model/element/PackageElement.java @@ -0,0 +1,72 @@ +/* PackageElement.java -- Represents a package. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * Represents a package, providing access to information about + * it and its members. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.util.Elements#getPackageOf(Element) + */ +public interface PackageElement + extends Element +{ + + /** + * Returns the fully qualified name (<emph>canonical + * name</emph>) of the package, as specified in section + * 6.7 of the Java Language Specification, or an empty + * name if the package is unnamed. + * + * @return the fully qualified name of the package. + * @see #isUnnamed() + */ + Name getQualifiedName(); + + /** + * Returns {@code true} if this is an unnamed package. + * Unnamed packages are detailed in section 7.4.2 of + * the Java Language Specification. + * + * @return true if this is an unnamed package. + */ + boolean isUnnamed(); + +} diff --git a/javax/lang/model/element/TypeElement.java b/javax/lang/model/element/TypeElement.java new file mode 100644 index 000000000..2e028fe40 --- /dev/null +++ b/javax/lang/model/element/TypeElement.java @@ -0,0 +1,126 @@ +/* TypeElement.java -- Represents a class or interface element. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +import java.util.List; + +import javax.lang.model.type.TypeMirror; + +/** + * <p>Represents a class or interface program element. + * Note that enumerations are a kind of class and annotations + * are a kind of interface. The element provides access + * to information about the type and its members.</p> + * <p>A distinction is made between elements and types, + * with the latter being an invocation of the former. + * This distinction is most clear when looking at + * parameterized types. A {@code TypeElement} represents the + * general type, such as {@code java.util.Set}, while + * a {@link DeclaredType} instance represents different + * instantiations such as {@code java.util.Set<String>}, + * {@code java.util.Set<Integer>} and the raw type + * {@code java.util.Set}.</p> + * <p>The methods of this interface return elements in the + * natural order of the underlying information. So, for + * example, if the element is derived from a Java source + * file, elements are returned in the order they appear + * in the source code.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface TypeElement + extends Element +{ + + /** + * Returns the interface types directly implemented by this + * class or extended by this interface. If there are none, + * an empty list is returned. + * + * @return the interface types directly implemented by this + * class or extended by this interface. + */ + List<? extends TypeMirror> getInterfaces(); + + /** + * Returns the direct superclass of this element. If this + * is an interface or the class {@link Object}, then a + * instance of {@link javax.lang.model.type.NoType} with + * the kind {@link javax.lang.model.type.TypeKind#NONE} is + * returned. + * + * @return the direct superclass or {@code NoType} if there + * isn't one. + */ + TypeMirror getSuperclass(); + + /** + * Returns the formal type parameters of this element in the + * order they were declared. If there are none, then an empty + * list is returned. + * + * @return the formal type parameters. + */ + List<? extends TypeParameterElement> getTypeParameters(); + + /** + * Returns the fully qualified or <emph>canonical</emph> + * name of this type element. For a local or anonymous + * class, the empty string is returned. Generic types + * do not include their type parameters in the returned + * string i.e. {@code "java.util.Set"} not + * {@code "java.util.Set<E>"}. A period ({@code "."}) is + * the only separator used, including for nested classes + * such as {@code "java.util.Map.Entry"}. See + * Section 6.7 of the Java Language Specification for + * more details. + * + * @return the canonical name of this type element. + * @see javax.lang.model.util.Elements#getBinaryName(TypeElement) + */ + Name getQualifiedName(); + + /** + * Returns the nesting kind of this element. + * + * @return the nesting kind. + */ + NestingKind getNestingKind(); + +} diff --git a/javax/lang/model/element/TypeParameterElement.java b/javax/lang/model/element/TypeParameterElement.java new file mode 100644 index 000000000..fa5fb7424 --- /dev/null +++ b/javax/lang/model/element/TypeParameterElement.java @@ -0,0 +1,82 @@ +/* TypeParameterElement.java -- Represents a formal type parameter. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +import java.util.List; + +import javax.lang.model.type.TypeMirror; + +/** + * Represents a formal type parameter used by a generic class, + * interface, method or constructor element. A type parameter + * is a declaration of a {@link javax.lang.model.type.TypeVariable}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.type.TypeVariable + */ +public interface TypeParameterElement + extends Element +{ + + /** + * Returns the bounds of the type parameter. These are the types + * declared after the {@code extends} clause. For example, + * the bounds for the type parameter {@code T} in + * {@code Set<T extends Integer>} would be a single element + * list containing the type mirror for {@code Integer}. Similarly, + * for {@code Set<T extends Number & Runnable>}, the bounds + * would be a two element list containing the type mirrors + * for {@code Number} and {@code Runnable}. For a parameter + * with no explicit bounds, {@code Object} is assumed to be + * the sole bound and an empty list is returned. + * + * @return the bounds of this type parameter, or an empty list if + * there are none. + */ + List<? extends TypeMirror> getBounds(); + + /** + * Returns the generic class, interface, method or constructor + * in which this type parameter is used. + * + * @return the element parameterised by this type parameter. + */ + Element getGenericElement(); + +} diff --git a/javax/lang/model/element/UnknownAnnotationValueException.java b/javax/lang/model/element/UnknownAnnotationValueException.java new file mode 100644 index 000000000..dd9056b5a --- /dev/null +++ b/javax/lang/model/element/UnknownAnnotationValueException.java @@ -0,0 +1,106 @@ +/* UnknownAnnotationValueException.java -- Thrown by an unknown annotation value. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * Thrown when an unknown annotation value is encountered, + * usually by a {@link AnnotationValueVisitor}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see AnnotationValueVisitor#visitUnknown(AnnotationValue,P) + */ +public class UnknownAnnotationValueException + extends RuntimeException +{ + + private static final long serialVersionUID = 269L; + + /** + * The unknown annotation value. + */ + private AnnotationValue annValue; + + /** + * The additional parameter. + */ + private Object param; + + /** + * Constructs a new {@code UnknownAnnotationValueException} + * for the specified annotation value. An additional + * object may also be passed to give further context as + * to where the exception occurred, such as the additional parameter + * used by visitor classes. + * + * @param annValue the unknown annotation value or {@code null}. + * @param param the additional parameter or {@code null}. + */ + public UnknownAnnotationValueException(AnnotationValue annValue, + Object param) + { + this.annValue = annValue; + this.param = param; + } + + /** + * Returns the additional parameter or {@code null} if + * unavailable. + * + * @return the additional parameter. + */ + public Object getArgument() + { + return param; + } + + /** + * Returns the unknown annotation value or {@code null} + * if unavailable. The value may be {@code null} if + * the value is not {@link java.io.Serializable} but the + * exception has been serialized and read back in. + * + * @return the unknown annotation value. + */ + public AnnotationValue getUnknownAnnotationValue() + { + return annValue; + } + + +} diff --git a/javax/lang/model/element/UnknownElementException.java b/javax/lang/model/element/UnknownElementException.java new file mode 100644 index 000000000..cdf5f1877 --- /dev/null +++ b/javax/lang/model/element/UnknownElementException.java @@ -0,0 +1,105 @@ +/* UnknownElementException.java -- Thrown by an unknown element. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * Thrown when an unknown element is encountered, + * usually by a {@link ElementVisitor}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see ElementVisitor#visitUnknown(Element,P) + */ +public class UnknownElementException + extends RuntimeException +{ + + private static final long serialVersionUID = 269L; + + /** + * The unknown element. + */ + private Element element; + + /** + * The additional parameter. + */ + private Object param; + + /** + * Constructs a new {@code UnknownElementException} + * for the specified element. An additional + * object may also be passed to give further context as + * to where the exception occurred, such as the additional parameter + * used by visitor classes. + * + * @param element the unknown element or {@code null}. + * @param param the additional parameter or {@code null}. + */ + public UnknownElementException(Element element, Object param) + { + this.element = element; + this.param = param; + } + + /** + * Returns the additional parameter or {@code null} if + * unavailable. + * + * @return the additional parameter. + */ + public Object getArgument() + { + return param; + } + + /** + * Returns the unknown element or {@code null} + * if unavailable. The element may be {@code null} if + * the value is not {@link java.io.Serializable} but the + * exception has been serialized and read back in. + * + * @return the unknown element. + */ + public Element getUnknownElement() + { + return element; + } + + +} diff --git a/javax/lang/model/element/VariableElement.java b/javax/lang/model/element/VariableElement.java new file mode 100644 index 000000000..2ff817f15 --- /dev/null +++ b/javax/lang/model/element/VariableElement.java @@ -0,0 +1,63 @@ +/* VariableElement.java -- Represents a field, enum constant, parameter or variable. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.element; + +/** + * Represents a field, enumeration constant, local variable or + * a method, constructor or exception parameter. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface VariableElement + extends Element +{ + + /** + * Returns the constant value of the field if it has one + * or {@code null} otherwise. To have a constant value, + * a field must be declared {@code final} and be of either + * a primitive type or of type {@code String}. Enumeration + * constants do not meet this criteria and are not compile-time + * constants. + * + * @return the constant value of this variable if applicable. + */ + Object getConstantValue(); + +} |