rt/emul/mini/src/main/java/java/lang/reflect/Constructor.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 604 emul/mini/src/main/java/java/lang/reflect/Constructor.java@3fcc279c921b
child 1321 7a78a84ab583
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
jaroslav@601
     1
/*
jaroslav@601
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
jaroslav@601
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@601
     4
 *
jaroslav@601
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@601
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@601
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@601
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@601
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@601
    10
 *
jaroslav@601
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@601
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@601
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@601
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@601
    15
 * accompanied this code).
jaroslav@601
    16
 *
jaroslav@601
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@601
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@601
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@601
    20
 *
jaroslav@601
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@601
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@601
    23
 * questions.
jaroslav@601
    24
 */
jaroslav@601
    25
jaroslav@601
    26
package java.lang.reflect;
jaroslav@601
    27
jaroslav@601
    28
import java.lang.annotation.Annotation;
jaroslav@604
    29
import org.apidesign.bck2brwsr.emul.reflect.TypeProvider;
jaroslav@601
    30
jaroslav@601
    31
/**
jaroslav@601
    32
 * {@code Constructor} provides information about, and access to, a single
jaroslav@601
    33
 * constructor for a class.
jaroslav@601
    34
 *
jaroslav@601
    35
 * <p>{@code Constructor} permits widening conversions to occur when matching the
jaroslav@601
    36
 * actual parameters to newInstance() with the underlying
jaroslav@601
    37
 * constructor's formal parameters, but throws an
jaroslav@601
    38
 * {@code IllegalArgumentException} if a narrowing conversion would occur.
jaroslav@601
    39
 *
jaroslav@601
    40
 * @param <T> the class in which the constructor is declared
jaroslav@601
    41
 *
jaroslav@601
    42
 * @see Member
jaroslav@601
    43
 * @see java.lang.Class
jaroslav@601
    44
 * @see java.lang.Class#getConstructors()
jaroslav@601
    45
 * @see java.lang.Class#getConstructor(Class[])
jaroslav@601
    46
 * @see java.lang.Class#getDeclaredConstructors()
jaroslav@601
    47
 *
jaroslav@601
    48
 * @author      Kenneth Russell
jaroslav@601
    49
 * @author      Nakul Saraiya
jaroslav@601
    50
 */
jaroslav@601
    51
public final
jaroslav@601
    52
    class Constructor<T> extends AccessibleObject implements
jaroslav@601
    53
                                                    GenericDeclaration,
