diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2012-11-13 01:34:17 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2012-11-13 01:34:17 +0000 |
commit | c225934da3e25feb0ece274f8c4978c95938301a (patch) | |
tree | e8353f15b21db6ade2b2a8549c8c59c8ac217c70 | |
parent | c814d82e5a435f93150cd28b7cf0f9d600ff400d (diff) | |
download | classpath-c225934da3e25feb0ece274f8c4978c95938301a.tar.gz |
Start implementing classes/fields/methods necessary to build ecj.
2012-11-12 Andrew John Hughes <gnu_andrew@member.fsf.org>
New files to start supporting recent versions
of ecj & javac.
* javax/annotation/processing/Filer.java: Stub.
* javax/annotation/processing/Messager.java: Likewise.
* javax/annotation/processing/ProcessingEnvironment.java:
(getElementUtils()): Added.
(getFiler()): Likewise.
(getLocale()): Likewise.
(getMessager()): Likewise.
* javax/annotation/processing/RoundEnvironment.java:
(errorRaised()): Likewise.
(getElementsAnnotatedWith(Class)): Likewise.
(getElementsAnnotatedWith(TypeElement)): Likewise.
(getRootElements()): Likewise.
(processingOver()): Likewise.
* javax/lang/model/SourceVersion.java:
(RELEASE_0): Likewise.
(RELEASE_1): Likewise.
(RELEASE_2): Likewise.
(RELEASE_3): Likewise.
(RELEASE_4): Likewise.
(RELEASE_5): Likewise.
(RELEASE_6): Likewise.
(isIdentifier(CharSequence)): Likewise.
(latest()): Likewise.
(latestSupported()): Likewise.
* javax/lang/model/element/Element.java:
(accept(ElementVisitor,P)): Likewise.
(equals(Object)): Likewise.
(getAnnotation(Class)): Likewise.
(getEnclosedElements()): Likewise.
(getEnclosingElement()): Likewise.
(getKind()): Likewise.
(hashCode()): Likewise.
* javax/lang/model/element/ElementKind.java:
(ANNOTATION_TYPE): Likewise.
(CLASS): Likewise.
(CONSTRUCTOR): Likewise.
(ENUM): Likewise.
(ENUM_CONSTANT): Likewise.
(EXCEPTION_PARAMETER): Likewise.
(FIELD): Likewise.
(INSTANCE_INIT): Likewise.
(INTERFACE): Likewise.
(LOCAL_VARIABLE): Likewise.
(METHOD): Likewise.
(OTHER): Likewise.
(PACKAGE): Likewise.
(PARAMETER): Likewise.
(STATIC_INIT): Likewise.
(TYPE_PARAMETER): Likewise.
* javax/lang/model/element/ElementVisitor.java:
(visit(Element)): Likewise.
(visit(Element, P)): Likewise.
(visitType(TypeElement, P): Likewise.
(visitUnknown(Element, P): Likewise.
* javax/lang/model/element/TypeElement.java: Stub.
* javax/lang/model/util/ElementFilter.java:
(typesIn(Set)): Implemented.
(FilteredSet): Class which typesIn returns an instance of.
(FilteredSet.elements): New field.
(FilteredSet.clazz): Likewise.
(FilteredSet.FilteredSet(Set,Class)): Implemented.
(FilteredSet.add(E)): Likewise.
(FilteredSet.addAll(Collection)): Likewise.
(FilteredSet.clear()): Likewise.
(FilteredSet.contains(Object)): Likewise.
(FilteredSet.containsAll(Collection)): Likewise.
(FilteredSet.equals(Object)): Likewise.
(FilteredSet.hashCode()): Likewise.
(FilteredSet.isEmpty()): Likewise.
(FilteredSet.iterator()): Likewise.
(FilteredSet.remove(Object)): Likewise.
(FilteredSet.removeAll(Collection)): Likewise.
(FilteredSet.retainAll(Collection)): Likewise.
(FilteredSet.size()): Likewise.
(FilteredSet.toArray()): Likewise.
(FilteredSet.toArray(T[])): Likewise.
(FilteredIterator): Class which FilteredSet.iterator()
provides an instance of.
(FilteredIterator.iterator): New field.
(FilteredIterator.clazz): Likewise.
(FilteredIterator.next): Likewise.
(FilteredIterator.FilteredIterator(Iterator,Class)): Implemented.
(FilteredIterator.hasNext()): Likewise.
(FilteredIterator.next()): Likewise.
(FilteredIterator.remove()): Likewise.
* javax/lang/model/util/Elements.java:
(getAllMembers(TypeElement)): Likewise.
(getConstantExpression(Object)): Likewise.
(getDocComment(Object)): Likewise.
(getTypeElement(CharSequence)): Likewise.
(hides(Element,Element)): Likewise.
(isDeprecated(Element)): Likewise.
(printElements(Writer,Element...)): Likewise.
* javax/lang/model/util/Types.java: Stub.
Signed-off-by: Andrew John Hughes <gnu_andrew@member.fsf.org>
-rw-r--r-- | ChangeLog | 99 | ||||
-rw-r--r-- | javax/annotation/processing/Filer.java | 91 | ||||
-rw-r--r-- | javax/annotation/processing/Messager.java | 56 | ||||
-rw-r--r-- | javax/annotation/processing/ProcessingEnvironment.java | 100 | ||||
-rw-r--r-- | javax/annotation/processing/RoundEnvironment.java | 119 | ||||
-rw-r--r-- | javax/lang/model/SourceVersion.java | 102 | ||||
-rw-r--r-- | javax/lang/model/element/Element.java | 161 | ||||
-rw-r--r-- | javax/lang/model/element/ElementKind.java | 65 | ||||
-rw-r--r-- | javax/lang/model/element/ElementVisitor.java | 105 | ||||
-rw-r--r-- | javax/lang/model/element/TypeElement.java | 65 | ||||
-rw-r--r-- | javax/lang/model/util/ElementFilter.java | 425 | ||||
-rw-r--r-- | javax/lang/model/util/Elements.java | 123 | ||||
-rw-r--r-- | javax/lang/model/util/Types.java | 47 |
13 files changed, 1558 insertions, 0 deletions
@@ -1,3 +1,102 @@ +2012-11-12 Andrew John Hughes <gnu_andrew@member.fsf.org> + + New files to start supporting recent versions + of ecj & javac. + * javax/annotation/processing/Filer.java: Stub. + * javax/annotation/processing/Messager.java: Likewise. + * javax/annotation/processing/ProcessingEnvironment.java: + (getElementUtils()): Added. + (getFiler()): Likewise. + (getLocale()): Likewise. + (getMessager()): Likewise. + * javax/annotation/processing/RoundEnvironment.java: + (errorRaised()): Likewise. + (getElementsAnnotatedWith(Class)): Likewise. + (getElementsAnnotatedWith(TypeElement)): Likewise. + (getRootElements()): Likewise. + (processingOver()): Likewise. + * javax/lang/model/SourceVersion.java: + (RELEASE_0): Likewise. + (RELEASE_1): Likewise. + (RELEASE_2): Likewise. + (RELEASE_3): Likewise. + (RELEASE_4): Likewise. + (RELEASE_5): Likewise. + (RELEASE_6): Likewise. + (isIdentifier(CharSequence)): Likewise. + (latest()): Likewise. + (latestSupported()): Likewise. + * javax/lang/model/element/Element.java: + (accept(ElementVisitor,P)): Likewise. + (equals(Object)): Likewise. + (getAnnotation(Class)): Likewise. + (getEnclosedElements()): Likewise. + (getEnclosingElement()): Likewise. + (getKind()): Likewise. + (hashCode()): Likewise. + * javax/lang/model/element/ElementKind.java: + (ANNOTATION_TYPE): Likewise. + (CLASS): Likewise. + (CONSTRUCTOR): Likewise. + (ENUM): Likewise. + (ENUM_CONSTANT): Likewise. + (EXCEPTION_PARAMETER): Likewise. + (FIELD): Likewise. + (INSTANCE_INIT): Likewise. + (INTERFACE): Likewise. + (LOCAL_VARIABLE): Likewise. + (METHOD): Likewise. + (OTHER): Likewise. + (PACKAGE): Likewise. + (PARAMETER): Likewise. + (STATIC_INIT): Likewise. + (TYPE_PARAMETER): Likewise. + * javax/lang/model/element/ElementVisitor.java: + (visit(Element)): Likewise. + (visit(Element, P)): Likewise. + (visitType(TypeElement, P): Likewise. + (visitUnknown(Element, P): Likewise. + * javax/lang/model/element/TypeElement.java: Stub. + * javax/lang/model/util/ElementFilter.java: + (typesIn(Set)): Implemented. + (FilteredSet): Class which typesIn returns an instance of. + (FilteredSet.elements): New field. + (FilteredSet.clazz): Likewise. + (FilteredSet.FilteredSet(Set,Class)): Implemented. + (FilteredSet.add(E)): Likewise. + (FilteredSet.addAll(Collection)): Likewise. + (FilteredSet.clear()): Likewise. + (FilteredSet.contains(Object)): Likewise. + (FilteredSet.containsAll(Collection)): Likewise. + (FilteredSet.equals(Object)): Likewise. + (FilteredSet.hashCode()): Likewise. + (FilteredSet.isEmpty()): Likewise. + (FilteredSet.iterator()): Likewise. + (FilteredSet.remove(Object)): Likewise. + (FilteredSet.removeAll(Collection)): Likewise. + (FilteredSet.retainAll(Collection)): Likewise. + (FilteredSet.size()): Likewise. + (FilteredSet.toArray()): Likewise. + (FilteredSet.toArray(T[])): Likewise. + (FilteredIterator): Class which FilteredSet.iterator() + provides an instance of. + (FilteredIterator.iterator): New field. + (FilteredIterator.clazz): Likewise. + (FilteredIterator.next): Likewise. + (FilteredIterator.FilteredIterator(Iterator,Class)): Implemented. + (FilteredIterator.hasNext()): Likewise. + (FilteredIterator.next()): Likewise. + (FilteredIterator.remove()): Likewise. + * javax/lang/model/util/Elements.java: + (getAllMembers(TypeElement)): Likewise. + (getConstantExpression(Object)): Likewise. + (getDocComment(Object)): Likewise. + (getTypeElement(CharSequence)): Likewise. + (hides(Element,Element)): Likewise. + (isDeprecated(Element)): Likewise. + (printElements(Writer,Element...)): Likewise. + * javax/lang/model/util/Types.java: Stub. + 2012-11-02 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/55182 diff --git a/javax/annotation/processing/Filer.java b/javax/annotation/processing/Filer.java new file mode 100644 index 000000000..4da90ca63 --- /dev/null +++ b/javax/annotation/processing/Filer.java @@ -0,0 +1,91 @@ +/* Filer.java -- Manages file creation for an annotation processor. + 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.annotation.processing; + +/** + * <p>This interface supports the creation of new files by the + * annotation processor. Creating files via this interface means + * that they can be tracked by the annotation processing tool. + * Once the file streams are closed, the tool will automatically + * consider them for processing.</p> + * <p>Files are separated into three types: source files, class + * files and resource files. Two locations are defined; one + * for source files and one for class files (resource files + * may use either). Locations are specified using a relative + * path separated by {@code '/'} and not including the + * segments {@code '.'} and {@code '..'} so that they may only + * refer to subdirectories. A valid relative name must match + * the "path-rootless" rule of RFC 3986, section 3.3.</p> + * <p>The file creation methods take a variable number of + * originating elements, which can be used by the tool to + * handle dependency management. For example, if a + * file is generated due to the presence of a particular + * method, the element representing that method may be + * specified as an originating element. Whether this + * information is used by the tool or not is left down + * to the implementator.</p> + * <p>Each run of the annotation processing tool may only + * create a file with a given pathname once. Attempts + * to create the same file a second time will result in + * a {@link FilerException}. The same behaviour results + * from trying to overwrite the initial source files, which + * are classed as being created in the zeroth round of + * processing. The same exception will be thrown if + * the same name is used for both a source file and a + * class file.</p> + * <p>Processors must not knowingly attempt to overwrite + * files that weren't generated by themselves or a similar + * tool. Similarly, the user invoking the tool should + * not configure it so that it will end up overwriting + * files that weren't generated. A {@code Filer} + * implementation may include safeguards so as not to + * overwrite class files such as {@code java.lang.Object}.</p> + * <p>The {@link javax.lang.annotation.Generated} + * annotation is available to denote generated files + * if needed. Some of the effect of overwriting files may + * be achieved by using a decorator-style design + * pattern and either a generated superclass or a series + * of generated subclasses. In the latter case, + * the class would provide the appropriate generated + * subclass via the factory pattern.</p> + * + * @since 1.6 + */ +public interface Filer +{ +} diff --git a/javax/annotation/processing/Messager.java b/javax/annotation/processing/Messager.java new file mode 100644 index 000000000..97d64470e --- /dev/null +++ b/javax/annotation/processing/Messager.java @@ -0,0 +1,56 @@ +/* Messager.java -- Allows an annotation processor to report messages. + 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.annotation.processing; + +/** + * Provides a way for an annotation processor to report + * messages to the user. Messages may use elements, + * annotations and annotation values to provide a location + * hint, but these may be either unavailable or only + * approximate. Printing a message of kind + * {@link javax.tools.Diagnostic,Kind#ERROR} will cause + * an error to be raised. How the messages are displayed + * is left to the implementor; it may be a simple use of + * {@code System.out} and/or {@code System.err} or something + * more graphical if the application has a user interface. + * + * @since 1.6 + */ +public interface Messager +{ +} diff --git a/javax/annotation/processing/ProcessingEnvironment.java b/javax/annotation/processing/ProcessingEnvironment.java new file mode 100644 index 000000000..4373ad9da --- /dev/null +++ b/javax/annotation/processing/ProcessingEnvironment.java @@ -0,0 +1,100 @@ +/* ProcessingEnvironment.java -- Links the annotation processor to the framework. + 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.annotation.processing; + +import java.util.Locale; + +import javax.lang.model.util.Elements; + +/** + * Provides the annotation processor with access to the + * facilities of the framework, such as the + * {@link Filer} for creating files and the + * {@link Messager} for printing messages to the user. + * It is possible to wrap implementations of this interface + * in order to provide additional functionality. However, + * doing so requires also implementing the dependent + * facility objects, such as the {@code Filer}, so that + * these additional changes are reflected throughout. + * + * @since 1.6 + */ +public interface ProcessingEnvironment +{ + + /** + * Returns an implementation of a number of utility + * methods which provide additional functionality for + * working with (@link javax.lang.model.element.Element} + * instances. + * + * @return the element utilities. + */ + Elements getElementUtils(); + + /** + * Returns an implementation of the {@link Filer} + * which can be used to create source, class or + * resource files. + * + * @return the filer. + */ + Filer getFiler(); + + /** + * Returns the locale used to localise messages from + * the {@link Messager} or {@code null} if one has not + * been set. + * + * @return the current locale or {@code null} if no + * locale has been setup. + */ + Locale getLocale(); + + /** + * Returns an implementation of the {@link Messager} + * which is used to report back to the user, whether + * that be with errors, warnings or other issues. + * + * @return the messager. + */ + Messager getMessager(); + + + +} diff --git a/javax/annotation/processing/RoundEnvironment.java b/javax/annotation/processing/RoundEnvironment.java new file mode 100644 index 000000000..008b9e0ab --- /dev/null +++ b/javax/annotation/processing/RoundEnvironment.java @@ -0,0 +1,119 @@ +/* RoundEnvironment.java -- Represents a round of annotation processing. + 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.annotation.processing; + +import java.lang.annotation.Annotation; + +import java.util.Set; + +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; + +/** + * Provides information used in a round of annotation processing. + * Annotation processing frameworks should provide an implementation + * of this interface, so that processors can be supplied with an instance + * in order to query information about their environment. + * + * @since 1.6 + */ +public interface RoundEnvironment +{ + + /** + * Returns true if the previous round of annotation processing + * raised an error. + * + * @return true if the previous round raised an error. + */ + boolean errorRaised(); + + /** + * Returns the elements annotated with the given annotation type. + * Only the package and type elements, and their constituent + * member, parameter and type parameter elements, included in this + * round of annotation processing are returned. Both root type + * elements and any member type elements nested within them are + * included. The annotation may be used directly or inherited + * by another annotation. Elements in a package are not included + * simply because a package-info file was generated. + * + * @param annotation the annotation type requested. + * @return the elements annotated with the given annotation type + * or an empty set if none were found. + * @throws IllegalArgumentException if @code{annotation} does not + * represent an annotation type. + */ + Set<? extends Element> getElementsAnnotatedWith(Class <? extends Annotation> annotation); + + /** + * Returns the elements annotated with the given annotation type. + * Only the package and type elements, and their constituent + * member, parameter and type parameter elements, included in this + * round of annotation processing are returned. Both root type + * elements and any member type elements nested within them are + * included. The annotation may be used directly or inherited + * by another annotation. Elements in a package are not included + * simply because a package-info file was generated. + * + * @param annotation the annotation type requested. + * @return the elements annotated with the given annotation type + * or an empty set if none were found. + * @throws IllegalArgumentException if @code{annotation} does not + * represent an annotation type. + */ + Set<? extends Element> getElementsAnnotatedWith(TypeElement annotation); + + /** + * Returns the root elements generated by the previous round of + * annotation processing. + * + * @return the elements generated by the previous round or an + * empty set if none were generated. + */ + Set<? extends Element> getRootElements(); + + /** + * Returns true if there will not be another round of processing + * on the elements generated by this round. + * + * @return true if the generated types will not be further processed. + */ + boolean processingOver(); + +} 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 +{ +} |