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