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