From f41a2c18c6dd259d21cf72a0e66e68c7a0c9a808 Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Sat, 26 Sep 2015 20:35:22 -0400 Subject: Add remaining javax.lang.model.util classes for Java 6. 2015-09-26 Andrew John Hughes * javax/lang/model/type/WildcardType.java: Remove unneeded import. * javax/lang/model/util/AbstractTypeVisitor6.java: Implemented. (AbstractTypeVisitor6()): Implemented. (visit(TypeMirror)): Likewise. (visit(TypeMirror,P)): Likewise. (visitUnknown(TypeMirror, P)): Likewise. (visitUnion(TypeMirror, P)): Likewise. * javax/lang/model/util/ElementKindVisitor6.java: Implemented. (ElementKindVisitor6): Implemented. (ElementKindVisitor6(R)): Likewise. (visitExecutable(ExecutableElement,P)): Likewise. (visitExecutableAsConstructor(ExecutableElement,P)): Likewise. (visitExecutableAsInstanceInit(ExecutableElement,P)): Likewise. (visitExecutableAsMethod(ExecutableElement,P)): Likewise. (visitExecutableAsStaticInit(ExecutableElement,P)): Likewise. (visitPackage(PackageElement,P)): Likewise. (visitTypeAsAnnotationType(TypeElement,P)): Likewise. (visitTypeAsClass(TypeElement,P)): Likewise. (visitTypeAsEnum(TypeElement,P)): Likewise. (visitTypeAsInterface(TypeElement,P)): Likewise. (visitTypeParameter(TypeParameterElement,P)): Likewise. (visitVariable(VariableElement,P)): Likewise. (visitVariableAsEnumConstant(VariableElement,P)): Likewise. (visitVariableAsExceptionParameter(VariableElement,P)): Likewise. (visitVariableAsField(VariableElement,P)): Likewise. (visitVariableAsLocalVariable(VariableElement,P)): Likewise. (visitVariableAsParameter(VariableElement,P)): Likewise. (visitVariableAsResourceVariable(VariableElement,P)): Likewise. * javax/lang/model/util/SimpleAnnotationValueVisitor6.java: (DEFAULT_VALUE): Added. (SimpleAnnotationValueVisitor6()): Implemented. (SimpleAnnotationValueVisitor6(R)): Likewise. (defaultAction(Object,P)): Likewise. (visitBoolean(boolean,P)): Likewise. (visitByte(byte,P)): Likewise. (visitChar(char,P)): Likewise. (visitDouble(double,P)): Likewise. (visitFloat(float,P)): Likewise. (visitInt(int,P)): Likewise. (visitLong(long,P)): Likewise. (visitShort(short,P)): Likewise. (visitString(String,P)): Likewise. (visitType(TypeMirror,P)): Likewise. (visitEnumConstant(VariableElement,P)): Likewise. (visitAnnotation(AnnotationMirror,P)): Likewise. (visitArray(List,P)): Likewise. * javax/lang/model/util/SimpleElementVisitor6.java: Fix missing brace in Javadoc. Add missing @return documentation. * javax/lang/model/util/SimpleTypeVisitor6.java: (DEFAULT_VALUE): Added. (SimpleTypeVisitor6()): Implemented. (SimpleTypeVisitor6(R)): Likewise. (defaultAction(TypeMirror,P)): Likewise. (visitPrimitive(PrimitiveType,P)): Likewise. (visitNull(NullType,P)): Likewise. (visitArray(ArrayType,P)): Likewise. (visitDeclared(DeclaredType,P)): Likewise. (visitError(ErrorType,P)): Likewise. (visitTypeVariable(TypeVariable,P)): Likewise. (visitWildcard(WildcardType,P)): Likewise. (visitExecutable(ExecutableType,P)): Likewise. (visitNoType(NoType,P)): Likewise. * javax/lang/model/util/TypeKindVisitor6.java: (TypeKindVisitor6()): Implemented. (TypeKindVisitor6(R)): Likewise. (visitNoType(NoType,P)): Likewise. (visitNoTypeAsNone(NoType,P)): Likewise. (visitNoTypeAsPackage(NoType,P)): Likewise. (visitNoTypeAsVoid(NoType,P)): Likewise. (visitPrimitive(PrimitiveType,P)): Likewise. (visitPrimitiveAsBoolean(PrimitiveType,P)): Likewise. (visitPrimitiveAsByte(PrimitiveType,P)): Likewise. (visitPrimitiveAsChar(PrimitiveType,P)): Likewise. (visitPrimitiveAsDouble(PrimitiveType,P)): Likewise. (visitPrimitiveAsFloat(PrimitiveType,P)): Likewise. (visitPrimitiveAsint(PrimitiveType,P)): Likewise. (visitPrimitiveAsLong(PrimitiveType,P)): Likewise. (visitPrimitiveAsShort(PrimitiveType,P)): Likewise. --- ChangeLog | 85 ++++ javax/lang/model/type/WildcardType.java | 2 - javax/lang/model/util/AbstractTypeVisitor6.java | 144 +++++++ javax/lang/model/util/ElementKindVisitor6.java | 433 +++++++++++++++++++++ .../model/util/SimpleAnnotationValueVisitor6.java | 313 +++++++++++++++ javax/lang/model/util/SimpleElementVisitor6.java | 7 +- javax/lang/model/util/SimpleTypeVisitor6.java | 257 ++++++++++++ javax/lang/model/util/TypeKindVisitor6.java | 324 +++++++++++++++ 8 files changed, 1562 insertions(+), 3 deletions(-) create mode 100644 javax/lang/model/util/AbstractTypeVisitor6.java create mode 100644 javax/lang/model/util/ElementKindVisitor6.java create mode 100644 javax/lang/model/util/SimpleAnnotationValueVisitor6.java create mode 100644 javax/lang/model/util/SimpleTypeVisitor6.java create mode 100644 javax/lang/model/util/TypeKindVisitor6.java diff --git a/ChangeLog b/ChangeLog index 10faf8e4b..e4df08d6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,88 @@ +2015-09-26 Andrew John Hughes + + * javax/lang/model/type/WildcardType.java: + Remove unneeded import. + * javax/lang/model/util/AbstractTypeVisitor6.java: + Implemented. + (AbstractTypeVisitor6()): Implemented. + (visit(TypeMirror)): Likewise. + (visit(TypeMirror,P)): Likewise. + (visitUnknown(TypeMirror, P)): Likewise. + (visitUnion(TypeMirror, P)): Likewise. + * javax/lang/model/util/ElementKindVisitor6.java: + Implemented. + (ElementKindVisitor6): Implemented. + (ElementKindVisitor6(R)): Likewise. + (visitExecutable(ExecutableElement,P)): Likewise. + (visitExecutableAsConstructor(ExecutableElement,P)): Likewise. + (visitExecutableAsInstanceInit(ExecutableElement,P)): Likewise. + (visitExecutableAsMethod(ExecutableElement,P)): Likewise. + (visitExecutableAsStaticInit(ExecutableElement,P)): Likewise. + (visitPackage(PackageElement,P)): Likewise. + (visitTypeAsAnnotationType(TypeElement,P)): Likewise. + (visitTypeAsClass(TypeElement,P)): Likewise. + (visitTypeAsEnum(TypeElement,P)): Likewise. + (visitTypeAsInterface(TypeElement,P)): Likewise. + (visitTypeParameter(TypeParameterElement,P)): Likewise. + (visitVariable(VariableElement,P)): Likewise. + (visitVariableAsEnumConstant(VariableElement,P)): Likewise. + (visitVariableAsExceptionParameter(VariableElement,P)): Likewise. + (visitVariableAsField(VariableElement,P)): Likewise. + (visitVariableAsLocalVariable(VariableElement,P)): Likewise. + (visitVariableAsParameter(VariableElement,P)): Likewise. + (visitVariableAsResourceVariable(VariableElement,P)): Likewise. + * javax/lang/model/util/SimpleAnnotationValueVisitor6.java: + (DEFAULT_VALUE): Added. + (SimpleAnnotationValueVisitor6()): Implemented. + (SimpleAnnotationValueVisitor6(R)): Likewise. + (defaultAction(Object,P)): Likewise. + (visitBoolean(boolean,P)): Likewise. + (visitByte(byte,P)): Likewise. + (visitChar(char,P)): Likewise. + (visitDouble(double,P)): Likewise. + (visitFloat(float,P)): Likewise. + (visitInt(int,P)): Likewise. + (visitLong(long,P)): Likewise. + (visitShort(short,P)): Likewise. + (visitString(String,P)): Likewise. + (visitType(TypeMirror,P)): Likewise. + (visitEnumConstant(VariableElement,P)): Likewise. + (visitAnnotation(AnnotationMirror,P)): Likewise. + (visitArray(List,P)): Likewise. + * javax/lang/model/util/SimpleElementVisitor6.java: + Fix missing brace in Javadoc. Add missing @return + documentation. + * javax/lang/model/util/SimpleTypeVisitor6.java: + (DEFAULT_VALUE): Added. + (SimpleTypeVisitor6()): Implemented. + (SimpleTypeVisitor6(R)): Likewise. + (defaultAction(TypeMirror,P)): Likewise. + (visitPrimitive(PrimitiveType,P)): Likewise. + (visitNull(NullType,P)): Likewise. + (visitArray(ArrayType,P)): Likewise. + (visitDeclared(DeclaredType,P)): Likewise. + (visitError(ErrorType,P)): Likewise. + (visitTypeVariable(TypeVariable,P)): Likewise. + (visitWildcard(WildcardType,P)): Likewise. + (visitExecutable(ExecutableType,P)): Likewise. + (visitNoType(NoType,P)): Likewise. + * javax/lang/model/util/TypeKindVisitor6.java: + (TypeKindVisitor6()): Implemented. + (TypeKindVisitor6(R)): Likewise. + (visitNoType(NoType,P)): Likewise. + (visitNoTypeAsNone(NoType,P)): Likewise. + (visitNoTypeAsPackage(NoType,P)): Likewise. + (visitNoTypeAsVoid(NoType,P)): Likewise. + (visitPrimitive(PrimitiveType,P)): Likewise. + (visitPrimitiveAsBoolean(PrimitiveType,P)): Likewise. + (visitPrimitiveAsByte(PrimitiveType,P)): Likewise. + (visitPrimitiveAsChar(PrimitiveType,P)): Likewise. + (visitPrimitiveAsDouble(PrimitiveType,P)): Likewise. + (visitPrimitiveAsFloat(PrimitiveType,P)): Likewise. + (visitPrimitiveAsint(PrimitiveType,P)): Likewise. + (visitPrimitiveAsLong(PrimitiveType,P)): Likewise. + (visitPrimitiveAsShort(PrimitiveType,P)): Likewise. + 2015-06-19 Andrew John Hughes * NEWS: Mention PR66376. diff --git a/javax/lang/model/type/WildcardType.java b/javax/lang/model/type/WildcardType.java index 20dfd827a..826881744 100644 --- a/javax/lang/model/type/WildcardType.java +++ b/javax/lang/model/type/WildcardType.java @@ -37,8 +37,6 @@ exception statement from your version. */ package javax.lang.model.type; -import javax.lang.model.element.Element; - /** *

Represents a wildcard type argument, which may take one * of three forms:

diff --git a/javax/lang/model/util/AbstractTypeVisitor6.java b/javax/lang/model/util/AbstractTypeVisitor6.java new file mode 100644 index 000000000..7d907187d --- /dev/null +++ b/javax/lang/model/util/AbstractTypeVisitor6.java @@ -0,0 +1,144 @@ +/* AbstractTypeVisitor6.java -- A visitor of types for 1.6. + Copyright (C) 2015 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 javax.lang.model.SourceVersion; + +import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVisitor; +import javax.lang.model.type.UnionType; +import javax.lang.model.type.UnknownTypeException; + +/** + *

A skeletal implementation of {@link TypeVisitor} for the + * 1.6 version of the Java programming language + * ({@link SourceVersion#RELEASE_6}). Implementors can extend this + * class and need provide only implementations of the + * {@code visitXYZ} methods appropriate to 1.6.

+ *

As the interface this class implements may be extended in future, + * in order to support later language versions, methods beginning with + * the phrase {@code "visit"} should be avoided in subclasses. This + * class itself will be extended to direct these new methods to the + * {@link #visitUnknown(TypeMirror,P) method and a new class will be + * added to provide implementations for the new language version. + * At this time, all or some of this class may be deprecated.

+ * + * @param the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param

the type of the additional parameter supplied to the visitor's + * methods. {@code Void} can be used where no additional + * parameter is required. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public abstract class AbstractTypeVisitor6 implements TypeVisitor +{ + + /** + * Constructs a new {@code AbstractTypeVisitor6}. + */ + protected AbstractTypeVisitor6() {} + + /** + * Visits a type mirror by passing itself to the type + * mirror's {@code accept} method, with {@code null} for the additional + * parameter i.e. {@code{v.visit(typeMirror)} is equivalent to + * {@code{typeMirror.accept(v, null)}. + * + * @param typeMirror the type to visit. + * @return the return value specific to the visitor. + */ + @Override + public final R visit(TypeMirror typeMirror) + { + return typeMirror.accept(this, null); + } + + /** + * Visits a type mirror by passing itself to the type + * mirror's {@code accept} method, with the specified value as the additional + * parameter i.e. {@code{v.visit(typeMirror, parameter)} is equivalent to + * {@code{typeMirror.accept(v, parameter)}. + * + * @param typeMirror the type to visit. + * @param parameter the value to use as the additional parameter. + * @return the return value specific to the visitor. + */ + @Override + public final R visit(TypeMirror typeMirror, P parameter) + { + return typeMirror.accept(this, parameter); + } + + /** + * Visits an unknown type mirror. This method is called if + * this visitor is used in a version of the language later + * than 1.6, where new types have been added. This + * implementation always throws a {@link UnknownTypeException} + * but this is not required of subclasses. + * + * @param typeMirror the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * @return the return value specific to the visitor. + * @throws UnknownTypeException by default. + */ + @Override + public R visitUnknown(TypeMirror typeMirror, P parameter) + { + throw new UnknownTypeException(typeMirror, parameter); + } + + /** + * Provides a default implementation for the {@code visitUnion} method + * added in 1.7, so that existing subclasses continue to compile. It + * simply redirects to {@link #visitUnknown(TypeMirror,P)}. + * + * @param type the union type 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. + * @since 1.7 + */ + @Override + public R visitUnion(UnionType type, P parameter) + { + return visitUnknown(type, parameter); + } + +} diff --git a/javax/lang/model/util/ElementKindVisitor6.java b/javax/lang/model/util/ElementKindVisitor6.java new file mode 100644 index 000000000..8e9760ac3 --- /dev/null +++ b/javax/lang/model/util/ElementKindVisitor6.java @@ -0,0 +1,433 @@ +/* ElementKindVisitor6.java -- An element visitor implementation for 1.6. + Copyright (C) 2015 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 javax.annotation.processing.SupportedSourceVersion; + +import javax.lang.model.SourceVersion; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementVisitor; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.TypeParameterElement; +import javax.lang.model.element.VariableElement; + +/** + *

An implementation of {@link ElementVisitor} for the + * 1.6 version of the Java programming language + * ({@link SourceVersion#RELEASE_6}) which redirects each + * {@code visitXYZ} method call to a more specific + * {@code visitXYZAsKind} method, depending on the kind + * of the first argument. For example, a call to + * {@code visitExecutable} redirects to {@code visitExecutableAsConstructor}, + * {@code visitExecutableAsInstanceInit}, + * {@code visitExecutableAsMethod} or {@code visitExecutableAsStaticInit}, + * depending on the type of executable supplied. {@code visitXYZAsKind} then + * redirects to {@code defaultAction(element, parameter)}. + * Implementors may extend this class and provide alternative + * implementations of {@link #defaultAction(Element, P)} and + * the {@code visitXYZKind} methods as appropriate.

+ *

As the interface this class implements may be extended in future, + * in order to support later language versions, methods beginning with + * the phrase {@code "visit"} should be avoided in subclasses. This + * class itself will be extended to direct these new methods to the + * {@link #visitUnknown(Element,P)} method and a new class will be + * added to provide implementations for the new language version. + * At this time, all or some of this class may be deprecated.

+ * + * @param the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param

the type of the additional parameter supplied to the visitor's + * methods. {@code Void} can be used if this is not needed. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class ElementKindVisitor6 extends SimpleElementVisitor6 +{ + + /** + * Constructs a new {@link ElementKindVisitor6} with a {@code null} + * default value. + */ + protected ElementKindVisitor6() + { + this(null); + } + + /** + * Constructs a new {@link ElementKindVisitor6} with the specified + * default value. + * + * @param defaultValue the value to assign to {@link SimpleElementVisitor6#DEFAULT_VALUE}. + */ + protected ElementKindVisitor6(R defaultValue) + { + super(defaultValue); + } + + /** + * Visits an executable element. This implementation dispatches + * the call to the appropriate visit method, corresponding to the + * exact kind of executable element: {@code CONSTRUCTOR}, + * {@code INSTANCE_INIT}, {@code METHOD} or {@code STATIC_INIT}. + * For example, a constructor element will be redirected to the + * {@link visitExecutableAsConstructor(ExecutableElement,P)} method. + * + * @param element the executable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of the kind-specific method. + */ + @Override + public R visitExecutable(ExecutableElement element, P parameter) + { + switch (element.getKind()) + { + case CONSTRUCTOR: + return visitExecutableAsConstructor(element, parameter); + case INSTANCE_INIT: + return visitExecutableAsInstanceInit(element, parameter); + case METHOD: + return visitExecutableAsMethod(element, parameter); + case STATIC_INIT: + return visitExecutableAsStaticInit(element, parameter); + default: + return super.visitExecutable(element, parameter); + } + } + + /** + * Visits a {@code CONSTRUCTOR} executable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the constructor element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitExecutableAsConstructor(ExecutableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits an {@code INSTANCE_INIT} executable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the instance initializer element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitExecutableAsInstanceInit(ExecutableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code METHOD} executable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the method element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitExecutableAsMethod(ExecutableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code STATIC_INIT} executable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the static initializer element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitExecutableAsStaticInit(ExecutableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a package element. This implementation simply + * calls {@code defaultAction(element, parameter)}. + * + * @param element the package element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + @Override + public R visitPackage(PackageElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a type element. This implementation dispatches + * the call to the appropriate visit method, corresponding to the + * exact kind of type element: {@code ANNOTATION_TYPE}, + * {@code CLASS}, {@code ENUM} or {@code INTERFACE}. + * For example, an annotation type element will be redirected to the + * {@link visitTypeAsAnnotationType(TypeElement,P)} method. + * + * @param element the type element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of the kind-specific method. + */ + @Override + public R visitType(TypeElement element, P parameter) + { + switch (element.getKind()) + { + case ANNOTATION_TYPE: + return visitTypeAsAnnotationType(element, parameter); + case CLASS: + return visitTypeAsClass(element, parameter); + case ENUM: + return visitTypeAsEnum(element, parameter); + case INTERFACE: + return visitTypeAsInterface(element, parameter); + default: + return super.visitType(element, parameter); + } + } + + /** + * Visits an {@code ANNOTATION_TYPE} type element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the annotation type element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitTypeAsAnnotationType(TypeElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code CLASS} type element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the class element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitTypeAsClass(TypeElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code ENUM} type element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the enumeration element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitTypeAsEnum(TypeElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits an {@code INTERFACE} type element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the interface element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitTypeAsInterface(TypeElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a type parameter element. This implementation simply + * calls {@code defaultAction(element, parameter)}. + * + * @param element the type parameter element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + @Override + public R visitTypeParameter(TypeParameterElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a variable element. This implementation dispatches + * the call to the appropriate visit method, corresponding to the + * exact kind of variable element: {@code ENUM_CONSTANT}, + * {@code EXCEPTION_PARAMETER}, {@code FIELD}, {@code LOCAL_VARIABLE}, + * {@code PARAMETER} or {@code RESOURCE_VARIABLE}. + * For example, a field variable element will be redirected to the + * {@link visitVariableAsField(TypeElement,P)} method. + * + * @param element the variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of the kind-specific method. + */ + @Override + public R visitVariable(VariableElement element, P parameter) + { + switch (element.getKind()) + { + case ENUM_CONSTANT: + return visitVariableAsEnumConstant(element, parameter); + case EXCEPTION_PARAMETER: + return visitVariableAsExceptionParameter(element, parameter); + case FIELD: + return visitVariableAsField(element, parameter); + case LOCAL_VARIABLE: + return visitVariableAsField(element, parameter); + case PARAMETER: + return visitVariableAsParameter(element, parameter); + case RESOURCE_VARIABLE: + return visitVariableAsResourceVariable(element, parameter); + default: + return super.visitVariable(element, parameter); + } + } + + /** + * Visits an {@code ENUM_CONSTANT} variable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the enum constant variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitVariableAsEnumConstant(VariableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits an {@code EXCEPTION_PARAMETER} variable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the exception parameter variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitVariableAsExceptionParameter(VariableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code FIELD} variable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the field variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitVariableAsField(VariableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code LOCAL_VARIABLE} variable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the local variable variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitVariableAsLocalVariable(VariableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code PARAMETER} variable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the parameter variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitVariableAsParameter(VariableElement element, P parameter) + { + return defaultAction(element, parameter); + } + + /** + * Visits a {@code RESOURCE_VARIABLE} variable element. This implementation + * simply calls {@code defaultAction(element, parameter)}. + * + * @param element the resource variable variable element to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. + */ + public R visitVariableAsResourceVariable(VariableElement element, P parameter) + { + return defaultAction(element, parameter); + } + +} + + diff --git a/javax/lang/model/util/SimpleAnnotationValueVisitor6.java b/javax/lang/model/util/SimpleAnnotationValueVisitor6.java new file mode 100644 index 000000000..50f51fa1f --- /dev/null +++ b/javax/lang/model/util/SimpleAnnotationValueVisitor6.java @@ -0,0 +1,313 @@ +/* SimpleAnnotationValueVisitor6.java -- A simple visitor implementation for 1.6. + Copyright (C) 2015 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.List; + +import javax.annotation.processing.SupportedSourceVersion; + +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; + +/** + *

A simple implementation of {@link AnnotationValueVisitor} for the + * 1.6 version of the Java programming language + * ({@link SourceVersion#RELEASE_6}). Each {@code visitXYZ} method + * redirects to {@code defaultAction(value, parameter)}. + * Implementors may extend this class and provide alternative + * implementations of {@link #defaultAction(Object, P)} and + * the {@code visitXYZ} methods as appropriate.

+ *

As the interface this class implements may be extended in future, + * in order to support later language versions, methods beginning with + * the phrase {@code "visit"} should be avoided in subclasses. This + * class itself will be extended to direct these new methods to the + * {@link #visitUnknown(AnnotationValue,P)} method and a new class will be + * added to provide implementations for the new language version. + * At this time, all or some of this class may be deprecated.

+ * + * @param the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param

the type of the additional parameter supplied to the visitor's + * methods. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class SimpleAnnotationValueVisitor6 extends AbstractAnnotationValueVisitor6 +{ + + /** + * The default value returned by calls to {@link #defaultAction(Object, P)}. + */ + protected final R DEFAULT_VALUE; + + /** + * Constructs a new {@link SimpleAnnotationValueVisitor6} with a {@code null} + * default value. + */ + protected SimpleAnnotationValueVisitor6() + { + this(null); + } + + /** + * Constructs a new {@link SimpleAnnotationValueVisitor6} with the specified + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}. + */ + protected SimpleAnnotationValueVisitor6(R defaultValue) + { + DEFAULT_VALUE = defaultValue; + } + + /** + * The default action for all visitor methods. The default implementation + * simply returns {@link #DEFAULT_VALUE}. + * + * @param obj the object to act upon. + * @param parameter the optional parameter supplied to the visitor. + * @return {@link #DEFAULT_VALUE}. + */ + protected R defaultAction(Object obj, P parameter) + { + return DEFAULT_VALUE; + } + + /** + * Visits a boolean value in an annotation. This implementation simply + * calls {@code defaultAction(bool, parameter)}. + * + * @param bool the boolean value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(bool, parameter)}. + */ + @Override + public R visitBoolean(boolean bool, P parameter) + { + return defaultAction(bool, parameter); + } + + /** + * Visits a byte value in an annotation. This implementation simply + * calls {@code defaultAction(val, parameter)}. + * + * @param val the byte value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(val, parameter)}. + */ + @Override + public R visitByte(byte val, P parameter) + { + return defaultAction(val, parameter); + } + + /** + * Visits a character value in an annotation. This implementation simply + * calls {@code defaultAction(character, parameter)}. + * + * @param character the character value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(character, parameter)}. + */ + @Override + public R visitChar(char character, P parameter) + { + return defaultAction(character, parameter); + } + + /** + * Visits a double value in an annotation. This implementation simply + * calls {@code defaultAction(val, parameter)}. + * + * @param val the double value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(val, parameter)}. + */ + @Override + public R visitDouble(double val, P parameter) + { + return defaultAction(val, parameter); + } + + /** + * Visits a float value in an annotation. This implementation simply + * calls {@code defaultAction(val, parameter)}. + * + * @param val the float value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(val, parameter)}. + */ + @Override + public R visitFloat(float val, P parameter) + { + return defaultAction(val, parameter); + } + + /** + * Visits an integer value in an annotation. This implementation simply + * calls {@code defaultAction(val, parameter)}. + * + * @param val the integer value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(val, parameter)}. + */ + @Override + public R visitInt(int val, P parameter) + { + return defaultAction(val, parameter); + } + + /** + * Visits a long value in an annotation. This implementation simply + * calls {@code defaultAction(val, parameter)}. + * + * @param val the long value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(val, parameter)}. + */ + @Override + public R visitLong(long val, P parameter) + { + return defaultAction(val, parameter); + } + + /** + * Visits a short value in an annotation. This implementation simply + * calls {@code defaultAction(val, parameter)}. + * + * @param val the short value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(val, parameter)}. + */ + @Override + public R visitShort(short val, P parameter) + { + return defaultAction(val, parameter); + } + + /** + * Visits a String value in an annotation. This implementation simply + * calls {@code defaultAction(str, parameter)}. + * + * @param str the String value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(str, parameter)}. + */ + @Override + public R visitString(String str, P parameter) + { + return defaultAction(str, parameter); + } + + /** + * Visits a type value in an annotation. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the type value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitType(TypeMirror type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits an enumeration constant in an annotation. This implementation simply + * calls {@code defaultAction(enumConst, parameter)}. + * + * @param enumConst the enumeration constant to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(enumConst, parameter)}. + */ + @Override + public R visitEnumConstant(VariableElement enumConst, P parameter) + { + return defaultAction(enumConst, parameter); + } + + /** + * Visits an annotation value in an annotation. This implementation simply + * calls {@code defaultAction(annotation, parameter)}. + * + * @param annotation the annotation value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(annotation, parameter)}. + */ + @Override + public R visitAnnotation(AnnotationMirror annotation, P parameter) + { + return defaultAction(annotation, parameter); + } + + /** + * Visits an array value in an annotation. This implementation simply + * calls {@code defaultAction(array, parameter)}. + * + * @param array the array value to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(array, parameter)}. + */ + @Override + public R visitArray(List array, P parameter) + { + return defaultAction(array, parameter); + } + +} + + diff --git a/javax/lang/model/util/SimpleElementVisitor6.java b/javax/lang/model/util/SimpleElementVisitor6.java index 21cac478b..f41315087 100644 --- a/javax/lang/model/util/SimpleElementVisitor6.java +++ b/javax/lang/model/util/SimpleElementVisitor6.java @@ -61,7 +61,7 @@ import javax.lang.model.element.VariableElement; * in order to support later language versions, methods beginning with * the phrase {@code "visit"} should be avoided in subclasses. This * class itself will be extended to direct these new methods to the - * {@link #visitUnknown(Element,P) method and a new class will be + * {@link #visitUnknown(Element,P)} method and a new class will be * added to provide implementations for the new language version. * At this time, all or some of this class may be deprecated.

* @@ -122,6 +122,7 @@ public class SimpleElementVisitor6 extends AbstractElementVisitor6 * @param element the executable element to visit. * @param parameter the additional parameter, specific to the visitor. * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. */ @Override public R visitExecutable(ExecutableElement element, P parameter) @@ -137,6 +138,7 @@ public class SimpleElementVisitor6 extends AbstractElementVisitor6 * @param element the package element to visit. * @param parameter the additional parameter, specific to the visitor. * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. */ @Override public R visitPackage(PackageElement element, P parameter) @@ -151,6 +153,7 @@ public class SimpleElementVisitor6 extends AbstractElementVisitor6 * @param element the type element to visit. * @param parameter the additional parameter, specific to the visitor. * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. */ @Override public R visitType(TypeElement element, P parameter) @@ -165,6 +168,7 @@ public class SimpleElementVisitor6 extends AbstractElementVisitor6 * @param element the type parameter element to visit. * @param parameter the additional parameter, specific to the visitor. * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. */ @Override public R visitTypeParameter(TypeParameterElement element, P parameter) @@ -179,6 +183,7 @@ public class SimpleElementVisitor6 extends AbstractElementVisitor6 * @param element the variable element to visit. * @param parameter the additional parameter, specific to the visitor. * May be {@code null}. + * @return the result of {@code defaultAction(element, parameter)}. */ @Override public R visitVariable(VariableElement element, P parameter) diff --git a/javax/lang/model/util/SimpleTypeVisitor6.java b/javax/lang/model/util/SimpleTypeVisitor6.java new file mode 100644 index 000000000..c41c77ece --- /dev/null +++ b/javax/lang/model/util/SimpleTypeVisitor6.java @@ -0,0 +1,257 @@ +/* SimpleTypeVisitor6.java -- A simple visitor implementation for 1.6. + Copyright (C) 2015 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 javax.annotation.processing.SupportedSourceVersion; + +import javax.lang.model.SourceVersion; +import javax.lang.model.type.ArrayType; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.ErrorType; +import javax.lang.model.type.ExecutableType; +import javax.lang.model.type.NoType; +import javax.lang.model.type.NullType; +import javax.lang.model.type.PrimitiveType; +import javax.lang.model.type.WildcardType; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVariable; + +/** + *

A simple implementation of {@link TypeVisitor} for the + * 1.6 version of the Java programming language + * ({@link SourceVersion#RELEASE_6}). Each {@code visitXYZ} method + * redirects to {@code defaultAction(type, parameter)}. + * Implementors may extend this class and provide alternative + * implementations of {@link #defaultAction(TypeMirror, P)} and + * the {@code visitXYZ} methods as appropriate.

+ *

As the interface this class implements may be extended in future, + * in order to support later language versions, methods beginning with + * the phrase {@code "visit"} should be avoided in subclasses. This + * class itself will be extended to direct these new methods to the + * {@link #visitUnknown(TypeMirror,P)} method and a new class will be + * added to provide implementations for the new language version. + * At this time, all or some of this class may be deprecated.

+ * + * @param the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param

the type of the additional parameter supplied to the visitor's + * methods. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class SimpleTypeVisitor6 extends AbstractTypeVisitor6 +{ + + /** + * The default value returned by calls to {@link #defaultAction(TypeMirror, P)}. + */ + protected final R DEFAULT_VALUE; + + /** + * Constructs a new {@link SimpleAnnotationValueVisitor6} with a {@code null} + * default value. + */ + protected SimpleTypeVisitor6() + { + this(null); + } + + /** + * Constructs a new {@link SimpleTypeVisitor6} with the specified + * default value. + * + * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}. + */ + protected SimpleTypeVisitor6(R defaultValue) + { + DEFAULT_VALUE = defaultValue; + } + + /** + * The default action for all visitor methods. The default implementation + * simply returns {@link #DEFAULT_VALUE}. + * + * @param type the type to act upon. + * @param parameter the optional parameter supplied to the visitor. + * @return {@link #DEFAULT_VALUE}. + */ + protected R defaultAction(TypeMirror type, P parameter) + { + return DEFAULT_VALUE; + } + + /** + * Visits a primitive type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the primitive type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitPrimitive(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a null type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the null type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitNull(NullType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits an array type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the array type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitArray(ArrayType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a declared type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the declared type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitDeclared(DeclaredType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits an error type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the error type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitError(ErrorType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a type variable. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the type variable to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitTypeVariable(TypeVariable type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a wildcard type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the wildcard type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitWildcard(WildcardType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits an executable type. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the executable type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitExecutable(ExecutableType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a NoType instance. This implementation simply + * calls {@code defaultAction(type, parameter)}. + * + * @param type the NoType instance to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + @Override + public R visitNoType(NoType type, P parameter) + { + return defaultAction(type, parameter); + } + +} + + diff --git a/javax/lang/model/util/TypeKindVisitor6.java b/javax/lang/model/util/TypeKindVisitor6.java new file mode 100644 index 000000000..7cde08cf7 --- /dev/null +++ b/javax/lang/model/util/TypeKindVisitor6.java @@ -0,0 +1,324 @@ +/* TypeKindVisitor6.java -- A type visitor implementation for 1.6. + Copyright (C) 2015 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 javax.annotation.processing.SupportedSourceVersion; + +import javax.lang.model.SourceVersion; +import javax.lang.model.type.NoType; +import javax.lang.model.type.PrimitiveType; + +/** + *

An implementation of {@link TypeVisitor} for the + * 1.6 version of the Java programming language + * ({@link SourceVersion#RELEASE_6}) which redirects each + * {@code visitXYZ} method call to a more specific + * {@code visitXYZAsKind} method, depending on the kind + * of the first argument. For example, a call to + * {@code visitNoType} redirects to {@code visitNoTypeAsNone}, + * {@code visitNoTypeAsPackage} or {@code visitNoTypeAsVoid}, + * depending on the type of {@code NoType} supplied. {@code visitXYZAsKind} then + * redirects to {@code defaultAction(element, parameter)}. + * Implementors may extend this class and provide alternative + * implementations of {@link #defaultAction(TypeMirror, P)} and + * the {@code visitXYZKind} methods as appropriate.

+ *

As the interface this class implements may be extended in future, + * in order to support later language versions, methods beginning with + * the phrase {@code "visit"} should be avoided in subclasses. This + * class itself will be extended to direct these new methods to the + * {@link #visitUnknown(TypeMirror,P)} method and a new class will be + * added to provide implementations for the new language version. + * At this time, all or some of this class may be deprecated.

+ * + * @param the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param

the type of the additional parameter supplied to the visitor's + * methods. {@code Void} can be used if this is not needed. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class TypeKindVisitor6 extends SimpleTypeVisitor6 +{ + + /** + * Constructs a new {@link TypeKindVisitor6} with a {@code null} + * default value. + */ + protected TypeKindVisitor6() + { + this(null); + } + + /** + * Constructs a new {@link TypeKindVisitor6} with the specified + * default value. + * + * @param defaultValue the value to assign to {@link SimpleTypeVisitor6#DEFAULT_VALUE}. + */ + protected TypeKindVisitor6(R defaultValue) + { + super(defaultValue); + } + + /** + * Visits a {@code NoType} instance. This implementation dispatches + * the call to the appropriate visit method, corresponding to the + * exact kind of {@code NoType}: {@code NONE}, {@code PACKAGE} or + * {@code VOID}. For example, a package type will be redirected to the + * {@link visitNoTypeAsPackage(NoType,P)} method. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of the kind-specific method. + */ + @Override + public R visitNoType(NoType type, P parameter) + { + switch (type.getKind()) + { + case NONE: + return visitNoTypeAsNone(type, parameter); + case PACKAGE: + return visitNoTypeAsPackage(type, parameter); + case VOID: + return visitNoTypeAsVoid(type, parameter); + default: + return super.visitNoType(type, parameter); + } + } + + /** + * Visits a {@code NONE} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitNoTypeAsNone(NoType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code PACKAGE} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitNoTypeAsPackage(NoType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code VOID} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitNoTypeAsVoid(NoType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a primitive type. This implementation dispatches + * the call to the appropriate visit method, corresponding to the + * exact kind of primitive: {@code BOOLEAN}, {@code BYTE}, + * {@code CHAR}, {@code DOUBLE}, {@code FLOAT}, {@code INT}, + * {@code LONG} or {@code SHORT}. For example, a boolean will be + * redirected to the {@link visitPrimitiveAsBoolean(PrimitiveType,P)} + * method. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of the kind-specific method. + */ + @Override + public R visitPrimitive(PrimitiveType type, P parameter) + { + switch (type.getKind()) + { + case BOOLEAN: + return visitPrimitiveAsBoolean(type, parameter); + case BYTE: + return visitPrimitiveAsByte(type, parameter); + case CHAR: + return visitPrimitiveAsChar(type, parameter); + case DOUBLE: + return visitPrimitiveAsDouble(type, parameter); + case FLOAT: + return visitPrimitiveAsFloat(type, parameter); + case INT: + return visitPrimitiveAsInt(type, parameter); + case LONG: + return visitPrimitiveAsLong(type, parameter); + case SHORT: + return visitPrimitiveAsShort(type, parameter); + default: + return super.visitPrimitive(type, parameter); + } + } + + /** + * Visits a {@code BOOLEAN} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsBoolean(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code BYTE} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsByte(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code CHAR} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsChar(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code DOUBLE} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsDouble(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code FLOAT} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsFloat(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code INT} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsInt(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code LONG} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsLong(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + + /** + * Visits a {@code SHORT} type. This implementation + * simply calls {@code defaultAction(type, parameter)}. + * + * @param type the type to visit. + * @param parameter the additional parameter, specific to the visitor. + * May be {@code null}. + * @return the result of {@code defaultAction(type, parameter)}. + */ + public R visitPrimitiveAsShort(PrimitiveType type, P parameter) + { + return defaultAction(type, parameter); + } + +} + + -- cgit v1.2.1