summaryrefslogtreecommitdiff
path: root/javax/lang/model
diff options
context:
space:
mode:
Diffstat (limited to 'javax/lang/model')
-rw-r--r--javax/lang/model/SourceVersion.java102
-rw-r--r--javax/lang/model/element/Element.java161
-rw-r--r--javax/lang/model/element/ElementKind.java65
-rw-r--r--javax/lang/model/element/ElementVisitor.java105
-rw-r--r--javax/lang/model/element/TypeElement.java65
-rw-r--r--javax/lang/model/util/ElementFilter.java425
-rw-r--r--javax/lang/model/util/Elements.java123
-rw-r--r--javax/lang/model/util/Types.java47
8 files changed, 1093 insertions, 0 deletions
diff --git a/javax/lang/model/SourceVersion.java b/javax/lang/model/SourceVersion.java
new file mode 100644
index 000000000..89d88d9fa
--- /dev/null
+++ b/javax/lang/model/SourceVersion.java
@@ -0,0 +1,102 @@
+/* SourceVersion.java -- Source versions of the Java programming language.
+ 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;
+
+/**
+ * Source versions of the Java programming language.
+ * Note that this will be extended with additional
+ * constants to represent new versions.
+ *
+ * @since 1.6
+ */
+public enum SourceVersion
+{
+ /** The original version of Java. */ RELEASE_0,
+ /** Java 1.1 */ RELEASE_1,
+ /** Java 1.2 */ RELEASE_2,
+ /** Java 1.3 */ RELEASE_3,
+ /** Java 1.4 */ RELEASE_4,
+ /** Java 5 */ RELEASE_5,
+ /** Java 6 */ RELEASE_6;
+
+ /**
+ * Returns true if {@code name} is a syntactically valid identifier or
+ * keyword in the latest version of the language. That is, this
+ * method returns true if the {@link Character#isJavaIdentifierStart(int)}
+ * holds for the first character and {@link Character#isJavaIdentifierPart(int)}
+ * for the rest. This matches all regular identifiers, keywords
+ * and the literals {@code true}, {@code false} and {@code null}.
+ *
+ * @param name the name to check.
+ * @return true if {@code name} represents a valid identifier, keyword or literal.
+ */
+ public static boolean isIdentifier(CharSequence name)
+ {
+ int size = name.length();
+ if (size > 0 && Character.isJavaIdentifierStart(name.charAt(0)))
+ {
+ for (int a = 1; a < size; ++a)
+ if (!Character.isJavaIdentifierPart(name.charAt(a)))
+ return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns the latest source version that can be modeled.
+ *
+ * @return the latest modelable source version.
+ */
+ public static SourceVersion latest()
+ {
+ return RELEASE_6;
+ }
+
+ /**
+ * Returns the latest source version fully supported
+ * by GNU Classpath. Must be at least {@code RELEASE_5}.
+ *
+ * @return the latest supported source version.
+ */
+ public static SourceVersion latestSupported()
+ {
+ return RELEASE_5;
+ }
+
+}
diff --git a/javax/lang/model/element/Element.java b/javax/lang/model/element/Element.java
new file mode 100644
index 000000000..bd90bed27
--- /dev/null
+++ b/javax/lang/model/element/Element.java
@@ -0,0 +1,161 @@
+/* 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;
+
+/**
+ * <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>
+ *
+ * @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();
+
+}
diff --git a/javax/lang/model/element/ElementKind.java b/javax/lang/model/element/ElementKind.java
new file mode 100644
index 000000000..95ee134f6
--- /dev/null
+++ b/javax/lang/model/element/ElementKind.java
@@ -0,0 +1,65 @@
+/* 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>
+ *
+ * @since 1.6
+ */
+public enum ElementKind
+{
+ ANNOTATION_TYPE,
+ CLASS,
+ CONSTRUCTOR,
+ ENUM,
+ ENUM_CONSTANT,
+ EXCEPTION_PARAMETER,
+ FIELD,
+ INSTANCE_INIT,
+ INTERFACE,
+ LOCAL_VARIABLE,
+ METHOD,
+ OTHER,
+ PACKAGE,
+ PARAMETER,
+ STATIC_INIT,
+ TYPE_PARAMETER;
+}
diff --git a/javax/lang/model/element/ElementVisitor.java b/javax/lang/model/element/ElementVisitor.java
new file mode 100644
index 000000000..0f112b98b
--- /dev/null
+++ b/javax/lang/model/element/ElementVisitor.java
@@ -0,0 +1,105 @@
+/* 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.
+ *
+ * @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(e, 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.
+ */
+ R visitUnknown(Element element, P param);
+
+}
diff --git a/javax/lang/model/element/TypeElement.java b/javax/lang/model/element/TypeElement.java
new file mode 100644
index 000000000..a0e2c7c99
--- /dev/null
+++ b/javax/lang/model/element/TypeElement.java
@@ -0,0 +1,65 @@
+/* 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;
+
+/**
+ * <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>
+ *
+ * @since 1.6
+ */
+public interface TypeElement
+ extends Element
+{
+}
diff --git a/javax/lang/model/util/ElementFilter.java b/javax/lang/model/util/ElementFilter.java
new file mode 100644
index 000000000..b91a1debc
--- /dev/null
+++ b/javax/lang/model/util/ElementFilter.java
@@ -0,0 +1,425 @@
+/* ElementFilter.java -- Filter for a collection of 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.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+
+/**
+ * <p>Filter for selecting elements of interest from a collection.
+ * The returned collections are new instances, but use the original
+ * collection as a backing store. They are not safe for concurrent
+ * access. The iteration order remains the same. Null values are
+ * not allowed and will throw a {@code NullPointerException}.</p>
+ *<p>For convenience, a static import may be used to allow the
+ * methods to be called more succinctly.</p>
+ *
+ * @since 1.6
+ */
+public class ElementFilter
+{
+
+ /**
+ * Returns a set containing just the {@link TypeElement}s
+ * held in {@code elements}.
+ *
+ * @param elements the elements to filter.
+ * @return the filtered set.
+ */
+ public static Set<TypeElement> typesIn(Set<? extends Element> elements)
+ {
+ return new FilteredSet<TypeElement>(elements, TypeElement.class);
+ }
+
+ /**
+ * Provides a filtered view of the given set, returning only
+ * instances which are instances of the specified class or
+ * one of its subclasses.
+ */
+ private static final class FilteredSet<E extends Element> implements Set<E>
+ {
+
+ /**
+ * The set being filtered.
+ */
+ private Set<Element> elements;
+
+ /**
+ * The class returned elements must be instances of.
+ */
+ private Class<E> clazz;
+
+ /**
+ * Constructs a new filtered set, returning
+ * only instances of {@code clazz} from
+ * {@code elements}.
+ *
+ * @param elements the set to filter.
+ * @param clazz the class returned elements must be instances of.
+ * @throws NullPointerException if the set contains a null element.
+ */
+ @SuppressWarnings("unchecked")
+ public FilteredSet(Set<? extends Element> elements, Class<E> clazz)
+ {
+ this.elements = (Set<Element>) elements;
+ this.clazz = clazz;
+ for (Element e : elements)
+ if (e == null)
+ throw new NullPointerException("Sets can not contain null values.");
+ }
+
+ /**
+ * Adds an element to the set by passing it to the backing set.
+ *
+ * @param elem the element to add.
+ * @return true if the element was added.
+ */
+ public boolean add(E elem)
+ {
+ return elements.add(elem);
+ }
+
+ /**
+ * Add all elements of the given collection, which aren't already
+ * present in this set, to this set. If the supplied collection
+ * is also a set, the resulting set is the union of the two.
+ * This call is passed to the backing set.
+ *
+ * @param coll the collection of elements to add.
+ * @return true if the set was modified.
+ */
+ public boolean addAll(Collection<? extends E> coll)
+ {
+ return elements.addAll(coll);
+ }
+
+ /**
+ * Removes all elements from the set.
+ */
+ public void clear()
+ {
+ elements.clear();
+ }
+
+ /**
+ * Returns true if the element is an instance of the
+ * filter class and the backing set contains the given element.
+ *
+ * @param obj the object to check for.
+ * @return true if the backing set contains the element.
+ */
+ public boolean contains(Object obj)
+ {
+ if (clazz.isInstance(obj))
+ return elements.contains(obj);
+ return false;
+ }
+
+ /**
+ * Returns true if the set contains all elements of the
+ * given collection. If the collection is also a set,
+ * a return value of {@code true} means that the given
+ * set is a subset of this set.
+ *
+ * @param coll the collection of elements to check.
+ * @return true if the set contains all elements in {@code coll}.
+ */
+ public boolean containsAll(Collection<?> coll)
+ {
+ for (Object obj : coll)
+ if (!contains(obj))
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns true if the specified object is also a set
+ * of the same size and every member of it is also contained
+ * in this set.
+ *
+ * @param obj the object to compare.
+ * @return true if the above requirements are met.
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ return false;
+ if (obj instanceof Set)
+ {
+ Set<?> otherSet = (Set<?>) obj;
+ return size() == otherSet.size() &&
+ containsAll(otherSet);
+ }
+ return false;
+ }
+
+ /**
+ * Returns the hashcode of the set. The hash code is computed
+ * by taking the sum of the hash codes of the objects in the set.
+ *
+ * @return the hashcode of this set.
+ */
+ public int hashCode()
+ {
+ int sum = 0;
+ for (E elem : this)
+ sum += elem.hashCode();
+ return sum;
+ }
+
+ /**
+ * Returns true if the set contains no elements.
+ *
+ * @return true if the size is zero.
+ */
+ public boolean isEmpty()
+ {
+ return size() == 0;
+ }
+
+ /**
+ * Returns an iterator over the set's elements.
+ *
+ * @return the iterator.
+ */
+ public Iterator<E> iterator()
+ {
+ return new FilteredIterator<E>(elements.iterator(), clazz);
+ }
+
+ /**
+ * Removes an element from the set if present.
+ *
+ * @param obj the object to remove.
+ * @return true if the set contained the element.
+ */
+ public boolean remove(Object obj)
+ {
+ if (clazz.isInstance(obj))
+ return elements.remove(obj);
+ return false;
+ }
+
+ /**
+ * Removes from the set all elements contained in the specified
+ * collection. If the collection is also a set, the resulting
+ * set is the asymmetric set difference of the two.
+ *
+ * @param coll the collection of elements to remove.
+ * @return true if the set changed.
+ */
+ public boolean removeAll(Collection<?> coll)
+ {
+ boolean modified = false;
+ for (Object obj : coll)
+ if (remove(obj))
+ modified = true;
+ return modified;
+ }
+
+ /**
+ * Retains only the elements in this set which are also contained in
+ * the specified collection. If the collection is also a set, the
+ * resulting set is the intersection of the two.
+ *
+ * @param coll the collection of elements to remove.
+ * @return true if the set changed.
+ */
+ public boolean retainAll(Collection<?> coll)
+ {
+ boolean modified = false;
+ for (E elem : this)
+ if (!coll.contains(elem))
+ {
+ remove(elem);
+ modified = true;
+ }
+ return modified;
+ }
+
+ /**
+ * Returns the size of this set. This is the size of the backing
+ * set, minus any elements which aren't instances of the filter class.
+ *
+ * @return the size of the set.
+ */
+ public int size()
+ {
+ int count = 0;
+ for (Element elem : elements)
+ if (clazz.isInstance(elem))
+ ++count;
+ return count;
+ }
+
+ /**
+ * Returns a new array containing all the elements in the set.
+ * Modifications to the array do not affect the set.
+ *
+ * @return an array of all elements in the set.
+ */
+ public Object[] toArray()
+ {
+ int size = size();
+ Object[] array = new Object[size];
+ Iterator<E> iterator = iterator();
+ for (int a = 0; a < size; ++a)
+ array[a] = iterator.next();
+ return array;
+ }
+
+ /**
+ * Returns a array containing all the elements in the set with
+ * the runtime type of the specified array. If all the elements
+ * from the set fit into the specified array, it will be used
+ * for the returned array and any remaining space will be
+ * populated with {@code null} values. Otherwise, a new array
+ * will be allocated.
+ *
+ * @param array the array which may be reused to provide the
+ * return value of this method.
+ * @return an array containing all elements in the set.
+ */
+ public <T> T[] toArray(T[] array)
+ {
+ int a, size = size();
+ Iterator<E> iterator = iterator();
+ if (array.length < size)
+ {
+ @SuppressWarnings("unchecked")
+ T[] newArray = (T[]) new Object[size];
+ array = newArray;
+ }
+ @SuppressWarnings("unchecked")
+ E[] elemArray = (E[]) array;
+ for (a = 0; a < size; ++a)
+ elemArray[a] = iterator.next();
+ for (; a < array.length; ++a)
+ elemArray[a] = null;
+ return array;
+ }
+
+ }
+
+ /**
+ * Provides a filtered view of the given iterator, returning only
+ * instances which are instances of the specified class or
+ * one of its subclasses.
+ */
+ private static final class FilteredIterator<E extends Element> implements Iterator<E>
+ {
+
+ /**
+ * The iterator to filter.
+ */
+ private Iterator<Element> iterator;
+
+ /**
+ * The class returned elements must be instances of.
+ */
+ private Class<E> clazz;
+
+ /**
+ * Holds the next object if we had to retrieve it
+ * in the {@link #hasNext()} method.
+ */
+ private E next;
+
+ /**
+ * Constructs a new filtered iterator which only returns
+ * elements that are a subclass of the given class.
+ *
+ * @param iterator the iterator to filter.
+ * @param clazz the class returned elements must be instances of.
+ */
+ public FilteredIterator(Iterator<Element> iterator, Class<E> clazz)
+ {
+ this.iterator = iterator;
+ this.clazz = clazz;
+ }
+
+ /**
+ * Returns true if there are more elements to come.
+ *
+ * @return true if there are more elements to retrieve.
+ */
+ public boolean hasNext()
+ {
+ while (iterator.hasNext() && next == null)
+ {
+ next = clazz.cast(iterator.next());
+ if (!clazz.isInstance(next))
+ next = null;
+ }
+ return next != null;
+ }
+
+ /**
+ * Returns the next element in the iteration which is an
+ * instance of the specified class.
+ *
+ * @return the next element.
+ */
+ public E next()
+ {
+ if (next == null)
+ if (!hasNext())
+ throw new NoSuchElementException("No more elements to return.");
+ E retVal = next;
+ next = null;
+ return retVal;
+ }
+
+ /**
+ * Removes the last element returned by the iterator.
+ * As we only return elements that match the filter,
+ * the underlying iterator will always remove one of those.
+ */
+ public void remove()
+ {
+ iterator.remove();
+ }
+
+ }
+}
+
diff --git a/javax/lang/model/util/Elements.java b/javax/lang/model/util/Elements.java
new file mode 100644
index 000000000..2d09b9b23
--- /dev/null
+++ b/javax/lang/model/util/Elements.java
@@ -0,0 +1,123 @@
+/* Elements.java -- Utility methods for operating on 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.util;
+
+import java.io.Writer;
+
+import java.util.List;
+
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+
+/**
+ * Utility methods for operating on elements.
+ *
+ * @since 1.6
+ */
+public interface Elements
+{
+
+ /**
+ * Returns all members of a type element, whether declared
+ * directly in that element or inherited. For a class element,
+ * this includes all constructors, but not local or anonymous
+ * classes.
+ *
+ * @param type the type to return the members of.
+ * @return all members of the type.
+ * @see Element#getEnclosedElements()
+ */
+ List<? extends Element> getAllMembers(TypeElement type);
+
+ /**
+ * Returns the text of a constant expression which represents
+ * either a primitive value or a {@link String}. The returned
+ * text is in a form suitable for inclusion in source code.
+ *
+ * @param value a primitive value or string.
+ * @return the text of the constant expression.
+ * @throws IllegalArgumentExpression if the argument is not a
+ * primitive value or string.
+ */
+ String getConstantExpression(Object value);
+
+ /**
+ * Returns the text of the documentation comment attached to
+ * an element.
+ *
+ * @param elem the element whose comment should be returned.
+ * @return the documentation comment, or {@code null} if there is none.
+ */
+ String getDocComment(Element elem);
+
+ /**
+ * Returns a type element, given its canonical name.
+ *
+ * @param name the canonical name of the element.
+ * @return the named type element or {@code null} if it wasn't found.
+ */
+ TypeElement getTypeElement(CharSequence name);
+
+ /**
+ * Tests whether a type, method or field hides another.
+ *
+ * @param hider the element that is doing the hiding.
+ * @param hidden the element hidden by the hider.
+ * @return true if, and only if, the hider hides the hidden element.
+ */
+ boolean hides(Element hider, Element hidden);
+
+ /**
+ * Returns true if the specified element has been deprecated.
+ *
+ * @param elem the element to check for deprecation.
+ * @return true if the element is deprecated.
+ */
+ boolean isDeprecated(Element elem);
+
+ /**
+ * Prints out a representation of the elements in the order specified
+ * using the supplied writer. The main purpose of this method is for
+ * debugging purposes and the format of the output is not defined.
+ *
+ * @param writer the writer to send the output to.
+ * @param elements the elements to print.
+ */
+ void printElements(Writer w, Element... elements);
+
+}
diff --git a/javax/lang/model/util/Types.java b/javax/lang/model/util/Types.java
new file mode 100644
index 000000000..35abf1a08
--- /dev/null
+++ b/javax/lang/model/util/Types.java
@@ -0,0 +1,47 @@
+/* Types.java -- Utility methods for operating on types.
+ 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.util;
+
+/**
+ * Utility methods for operating on types.
+ *
+ * @since 1.6
+ */
+public interface Types
+{
+}