jaroslav@601
    54
                                                    Member {
jaroslav@601
    55
jaroslav@601
    56
    private Class<T>            clazz;
jaroslav@601
    57
    private int                 slot;
jaroslav@601
    58
    private Class<?>[]          parameterTypes;
jaroslav@601
    59
    private Class<?>[]          exceptionTypes;
jaroslav@601
    60
    private int                 modifiers;
jaroslav@601
    61
    // Generics and annotations support
jaroslav@601
    62
    private transient String    signature;
jaroslav@601
    63
    private byte[]              annotations;
jaroslav@601
    64
    private byte[]              parameterAnnotations;
jaroslav@601
    65
jaroslav@601
    66
jaroslav@601
    67
    // For sharing of ConstructorAccessors. This branching structure
jaroslav@601
    68
    // is currently only two levels deep (i.e., one root Constructor
jaroslav@601
    69
    // and potentially many Constructor objects pointing to it.)
jaroslav@601
    70
    private Constructor<T>      root;
jaroslav@601
    71
jaroslav@601
    72
    /**
jaroslav@601
    73
     * Package-private constructor used by ReflectAccess to enable
jaroslav@601
    74
     * instantiation of these objects in Java code from the java.lang
jaroslav@601
    75
     * package via sun.reflect.LangReflectAccess.
jaroslav@601
    76
     */
jaroslav@601
    77
    Constructor(Class<T> declaringClass,
jaroslav@601
    78
                Class<?>[] parameterTypes,
jaroslav@601
    79
                Class<?>[] checkedExceptions,
jaroslav@601
    80
                int modifiers,
jaroslav@601
    81
                int slot,
jaroslav@601
    82
                String signature,
jaroslav@601
    83
                byte[] annotations,
jaroslav@601
    84
                byte[] parameterAnnotations)
jaroslav@601
    85
    {
jaroslav@601
    86
        this.clazz = declaringClass;
jaroslav@601
    87
        this.parameterTypes = parameterTypes;
jaroslav@601
    88
        this.exceptionTypes = checkedExceptions;
jaroslav@601
    89
        this.modifiers = modifiers;
jaroslav@601
    90
        this.slot = slot;
jaroslav@601
    91
        this.signature = signature;
jaroslav@601
    92
        this.annotations = annotations;
jaroslav@601
    93
        this.parameterAnnotations = parameterAnnotations;
jaroslav@601
    94
    }
jaroslav@601
    95
jaroslav@601
    96
    /**
jaroslav@601
    97
     * Package-private routine (exposed to java.lang.Class via
jaroslav@601
    98
     * ReflectAccess) which returns a copy of this Constructor. The copy's
jaroslav@601
    99
     * "root" field points to this Constructor.
jaroslav@601
   100
     */
jaroslav@601
   101
    Constructor<T> copy() {
jaroslav@604
   102
        return this;
jaroslav@601
   103
    }
jaroslav@601
   104
jaroslav@601
   105
    /**
jaroslav@601
   106
     * Returns the {@code Class} object representing the class that declares
jaroslav@601
   107
     * the constructor represented by this {@code Constructor} object.
jaroslav@601
   108
     */
jaroslav@601
   109
    public Class<T> getDeclaringClass() {
jaroslav@601
   110
        return clazz;
jaroslav@601
   111
    }
jaroslav@601
   112
jaroslav@601
   113
    /**
jaroslav@601
   114
     * Returns the name of this constructor, as a string.  This is
jaroslav@601
   115
     * the binary name of the constructor's declaring class.
jaroslav@601
   116
     */
jaroslav@601
   117
    public String getName() {
jaroslav@601
   118
        return getDeclaringClass().getName();
jaroslav@601
   119
    }
jaroslav@601
   120
jaroslav@601
   121
    /**
jaroslav@601
   122
     * Returns the Java language modifiers for the constructor
jaroslav@601
   123
     * represented by this {@code Constructor} object, as an integer. The
jaroslav@601
   124
     * {@code Modifier} class should be used to decode the modifiers.
jaroslav@601
   125
     *
jaroslav@601
   126
     * @see Modifier
jaroslav@601
   127
     */
jaroslav@601
   128
    public int getModifiers() {
jaroslav@601
   129
        return modifiers;
jaroslav@601
   130
    }
jaroslav@601
   131
jaroslav@601
   132
    /**
jaroslav@601
   133
     * Returns an array of {@code TypeVariable} objects that represent the
jaroslav@601
   134
     * type variables declared by the generic declaration represented by this
jaroslav@601
   135
     * {@code GenericDeclaration} object, in declaration order.  Returns an
jaroslav@601
   136
     * array of length 0 if the underlying generic declaration declares no type
jaroslav@601
   137
     * variables.
jaroslav@601
   138
     *
jaroslav@601
   139
     * @return an array of {@code TypeVariable} objects that represent
jaroslav@601
   140
     *     the type variables declared by this generic declaration
jaroslav@601
   141
     * @throws GenericSignatureFormatError if the generic
jaroslav@601
   142
     *     signature of this generic declaration does not conform to
jaroslav@601
   143
     *     the format specified in
jaroslav@601
   144
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
jaroslav@601
   145
     * @since 1.5
jaroslav@601
   146
     */
jaroslav@601
   147
    public TypeVariable<Constructor<T>>[] getTypeParameters() {
jaroslav@604
   148
        return TypeProvider.getDefault().getTypeParameters(this);
jaroslav@601
   149
    }
jaroslav@601
   150
jaroslav@601
   151
jaroslav@601
   152
    /**
jaroslav@601
   153
     * Returns an array of {@code Class} objects that represent the formal
jaroslav@601
   154
     * parameter types, in declaration order, of the constructor
jaroslav@601
   155
     * represented by this {@code Constructor} object.  Returns an array of
jaroslav@601
   156
     * length 0 if the underlying constructor takes no parameters.
jaroslav@601
   157
     *
jaroslav@601
   158
     * @return the parameter types for the constructor this object
jaroslav@601
   159
     * represents
jaroslav@601
   160
     */
jaroslav@601
   161
    public Class<?>[] getParameterTypes() {
jaroslav@601
   162
        return (Class<?>[]) parameterTypes.clone();
jaroslav@601
   163
    }
jaroslav@601
   164
jaroslav@601
   165
jaroslav@601
   166
    /**
jaroslav@601
   167
     * Returns an array of {@code Type} objects that represent the formal
jaroslav@601
   168
     * parameter types, in declaration order, of the method represented by
jaroslav@601
   169
     * this {@code Constructor} object. Returns an array of length 0 if the
jaroslav@601
   170
     * underlying method takes no parameters.
jaroslav@601
   171
     *
jaroslav@601
   172
     * <p>If a formal parameter type is a parameterized type,
jaroslav@601
   173
     * the {@code Type} object returned for it must accurately reflect
jaroslav@601
   174
     * the actual type parameters used in the source code.
jaroslav@601
   175
     *
jaroslav@601
   176
     * <p>If a formal parameter type is a type variable or a parameterized
jaroslav@601
   177
     * type, it is created. Otherwise, it is resolved.
jaroslav@601
   178
     *
jaroslav@601
   179
     * @return an array of {@code Type}s that represent the formal
jaroslav@601
   180
     *     parameter types of the underlying method, in declaration order
jaroslav@601
   181
     * @throws GenericSignatureFormatError
jaroslav@601
   182
     *     if the generic method signature does not conform to the format
jaroslav@601
   183
     *     specified in
jaroslav@601
   184
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
jaroslav@601
   185
     * @throws TypeNotPresentException if any of the parameter
jaroslav@601
   186
     *     types of the underlying method refers to a non-existent type
jaroslav@601
   187
     *     declaration
jaroslav@601
   188
     * @throws MalformedParameterizedTypeException if any of
jaroslav@601
   189
     *     the underlying method's parameter types refer to a parameterized
jaroslav@601
   190
     *     type that cannot be instantiated for any reason
jaroslav@601
   191
     * @since 1.5
jaroslav@601
   192
     */
jaroslav@601
   193
    public Type[] getGenericParameterTypes() {
jaroslav@604
   194
        return TypeProvider.getDefault().getGenericParameterTypes(this);
jaroslav@601
   195
    }
jaroslav@601
   196
jaroslav@601
   197
jaroslav@601
   198
    /**
jaroslav@601
   199
     * Returns an array of {@code Class} objects that represent the types
jaroslav@601
   200
     * of exceptions declared to be thrown by the underlying constructor
jaroslav@601
   201
     * represented by this {@code Constructor} object.  Returns an array of
jaroslav@601
   202
     * length 0 if the constructor declares no exceptions in its {@code throws} clause.
jaroslav@601
   203
     *
jaroslav@601
   204
     * @return the exception types declared as being thrown by the
jaroslav@601
   205
     * constructor this object represents
jaroslav@601
   206
     */
jaroslav@601
   207
    public Class<?>[] getExceptionTypes() {
jaroslav@601
   208
        return (Class<?>[])exceptionTypes.clone();
jaroslav@601
   209
    }
jaroslav@601
   210
jaroslav@601
   211
jaroslav@601
   212
    /**
jaroslav@601
   213
     * Returns an array of {@code Type} objects that represent the
jaroslav@601
   214
     * exceptions declared to be thrown by this {@code Constructor} object.
jaroslav@601
   215
     * Returns an array of length 0 if the underlying method declares
jaroslav@601
   216
     * no exceptions in its {@code throws} clause.
jaroslav@601
   217
     *
jaroslav@601
   218
     * <p>If an exception type is a type variable or a parameterized
jaroslav@601
   219
     * type, it is created. Otherwise, it is resolved.
jaroslav@601
   220
     *
jaroslav@601
   221
     * @return an array of Types that represent the exception types
jaroslav@601
   222
     *     thrown by the underlying method
jaroslav@601
   223
     * @throws GenericSignatureFormatError
jaroslav@601
   224
     *     if the generic method signature does not conform to the format
jaroslav@601
   225
     *     specified in
jaroslav@601
   226
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
jaroslav@601
   227
     * @throws TypeNotPresentException if the underlying method's
jaroslav@601
   228
     *     {@code throws} clause refers to a non-existent type declaration
jaroslav@601
   229
     * @throws MalformedParameterizedTypeException if
jaroslav@601
   230
     *     the underlying method's {@code throws} clause refers to a
jaroslav@601
   231
     *     parameterized type that cannot be instantiated for any reason
jaroslav@601
   232
     * @since 1.5
jaroslav@601
   233
     */
jaroslav@601
   234
      public Type[] getGenericExceptionTypes() {
jaroslav@604
   235
          return TypeProvider.getDefault().getGenericExceptionTypes(this);
jaroslav@601
   236
      }
jaroslav@601
   237
jaroslav@601
   238
    /**
jaroslav@601
   239
     * Compares this {@code Constructor} against the specified object.
jaroslav@601
   240
     * Returns true if the objects are the same.  Two {@code Constructor} objects are
jaroslav@601
   241
     * the same if they were declared by the same class and have the
jaroslav@601
   242
     * same formal parameter types.
jaroslav@601
   243
     */
jaroslav@601
   244
    public boolean equals(Object obj) {
jaroslav@601
   245
        if (obj != null && obj instanceof Constructor) {
jaroslav@601
   246
            Constructor<?> other = (Constructor<?>)obj;
jaroslav@601
   247
            if (getDeclaringClass() == other.getDeclaringClass()) {
jaroslav@601
   248
                /* Avoid unnecessary cloning */
jaroslav@601
   249
                Class<?>[] params1 = parameterTypes;
jaroslav@601
   250
                Class<?>[] params2 = other.parameterTypes;
jaroslav@601
   251
                if (params1.length == params2.length) {
jaroslav@601
   252
                    for (int i = 0; i < params1.length; i++) {
jaroslav@601
   253
                        if (params1[i] != params2[i])
jaroslav@601
   254
                            return false;
jaroslav@601
   255
                    }
jaroslav@601
   256
                    return true;
jaroslav@601
   257
                }
jaroslav@601
   258
            }
jaroslav@601
   259
        }
jaroslav@601
   260
        return false;
jaroslav@601
   261
    }
jaroslav@601
   262
jaroslav@601
   263
    /**
jaroslav@601
   264
     * Returns a hashcode for this {@code Constructor}. The hashcode is
jaroslav@601
   265
     * the same as the hashcode for the underlying constructor's
jaroslav@601
   266
     * declaring class name.
jaroslav@601
   267
     */
jaroslav@601
   268
    public int hashCode() {
jaroslav@601
   269
        return getDeclaringClass().getName().hashCode();
jaroslav@601
   270
    }
jaroslav@601
   271
jaroslav@601
   272
    /**
jaroslav@601
   273
     * Returns a string describing this {@code Constructor}.  The string is
jaroslav@601
   274
     * formatted as the constructor access modifiers, if any,
jaroslav@601
   275
     * followed by the fully-qualified name of the declaring class,
jaroslav@601
   276
     * followed by a parenthesized, comma-separated list of the
jaroslav@601
   277
     * constructor's formal parameter types.  For example:
jaroslav@601
   278
     * <pre>
jaroslav@601
   279
     *    public java.util.Hashtable(int,float)
jaroslav@601
   280
     * </pre>
jaroslav@601
   281
     *
jaroslav@601
   282
     * <p>The only possible modifiers for constructors are the access
jaroslav@601
   283
     * modifiers {@code public}, {@code protected} or
jaroslav@601
   284
     * {@code private}.  Only one of these may appear, or none if the
jaroslav@601
   285
     * constructor has default (package) access.
jaroslav@601
   286
     */
jaroslav@601
   287
    public String toString() {
jaroslav@601
   288
        try {
jaroslav@601
   289
            StringBuffer sb = new StringBuffer();
jaroslav@601
   290
            int mod = getModifiers() & Modifier.constructorModifiers();
jaroslav@601
   291
            if (mod != 0) {
jaroslav@601
   292
                sb.append(Modifier.toString(mod) + " ");
jaroslav@601
   293
            }
jaroslav@601
   294
            sb.append(Field.getTypeName(getDeclaringClass()));
jaroslav@601
   295
            sb.append("(");
jaroslav@601
   296
            Class<?>[] params = parameterTypes; // avoid clone
jaroslav@601
   297
            for (int j = 0; j < params.length; j++) {
jaroslav@601
   298
                sb.append(Field.getTypeName(params[j]));
jaroslav@601
   299
                if (j < (params.length - 1))
jaroslav@601
   300
                    sb.append(",");
jaroslav@601
   301
            }
jaroslav@601
   302
            sb.append(")");
jaroslav@601
   303
            Class<?>[] exceptions = exceptionTypes; // avoid clone
jaroslav@601
   304
            if (exceptions.length > 0) {
jaroslav@601
   305
                sb.append(" throws ");
jaroslav@601
   306
                for (int k = 0; k < exceptions.length; k++) {
jaroslav@601
   307
                    sb.append(exceptions[k].getName());
jaroslav@601
   308
                    if (k < (exceptions.length - 1))
jaroslav@601
   309
                        sb.append(",");
jaroslav@601
   310
                }
jaroslav@601
   311
            }
jaroslav@601
   312
            return sb.toString();
jaroslav@601
   313
        } catch (Exception e) {
jaroslav@601
   314
            return "<" + e + ">";
jaroslav@601
   315
        }
jaroslav@601
   316
    }
jaroslav@601
   317
jaroslav@601
   318
    /**
jaroslav@601
   319
     * Returns a string describing this {@code Constructor},
jaroslav@601
   320
     * including type parameters.  The string is formatted as the
jaroslav@601
   321
     * constructor access modifiers, if any, followed by an
jaroslav@601
   322
     * angle-bracketed comma separated list of the constructor's type
jaroslav@601
   323
     * parameters, if any, followed by the fully-qualified name of the
jaroslav@601
   324
     * declaring class, followed by a parenthesized, comma-separated
jaroslav@601
   325
     * list of the constructor's generic formal parameter types.
jaroslav@601
   326
     *
jaroslav@601
   327
     * If this constructor was declared to take a variable number of
jaroslav@601
   328
     * arguments, instead of denoting the last parameter as
jaroslav@601
   329
     * "<tt><i>Type</i>[]</tt>", it is denoted as
jaroslav@601
   330
     * "<tt><i>Type</i>...</tt>".
jaroslav@601
   331
     *
jaroslav@601
   332
     * A space is used to separate access modifiers from one another
jaroslav@601
   333
     * and from the type parameters or return type.  If there are no
jaroslav@601
   334
     * type parameters, the type parameter list is elided; if the type
jaroslav@601
   335
     * parameter list is present, a space separates the list from the
jaroslav@601
   336
     * class name.  If the constructor is declared to throw
jaroslav@601
   337
     * exceptions, the parameter list is followed by a space, followed
jaroslav@601
   338
     * by the word "{@code throws}" followed by a
jaroslav@601
   339
     * comma-separated list of the thrown exception types.
jaroslav@601
   340
     *
jaroslav@601
   341
     * <p>The only possible modifiers for constructors are the access
jaroslav@601
   342
     * modifiers {@code public}, {@code protected} or
jaroslav@601
   343
     * {@code private}.  Only one of these may appear, or none if the
jaroslav@601
   344
     * constructor has default (package) access.
jaroslav@601
   345
     *
jaroslav@601
   346
     * @return a string describing this {@code Constructor},
jaroslav@601
   347
     * include type parameters
jaroslav@601
   348
     *
jaroslav@601
   349
     * @since 1.5
jaroslav@601
   350
     */
jaroslav@601
   351
    public String toGenericString() {
jaroslav@601
   352
        try {
jaroslav@601
   353
            StringBuilder sb = new StringBuilder();
jaroslav@601
   354
            int mod = getModifiers() & Modifier.constructorModifiers();
jaroslav@601
   355
            if (mod != 0) {
jaroslav@601
   356
                sb.append(Modifier.toString(mod) + " ");
jaroslav@601
   357
            }
jaroslav@601
   358
            TypeVariable<?>[] typeparms = getTypeParameters();
jaroslav@601
   359
            if (typeparms.length > 0) {
jaroslav@601
   360
                boolean first = true;
jaroslav@601
   361
                sb.append("<");
jaroslav@601
   362
                for(TypeVariable<?> typeparm: typeparms) {
jaroslav@601
   363
                    if (!first)
jaroslav@601
   364
                        sb.append(",");
jaroslav@601
   365
                    // Class objects can't occur here; no need to test
jaroslav@601
   366
                    // and call Class.getName().
jaroslav@601
   367
                    sb.append(typeparm.toString());
jaroslav@601
   368
                    first = false;
jaroslav@601
   369
                }
jaroslav@601
   370
                sb.append("> ");
jaroslav@601
   371
            }
jaroslav@601
   372
            sb.append(Field.getTypeName(getDeclaringClass()));
jaroslav@601
   373
            sb.append("(");
jaroslav@601
   374
            Type[] params = getGenericParameterTypes();
jaroslav@601
   375
            for (int j = 0; j < params.length; j++) {
jaroslav@601
   376
                String param = (params[j] instanceof Class<?>)?
jaroslav@601
   377
                    Field.getTypeName((Class<?>)params[j]):
jaroslav@601
   378
                    (params[j].toString());
jaroslav@601
   379
                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
jaroslav@601
   380
                    param = param.replaceFirst("\\[\\]$", "...");
jaroslav@601
   381
                sb.append(param);
jaroslav@601
   382
                if (j < (params.length - 1))
jaroslav@601
   383
                    sb.append(",");
jaroslav@601
   384
            }
jaroslav@601
   385
            sb.append(")");
jaroslav@601
   386
            Type[] exceptions = getGenericExceptionTypes();
jaroslav@601
   387
            if (exceptions.length > 0) {
jaroslav@601
   388
                sb.append(" throws ");
jaroslav@601
   389
                for (int k = 0; k < exceptions.length; k++) {
jaroslav@601
   390
                    sb.append((exceptions[k] instanceof Class)?
jaroslav@601
   391
                              ((Class<?>)exceptions[k]).getName():
jaroslav@601
   392
                              exceptions[k].toString());
jaroslav@601
   393
                    if (k < (exceptions.length - 1))
jaroslav@601
   394
                        sb.append(",");
jaroslav@601
   395
                }
jaroslav@601
   396
            }
jaroslav@601
   397
            return sb.toString();
jaroslav@601
   398
        } catch (Exception e) {
jaroslav@601
   399
            return "<" + e + ">";
jaroslav@601
   400
        }
jaroslav@601
   401
    }
jaroslav@601
   402
jaroslav@601
   403
    /**
jaroslav@601
   404
     * Uses the constructor represented by this {@code Constructor} object to
jaroslav@601
   405
     * create and initialize a new instance of the constructor's
jaroslav@601
   406
     * declaring class, with the specified initialization parameters.
jaroslav@601
   407
     * Individual parameters are automatically unwrapped to match
jaroslav@601
   408
     * primitive formal parameters, and both primitive and reference
jaroslav@601
   409
     * parameters are subject to method invocation conversions as necessary.
jaroslav@601
   410
     *
jaroslav@601
   411
     * <p>If the number of formal parameters required by the underlying constructor
jaroslav@601
   412
     * is 0, the supplied {@code initargs} array may be of length 0 or null.
jaroslav@601
   413
     *
jaroslav@601
   414
     * <p>If the constructor's declaring class is an inner class in a
jaroslav@601
   415
     * non-static context, the first argument to the constructor needs
jaroslav@601
   416
     * to be the enclosing instance; see section 15.9.3 of
jaroslav@601
   417
     * <cite>The Java&trade; Language Specification</cite>.
jaroslav@601
   418
     *
jaroslav@601
   419
     * <p>If the required access and argument checks succeed and the
jaroslav@601
   420
     * instantiation will proceed, the constructor's declaring class
jaroslav@601
   421
     * is initialized if it has not already been initialized.
jaroslav@601
   422
     *
jaroslav@601
   423
     * <p>If the constructor completes normally, returns the newly
jaroslav@601
   424
     * created and initialized instance.
jaroslav@601
   425
     *
jaroslav@601
   426
     * @param initargs array of objects to be passed as arguments to
jaroslav@601
   427
     * the constructor call; values of primitive types are wrapped in
jaroslav@601
   428
     * a wrapper object of the appropriate type (e.g. a {@code float}
jaroslav@601
   429
     * in a {@link java.lang.Float Float})
jaroslav@601
   430
     *
jaroslav@601
   431
     * @return a new object created by calling the constructor
jaroslav@601
   432
     * this object represents
jaroslav@601
   433
     *
jaroslav@601
   434
     * @exception IllegalAccessException    if this {@code Constructor} object
jaroslav@601
   435
     *              is enforcing Java language access control and the underlying
jaroslav@601
   436
     *              constructor is inaccessible.
jaroslav@601
   437
     * @exception IllegalArgumentException  if the number of actual
jaroslav@601
   438
     *              and formal parameters differ; if an unwrapping
jaroslav@601
   439
     *              conversion for primitive arguments fails; or if,
jaroslav@601
   440
     *              after possible unwrapping, a parameter value
jaroslav@601
   441
     *              cannot be converted to the corresponding formal
jaroslav@601
   442
     *              parameter type by a method invocation conversion; if
jaroslav@601
   443
     *              this constructor pertains to an enum type.
jaroslav@601
   444
     * @exception InstantiationException    if the class that declares the
jaroslav@601
   445
     *              underlying constructor represents an abstract class.
jaroslav@601
   446
     * @exception InvocationTargetException if the underlying constructor
jaroslav@601
   447
     *              throws an exception.
jaroslav@601
   448
     * @exception ExceptionInInitializerError if the initialization provoked
jaroslav@601
   449
     *              by this method fails.
jaroslav@601
   450
     */
jaroslav@601
   451
    public T newInstance(Object ... initargs)
jaroslav@601
   452
        throws InstantiationException, IllegalAccessException,
jaroslav@601
   453
               IllegalArgumentException, InvocationTargetException
jaroslav@601
   454
    {
jaroslav@604
   455
        throw new SecurityException();
jaroslav@601
   456
    }
jaroslav@601
   457
jaroslav@601
   458
    /**
jaroslav@601
   459
     * Returns {@code true} if this constructor was declared to take
jaroslav@601
   460
     * a variable number of arguments; returns {@code false}
jaroslav@601
   461
     * otherwise.
jaroslav@601
   462
     *
jaroslav@601
   463
     * @return {@code true} if an only if this constructor was declared to
jaroslav@601
   464
     * take a variable number of arguments.
jaroslav@601
   465
     * @since 1.5
jaroslav@601
   466
     */
jaroslav@601
   467
    public boolean isVarArgs() {
jaroslav@601
   468
        return (getModifiers() & Modifier.VARARGS) != 0;
jaroslav@601
   469
    }
jaroslav@601
   470
jaroslav@601
   471
    /**
jaroslav@601
   472
     * Returns {@code true} if this constructor is a synthetic
jaroslav@601
   473
     * constructor; returns {@code false} otherwise.
jaroslav@601
   474
     *
jaroslav@601
   475
     * @return true if and only if this constructor is a synthetic
jaroslav@601
   476
     * constructor as defined by
jaroslav@601
   477
     * <cite>The Java&trade; Language Specification</cite>.
jaroslav@601
   478
     * @since 1.5
jaroslav@601
   479
     */
jaroslav@601
   480
    public boolean isSynthetic() {
jaroslav@601
   481
        return Modifier.isSynthetic(getModifiers());
jaroslav@601
   482
    }
jaroslav@601
   483
jaroslav@601
   484
    int getSlot() {
jaroslav@601
   485
        return slot;
jaroslav@601
   486
    }
jaroslav@601
   487
jaroslav@601
   488
   String getSignature() {
jaroslav@601
   489
            return signature;
jaroslav@601
   490
   }
jaroslav@601
   491
jaroslav@601
   492
    byte[] getRawAnnotations() {
jaroslav@601
   493
        return annotations;
jaroslav@601
   494
    }
jaroslav@601
   495
jaroslav@601
   496
    byte[] getRawParameterAnnotations() {
jaroslav@601
   497
        return parameterAnnotations;
jaroslav@601
   498
    }
jaroslav@601
   499
jaroslav@601
   500
    /**
jaroslav@601
   501
     * @throws NullPointerException {@inheritDoc}
jaroslav@601
   502
     * @since 1.5
jaroslav@601
   503
     */
jaroslav@601
   504
    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
jaroslav@601
   505
        if (annotationClass == null)
jaroslav@601
   506
            throw new NullPointerException();
jaroslav@601
   507
jaroslav@604
   508
        return null; // XXX (T) declaredAnnotations().get(annotationClass);
jaroslav@601
   509
    }
