jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java
author mli
Mon, 27 Mar 2017 18:52:47 -0700
changeset 44369 b5c4e28a7521
parent 44359 c6761862ca0b
child 45332 9c9e51c44638
permissions -rw-r--r--
8176865: overridden api has a wrong since value in java.base module Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15294
df55735ea03c 8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents: 14910
diff changeset
     2
 * Copyright (c) 1996, 2013, 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
32834
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 32033
diff changeset
    28
import jdk.internal.misc.SharedSecrets;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    29
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    30
import jdk.internal.reflect.ConstructorAccessor;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    31
import jdk.internal.reflect.Reflection;
40175
8df87018d96a 8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents: 37363
diff changeset
    32
import jdk.internal.vm.annotation.ForceInline;
21361
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
    33
import sun.reflect.annotation.TypeAnnotation;
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
    34
import sun.reflect.annotation.TypeAnnotationParser;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.reflect.generics.repository.ConstructorRepository;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.reflect.generics.factory.CoreReflectionFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.reflect.generics.factory.GenericsFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.reflect.generics.scope.ConstructorScope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.annotation.AnnotationFormatError;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
    41
import java.util.StringJoiner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {@code Constructor} provides information about, and access to, a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * constructor for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>{@code Constructor} permits widening conversions to occur when matching the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * actual parameters to newInstance() with the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * constructor's formal parameters, but throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@code IllegalArgumentException} if a narrowing conversion would occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @param <T> the class in which the constructor is declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see Member
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see java.lang.Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see java.lang.Class#getConstructors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see java.lang.Class#getConstructor(Class[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see java.lang.Class#getDeclaredConstructors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author      Kenneth Russell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @author      Nakul Saraiya
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
    63
public final class Constructor<T> extends Executable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private Class<T>            clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private int                 slot;
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
    66
    private Class<?>[]          parameterTypes;
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
    67
    private Class<?>[]          exceptionTypes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private int                 modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // Generics and annotations support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private transient String    signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // generic info repository; lazily initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private transient ConstructorRepository genericInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private byte[]              annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private byte[]              parameterAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Generics infrastructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Accessor for factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private GenericsFactory getFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // create scope and factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return CoreReflectionFactory.make(this, ConstructorScope.make(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // Accessor for generic info repository
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
    84
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
    85
    ConstructorRepository getGenericInfo() {
2
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.)
26455
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   100
    //
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   101
    // If this branching structure would ever contain cycles, deadlocks can
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   102
    // occur in annotation code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private Constructor<T>      root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
26455
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   106
     * Used by Excecutable for annotation sharing.
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   107
     */
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   108
    @Override
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   109
    Executable getRoot() {
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   110
        return root;
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   111
    }
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   112
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   113
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Package-private constructor used by ReflectAccess to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * instantiation of these objects in Java code from the java.lang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * package via sun.reflect.LangReflectAccess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    Constructor(Class<T> declaringClass,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   119
                Class<?>[] parameterTypes,
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 3941
diff changeset
   120
                Class<?>[] checkedExceptions,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                byte[] annotations,
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   125
                byte[] parameterAnnotations) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this.clazz = declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.parameterTypes = parameterTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.exceptionTypes = checkedExceptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.slot = slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this.annotations = annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        this.parameterAnnotations = parameterAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Package-private routine (exposed to java.lang.Class via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * ReflectAccess) which returns a copy of this Constructor. The copy's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * "root" field points to this Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    Constructor<T> copy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // This routine enables sharing of ConstructorAccessor objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // among Constructor objects which refer to the same underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // method in the VM. (All of this contortion is only necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // because of the "accessibility" bit in AccessibleObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // which implicitly requires that new java.lang.reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // objects be fabricated for each reflective call on Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // objects.)
26455
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   149
        if (this.root != null)
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   150
            throw new IllegalArgumentException("Can not copy a non-root Constructor");
