author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 24709 | jdk/src/share/classes/java/lang/reflect/Executable.java@52f4fc801542 |
child 25991 | e48157b42439 |
permissions | -rw-r--r-- |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
1 |
/* |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
4 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
10 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
15 |
* accompanied this code). |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
16 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
20 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
23 |
* questions. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
24 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
25 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
26 |
package java.lang.reflect; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
27 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
28 |
import java.lang.annotation.*; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
29 |
import java.util.Map; |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
30 |
import java.util.Objects; |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
31 |
import sun.reflect.annotation.AnnotationParser; |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
32 |
import sun.reflect.annotation.AnnotationSupport; |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
33 |
import sun.reflect.annotation.TypeAnnotationParser; |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
34 |
import sun.reflect.annotation.TypeAnnotation; |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
35 |
import sun.reflect.generics.repository.ConstructorRepository; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
36 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
37 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
38 |
* A shared superclass for the common functionality of {@link Method} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
39 |
* and {@link Constructor}. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
40 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
41 |
* @since 1.8 |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
42 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
43 |
public abstract class Executable extends AccessibleObject |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
44 |
implements Member, GenericDeclaration { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
45 |
/* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
46 |
* Only grant package-visibility to the constructor. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
47 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
48 |
Executable() {} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
49 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
50 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
51 |
* Accessor method to allow code sharing |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
52 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
53 |
abstract byte[] getAnnotationBytes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
54 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
55 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
56 |
* Does the Executable have generic information. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
57 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
58 |
abstract boolean hasGenericInformation(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
59 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
60 |
abstract ConstructorRepository getGenericInfo(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
61 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
62 |
boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
63 |
/* Avoid unnecessary cloning */ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
64 |
if (params1.length == params2.length) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
65 |
for (int i = 0; i < params1.length; i++) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
66 |
if (params1[i] != params2[i]) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
67 |
return false; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
68 |
} |
10142
43c81972df7b
7073296: Executable.equalParamTypes() incorrectly returns true when the number of params differs.
mduigou
parents:
10127
diff
changeset
|
69 |
return true; |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
70 |
} |
10142
43c81972df7b
7073296: Executable.equalParamTypes() incorrectly returns true when the number of params differs.
mduigou
parents:
10127
diff
changeset
|
71 |
return false; |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
72 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
73 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
74 |
Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
75 |
return AnnotationParser.parseParameterAnnotations( |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
76 |
parameterAnnotations, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
77 |
sun.misc.SharedSecrets.getJavaLangAccess(). |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
78 |
getConstantPool(getDeclaringClass()), |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
79 |
getDeclaringClass()); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
80 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
81 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
82 |
void separateWithCommas(Class<?>[] types, StringBuilder sb) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
83 |
for (int j = 0; j < types.length; j++) { |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
84 |
sb.append(types[j].getTypeName()); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
85 |
if (j < (types.length - 1)) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
86 |
sb.append(","); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
87 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
88 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
89 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
90 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
91 |
void printModifiersIfNonzero(StringBuilder sb, int mask, boolean isDefault) { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
92 |
int mod = getModifiers() & mask; |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
93 |
|
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
94 |
if (mod != 0 && !isDefault) { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
95 |
sb.append(Modifier.toString(mod)).append(' '); |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
96 |
} else { |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
97 |
int access_mod = mod & Modifier.ACCESS_MODIFIERS; |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
98 |
if (access_mod != 0) |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
99 |
sb.append(Modifier.toString(access_mod)).append(' '); |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
100 |
if (isDefault) |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
101 |
sb.append("default "); |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
102 |
mod = (mod & ~Modifier.ACCESS_MODIFIERS); |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
103 |
if (mod != 0) |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
104 |
sb.append(Modifier.toString(mod)).append(' '); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
105 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
106 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
107 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
108 |
String sharedToString(int modifierMask, |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
109 |
boolean isDefault, |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
110 |
Class<?>[] parameterTypes, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
111 |
Class<?>[] exceptionTypes) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
112 |
try { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
113 |
StringBuilder sb = new StringBuilder(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
114 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
115 |
printModifiersIfNonzero(sb, modifierMask, isDefault); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
116 |
specificToStringHeader(sb); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
117 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
118 |
sb.append('('); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
119 |
separateWithCommas(parameterTypes, sb); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
120 |
sb.append(')'); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
121 |
if (exceptionTypes.length > 0) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
122 |
sb.append(" throws "); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
123 |
separateWithCommas(exceptionTypes, sb); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
124 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
125 |
return sb.toString(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
126 |
} catch (Exception e) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
127 |
return "<" + e + ">"; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
128 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
129 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
130 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
131 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
132 |
* Generate toString header information specific to a method or |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
133 |
* constructor. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
134 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
135 |
abstract void specificToStringHeader(StringBuilder sb); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
136 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
137 |
String sharedToGenericString(int modifierMask, boolean isDefault) { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
138 |
try { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
139 |
StringBuilder sb = new StringBuilder(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
140 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16058
diff
changeset
|
141 |
printModifiersIfNonzero(sb, modifierMask, isDefault); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
142 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
143 |
TypeVariable<?>[] typeparms = getTypeParameters(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
144 |
if (typeparms.length > 0) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
145 |
boolean first = true; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
146 |
sb.append('<'); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
147 |
for(TypeVariable<?> typeparm: typeparms) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
148 |
if (!first) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
149 |
sb.append(','); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
150 |
// Class objects can't occur here; no need to test |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
151 |
// and call Class.getName(). |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
152 |
sb.append(typeparm.toString()); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
153 |
first = false; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
154 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
155 |
sb.append("> "); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
156 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
157 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
158 |
specificToGenericStringHeader(sb); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
159 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
160 |
sb.append('('); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
161 |
Type[] params = getGenericParameterTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
162 |
for (int j = 0; j < params.length; j++) { |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
163 |
String param = params[j].getTypeName(); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
164 |
if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
165 |
param = param.replaceFirst("\\[\\]$", "..."); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
166 |
sb.append(param); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
167 |
if (j < (params.length - 1)) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
168 |
sb.append(','); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
169 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
170 |
sb.append(')'); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
171 |
Type[] exceptions = getGenericExceptionTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
172 |
if (exceptions.length > 0) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
173 |
sb.append(" throws "); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
174 |
for (int k = 0; k < exceptions.length; k++) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
175 |
sb.append((exceptions[k] instanceof Class)? |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
176 |
((Class)exceptions[k]).getName(): |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
177 |
exceptions[k].toString()); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
178 |
if (k < (exceptions.length - 1)) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
179 |
sb.append(','); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
180 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
181 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
182 |
return sb.toString(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
183 |
} catch (Exception e) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
184 |
return "<" + e + ">"; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
185 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
186 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
187 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
188 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
189 |
* Generate toGenericString header information specific to a |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
190 |
* method or constructor. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
191 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
192 |
abstract void specificToGenericStringHeader(StringBuilder sb); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
193 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
194 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
195 |
* Returns the {@code Class} object representing the class or interface |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
196 |
* that declares the executable represented by this object. |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
197 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
198 |
public abstract Class<?> getDeclaringClass(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
199 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
200 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
201 |
* Returns the name of the executable represented by this object. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
202 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
203 |
public abstract String getName(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
204 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
205 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
206 |
* Returns the Java language {@linkplain Modifier modifiers} for |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
207 |
* the executable represented by this object. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
208 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
209 |
public abstract int getModifiers(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
210 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
211 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
212 |
* Returns an array of {@code TypeVariable} objects that represent the |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
213 |
* type variables declared by the generic declaration represented by this |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
214 |
* {@code GenericDeclaration} object, in declaration order. Returns an |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
215 |
* array of length 0 if the underlying generic declaration declares no type |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
216 |
* variables. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
217 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
218 |
* @return an array of {@code TypeVariable} objects that represent |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
219 |
* the type variables declared by this generic declaration |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
220 |
* @throws GenericSignatureFormatError if the generic |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
221 |
* signature of this generic declaration does not conform to |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
222 |
* the format specified in |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
223 |
* <cite>The Java™ Virtual Machine Specification</cite> |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
224 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
225 |
public abstract TypeVariable<?>[] getTypeParameters(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
226 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
227 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
228 |
* Returns an array of {@code Class} objects that represent the formal |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
229 |
* parameter types, in declaration order, of the executable |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
230 |
* represented by this object. Returns an array of length |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
231 |
* 0 if the underlying executable takes no parameters. |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
232 |
* |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
233 |
* @return the parameter types for the executable this object |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
234 |
* represents |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
235 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
236 |
public abstract Class<?>[] getParameterTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
237 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
238 |
/** |
17177 | 239 |
* Returns the number of formal parameters (whether explicitly |
240 |
* declared or implicitly declared or neither) for the executable |
|
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
241 |
* represented by this object. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
242 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
243 |
* @return The number of formal parameters for the executable this |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
244 |
* object represents |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
245 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
246 |
public int getParameterCount() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
247 |
throw new AbstractMethodError(); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
248 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
249 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
250 |
/** |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
251 |
* Returns an array of {@code Type} objects that represent the formal |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
252 |
* parameter types, in declaration order, of the executable represented by |
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
253 |
* this object. Returns an array of length 0 if the |
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
254 |
* underlying executable takes no parameters. |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
255 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
256 |
* <p>If a formal parameter type is a parameterized type, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
257 |
* the {@code Type} object returned for it must accurately reflect |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
258 |
* the actual type parameters used in the source code. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
259 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
260 |
* <p>If a formal parameter type is a type variable or a parameterized |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
261 |
* type, it is created. Otherwise, it is resolved. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
262 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
263 |
* @return an array of {@code Type}s that represent the formal |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
264 |
* parameter types of the underlying executable, in declaration order |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
265 |
* @throws GenericSignatureFormatError |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
266 |
* if the generic method signature does not conform to the format |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
267 |
* specified in |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
268 |
* <cite>The Java™ Virtual Machine Specification</cite> |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
269 |
* @throws TypeNotPresentException if any of the parameter |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
270 |
* types of the underlying executable refers to a non-existent type |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
271 |
* declaration |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
272 |
* @throws MalformedParameterizedTypeException if any of |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
273 |
* the underlying executable's parameter types refer to a parameterized |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
274 |
* type that cannot be instantiated for any reason |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
275 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
276 |
public Type[] getGenericParameterTypes() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
277 |
if (hasGenericInformation()) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
278 |
return getGenericInfo().getParameterTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
279 |
else |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
280 |
return getParameterTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
281 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
282 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
283 |
/** |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
284 |
* Returns an array of {@code Parameter} objects that represent |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
285 |
* all the parameters to the underlying executable represented by |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
286 |
* this object. Returns an array of length 0 if the executable |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
287 |
* has no parameters. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
288 |
* |
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
289 |
* <p>The parameters of the underlying executable do not necessarily |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15511
diff
changeset
|
290 |
* have unique names, or names that are legal identifiers in the |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15511
diff
changeset
|
291 |
* Java programming language (JLS 3.8). |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15511
diff
changeset
|
292 |
* |
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
293 |
* @throws MalformedParametersException if the class file contains |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
294 |
* a MethodParameters attribute that is improperly formatted. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
295 |
* @return an array of {@code Parameter} objects representing all |
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
296 |
* the parameters to the executable this object represents. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
297 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
298 |
public Parameter[] getParameters() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
299 |
// TODO: This may eventually need to be guarded by security |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
300 |
// mechanisms similar to those in Field, Method, etc. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
301 |
// |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
302 |
// Need to copy the cached array to prevent users from messing |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
303 |
// with it. Since parameters are immutable, we can |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
304 |
// shallow-copy. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
305 |
return privateGetParameters().clone(); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
306 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
307 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
308 |
private Parameter[] synthesizeAllParams() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
309 |
final int realparams = getParameterCount(); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
310 |
final Parameter[] out = new Parameter[realparams]; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
311 |
for (int i = 0; i < realparams; i++) |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
312 |
// TODO: is there a way to synthetically derive the |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
313 |
// modifiers? Probably not in the general case, since |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
314 |
// we'd have no way of knowing about them, but there |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
315 |
// may be specific cases. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
316 |
out[i] = new Parameter("arg" + i, 0, this, i); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
317 |
return out; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
318 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
319 |
|
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
320 |
private void verifyParameters(final Parameter[] parameters) { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
321 |
final int mask = Modifier.FINAL | Modifier.SYNTHETIC | Modifier.MANDATED; |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
322 |
|
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
323 |
if (getParameterTypes().length != parameters.length) |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
324 |
throw new MalformedParametersException("Wrong number of parameters in MethodParameters attribute"); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
325 |
|
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
326 |
for (Parameter parameter : parameters) { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
327 |
final String name = parameter.getRealName(); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
328 |
final int mods = parameter.getModifiers(); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
329 |
|
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
330 |
if (name != null) { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
331 |
if (name.isEmpty() || name.indexOf('.') != -1 || |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
332 |
name.indexOf(';') != -1 || name.indexOf('[') != -1 || |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
333 |
name.indexOf('/') != -1) { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
334 |
throw new MalformedParametersException("Invalid parameter name \"" + name + "\""); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
335 |
} |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
336 |
} |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
337 |
|
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
338 |
if (mods != (mods & mask)) { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
339 |
throw new MalformedParametersException("Invalid parameter modifiers"); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
340 |
} |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
341 |
} |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
342 |
} |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
343 |
|
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
344 |
private Parameter[] privateGetParameters() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
345 |
// Use tmp to avoid multiple writes to a volatile. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
346 |
Parameter[] tmp = parameters; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
347 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
348 |
if (tmp == null) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
349 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
350 |
// Otherwise, go to the JVM to get them |
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
351 |
try { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
352 |
tmp = getParameters0(); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
353 |
} catch(IllegalArgumentException e) { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
354 |
// Rethrow ClassFormatErrors |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
355 |
throw new MalformedParametersException("Invalid constant pool index"); |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
356 |
} |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
357 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
358 |
// If we get back nothing, then synthesize parameters |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
359 |
if (tmp == null) { |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
360 |
hasRealParameterData = false; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
361 |
tmp = synthesizeAllParams(); |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
362 |
} else { |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
363 |
hasRealParameterData = true; |
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
20482
diff
changeset
|
364 |
verifyParameters(tmp); |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
365 |
} |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
366 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
367 |
parameters = tmp; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
368 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
369 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
370 |
return tmp; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
371 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
372 |
|
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
373 |
boolean hasRealParameterData() { |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
374 |
// If this somehow gets called before parameters gets |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
375 |
// initialized, force it into existence. |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
376 |
if (parameters == null) { |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
377 |
privateGetParameters(); |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
378 |
} |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
379 |
return hasRealParameterData; |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
380 |
} |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
381 |
|
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
382 |
private transient volatile boolean hasRealParameterData; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
383 |
private transient volatile Parameter[] parameters; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
384 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
385 |
private native Parameter[] getParameters0(); |
21361
6e4ef4e0097f
8023651: j.l.r.Constructor.getAnnotatedReceiverType() and j.l.r.Constructor.getAnnotatedReturnType() for inner classes return incorrect result
jfranck
parents:
21316
diff
changeset
|
386 |
native byte[] getTypeAnnotationBytes0(); |
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
387 |
|
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
388 |
// Needed by reflectaccess |
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
389 |
byte[] getTypeAnnotationBytes() { |
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
390 |
return getTypeAnnotationBytes0(); |
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
391 |
} |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
392 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
393 |
/** |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
394 |
* Returns an array of {@code Class} objects that represent the |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
395 |
* types of exceptions declared to be thrown by the underlying |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
396 |
* executable represented by this object. Returns an array of |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
397 |
* length 0 if the executable declares no exceptions in its {@code |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
398 |
* throws} clause. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
399 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
400 |
* @return the exception types declared as being thrown by the |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
401 |
* executable this object represents |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
402 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
403 |
public abstract Class<?>[] getExceptionTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
404 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
405 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
406 |
* Returns an array of {@code Type} objects that represent the |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
407 |
* exceptions declared to be thrown by this executable object. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
408 |
* Returns an array of length 0 if the underlying executable declares |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
409 |
* no exceptions in its {@code throws} clause. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
410 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
411 |
* <p>If an exception type is a type variable or a parameterized |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
412 |
* type, it is created. Otherwise, it is resolved. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
413 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
414 |
* @return an array of Types that represent the exception types |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
415 |
* thrown by the underlying executable |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
416 |
* @throws GenericSignatureFormatError |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
417 |
* if the generic method signature does not conform to the format |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
418 |
* specified in |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
419 |
* <cite>The Java™ Virtual Machine Specification</cite> |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
420 |
* @throws TypeNotPresentException if the underlying executable's |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
421 |
* {@code throws} clause refers to a non-existent type declaration |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
422 |
* @throws MalformedParameterizedTypeException if |
11996
19e65c956b22
7149626: (reflect) Improve javadoc of java.lang.reflect.Executable
darcy
parents:
10342
diff
changeset
|
423 |
* the underlying executable's {@code throws} clause refers to a |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
424 |
* parameterized type that cannot be instantiated for any reason |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
425 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
426 |
public Type[] getGenericExceptionTypes() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
427 |
Type[] result; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
428 |
if (hasGenericInformation() && |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
429 |
((result = getGenericInfo().getExceptionTypes()).length > 0)) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
430 |
return result; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
431 |
else |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
432 |
return getExceptionTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
433 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
434 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
435 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
436 |
* Returns a string describing this {@code Executable}, including |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
437 |
* any type parameters. |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
438 |
* @return a string describing this {@code Executable}, including |
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
439 |
* any type parameters |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
440 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
441 |
public abstract String toGenericString(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
442 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
443 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
444 |
* Returns {@code true} if this executable was declared to take a |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
445 |
* variable number of arguments; returns {@code false} otherwise. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
446 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
447 |
* @return {@code true} if an only if this executable was declared |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
448 |
* to take a variable number of arguments. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
449 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
450 |
public boolean isVarArgs() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
451 |
return (getModifiers() & Modifier.VARARGS) != 0; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
452 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
453 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
454 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
455 |
* Returns {@code true} if this executable is a synthetic |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
456 |
* construct; returns {@code false} otherwise. |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
457 |
* |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
458 |
* @return true if and only if this executable is a synthetic |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
459 |
* construct as defined by |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
460 |
* <cite>The Java™ Language Specification</cite>. |
14910 | 461 |
* @jls 13.1 The Form of a Binary |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
462 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
463 |
public boolean isSynthetic() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
464 |
return Modifier.isSynthetic(getModifiers()); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
465 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
466 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
467 |
/** |
19838
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
468 |
* Returns an array of arrays of {@code Annotation}s that |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
469 |
* represent the annotations on the formal parameters, in |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
470 |
* declaration order, of the {@code Executable} represented by |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
471 |
* this object. Synthetic and mandated parameters (see |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
472 |
* explanation below), such as the outer "this" parameter to an |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
473 |
* inner class constructor will be represented in the returned |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
474 |
* array. If the executable has no parameters (meaning no formal, |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
475 |
* no synthetic, and no mandated parameters), a zero-length array |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
476 |
* will be returned. If the {@code Executable} has one or more |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
477 |
* parameters, a nested array of length zero is returned for each |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
478 |
* parameter with no annotations. The annotation objects contained |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
479 |
* in the returned arrays are serializable. The caller of this |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
480 |
* method is free to modify the returned arrays; it will have no |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
481 |
* effect on the arrays returned to other callers. |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
482 |
* |
19838
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
483 |
* A compiler may add extra parameters that are implicitly |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
484 |
* declared in source ("mandated"), as well as parameters that |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
485 |
* are neither implicitly nor explicitly declared in source |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
486 |
* ("synthetic") to the parameter list for a method. See {@link |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
487 |
* java.lang.reflect.Parameter} for more information. |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
488 |
* |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
489 |
* @see java.lang.reflect.Parameter |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
490 |
* @see java.lang.reflect.Parameter#getAnnotations |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
491 |
* @return an array of arrays that represent the annotations on |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
492 |
* the formal and implicit parameters, in declaration order, of |
e2815bcfacf0
6962494: Update documentation on Executable.getParameterAnnotations()
emc
parents:
18775
diff
changeset
|
493 |
* the executable represented by this object |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
494 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
495 |
public abstract Annotation[][] getParameterAnnotations(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
496 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
497 |
Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
498 |
byte[] parameterAnnotations) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
499 |
int numParameters = parameterTypes.length; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
500 |
if (parameterAnnotations == null) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
501 |
return new Annotation[numParameters][0]; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
502 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
503 |
Annotation[][] result = parseParameterAnnotations(parameterAnnotations); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
504 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
505 |
if (result.length != numParameters) |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
506 |
handleParameterNumberMismatch(result.length, numParameters); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
507 |
return result; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
508 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
509 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
510 |
abstract void handleParameterNumberMismatch(int resultLength, int numParameters); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
511 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
512 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
513 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
514 |
* @throws NullPointerException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
515 |
*/ |
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
10142
diff
changeset
|
516 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
517 |
Objects.requireNonNull(annotationClass); |
15511
8f45487ac694
8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
15510
diff
changeset
|
518 |
return annotationClass.cast(declaredAnnotations().get(annotationClass)); |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
519 |
} |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
520 |
|
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
521 |
/** |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
522 |
* {@inheritDoc} |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
523 |
* @throws NullPointerException {@inheritDoc} |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
524 |
*/ |
15659
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
525 |
@Override |
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
526 |
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { |
14676
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
527 |
Objects.requireNonNull(annotationClass); |
985410ec95e3
7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
14342
diff
changeset
|
528 |
|
21316
ca0a7cd228c9
8004912: Repeating annotations - getAnnotationsByType(Class<T>) is not working as expected for few inheritance scenarios
alundblad
parents:
20506
diff
changeset
|
529 |
return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
530 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
531 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
532 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
533 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
534 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
535 |
public Annotation[] getDeclaredAnnotations() { |
15511
8f45487ac694
8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
15510
diff
changeset
|
536 |
return AnnotationParser.toArray(declaredAnnotations()); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
537 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
538 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
539 |
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
540 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
541 |
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
542 |
if (declaredAnnotations == null) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
543 |
declaredAnnotations = AnnotationParser.parseAnnotations( |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
544 |
getAnnotationBytes(), |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
545 |
sun.misc.SharedSecrets.getJavaLangAccess(). |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
546 |
getConstantPool(getDeclaringClass()), |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
547 |
getDeclaringClass()); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
548 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
549 |
return declaredAnnotations; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
550 |
} |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
551 |
|
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
552 |
/** |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
553 |
* Returns an {@code AnnotatedType} object that represents the use of a type to |
17436
79483ba40c55
8013541: Revise javadoc for Executable.getAnnotatedReturnType()
jfranck
parents:
17177
diff
changeset
|
554 |
* specify the return type of the method/constructor represented by this |
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
555 |
* Executable. |
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
556 |
* |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
557 |
* If this {@code Executable} object represents a constructor, the {@code |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
558 |
* AnnotatedType} object represents the type of the constructed object. |
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
559 |
* |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
560 |
* If this {@code Executable} object represents a method, the {@code |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
561 |
* AnnotatedType} object represents the use of a type to specify the return |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
562 |
* type of the method. |
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
563 |
* |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
564 |
* @return an object representing the return type of the method |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
565 |
* or constructor represented by this {@code Executable} |
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
566 |
*/ |
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15659
diff
changeset
|
567 |
public abstract AnnotatedType getAnnotatedReturnType(); |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
568 |
|
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
569 |
/* Helper for subclasses of Executable. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
570 |
* |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
571 |
* Returns an AnnotatedType object that represents the use of a type to |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
572 |
* specify the return type of the method/constructor represented by this |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
573 |
* Executable. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
574 |
*/ |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
575 |
AnnotatedType getAnnotatedReturnType0(Type returnType) { |
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
576 |
return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), |
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
577 |
sun.misc.SharedSecrets.getJavaLangAccess(). |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
578 |
getConstantPool(getDeclaringClass()), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
579 |
this, |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
580 |
getDeclaringClass(), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
581 |
returnType, |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
582 |
TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN); |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
583 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
584 |
|
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
585 |
/** |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
586 |
* Returns an {@code AnnotatedType} object that represents the use of a |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
587 |
* type to specify the receiver type of the method/constructor represented |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
588 |
* by this Executable object. The receiver type of a method/constructor is |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
589 |
* available only if the method/constructor has a <em>receiver |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
590 |
* parameter</em> (JLS 8.4.1). |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
591 |
* |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
592 |
* If this {@code Executable} object represents a constructor or instance |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
593 |
* method that does not have a receiver parameter, or has a receiver |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
594 |
* parameter with no annotations on its type, then the return value is an |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
595 |
* {@code AnnotatedType} object representing an element with no |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
596 |
* annotations. |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
597 |
* |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
598 |
* If this {@code Executable} object represents a static method, then the |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
599 |
* return value is null. |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
600 |
* |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
601 |
* @return an object representing the receiver type of the method or |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
602 |
* constructor represented by this {@code Executable} |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
603 |
*/ |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
604 |
public AnnotatedType getAnnotatedReceiverType() { |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
605 |
if (Modifier.isStatic(this.getModifiers())) |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
606 |
return null; |
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
607 |
return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), |
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
608 |
sun.misc.SharedSecrets.getJavaLangAccess(). |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
609 |
getConstantPool(getDeclaringClass()), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
610 |
this, |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
611 |
getDeclaringClass(), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
612 |
getDeclaringClass(), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
613 |
TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
614 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
615 |
|
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
616 |
/** |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
617 |
* Returns an array of {@code AnnotatedType} objects that represent the use |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
618 |
* of types to specify formal parameter types of the method/constructor |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
619 |
* represented by this Executable. The order of the objects in the array |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
620 |
* corresponds to the order of the formal parameter types in the |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
621 |
* declaration of the method/constructor. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
622 |
* |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
623 |
* Returns an array of length 0 if the method/constructor declares no |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
624 |
* parameters. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
625 |
* |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
626 |
* @return an array of objects representing the types of the |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
627 |
* formal parameters of the method or constructor represented by this |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
628 |
* {@code Executable} |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
629 |
*/ |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
630 |
public AnnotatedType[] getAnnotatedParameterTypes() { |
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
631 |
return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(), |
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
632 |
sun.misc.SharedSecrets.getJavaLangAccess(). |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
633 |
getConstantPool(getDeclaringClass()), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
634 |
this, |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
635 |
getDeclaringClass(), |
24709
52f4fc801542
8039916: AnnotatedType.getType() of a Executable parameters may return wrong type
jfranck
parents:
22083
diff
changeset
|
636 |
getGenericParameterTypes(), |
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
637 |
TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER); |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
638 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
639 |
|
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
640 |
/** |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
641 |
* Returns an array of {@code AnnotatedType} objects that represent the use |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
642 |
* of types to specify the declared exceptions of the method/constructor |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
643 |
* represented by this Executable. The order of the objects in the array |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
644 |
* corresponds to the order of the exception types in the declaration of |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
645 |
* the method/constructor. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
646 |
* |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
647 |
* Returns an array of length 0 if the method/constructor declares no |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
648 |
* exceptions. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
649 |
* |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
650 |
* @return an array of objects representing the declared |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
651 |
* exceptions of the method or constructor represented by this {@code |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19838
diff
changeset
|
652 |
* Executable} |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
653 |
*/ |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
654 |
public AnnotatedType[] getAnnotatedExceptionTypes() { |
20482
6dc1f81f522c
8009719: core reflection should get type annotation data from the VM lazily
jfranck
parents:
20481
diff
changeset
|
655 |
return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(), |
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
656 |
sun.misc.SharedSecrets.getJavaLangAccess(). |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
657 |
getConstantPool(getDeclaringClass()), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
658 |
this, |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
659 |
getDeclaringClass(), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
660 |
getGenericExceptionTypes(), |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17436
diff
changeset
|
661 |
TypeAnnotation.TypeAnnotationTarget.THROWS); |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
662 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
663 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
diff
changeset
|
664 |
} |