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