jaroslav@601
   510
jaroslav@601
   511
    /**
jaroslav@601
   512
     * @since 1.5
jaroslav@601
   513
     */
jaroslav@601
   514
    public Annotation[] getDeclaredAnnotations()  {
jaroslav@604
   515
        return new Annotation[0]; // XXX AnnotationParser.toArray(declaredAnnotations());
jaroslav@601
   516
    }
jaroslav@601
   517
jaroslav@601
   518
    /**
jaroslav@601
   519
     * Returns an array of arrays that represent the annotations on the formal
jaroslav@601
   520
     * parameters, in declaration order, of the method represented by
jaroslav@601
   521
     * this {@code Constructor} object. (Returns an array of length zero if the
jaroslav@601
   522
     * underlying method is parameterless.  If the method has one or more
jaroslav@601
   523
     * parameters, a nested array of length zero is returned for each parameter
jaroslav@601
   524
     * with no annotations.) The annotation objects contained in the returned
jaroslav@601
   525
     * arrays are serializable.  The caller of this method is free to modify
jaroslav@601
   526
     * the returned arrays; it will have no effect on the arrays returned to
jaroslav@601
   527
     * other callers.
jaroslav@601
   528
     *
jaroslav@601
   529
     * @return an array of arrays that represent the annotations on the formal
jaroslav@601
   530
     *    parameters, in declaration order, of the method represented by this
jaroslav@601
   531
     *    Constructor object
jaroslav@601
   532
     * @since 1.5
jaroslav@601
   533
     */