195a6f3e0cd0 8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents: 25991
diff changeset
   151
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 6534
diff changeset
   152
        Constructor<T> res = new Constructor<>(clazz,
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   153
                                               parameterTypes,
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   154
                                               exceptionTypes, modifiers, slot,
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   155
                                               signature,
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   156
                                               annotations,
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   157
                                               parameterAnnotations);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        res.root = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // Might as well eagerly propagate this if already present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        res.constructorAccessor = constructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   164
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   165
     * {@inheritDoc}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   166
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   167
     * <p> A {@code SecurityException} is also thrown if this object is a
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   168
     * {@code Constructor} object for the class {@code Class} and {@code flag}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   169
     * is true. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   170
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   171
     * @param flag {@inheritDoc}
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42997
diff changeset
   172
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42997
diff changeset
   173
     * @throws InaccessibleObjectException {@inheritDoc}
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42997
diff changeset
   174
     * @throws SecurityException if the request is denied by the security manager
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42997
diff changeset
   175
     *         or this is a constructor for {@code java.lang.Class}
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42997
diff changeset
   176
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42997
diff changeset
   177
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   178
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   179
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   180
    @CallerSensitive
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   181
    public void setAccessible(boolean flag) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   182
        AccessibleObject.checkPermission();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   183
        if (flag) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   184
            checkCanSetAccessible(Reflection.getCallerClass());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   185
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   186
        setAccessible0(flag);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   187
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   188
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   189
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   190
    void checkCanSetAccessible(Class<?> caller) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   191
        checkCanSetAccessible(caller, clazz);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   192
        if (clazz == Class.class) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   193
            // can we change this to InaccessibleObjectException?
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   194
            throw new SecurityException("Cannot make a java.lang.Class"
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   195
                                        + " constructor accessible");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   196
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   197
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   198
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   199
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   200
    boolean hasGenericInformation() {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   201
        return (getSignature() != null);
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   202
    }
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   203
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   204
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   205
    byte[] getAnnotationBytes() {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   206
        return annotations;
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   207
    }
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   208
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
42228
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   210
     * Returns the {@code Class} object representing the class that
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   211
     * declares the constructor represented by this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   213
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public Class<T> getDeclaringClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * 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
   220
     * the binary name of the constructor's declaring class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   222
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return getDeclaringClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   228
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   230
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   236
     * {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   237
     * @throws GenericSignatureFormatError {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   240
    @Override
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 10342
diff changeset
   241
    @SuppressWarnings({"rawtypes", "unchecked"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public TypeVariable<Constructor<T>>[] getTypeParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      if (getSignature() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          return (TypeVariable<Constructor<T>>[])new TypeVariable[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
42997
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
   250
    @Override
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
   251
    Class<?>[] getSharedParameterTypes() {
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
   252
        return parameterTypes;
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
   253
    }
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
   254
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   256
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   258
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public Class<?>[] getParameterTypes() {
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 10127
diff changeset
   260
        return parameterTypes.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   263
    /**
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   264
     * {@inheritDoc}
22083
1ac4a52255f4 8030785: Missing "since 1.8" javadoc for java.lang.reflect.Method:getParameterCount
darcy
parents: 21361
diff changeset
   265
     * @since 1.8
15294
df55735ea03c 8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents: 14910
diff changeset
   266
     */
df55735ea03c 8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents: 14910
diff changeset
   267
    public int getParameterCount() { return parameterTypes.length; }
df55735ea03c 8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents: 14910
diff changeset
   268
df55735ea03c 8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents: 14910
diff changeset
   269
    /**
df55735ea03c 8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents: 14910
diff changeset
   270
     * {@inheritDoc}
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   271
     * @throws GenericSignatureFormatError {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   272
     * @throws TypeNotPresentException {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   273
     * @throws MalformedParameterizedTypeException {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   274
     * @since 1.5
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   275
     */
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   276
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   277
    public Type[] getGenericParameterTypes() {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   278
        return super.getGenericParameterTypes();
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   279
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   282
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   284
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public Class<?>[] getExceptionTypes() {
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 10127
diff changeset
   286
        return exceptionTypes.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   291
     * {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   292
     * @throws GenericSignatureFormatError {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   293
     * @throws TypeNotPresentException {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   294
     * @throws MalformedParameterizedTypeException {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   297
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   298
    public Type[] getGenericExceptionTypes() {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   299
        return super.getGenericExceptionTypes();
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   300
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Compares this {@code Constructor} against the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Returns true if the objects are the same.  Two {@code Constructor} objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * the same if they were declared by the same class and have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * same formal parameter types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        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
   310
            Constructor<?> other = (Constructor<?>)obj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (getDeclaringClass() == other.getDeclaringClass()) {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   312
                return equalParamTypes(parameterTypes, other.parameterTypes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Returns a hashcode for this {@code Constructor}. The hashcode is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the same as the hashcode for the underlying constructor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * declaring class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return getDeclaringClass().getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Returns a string describing this {@code Constructor}.  The string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * formatted as the constructor access modifiers, if any,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * followed by the fully-qualified name of the declaring class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * followed by a parenthesized, comma-separated list of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * constructor's formal parameter types.  For example:
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 29125
diff changeset
   333
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *    public java.util.Hashtable(int,float)
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 29125
diff changeset
   335
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
42228
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   337
     * <p>If the constructor is declared to throw exceptions, the
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   338
     * parameter list is followed by a space, followed by the word
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   339
     * "{@code throws}" followed by a comma-separated list of the
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   340
     * thrown exception types.
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   341
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <p>The only possible modifiers for constructors are the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * modifiers {@code public}, {@code protected} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * {@code private}.  Only one of these may appear, or none if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * constructor has default (package) access.
16729
3b26e313ad81 8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents: 16058
diff changeset
   346
     *
3b26e313ad81 8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents: 16058
diff changeset
   347
     * @return a string describing this {@code Constructor}
29125
83b9bf8a6c2a 8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents: 26455
diff changeset
   348
     * @jls 8.8.3 Constructor Modifiers
83b9bf8a6c2a 8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents: 26455
diff changeset
   349
     * @jls 8.9.2 Enum Body Declarations
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public String toString() {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   352
        return sharedToString(Modifier.constructorModifiers(),
16729
3b26e313ad81 8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents: 16058
diff changeset
   353
                              false,
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   354
                              parameterTypes,
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   355
                              exceptionTypes);
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   356
    }
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   357
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   358
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   359
    void specificToStringHeader(StringBuilder sb) {
16743
b0b34102bb4c 6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents: 16729
diff changeset
   360
        sb.append(getDeclaringClass().getTypeName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   363
    @Override
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   364
    String toShortString() {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   365
        StringBuilder sb = new StringBuilder("constructor ");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   366
        sb.append(getDeclaringClass().getTypeName());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   367
        sb.append('(');
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   368
        StringJoiner sj = new StringJoiner(",");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   369
        for (Class<?> parameterType : getParameterTypes()) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   370
            sj.add(parameterType.getTypeName());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   371
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   372
        sb.append(sj);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   373
        sb.append(')');
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   374
        return sb.toString();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   375
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   376
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Returns a string describing this {@code Constructor},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * including type parameters.  The string is formatted as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * constructor access modifiers, if any, followed by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * angle-bracketed comma separated list of the constructor's type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * parameters, if any, followed by the fully-qualified name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * declaring class, followed by a parenthesized, comma-separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * list of the constructor's generic formal parameter types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * If this constructor was declared to take a variable number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * arguments, instead of denoting the last parameter as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 29125
diff changeset
   388
     * "<code><i>Type</i>[]</code>", it is denoted as
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 29125
diff changeset
   389
     * "<code><i>Type</i>...</code>".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * A space is used to separate access modifiers from one another
42228
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   392
     * and from the type parameters or class name.  If there are no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * type parameters, the type parameter list is elided; if the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * parameter list is present, a space separates the list from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * class name.  If the constructor is declared to throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * exceptions, the parameter list is followed by a space, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * by the word "{@code throws}" followed by a
42228
dd6cc832ffd4 8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents: 41560
diff changeset
   398
     * comma-separated list of the generic thrown exception types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * <p>The only possible modifiers for constructors are the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * modifiers {@code public}, {@code protected} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * {@code private}.  Only one of these may appear, or none if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * constructor has default (package) access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return a string describing this {@code Constructor},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * include type parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @since 1.5
29125
83b9bf8a6c2a 8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents: 26455
diff changeset
   409
     * @jls 8.8.3 Constructor Modifiers
83b9bf8a6c2a 8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents: 26455
diff changeset
   410
     * @jls 8.9.2 Enum Body Declarations
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   412
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public String toGenericString() {
16729
3b26e313ad81 8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents: 16058
diff changeset
   414
        return sharedToGenericString(Modifier.constructorModifiers(), false);
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   415
    }
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   416
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   417
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   418
    void specificToGenericStringHeader(StringBuilder sb) {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   419
        specificToStringHeader(sb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Uses the constructor represented by this {@code Constructor} object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * create and initialize a new instance of the constructor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * declaring class, with the specified initialization parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Individual parameters are automatically unwrapped to match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * primitive formal parameters, and both primitive and reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * parameters are subject to method invocation conversions as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * <p>If the number of formal parameters required by the underlying constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * is 0, the supplied {@code initargs} array may be of length 0 or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <p>If the constructor's declaring class is an inner class in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * 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
   435
     * 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
   436
     * <cite>The Java&trade; Language Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <p>If the required access and argument checks succeed and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * instantiation will proceed, the constructor's declaring class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * is initialized if it has not already been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <p>If the constructor completes normally, returns the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * created and initialized instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param initargs array of objects to be passed as arguments to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * the constructor call; values of primitive types are wrapped in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * a wrapper object of the appropriate type (e.g. a {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * in a {@link java.lang.Float Float})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @return a new object created by calling the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * this object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @exception IllegalAccessException    if this {@code Constructor} object
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 7816
diff changeset
   454
     *              is enforcing Java language access control and the underlying
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *              constructor is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @exception IllegalArgumentException  if the number of actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *              and formal parameters differ; if an unwrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *              conversion for primitive arguments fails; or if,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *              after possible unwrapping, a parameter value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *              cannot be converted to the corresponding formal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *              parameter type by a method invocation conversion; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *              this constructor pertains to an enum type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @exception InstantiationException    if the class that declares the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *              underlying constructor represents an abstract class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @exception InvocationTargetException if the underlying constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *              throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16743
diff changeset
   470
    @CallerSensitive
40175
8df87018d96a 8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents: 37363
diff changeset
   471
    @ForceInline // to ensure Reflection.getCallerClass optimization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public T newInstance(Object ... initargs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        throws InstantiationException, IllegalAccessException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
               IllegalArgumentException, InvocationTargetException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (!override) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32834
diff changeset
   477
            Class<?> caller = Reflection.getCallerClass();
41560
a66e7ee16cf9 6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents: 40175
diff changeset
   478
            checkAccess(caller, clazz, clazz, modifiers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if ((clazz.getModifiers() & Modifier.ENUM) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            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
   482
        ConstructorAccessor ca = constructorAccessor;   // read volatile
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   483
        if (ca == null) {
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   484
            ca = acquireConstructorAccessor();
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   485
        }
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 10127
diff changeset
   486
        @SuppressWarnings("unchecked")
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 10127
diff changeset
   487
        T inst = (T) ca.newInstance(initargs);
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 10127
diff changeset
   488
        return inst;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   492
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   495
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public boolean isVarArgs() {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   497
        return super.isVarArgs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   501
     * {@inheritDoc}
14910
337380568515 8005097: Tie isSynthetic javadoc to the JLS
darcy
parents: 14905
diff changeset
   502
     * @jls 13.1 The Form of a Binary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   505
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public boolean isSynthetic() {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   507
        return super.isSynthetic();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    // NOTE that there is no synchronization used here. It is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    // (though not efficient) to generate more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    // ConstructorAccessor for a given Constructor. However, avoiding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    // synchronization will probably make the implementation more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    // scalable.
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   515
    private ConstructorAccessor acquireConstructorAccessor() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        // First check to see if one has been created yet, and take it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // if so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        ConstructorAccessor tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (root != null) tmp = root.getConstructorAccessor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (tmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            constructorAccessor = tmp;
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   522
        } else {
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   523
            // 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
   524
            tmp = reflectionFactory.newConstructorAccessor(this);
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   525
            setConstructorAccessor(tmp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   527
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   528
        return tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    // Returns ConstructorAccessor for this Constructor object, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    // looking up the chain to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    ConstructorAccessor getConstructorAccessor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return constructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    // Sets the ConstructorAccessor for this Constructor object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    // (recursively) its root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    void setConstructorAccessor(ConstructorAccessor accessor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        constructorAccessor = accessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        // Propagate up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            root.setConstructorAccessor(accessor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    int getSlot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   551
    String getSignature() {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   552
        return signature;
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   553
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    byte[] getRawAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        return annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    byte[] getRawParameterAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return parameterAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   563
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   565
     * {@inheritDoc}
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   566
     * @throws NullPointerException  {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   570
        return super.getAnnotation(annotationClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   574
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    public Annotation[] getDeclaredAnnotations()  {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   578
        return super.getDeclaredAnnotations();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   582
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   585
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public Annotation[][] getParameterAnnotations() {
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   587
        return sharedGetParameterAnnotations(parameterTypes, parameterAnnotations);
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   588
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
10127
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   590
    @Override
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   591
    void handleParameterNumberMismatch(int resultLength, int numParameters) {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   592
        Class<?> declaringClass = getDeclaringClass();
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   593
        if (declaringClass.isEnum() ||
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   594
            declaringClass.isAnonymousClass() ||
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   595
            declaringClass.isLocalClass() )
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   596
            return ; // Can't do reliable parameter counting
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   597
        else {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   598
            if (!declaringClass.isMemberClass() || // top-level
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   599
                // Check for the enclosing instance parameter for
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   600
                // non-static member classes
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   601
                (declaringClass.isMemberClass() &&
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   602
                 ((declaringClass.getModifiers() & Modifier.STATIC) == 0)  &&
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   603
                 resultLength + 1 != numParameters) ) {
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   604
                throw new AnnotationFormatError(
c85d1ec57ee7 7007535: (reflect) Please generalize Constructor and Method
darcy
parents: 9266
diff changeset
   605
                          "Parameter annotations don't match number of parameters");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
15510
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   609
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   610
    /**
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   611
     * {@inheritDoc}
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   612
     * @since 1.8
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   613
     */
16058
5b8d8cec6280 8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents: 15510
diff changeset
   614
    @Override
15510
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   615
    public AnnotatedType getAnnotatedReturnType() {
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   616
        return getAnnotatedReturnType0(getDeclaringClass());
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 15294
diff changeset
   617
    }
21361
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   618
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   619
    /**
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   620
     * {@inheritDoc}
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   621
     * @since 1.8
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   622
     */
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   623
    @Override
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   624
    public AnnotatedType getAnnotatedReceiverType() {
25982
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   625
        Class<?> thisDeclClass = getDeclaringClass();
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   626
        Class<?> enclosingClass = thisDeclClass.getEnclosingClass();
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   627
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   628
        if (enclosingClass == null) {
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   629
            // A Constructor for a top-level class
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   630
            return null;
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   631
        }
21361
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   632
25982
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   633
        Class<?> outerDeclaringClass = thisDeclClass.getDeclaringClass();
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   634
        if (outerDeclaringClass == null) {
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   635
            // A constructor for a local or anonymous class
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   636
            return null;
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   637
        }
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   638
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   639
        // Either static nested or inner class
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   640
        if (Modifier.isStatic(thisDeclClass.getModifiers())) {
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   641
            // static nested
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   642
            return null;
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   643
        }
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   644
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   645
        // A Constructor for an inner class
21361
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   646
        return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
32834
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 32033
diff changeset
   647
                SharedSecrets.getJavaLangAccess().
25982
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   648
                    getConstantPool(thisDeclClass),
21361
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   649
                this,
25982
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   650
                thisDeclClass,
724303cf59ba 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
jfranck
parents: 22083
diff changeset
   651
                enclosingClass,
21361
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   652
                TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
6e4ef4e0097f 8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents: 20482
diff changeset
   653
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
}