diff options
Diffstat (limited to 'javax/lang/model/type')
-rw-r--r-- | javax/lang/model/type/ArrayType.java | 59 | ||||
-rw-r--r-- | javax/lang/model/type/DeclaredType.java | 101 | ||||
-rw-r--r-- | javax/lang/model/type/ErrorType.java | 51 | ||||
-rw-r--r-- | javax/lang/model/type/ExecutableType.java | 98 | ||||
-rw-r--r-- | javax/lang/model/type/MirroredTypeException.java | 85 | ||||
-rw-r--r-- | javax/lang/model/type/MirroredTypesException.java | 87 | ||||
-rw-r--r-- | javax/lang/model/type/NoType.java | 60 | ||||
-rw-r--r-- | javax/lang/model/type/NullType.java | 50 | ||||
-rw-r--r-- | javax/lang/model/type/PrimitiveType.java | 52 | ||||
-rw-r--r-- | javax/lang/model/type/ReferenceType.java | 51 | ||||
-rw-r--r-- | javax/lang/model/type/TypeKind.java | 112 | ||||
-rw-r--r-- | javax/lang/model/type/TypeMirror.java | 112 | ||||
-rw-r--r-- | javax/lang/model/type/TypeVariable.java | 87 | ||||
-rw-r--r-- | javax/lang/model/type/TypeVisitor.java | 188 | ||||
-rw-r--r-- | javax/lang/model/type/UnknownTypeException.java | 105 | ||||
-rw-r--r-- | javax/lang/model/type/WildcardType.java | 79 |
16 files changed, 1377 insertions, 0 deletions
diff --git a/javax/lang/model/type/ArrayType.java b/javax/lang/model/type/ArrayType.java new file mode 100644 index 000000000..94538bccd --- /dev/null +++ b/javax/lang/model/type/ArrayType.java @@ -0,0 +1,59 @@ +/* ArrayType.java -- Represents an array type. + 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.type; + +/** + * Represents an array type. Multidimensional arrays are + * represented as array types where the component type + * is also an array type. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface ArrayType + extends ReferenceType +{ + + /** + * Returns the component type of the array. + * + * @return the component type. + */ + TypeMirror getComponentType(); + +} diff --git a/javax/lang/model/type/DeclaredType.java b/javax/lang/model/type/DeclaredType.java new file mode 100644 index 000000000..08efb82b3 --- /dev/null +++ b/javax/lang/model/type/DeclaredType.java @@ -0,0 +1,101 @@ +/* DeclaredType.java -- Represents a class or interface type. + 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.type; + +import java.util.List; + +import javax.lang.model.element.Element; + +/** + * <p>Represents a type declared in the source code i.e. a class + * or an interface. This includes parameterised types, such + * as {@code Set<String>} as well as raw types, such as {@code Set}.</p> + * <p>A type represents the usage of a particular element and, as + * a result, multiple types can be represented by the same element. + * Both the {@code Set<String>} and {@code Set} types mentioned above + * would be represented by the same element.</p> + * <p>This interface is also used to represent <emph>intersection types</emph> + * which don't exist explicitly in the source code. For example, + * in {@code <T extends Number & Runnable>}, the bound is an intersection + * type. It is represented by a {@code DeclaredType} with {@code Number} + * as its superclass and {@code Runnable} as its single superinterface.</p> + * <p>To obtain the supertypes of a declared type, the method + * {@link javax.lang.model.util.Types#directSupertypes(TypeMirror)} should + * be used. This returns the superclass and any superinterfaces of the + * type with any type arguments substituted in.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.element.TypeElement + */ +public interface DeclaredType + extends ReferenceType +{ + + /** + * Returns the element which corresponds to this type. + * For example, the element for the type {@code Set<String>} + * would be the element for {@code Set}. + * + * @return the element corresponding to this type. + */ + Element asElement(); + + /** + * Returns the type of the innermost enclosing element or + * an instance of {@link NoType} with the kind {@link TypeKind#NONE} + * if this is a top-level type. Only types representing + * inner classes have enclosing instances. + * + * @return a type mirror for the enclosing type, if any. + */ + TypeMirror getEnclosingType(); + + /** + * Returns a list of the actual type arguments used by this + * type. For example, for {@code Set<String>}, the returned list + * would include a single type representing {@code String}. + * Only type arguments for this particular type are returned; type + * parameters for enclosing types are not included. If there are + * no type arguments, an empty list is returned. + * + * @return a list of the type arguments used by the type. + */ + List<? extends TypeMirror> getTypeArguments(); + +} diff --git a/javax/lang/model/type/ErrorType.java b/javax/lang/model/type/ErrorType.java new file mode 100644 index 000000000..34ac7a5e3 --- /dev/null +++ b/javax/lang/model/type/ErrorType.java @@ -0,0 +1,51 @@ +/* ErrorType.java -- Represents a type that can't be modelled. + 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.type; + +/** + * Represents a type that can't be modelled. This may be as + * a result of a number of reasons, such as a missing class file, + * an erroneous source file or a processing error. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface ErrorType + extends DeclaredType +{ +} diff --git a/javax/lang/model/type/ExecutableType.java b/javax/lang/model/type/ExecutableType.java new file mode 100644 index 000000000..72d81b4b7 --- /dev/null +++ b/javax/lang/model/type/ExecutableType.java @@ -0,0 +1,98 @@ +/* ExecutableType.java -- Represents a method, constructor or initialiser. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.type; + +import java.util.List; + +/** + * Represents something which may be executed i.e. a + * constructor, a method or an initialiser. The executable + * is viewed respective to a particular type. As a result, + * any type parameters will be substituted with actual type + * arguments as appropriate. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see + */ +public interface ExecutableType + extends TypeMirror +{ + + /** + * Returns the types of the formal parameters of this + * executable, or an empty list if the executable takes + * no parameters. For example, {@code doThis(int)} will + * return a list containing a single element, the type + * mirror for {@code int}. + * + * @return the executable's formal parameters. + */ + List<? extends TypeMirror> getParameterTypes(); + + /** + * Returns the return type of the executable. If the + * executable is a constructor or an initialiser, or + * does not return anything, this method will return + * an instance of {@link NoType} with the kind + * {@link TypeKind#VOID}. + * + * @return the return type of this executable. + */ + TypeMirror getReturnType(); + + /** + * Returns the types of any exceptions or other + * {@link Throwable}s mentioned in the {@code throws} + * clause of this executable, or an empty list if there + * are none. + * + * @return the exceptions and other throwables declared + * as thrown by this executable. + */ + List<? extends TypeMirror> getThrownTypes(); + + /** + * Returns the type variables declared by the formal type + * parameters or an empty list if there are none. + * + * @return the type variables declared by this executable. + */ + List<? extends TypeVariable> getTypeVariables(); + +} diff --git a/javax/lang/model/type/MirroredTypeException.java b/javax/lang/model/type/MirroredTypeException.java new file mode 100644 index 000000000..6c443ad58 --- /dev/null +++ b/javax/lang/model/type/MirroredTypeException.java @@ -0,0 +1,85 @@ +/* MirroredTypeException.java -- An attempt to access a TypeMirror's class. + 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.type; + +/** + * Thrown when an application attempts to access the + * {@link Class} object corresponding to a {@link TypeMirror}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.element.Element#getAnnotation(Class) + */ +public class MirroredTypeException + extends RuntimeException +{ + + private static final long serialVersionUID = 269L; + + /** + * The type mirror. + */ + private TypeMirror mirror; + + /** + * Constructs a new {@code MirroredTypeException} + * for the specified type. + * + * @param mirror the mirrored type accessed. May be + * {@code null}. + */ + public MirroredTypeException(TypeMirror mirror) + { + this.mirror = mirror; + } + + /** + * Returns the type mirror or {@code null} + * if unavailable. The type mirror may be {@code null} if + * the type mirror is not {@link java.io.Serializable} but the + * exception has been serialized and read back in. + * + * @return the type mirror. + */ + public TypeMirror getTypeMirror() + { + return mirror; + } + + +} diff --git a/javax/lang/model/type/MirroredTypesException.java b/javax/lang/model/type/MirroredTypesException.java new file mode 100644 index 000000000..2014b6d0c --- /dev/null +++ b/javax/lang/model/type/MirroredTypesException.java @@ -0,0 +1,87 @@ +/* MirroredTypesException.java -- An attempt to access a series of TypeMirror classes. + 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.type; + +import java.util.List; + +/** + * Thrown when an application attempts to access a sequence of + * {@link Class} objects, each corresponding to a {@link TypeMirror}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.element.Element#getAnnotation(Class) + */ +public class MirroredTypesException + extends RuntimeException +{ + + private static final long serialVersionUID = 269L; + + /** + * The type mirrors. + */ + private List<? extends TypeMirror> mirrors; + + /** + * Constructs a new {@code MirroredTypesException} + * for the specified types. + * + * @param mirrors the mirrored types accessed. May be + * {@code null}. + */ + public MirroredTypesException(List<? extends TypeMirror> mirrors) + { + this.mirrors = mirrors; + } + + /** + * Returns the type mirrors or {@code null} + * if unavailable. The list may be {@code null} if + * the type mirrors are not {@link java.io.Serializable} but the + * exception has been serialized and read back in. + * + * @return the type mirrors. + */ + public List<? extends TypeMirror> getTypeMirrors() + { + return mirrors; + } + + +} diff --git a/javax/lang/model/type/NoType.java b/javax/lang/model/type/NoType.java new file mode 100644 index 000000000..7cccc436a --- /dev/null +++ b/javax/lang/model/type/NoType.java @@ -0,0 +1,60 @@ +/* NoType.java -- Represents a pseudo-type used when nothing is appropriate. + 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.type; + +/** + * <p>Represents a pseudo-type used when a {@link TypeMirror} + * needs to be returned, but there is not one suitable.</p> + * <p>Further information is provided by the kind of the + * instance, as follows:</p> + * <ul> + * <li>{@link TypeKind#VOID}; used for method return types.</li> + * <li>{@link TypeKind#PACKAGE}; used for packages.</li> + * <li>{@link TypeKind#NONE}: used when nothing else fits. + * For example, requesting a superclass from + * {@code java.lang.Object}.</li> + * </ul> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see javax.lang.model.element.ExecutableElement#getReturnType() + */ +public interface NoType + extends TypeMirror +{ +} diff --git a/javax/lang/model/type/NullType.java b/javax/lang/model/type/NullType.java new file mode 100644 index 000000000..53f9819bd --- /dev/null +++ b/javax/lang/model/type/NullType.java @@ -0,0 +1,50 @@ +/* NullType.java -- Represents the null type. + 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.type; + +/** + * Represents the null type i.e. the type of the expression + * {@code null}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface NullType + extends ReferenceType +{ +} diff --git a/javax/lang/model/type/PrimitiveType.java b/javax/lang/model/type/PrimitiveType.java new file mode 100644 index 000000000..6586079df --- /dev/null +++ b/javax/lang/model/type/PrimitiveType.java @@ -0,0 +1,52 @@ +/* PrimitiveType.java -- Represents a primitive type. + 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.type; + +/** + * Represents a primitive type such as a {@code byte}, + * {@code boolean}, {@code char}, {@code double}, + * {@code float}, {@code int}, {@code long} or + * {@code short}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface PrimitiveType + extends TypeMirror +{ +} diff --git a/javax/lang/model/type/ReferenceType.java b/javax/lang/model/type/ReferenceType.java new file mode 100644 index 000000000..174104ee9 --- /dev/null +++ b/javax/lang/model/type/ReferenceType.java @@ -0,0 +1,51 @@ +/* ReferenceType.java -- Represents a type referred to by reference. + 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.type; + +/** + * Represents a type referred to by reference. This + * includes array types, class and interface types, + * type variables and the null type. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface ReferenceType + extends TypeMirror +{ +} diff --git a/javax/lang/model/type/TypeKind.java b/javax/lang/model/type/TypeKind.java new file mode 100644 index 000000000..37d2c9d5d --- /dev/null +++ b/javax/lang/model/type/TypeKind.java @@ -0,0 +1,112 @@ +/* TypeKind.java -- Represents the kind of a type. + 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.type; + +/** + * Represents the kind of a type mirror, such as a boolean or + * a declared type. This enumeration may be extended with + * further kinds to represent future versions of the language. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public enum TypeKind +{ + /** An array type. */ + ARRAY, + /** The primitive type boolean */ + BOOLEAN, + /** The primitive type byte */ + BYTE, + /** The primitive type char */ + CHAR, + /** A class or interface type */ + DECLARED, + /** The primitive type double */ + DOUBLE, + /** An unresolvable type */ + ERROR, + /** A method, constructor or initialiser */ + EXECUTABLE, + /** The primitive type float */ + FLOAT, + /** The primitive type int */ + INT, + /** The primitive type long */ + LONG, + /** A pseudo-type used when nothing else is appropriate */ + NONE, + /** The null type */ + NULL, + /** An implementation-reserved type */ + OTHER, + /** A psuedo-type used for packages */ + PACKAGE, + /** The primitive type short */ + SHORT, + /** A type variable */ + TYPEVAR, + /** A psuedo-type used for the void return type. */ + VOID, + /** A wildcard type argument. */ + WILDCARD; + + /** + * Returns true if this is a primitive type. + * + * @return true if this is a primitive type. + */ + public boolean isPrimitive() + { + switch (this) + { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + return true; + default: + return false; + } + } + +} diff --git a/javax/lang/model/type/TypeMirror.java b/javax/lang/model/type/TypeMirror.java new file mode 100644 index 000000000..1c8397b94 --- /dev/null +++ b/javax/lang/model/type/TypeMirror.java @@ -0,0 +1,112 @@ +/* TypeMirror.java -- Represents a realised type. + 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.type; + +/** + * <p> + * Represents a realised type in the Java programming language. For example, + * a {@code TypeMirror} may represent a primitive type, a declared type + * (classes and interfaces), an array type, a type variable or the + * {@code null} type. To complete the possible types, wildcard types + * are represented as is a pseudo-type to represent packages and + * {@code void}, and the signature and return types of executables + * (constructors, methods and initialisers). + * </p> + * <p>To compare two instances, use the utility methods in + * {@link javax.lang.model.util.Types} as there + * is no guarantee that == will hold. To determine the subtype of + * {@code TypeMirror}, use {@link #getKind()} or a visitor, as + * implementations may use the same class to implement multiple + * subinterfaces.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface TypeMirror +{ + + /** + * Applies a visitor to this type. + * + * @param <R> the return type of the visitor's methods. + * @param <P> the type of the additional parameter used in the visitor's + * methods. + * @param visitor the visitor to apply to the element. + * @param param the additional parameter to be sent to the visitor. + * @return the return value from the visitor. + */ + <R,P> R accept(TypeVisitor<R,P> visitor, P param); + + /** + * Obeys the general contract specified by {@link #equals(Object)} + * but does not indicate that two types represent the same type. + * For this, {@link javax.lang.model.Types#isSameType(TypeMirror, + * TypeMirror)} should be used and the result of this method and + * that method may differ. + * + * @param obj the object to compare. + * @return {@code true} if {@code this} and {@code obj} are equal. + */ + boolean equals(Object obj); + + /** + * Returns the kind of this element. + * + * @return the kind of element. + */ + TypeKind getKind(); + + /** + * Obeys the general contract of {@link java.lang.Object#hashCode()}. + * + * @return a hash code for this element. + * @see #equals(Object) + */ + int hashCode(); + + /** + * Returns an informative representation of the type. If possible, + * the form used should be the same as that used if the type was + * to be represented in source code. Any type names embedded in the + * result should be qualified where possible. + * + * @return a textual representation of the type. + */ + String toString(); + +} diff --git a/javax/lang/model/type/TypeVariable.java b/javax/lang/model/type/TypeVariable.java new file mode 100644 index 000000000..87b308780 --- /dev/null +++ b/javax/lang/model/type/TypeVariable.java @@ -0,0 +1,87 @@ +/* TypeVariable.java -- Represents a type variable. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.lang.model.type; + +import javax.lang.model.element.Element; + +/** + * Represents a type variable. Such variables may be the + * result of an explicitly declared type parameter on + * a type, method or constructor, or be created implicitly + * as a function of capture conversion on a wildcard type + * argument. See chapter 5 of the Java Language Specification. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface TypeVariable + extends ReferenceType +{ + + /** + * Returns the element which corresponds to this type variable. + * + * @return the element corresponding to this type variable. + */ + Element asElement(); + + /** + * Returns the lower bound of this type variable. While type + * variables can not be given an explicit lower bound, a + * non-trivial lower bound may be produced through capture + * conversion on a wildcard type argument. If this is not the + * case, the lower bound will be the {@link NullType}. + * + * @return the lower bound of this type variable. + */ + TypeMirror getLowerBound(); + + /** + * Returns the upper bound of this type variable. If an + * explicit upper bound was not given, this will return + * {@code java.lang.Object}. Where multiple upper bounds + * are specified, an intersection type is generated and + * represented as an instance of {@link DeclaredType}. + * The supertypes of this may be examined to find the + * actual bounds specified. + * + * @return the upper bound of this type variable. + */ + TypeMirror getUpperBound(); + +} diff --git a/javax/lang/model/type/TypeVisitor.java b/javax/lang/model/type/TypeVisitor.java new file mode 100644 index 000000000..3d2a327da --- /dev/null +++ b/javax/lang/model/type/TypeVisitor.java @@ -0,0 +1,188 @@ +/* TypeVisitor.java -- A visitor of 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.type; + +/** + * <p>A visitor for types. This is used when the specific + * type is not known at compile time. A visitor instance + * is passed to the {@link TypeMirror#accept(TypeVisitor,P)} method of + * the type, which then calls the specific {@code visitN} method + * appropriate to that specific type.</p> + * <p>The additional parameter supplied to visitor methods may or + * may not be optional, and so the class is free to throw a + * {@code NullPointerException} if {@code null} is passed as the + * additional parameter.</p> + * <p>As this interface may be extended to accomodate future language + * versions, implementators are encouraged to extend one of the + * appropriate abstract classes rather than implementating this + * interface. However, this interface should be used as the type + * for parameters and return values.</p> + * + * @param <R> the return type of the visitor's methods. {@code Void} + * can be used where there is no return value. + * @param <P> the type of the additional parameter supplied to the visitor's + * methods. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface TypeVisitor<R,P> +{ + + /** + * A convenience method for use when there is no additional + * parameter to pass. This is equivalent to {@code #visit(type, null)}. + * + * @param type the type to visit. + * @return the return value specific to the visitor. + */ + R visit(TypeMirror type); + + /** + * Visits a type. + * + * @param type the type to visit. + * @param param the additional parameter, specific to the visitor. + * May be {@code null} if permitted by the visitor. + */ + R visit(TypeMirror type, P param); + + /** + * Visits an unknown type. This method is called if + * a new type is added to the hierarchy which isn't yet + * handled by the visitor. + * + * @param type the 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. + * @throws UnknownTypeException if the implementation chooses to. + */ + R visitUnknown(TypeMirror type, P param); + + /** + * Visits a declared type. + * + * @param type the 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. + */ + R visitDeclared(DeclaredType type, P param); + + /** + * Visits an array type. + * + * @param type the array 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. + */ + R visitArray(ArrayType type, P param); + + /** + * Visits an error type. + * + * @param type the error 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. + */ + R visitError(ErrorType type, P param); + + /** + * Visits an executable type. + * + * @param type the executable 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. + */ + R visitExecutable(ExecutableType type, P param); + + /** + * Visits a {@link NoType} instance. + * + * @param type the instance 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 visitNoType(NoType type, P param); + + /** + * Visits the null type. + * + * @param type the 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. + */ + R visitNull(NullType type, P param); + + /** + * Visits a primitive type. + * + * @param type the primitive 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. + */ + R visitPrimitive(PrimitiveType type, P param); + + /** + * Visits a type variable. + * + * @param type the type variable 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 visitTypeVariable(TypeVariable type, P param); + + /** + * Visits a wildcard type. + * + * @param type the wildcard 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. + */ + R visitWildcard(WildcardType type, P param); + +} diff --git a/javax/lang/model/type/UnknownTypeException.java b/javax/lang/model/type/UnknownTypeException.java new file mode 100644 index 000000000..063e3a750 --- /dev/null +++ b/javax/lang/model/type/UnknownTypeException.java @@ -0,0 +1,105 @@ +/* UnknownTypeException.java -- Thrown by an unknown type. + 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.type; + +/** + * Thrown when an unknown type is encountered, + * usually by a {@link TypeVisitor}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + * @see TypeVisitor#visitUnknown(TypeMirror,P) + */ +public class UnknownTypeException + extends RuntimeException +{ + + private static final long serialVersionUID = 269L; + + /** + * The unknown type. + */ + private TypeMirror type; + + /** + * The additional parameter. + */ + private Object param; + + /** + * Constructs a new {@code UnknownTypeException} + * for the specified type. An additional + * object may also be passed to give further context as + * to where the exception occurred, such as the additional parameter + * used by visitor classes. + * + * @param type the unknown type or {@code null}. + * @param param the additional parameter or {@code null}. + */ + public UnknownTypeException(TypeMirror type, Object param) + { + this.type = type; + this.param = param; + } + + /** + * Returns the additional parameter or {@code null} if + * unavailable. + * + * @return the additional parameter. + */ + public Object getArgument() + { + return param; + } + + /** + * Returns the unknown type or {@code null} + * if unavailable. The type may be {@code null} if + * the value is not {@link java.io.Serializable} but the + * exception has been serialized and read back in. + * + * @return the unknown type. + */ + public TypeMirror getUnknownType() + { + return type; + } + + +} diff --git a/javax/lang/model/type/WildcardType.java b/javax/lang/model/type/WildcardType.java new file mode 100644 index 000000000..20dfd827a --- /dev/null +++ b/javax/lang/model/type/WildcardType.java @@ -0,0 +1,79 @@ +/* WildcardType.java -- Represents a wildcard type argument. + 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.type; + +import javax.lang.model.element.Element; + +/** + * <p>Represents a wildcard type argument, which may take one + * of three forms:</p> + * <ul> + * <li>{@code ?}</li> + * <li>{@code ? extends X}</li> + * <li>{@code ? super Y}</li> + * </ul> + * <p>i.e. it may have no bounds, an upper bound set by + * the {@code extends} clause or a lower bound set by + * the {@code super} clause, but not both.</p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +public interface WildcardType + extends TypeMirror +{ + + /** + * Returns the upper bound of this wildcard type, + * as declared by the {@code extends} clause, or + * {@code null} if one wasn't specified. + * + * @return the upper bound. + */ + TypeMirror getExtendsBound(); + + /** + * Returns the lower bound of this wildcard type, + * as declared by the {@code super} clause, or + * {@code null} if one wasn't specified. + * + * @return the upper bound. + */ + TypeMirror getSuperBound(); + +} |