jaroslav@601
   534
    public Annotation[][] getParameterAnnotations() {
jaroslav@601
   535
        int numParameters = parameterTypes.length;
jaroslav@601
   536
        if (parameterAnnotations == null)
jaroslav@601
   537
            return new Annotation[numParameters][0];
jaroslav@604
   538
        
jaroslav@604
   539
        return new Annotation[numParameters][0]; // XXX
jaroslav@604
   540
/*
jaroslav@601
   541
        Annotation[][] result = AnnotationParser.parseParameterAnnotations(
jaroslav@601
   542
            parameterAnnotations,
jaroslav@601
   543
            sun.misc.SharedSecrets.getJavaLangAccess().
jaroslav@601
   544
                getConstantPool(getDeclaringClass()),
jaroslav@601
   545
            getDeclaringClass());
jaroslav@601
   546
        if (result.length != numParameters) {
jaroslav@601
   547
            Class<?> declaringClass = getDeclaringClass();
jaroslav@601
   548
            if (declaringClass.isEnum() ||
jaroslav@601
   549
                declaringClass.isAnonymousClass() ||
jaroslav@601
   550
                declaringClass.isLocalClass() )
jaroslav@601
   551
                ; // Can't do reliable parameter counting
jaroslav@601
   552
            else {
jaroslav@601
   553
                if (!declaringClass.isMemberClass() || // top-level
jaroslav@601
   554
                    // Check for the enclosing instance parameter for
jaroslav@601
   555
                    // non-static member classes
jaroslav@601
   556
                    (declaringClass.isMemberClass() &&
jaroslav@601
   557
                     ((declaringClass.getModifiers() & Modifier.STATIC) == 0)  &&
jaroslav@601
   558
                     result.length + 1 != numParameters) ) {
jaroslav@601
   559
                    throw new AnnotationFormatError(
jaroslav@601
   560
                              "Parameter annotations don't match number of parameters");
jaroslav@601
   561
                }
jaroslav@601
   562
            }
jaroslav@601
   563
        }
jaroslav@601
   564
        return result;
jaroslav@604
   565
        */
jaroslav@601
   566
    }
jaroslav@601
   567
}