jdk/src/share/classes/java/lang/reflect/Constructor.java
author jjh
Wed, 13 Apr 2011 12:16:13 -0700
changeset 9266 121fb370f179
parent 9029 e92fcf58f684
child 10127 c85d1ec57ee7
permissions -rw-r--r--
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks 7032965: API files in java.io need to updated for references to JVM Spec with editions/hyperlinks 7032958: API files in java.lang need to updated for references to JLS with editions/hyperlinks 7032961: API files in java.lang need to updated for references to JVM with editions/hyperlinks 7032976: API files in javax.lang need to be updated for references to JLS with editions/hyperlinks 7032959: API files in java.util need to updated for references to JLS with editions/hyperlinks 7032962: API files in java.util need to updated for references to JVM Spec with editions/hyperlinks 7032967: API files in java.security need to updated for references to JVM Spec with editions/hyperlinks 7032955: API files in java.math need to updated for references to JLS with editions/hyperlinks Summary: Removed URLs and 'edition' references Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6534
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.reflect.ConstructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.reflect.Reflection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.reflect.generics.repository.ConstructorRepository;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.reflect.generics.factory.CoreReflectionFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.reflect.generics.factory.GenericsFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.reflect.generics.scope.ConstructorScope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.reflect.annotation.AnnotationParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.annotation.AnnotationFormatError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.Modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * {@code Constructor} provides information about, and access to, a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * constructor for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>{@code Constructor} permits widening conversions to occur when matching the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * actual parameters to newInstance() with the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * constructor's formal parameters, but throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * {@code IllegalArgumentException} if a narrowing conversion would occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @param <T> the class in which the constructor is declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see Member
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see java.lang.Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see java.lang.Class#getConstructors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see java.lang.Class#getConstructor(Class[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see java.lang.Class#getDeclaredConstructors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author      Kenneth Russell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author      Nakul Saraiya
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    class Constructor<T> extends AccessibleObject implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                                    GenericDeclaration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                                    Member {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private Class<T>            clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private int                 slot;
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
    67
    private Class<?>[]          parameterTypes;
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
    68
    private Class<?>[]          exceptionTypes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int                 modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // Generics and annotations support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private transient String    signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // generic info repository; lazily initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private transient ConstructorRepository genericInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private byte[]              annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private byte[]              parameterAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Generics infrastructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // Accessor for factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private GenericsFactory getFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // create scope and factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return CoreReflectionFactory.make(this, ConstructorScope.make(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Accessor for generic info repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private ConstructorRepository getGenericInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // lazily initialize repository if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (genericInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            // create and cache generic info repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            genericInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                ConstructorRepository.make(getSignature(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                           getFactory());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return genericInfo; //return cached repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private volatile ConstructorAccessor constructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // For sharing of ConstructorAccessors. This branching structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // is currently only two levels deep (i.e., one root Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // and potentially many Constructor objects pointing to it.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Constructor<T>      root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Package-private constructor used by ReflectAccess to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * instantiation of these objects in Java code from the java.lang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * package via sun.reflect.LangReflectAccess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    Constructor(Class<T> declaringClass,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   108
                Class<?>[] parameterTypes,
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   109
                Class<?>[] checkedExceptions,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                byte[] annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                byte[] parameterAnnotations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.clazz = declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this.parameterTypes = parameterTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.exceptionTypes = checkedExceptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.slot = slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.annotations = annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.parameterAnnotations = parameterAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Package-private routine (exposed to java.lang.Class via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * ReflectAccess) which returns a copy of this Constructor. The copy's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * "root" field points to this Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    Constructor<T> copy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // This routine enables sharing of ConstructorAccessor objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // among Constructor objects which refer to the same underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // method in the VM. (All of this contortion is only necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // because of the "accessibility" bit in AccessibleObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // which implicitly requires that new java.lang.reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // objects be fabricated for each reflective call on Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // objects.)
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 6534
diff changeset
   139
        Constructor<T> res = new Constructor<>(clazz,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                                parameterTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                                exceptionTypes, modifiers, slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                                signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                                annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                                parameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        res.root = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // Might as well eagerly propagate this if already present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        res.constructorAccessor = constructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Returns the {@code Class} object representing the class that declares
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * the constructor represented by this {@code Constructor} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public Class<T> getDeclaringClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Returns the name of this constructor, as a string.  This is
6534
ad71f5af4022 6294399: (reflect) Constructor.getName() returns fully qualified name of declaring class
darcy
parents: 5506
diff changeset
   161
     * the binary name of the constructor's declaring class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return getDeclaringClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Returns the Java language modifiers for the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * represented by this {@code Constructor} object, as an integer. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * {@code Modifier} class should be used to decode the modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see Modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Returns an array of {@code TypeVariable} objects that represent the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * type variables declared by the generic declaration represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * {@code GenericDeclaration} object, in declaration order.  Returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * array of length 0 if the underlying generic declaration declares no type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return an array of {@code TypeVariable} objects that represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *     the type variables declared by this generic declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @throws GenericSignatureFormatError if the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *     signature of this generic declaration does not conform to
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   189
     *     the format specified in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   190
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public TypeVariable<Constructor<T>>[] getTypeParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      if (getSignature() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
          return (TypeVariable<Constructor<T>>[])new TypeVariable[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns an array of {@code Class} objects that represent the formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * parameter types, in declaration order, of the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * represented by this {@code Constructor} object.  Returns an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * length 0 if the underlying constructor takes no parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @return the parameter types for the constructor this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public Class<?>[] getParameterTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return (Class<?>[]) parameterTypes.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns an array of {@code Type} objects that represent the formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * parameter types, in declaration order, of the method represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * this {@code Constructor} object. Returns an array of length 0 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * underlying method takes no parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <p>If a formal parameter type is a parameterized type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * the {@code Type} object returned for it must accurately reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * the actual type parameters used in the source code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>If a formal parameter type is a type variable or a parameterized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * type, it is created. Otherwise, it is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return an array of {@code Type}s that represent the formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *     parameter types of the underlying method, in declaration order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @throws GenericSignatureFormatError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *     if the generic method signature does not conform to the format
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   232
     *     specified in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   233
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws TypeNotPresentException if any of the parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *     types of the underlying method refers to a non-existent type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *     declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @throws MalformedParameterizedTypeException if any of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *     the underlying method's parameter types refer to a parameterized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *     type that cannot be instantiated for any reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public Type[] getGenericParameterTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (getSignature() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return getGenericInfo().getParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return getParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns an array of {@code Class} objects that represent the types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * of exceptions declared to be thrown by the underlying constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * represented by this {@code Constructor} object.  Returns an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * length 0 if the constructor declares no exceptions in its {@code throws} clause.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the exception types declared as being thrown by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * constructor this object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public Class<?>[] getExceptionTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return (Class<?>[])exceptionTypes.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Returns an array of {@code Type} objects that represent the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * exceptions declared to be thrown by this {@code Constructor} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Returns an array of length 0 if the underlying method declares
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * no exceptions in its {@code throws} clause.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <p>If an exception type is a type variable or a parameterized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * type, it is created. Otherwise, it is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @return an array of Types that represent the exception types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *     thrown by the underlying method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @throws GenericSignatureFormatError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *     if the generic method signature does not conform to the format
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   277
     *     specified in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   278
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @throws TypeNotPresentException if the underlying method's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *     {@code throws} clause refers to a non-existent type declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws MalformedParameterizedTypeException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *     the underlying method's {@code throws} clause refers to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *     parameterized type that cannot be instantiated for any reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      public Type[] getGenericExceptionTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
          Type[] result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
          if (getSignature() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
              ( (result = getGenericInfo().getExceptionTypes()).length > 0  ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
              return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
          else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
              return getExceptionTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Compares this {@code Constructor} against the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns true if the objects are the same.  Two {@code Constructor} objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * the same if they were declared by the same class and have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * same formal parameter types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (obj != null && obj instanceof Constructor) {
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   303
            Constructor<?> other = (Constructor<?>)obj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (getDeclaringClass() == other.getDeclaringClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                /* Avoid unnecessary cloning */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   306
                Class<?>[] params1 = parameterTypes;
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   307
                Class<?>[] params2 = other.parameterTypes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                if (params1.length == params2.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    for (int i = 0; i < params1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                        if (params1[i] != params2[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Returns a hashcode for this {@code Constructor}. The hashcode is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * the same as the hashcode for the underlying constructor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * declaring class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return getDeclaringClass().getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Returns a string describing this {@code Constructor}.  The string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * formatted as the constructor access modifiers, if any,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * followed by the fully-qualified name of the declaring class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * followed by a parenthesized, comma-separated list of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * constructor's formal parameter types.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *    public java.util.Hashtable(int,float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <p>The only possible modifiers for constructors are the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * modifiers {@code public}, {@code protected} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * {@code private}.  Only one of these may appear, or none if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * constructor has default (package) access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            StringBuffer sb = new StringBuffer();
3712
8851d55adef0 6261502: (reflect) Add the functionality to screen out the "inappropriate" modifier bits
darcy
parents: 2174
diff changeset
   347
            int mod = getModifiers() & Modifier.constructorModifiers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (mod != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                sb.append(Modifier.toString(mod) + " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            sb.append(Field.getTypeName(getDeclaringClass()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            sb.append("(");
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   353
            Class<?>[] params = parameterTypes; // avoid clone
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            for (int j = 0; j < params.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                sb.append(Field.getTypeName(params[j]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                if (j < (params.length - 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            sb.append(")");
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   360
            Class<?>[] exceptions = exceptionTypes; // avoid clone
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (exceptions.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                sb.append(" throws ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                for (int k = 0; k < exceptions.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    sb.append(exceptions[k].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    if (k < (exceptions.length - 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                        sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return "<" + e + ">";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Returns a string describing this {@code Constructor},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * including type parameters.  The string is formatted as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * constructor access modifiers, if any, followed by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * angle-bracketed comma separated list of the constructor's type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * parameters, if any, followed by the fully-qualified name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * declaring class, followed by a parenthesized, comma-separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * list of the constructor's generic formal parameter types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * If this constructor was declared to take a variable number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * arguments, instead of denoting the last parameter as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * "<tt><i>Type</i>[]</tt>", it is denoted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * "<tt><i>Type</i>...</tt>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * A space is used to separate access modifiers from one another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * and from the type parameters or return type.  If there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * type parameters, the type parameter list is elided; if the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * parameter list is present, a space separates the list from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * class name.  If the constructor is declared to throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * exceptions, the parameter list is followed by a space, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * by the word "{@code throws}" followed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * comma-separated list of the thrown exception types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <p>The only possible modifiers for constructors are the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * modifiers {@code public}, {@code protected} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * {@code private}.  Only one of these may appear, or none if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * constructor has default (package) access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return a string describing this {@code Constructor},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * include type parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public String toGenericString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            StringBuilder sb = new StringBuilder();
3712
8851d55adef0 6261502: (reflect) Add the functionality to screen out the "inappropriate" modifier bits
darcy
parents: 2174
diff changeset
   411
            int mod = getModifiers() & Modifier.constructorModifiers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (mod != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                sb.append(Modifier.toString(mod) + " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            TypeVariable<?>[] typeparms = getTypeParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (typeparms.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                sb.append("<");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                for(TypeVariable<?> typeparm: typeparms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    if (!first)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    // Class objects can't occur here; no need to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    // and call Class.getName().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    sb.append(typeparm.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                sb.append("> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            sb.append(Field.getTypeName(getDeclaringClass()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            sb.append("(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            Type[] params = getGenericParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            for (int j = 0; j < params.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                String param = (params[j] instanceof Class<?>)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    Field.getTypeName((Class<?>)params[j]):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    (params[j].toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    param = param.replaceFirst("\\[\\]$", "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                sb.append(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                if (j < (params.length - 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            sb.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            Type[] exceptions = getGenericExceptionTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (exceptions.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                sb.append(" throws ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                for (int k = 0; k < exceptions.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    sb.append((exceptions[k] instanceof Class)?
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   448
                              ((Class<?>)exceptions[k]).getName():
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                              exceptions[k].toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    if (k < (exceptions.length - 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            return "<" + e + ">";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Uses the constructor represented by this {@code Constructor} object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * create and initialize a new instance of the constructor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * declaring class, with the specified initialization parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Individual parameters are automatically unwrapped to match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * primitive formal parameters, and both primitive and reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * parameters are subject to method invocation conversions as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * <p>If the number of formal parameters required by the underlying constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * is 0, the supplied {@code initargs} array may be of length 0 or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * <p>If the constructor's declaring class is an inner class in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * non-static context, the first argument to the constructor needs
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   473
     * to be the enclosing instance; see section 15.9.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   474
     * <cite>The Java&trade; Language Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <p>If the required access and argument checks succeed and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * instantiation will proceed, the constructor's declaring class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * is initialized if it has not already been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <p>If the constructor completes normally, returns the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * created and initialized instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param initargs array of objects to be passed as arguments to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * the constructor call; values of primitive types are wrapped in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * a wrapper object of the appropriate type (e.g. a {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * in a {@link java.lang.Float Float})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @return a new object created by calling the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * this object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @exception IllegalAccessException    if this {@code Constructor} object
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 7816
diff changeset
   492
     *              is enforcing Java language access control and the underlying
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *              constructor is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @exception IllegalArgumentException  if the number of actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *              and formal parameters differ; if an unwrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *              conversion for primitive arguments fails; or if,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *              after possible unwrapping, a parameter value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *              cannot be converted to the corresponding formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *              parameter type by a method invocation conversion; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *              this constructor pertains to an enum type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @exception InstantiationException    if the class that declares the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *              underlying constructor represents an abstract class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @exception InvocationTargetException if the underlying constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *              throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    public T newInstance(Object ... initargs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        throws InstantiationException, IllegalAccessException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
               IllegalArgumentException, InvocationTargetException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (!override) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   514
                Class<?> caller = Reflection.getCallerClass(2);
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   515
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   516
                checkAccess(caller, clazz, null, modifiers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if ((clazz.getModifiers() & Modifier.ENUM) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            throw new IllegalArgumentException("Cannot reflectively create enum objects");
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   521
        ConstructorAccessor ca = constructorAccessor;   // read volatile
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   522
        if (ca == null) {
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   523
            ca = acquireConstructorAccessor();
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   524
        }
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   525
        return (T) ca.newInstance(initargs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Returns {@code true} if this constructor was declared to take
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * a variable number of arguments; returns {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @return {@code true} if an only if this constructor was declared to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * take a variable number of arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public boolean isVarArgs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        return (getModifiers() & Modifier.VARARGS) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Returns {@code true} if this constructor is a synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * constructor; returns {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @return true if and only if this constructor is a synthetic
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   546
     * constructor as defined by
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   547
     * <cite>The Java&trade; Language Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public boolean isSynthetic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return Modifier.isSynthetic(getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    // NOTE that there is no synchronization used here. It is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    // (though not efficient) to generate more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    // ConstructorAccessor for a given Constructor. However, avoiding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    // synchronization will probably make the implementation more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    // scalable.
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   559
    private ConstructorAccessor acquireConstructorAccessor() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // First check to see if one has been created yet, and take it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // if so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        ConstructorAccessor tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (root != null) tmp = root.getConstructorAccessor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (tmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            constructorAccessor = tmp;
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   566
        } else {
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   567
            // Otherwise fabricate one and propagate it up to the root
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   568
            tmp = reflectionFactory.newConstructorAccessor(this);
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   569
            setConstructorAccessor(tmp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   571
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   572
        return tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    // Returns ConstructorAccessor for this Constructor object, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    // looking up the chain to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    ConstructorAccessor getConstructorAccessor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return constructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    // Sets the ConstructorAccessor for this Constructor object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    // (recursively) its root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    void setConstructorAccessor(ConstructorAccessor accessor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        constructorAccessor = accessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        // Propagate up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            root.setConstructorAccessor(accessor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    int getSlot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
   String getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    byte[] getRawAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        return annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    byte[] getRawParameterAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        return parameterAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (annotationClass == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        return (T) declaredAnnotations().get(annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public Annotation[] getDeclaredAnnotations()  {
2174
0ffce164e4a4 6799230: Lazily load java.lang.annotation.Annotation class
mchung
parents: 2
diff changeset
   622
        return AnnotationParser.toArray(declaredAnnotations());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   625
    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   627
    private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (declaredAnnotations == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            declaredAnnotations = AnnotationParser.parseAnnotations(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                annotations, sun.misc.SharedSecrets.getJavaLangAccess().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                getConstantPool(getDeclaringClass()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        return declaredAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * Returns an array of arrays that represent the annotations on the formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * parameters, in declaration order, of the method represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * this {@code Constructor} object. (Returns an array of length zero if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * underlying method is parameterless.  If the method has one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * parameters, a nested array of length zero is returned for each parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * with no annotations.) The annotation objects contained in the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * arrays are serializable.  The caller of this method is free to modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * the returned arrays; it will have no effect on the arrays returned to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * other callers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @return an array of arrays that represent the annotations on the formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *    parameters, in declaration order, of the method represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *    Constructor object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    public Annotation[][] getParameterAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        int numParameters = parameterTypes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (parameterAnnotations == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            return new Annotation[numParameters][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        Annotation[][] result = AnnotationParser.parseParameterAnnotations(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            parameterAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            sun.misc.SharedSecrets.getJavaLangAccess().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                getConstantPool(getDeclaringClass()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if (result.length != numParameters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            Class<?> declaringClass = getDeclaringClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (declaringClass.isEnum() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                declaringClass.isAnonymousClass() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                declaringClass.isLocalClass() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                ; // Can't do reliable parameter counting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                if (!declaringClass.isMemberClass() || // top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    // Check for the enclosing instance parameter for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    // non-static member classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    (declaringClass.isMemberClass() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                     ((declaringClass.getModifiers() & Modifier.STATIC) == 0)  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                     result.length + 1 != numParameters) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    throw new AnnotationFormatError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                              "Parameter annotations don't match number of parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
}