author | mchung |
Thu, 04 Oct 2018 08:45:21 -0700 | |
changeset 52015 | 821bfc24d750 |
parent 50091 | 05979f6ba560 |
child 52020 | 4c247dde38ed |
permissions | -rw-r--r-- |
2 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.reflect; |
|
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 | 35 |
import sun.reflect.generics.repository.ConstructorRepository; |
36 |
import sun.reflect.generics.factory.CoreReflectionFactory; |
|
37 |
import sun.reflect.generics.factory.GenericsFactory; |
|
38 |
import sun.reflect.generics.scope.ConstructorScope; |
|
39 |
import java.lang.annotation.Annotation; |
|
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 | 42 |
|
43 |
/** |
|
44 |
* {@code Constructor} provides information about, and access to, a single |
|
45 |
* constructor for a class. |
|
46 |
* |
|
47 |
* <p>{@code Constructor} permits widening conversions to occur when matching the |
|
48 |
* actual parameters to newInstance() with the underlying |
|
49 |
* constructor's formal parameters, but throws an |
|
50 |
* {@code IllegalArgumentException} if a narrowing conversion would occur. |
|
51 |
* |
|
52 |
* @param <T> the class in which the constructor is declared |
|
53 |
* |
|
54 |
* @see Member |
|
55 |
* @see java.lang.Class |
|
56 |
* @see java.lang.Class#getConstructors() |
|
57 |
* @see java.lang.Class#getConstructor(Class[]) |
|
58 |
* @see java.lang.Class#getDeclaredConstructors() |
|
59 |
* |
|
60 |
* @author Kenneth Russell |
|
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 | 63 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
64 |
public final class Constructor<T> extends Executable { |
2 | 65 |
private Class<T> clazz; |
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 | 69 |
private int modifiers; |
70 |
// Generics and annotations support |
|
71 |
private transient String signature; |
|
72 |
// generic info repository; lazily initialized |
|
73 |
private transient ConstructorRepository genericInfo; |
|
74 |
private byte[] annotations; |
|
75 |
private byte[] parameterAnnotations; |
|
76 |
||
77 |
// Generics infrastructure |
|
78 |
// Accessor for factory |
|
79 |
private GenericsFactory getFactory() { |
|
80 |
// create scope and factory |
|
81 |
return CoreReflectionFactory.make(this, ConstructorScope.make(this)); |
|
82 |
} |
|
83 |
||
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 | 87 |
// lazily initialize repository if necessary |
88 |
if (genericInfo == null) { |
|
89 |
// create and cache generic info repository |
|
90 |
genericInfo = |
|
91 |
ConstructorRepository.make(getSignature(), |
|
92 |
getFactory()); |
|
93 |
} |
|
94 |
return genericInfo; //return cached repository |
|
95 |
} |
|
96 |
||
97 |
private volatile ConstructorAccessor constructorAccessor; |
|
98 |
// For sharing of ConstructorAccessors. This branching structure |
|
99 |
// is currently only two levels deep (i.e., one root Constructor |
|
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 | 104 |
private Constructor<T> root; |
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 | 112 |
* Package-private constructor used by ReflectAccess to enable |
113 |
* instantiation of these objects in Java code from the java.lang |
|
114 |
* package via sun.reflect.LangReflectAccess. |
|
115 |
*/ |
|
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 | 119 |
int modifiers, |
120 |
int slot, |
|
121 |
String signature, |
|
122 |
byte[] annotations, |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
123 |
byte[] parameterAnnotations) { |
2 | 124 |
this.clazz = declaringClass; |
125 |
this.parameterTypes = parameterTypes; |
|
126 |
this.exceptionTypes = checkedExceptions; |
|
127 |
this.modifiers = modifiers; |
|
128 |
this.slot = slot; |
|
129 |
this.signature = signature; |
|
130 |
this.annotations = annotations; |
|
131 |
this.parameterAnnotations = parameterAnnotations; |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Package-private routine (exposed to java.lang.Class via |
|
136 |
* ReflectAccess) which returns a copy of this Constructor. The copy's |
|
137 |
* "root" field points to this Constructor. |
|
138 |
*/ |
|
139 |
Constructor<T> copy() { |
|
140 |
// This routine enables sharing of ConstructorAccessor objects |
|
141 |
// among Constructor objects which refer to the same underlying |
|
142 |
// method in the VM. (All of this contortion is only necessary |
|
143 |
// because of the "accessibility" bit in AccessibleObject, |
|
144 |
// which implicitly requires that new java.lang.reflect |
|
145 |
// objects be fabricated for each reflective call on Class |
|
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 | 156 |
res.root = this; |
157 |
// Might as well eagerly propagate this if already present |
|
158 |
res.constructorAccessor = constructorAccessor; |
|
159 |
return res; |
|
160 |
} |
|
161 |
||
36511 | 162 |
/** |
163 |
* {@inheritDoc} |
|
164 |
* |
|
165 |
* <p> A {@code SecurityException} is also thrown if this object is a |
|
166 |
* {@code Constructor} object for the class {@code Class} and {@code flag} |
|
167 |
* is true. </p> |
|
168 |
* |
|
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 | 176 |
*/ |
177 |
@Override |
|
178 |
@CallerSensitive |
|
179 |
public void setAccessible(boolean flag) { |
|
180 |
AccessibleObject.checkPermission(); |
|
181 |
if (flag) { |
|
182 |
checkCanSetAccessible(Reflection.getCallerClass()); |
|
183 |
} |
|
184 |
setAccessible0(flag); |
|
185 |
} |
|
186 |
||
187 |
@Override |
|
188 |
void checkCanSetAccessible(Class<?> caller) { |
|
189 |
checkCanSetAccessible(caller, clazz); |
|
190 |
if (clazz == Class.class) { |
|
191 |
// can we change this to InaccessibleObjectException? |
|
192 |
throw new SecurityException("Cannot make a java.lang.Class" |
|
193 |
+ " constructor accessible"); |
|
194 |
} |
|
195 |
} |
|
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 | 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 | 210 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
211 |
@Override |
2 | 212 |
public Class<T> getDeclaringClass() { |
213 |
return clazz; |
|
214 |
} |
|
215 |
||
216 |
/** |
|
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 | 219 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
220 |
@Override |
2 | 221 |
public String getName() { |
222 |
return getDeclaringClass().getName(); |
|
223 |
} |
|
224 |
||
225 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
226 |
* {@inheritDoc} |
2 | 227 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
228 |
@Override |
2 | 229 |
public int getModifiers() { |
230 |
return modifiers; |
|
231 |
} |
|
232 |
||
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 | 236 |
* @since 1.5 |
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 | 240 |
public TypeVariable<Constructor<T>>[] getTypeParameters() { |
241 |
if (getSignature() != null) { |
|
242 |
return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters(); |
|
243 |
} else |
|
244 |
return (TypeVariable<Constructor<T>>[])new TypeVariable[0]; |
|
245 |
} |
|
246 |
||
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 | 258 |
/** |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
259 |
* {@inheritDoc} |
2 | 260 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
261 |
@Override |
2 | 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 | 264 |
} |
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 | 283 |
|
284 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
285 |
* {@inheritDoc} |
2 | 286 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
287 |
@Override |
2 | 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 | 290 |
} |
291 |
||
292 |
||
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 | 298 |
* @since 1.5 |
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 | 304 |
|
305 |
/** |
|
306 |
* Compares this {@code Constructor} against the specified object. |
|
307 |
* Returns true if the objects are the same. Two {@code Constructor} objects are |
|
308 |
* the same if they were declared by the same class and have the |
|
309 |
* same formal parameter types. |
|
310 |
*/ |
|
311 |
public boolean equals(Object obj) { |
|
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 | 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 | 316 |
} |
317 |
} |
|
318 |
return false; |
|
319 |
} |
|
320 |
||
321 |
/** |
|
322 |
* Returns a hashcode for this {@code Constructor}. The hashcode is |
|
323 |
* the same as the hashcode for the underlying constructor's |
|
324 |
* declaring class name. |
|
325 |
*/ |
|
326 |
public int hashCode() { |
|
327 |
return getDeclaringClass().getName().hashCode(); |
|
328 |
} |
|
329 |
||
330 |
/** |
|
331 |
* Returns a string describing this {@code Constructor}. The string is |
|
332 |
* formatted as the constructor access modifiers, if any, |
|
333 |
* followed by the fully-qualified name of the declaring class, |
|
334 |
* followed by a parenthesized, comma-separated list of the |
|
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 | 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 | 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 | 345 |
* <p>The only possible modifiers for constructors are the access |
346 |
* modifiers {@code public}, {@code protected} or |
|
347 |
* {@code private}. Only one of these may appear, or none if the |
|
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 | 353 |
*/ |
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 | 364 |
} |
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 | 380 |
/** |
381 |
* Returns a string describing this {@code Constructor}, |
|
382 |
* including type parameters. The string is formatted as the |
|
383 |
* constructor access modifiers, if any, followed by an |
|
384 |
* angle-bracketed comma separated list of the constructor's type |
|
385 |
* parameters, if any, followed by the fully-qualified name of the |
|
386 |
* declaring class, followed by a parenthesized, comma-separated |
|
387 |
* list of the constructor's generic formal parameter types. |
|
388 |
* |
|
389 |
* If this constructor was declared to take a variable number of |
|
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 | 393 |
* |
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 | 396 |
* type parameters, the type parameter list is elided; if the type |
397 |
* parameter list is present, a space separates the list from the |
|
398 |
* class name. If the constructor is declared to throw |
|
399 |
* exceptions, the parameter list is followed by a space, followed |
|
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 | 402 |
* |
403 |
* <p>The only possible modifiers for constructors are the access |
|
404 |
* modifiers {@code public}, {@code protected} or |
|
405 |
* {@code private}. Only one of these may appear, or none if the |
|
406 |
* constructor has default (package) access. |
|
407 |
* |
|
408 |
* @return a string describing this {@code Constructor}, |
|
409 |
* include type parameters |
|
410 |
* |
|
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 | 414 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
415 |
@Override |
2 | 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 | 423 |
} |
424 |
||
425 |
/** |
|
426 |
* Uses the constructor represented by this {@code Constructor} object to |
|
427 |
* create and initialize a new instance of the constructor's |
|
428 |
* declaring class, with the specified initialization parameters. |
|
429 |
* Individual parameters are automatically unwrapped to match |
|
430 |
* primitive formal parameters, and both primitive and reference |
|
431 |
* parameters are subject to method invocation conversions as necessary. |
|
432 |
* |
|
433 |
* <p>If the number of formal parameters required by the underlying constructor |
|
434 |
* is 0, the supplied {@code initargs} array may be of length 0 or null. |
|
435 |
* |
|
436 |
* <p>If the constructor's declaring class is an inner class in a |
|
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™ Language Specification</cite>. |
2 | 440 |
* |
441 |
* <p>If the required access and argument checks succeed and the |
|
442 |
* instantiation will proceed, the constructor's declaring class |
|
443 |
* is initialized if it has not already been initialized. |
|
444 |
* |
|
445 |
* <p>If the constructor completes normally, returns the newly |
|
446 |
* created and initialized instance. |
|
447 |
* |
|
448 |
* @param initargs array of objects to be passed as arguments to |
|
449 |
* the constructor call; values of primitive types are wrapped in |
|
450 |
* a wrapper object of the appropriate type (e.g. a {@code float} |
|
451 |
* in a {@link java.lang.Float Float}) |
|
452 |
* |
|
453 |
* @return a new object created by calling the constructor |
|
454 |
* this object represents |
|
455 |
* |
|
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 | 458 |
* constructor is inaccessible. |
459 |
* @exception IllegalArgumentException if the number of actual |
|
460 |
* and formal parameters differ; if an unwrapping |
|
461 |
* conversion for primitive arguments fails; or if, |
|
462 |
* after possible unwrapping, a parameter value |
|
463 |
* cannot be converted to the corresponding formal |
|
464 |
* parameter type by a method invocation conversion; if |
|
465 |
* this constructor pertains to an enum type. |
|
466 |
* @exception InstantiationException if the class that declares the |
|
467 |
* underlying constructor represents an abstract class. |
|
468 |
* @exception InvocationTargetException if the underlying constructor |
|
469 |
* throws an exception. |
|
470 |
* @exception ExceptionInInitializerError if the initialization provoked |
|
471 |
* by this method fails. |
|
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 | 475 |
public T newInstance(Object ... initargs) |
476 |
throws InstantiationException, IllegalAccessException, |
|
477 |
IllegalArgumentException, InvocationTargetException |
|
478 |
{ |
|
479 |
if (!override) { |
|
36511 | 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 | 482 |
} |
483 |
if ((clazz.getModifiers() & Modifier.ENUM) != 0) |
|
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 | 492 |
} |
493 |
||
494 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
495 |
* {@inheritDoc} |
2 | 496 |
* @since 1.5 |
497 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
498 |
@Override |
2 | 499 |
public boolean isVarArgs() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
500 |
return super.isVarArgs(); |
2 | 501 |
} |
502 |
||
503 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
504 |
* {@inheritDoc} |
14910 | 505 |
* @jls 13.1 The Form of a Binary |
2 | 506 |
* @since 1.5 |
507 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
508 |
@Override |
2 | 509 |
public boolean isSynthetic() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
510 |
return super.isSynthetic(); |
2 | 511 |
} |
512 |
||
513 |
// NOTE that there is no synchronization used here. It is correct |
|
514 |
// (though not efficient) to generate more than one |
|
515 |
// ConstructorAccessor for a given Constructor. However, avoiding |
|
516 |
// synchronization will probably make the implementation more |
|
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 | 519 |
// First check to see if one has been created yet, and take it |
520 |
// if so. |
|
521 |
ConstructorAccessor tmp = null; |
|
522 |
if (root != null) tmp = root.getConstructorAccessor(); |
|
523 |
if (tmp != null) { |
|
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 | 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 | 532 |
} |
533 |
||
534 |
// Returns ConstructorAccessor for this Constructor object, not |
|
535 |
// looking up the chain to the root |
|
536 |
ConstructorAccessor getConstructorAccessor() { |
|
537 |
return constructorAccessor; |
|
538 |
} |
|
539 |
||
540 |
// Sets the ConstructorAccessor for this Constructor object and |
|
541 |
// (recursively) its root |
|
542 |
void setConstructorAccessor(ConstructorAccessor accessor) { |
|
543 |
constructorAccessor = accessor; |
|
544 |
// Propagate up |
|
545 |
if (root != null) { |
|
546 |
root.setConstructorAccessor(accessor); |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
int getSlot() { |
|
551 |
return slot; |
|
552 |
} |
|
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 | 557 |
|
558 |
byte[] getRawAnnotations() { |
|
559 |
return annotations; |
|
560 |
} |
|
561 |
||
562 |
byte[] getRawParameterAnnotations() { |
|
563 |
return parameterAnnotations; |
|
564 |
} |
|
565 |
||
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
566 |
|
2 | 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 | 570 |
* @since 1.5 |
571 |
*/ |
|
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 | 574 |
} |
575 |
||
576 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
577 |
* {@inheritDoc} |
2 | 578 |
* @since 1.5 |
579 |
*/ |
|
580 |
public Annotation[] getDeclaredAnnotations() { |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
581 |
return super.getDeclaredAnnotations(); |
2 | 582 |
} |
583 |
||
584 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
585 |
* {@inheritDoc} |
2 | 586 |
* @since 1.5 |
587 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
588 |
@Override |
2 | 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 | 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 | 608 |
} |
609 |
} |
|
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 | 656 |
} |