author | mchung |
Thu, 04 Oct 2018 08:45:21 -0700 | |
changeset 52015 | 821bfc24d750 |
parent 47216 | 71c04702a3d5 |
child 52902 | e3398b2e1ab0 |
permissions | -rw-r--r-- |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
1 |
/* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
4 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
10 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
15 |
* accompanied this code). |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
16 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
20 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
23 |
* questions. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
24 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
25 |
package java.lang.reflect; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
26 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
27 |
import java.lang.annotation.*; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
28 |
import java.util.HashMap; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
29 |
import java.util.Map; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
30 |
import java.util.Objects; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
31 |
import sun.reflect.annotation.AnnotationSupport; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
32 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
33 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
34 |
* Information about method parameters. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
35 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
36 |
* A {@code Parameter} provides information about method parameters, |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
37 |
* including its name and modifiers. It also provides an alternate |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
38 |
* means of obtaining attributes for the parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
39 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
40 |
* @since 1.8 |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
41 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
42 |
public final class Parameter implements AnnotatedElement { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
43 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
44 |
private final String name; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
45 |
private final int modifiers; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
46 |
private final Executable executable; |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
47 |
private final int index; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
48 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
49 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
50 |
* Package-private constructor for {@code Parameter}. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
51 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
52 |
* If method parameter data is present in the classfile, then the |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
53 |
* JVM creates {@code Parameter} objects directly. If it is |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
54 |
* absent, however, then {@code Executable} uses this constructor |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
55 |
* to synthesize them. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
56 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
57 |
* @param name The name of the parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
58 |
* @param modifiers The modifier flags for the parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
59 |
* @param executable The executable which defines this parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
60 |
* @param index The index of the parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
61 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
62 |
Parameter(String name, |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
63 |
int modifiers, |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
64 |
Executable executable, |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
65 |
int index) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
66 |
this.name = name; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
67 |
this.modifiers = modifiers; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
68 |
this.executable = executable; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
69 |
this.index = index; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
70 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
71 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
72 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
73 |
* Compares based on the executable and the index. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
74 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
75 |
* @param obj The object to compare. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
76 |
* @return Whether or not this is equal to the argument. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
77 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
78 |
public boolean equals(Object obj) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
79 |
if(obj instanceof Parameter) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
80 |
Parameter other = (Parameter)obj; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
81 |
return (other.executable.equals(executable) && |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
82 |
other.index == index); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
83 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
84 |
return false; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
85 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
86 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
87 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
88 |
* Returns a hash code based on the executable's hash code and the |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
89 |
* index. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
90 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
91 |
* @return A hash code based on the executable's hash code. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
92 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
93 |
public int hashCode() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
94 |
return executable.hashCode() ^ index; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
95 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
96 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
97 |
/** |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
98 |
* Returns true if the parameter has a name according to the class |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
99 |
* file; returns false otherwise. Whether a parameter has a name |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
100 |
* is determined by the {@literal MethodParameters} attribute of |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
101 |
* the method which declares the parameter. |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
102 |
* |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
103 |
* @return true if and only if the parameter has a name according |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
104 |
* to the class file. |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
105 |
*/ |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
106 |
public boolean isNamePresent() { |
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
19031
diff
changeset
|
107 |
return executable.hasRealParameterData() && name != null; |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
108 |
} |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
109 |
|
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
110 |
/** |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
111 |
* Returns a string describing this parameter. The format is the |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
112 |
* modifiers for the parameter, if any, in canonical order as |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
113 |
* recommended by <cite>The Java™ Language |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
114 |
* Specification</cite>, followed by the fully- qualified type of |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
115 |
* the parameter (excluding the last [] if the parameter is |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
116 |
* variable arity), followed by "..." if the parameter is variable |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
117 |
* arity, followed by a space, followed by the name of the |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
118 |
* parameter. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
119 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
120 |
* @return A string representation of the parameter and associated |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
121 |
* information. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
122 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
123 |
public String toString() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
124 |
final StringBuilder sb = new StringBuilder(); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
125 |
final Type type = getParameterizedType(); |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16009
diff
changeset
|
126 |
final String typename = type.getTypeName(); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
127 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
128 |
sb.append(Modifier.toString(getModifiers())); |
16009 | 129 |
|
130 |
if(0 != modifiers) |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16009
diff
changeset
|
131 |
sb.append(' '); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
132 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
133 |
if(isVarArgs()) |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
134 |
sb.append(typename.replaceFirst("\\[\\]$", "...")); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
135 |
else |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
136 |
sb.append(typename); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
137 |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16009
diff
changeset
|
138 |
sb.append(' '); |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
139 |
sb.append(getName()); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
140 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
141 |
return sb.toString(); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
142 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
143 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
144 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
145 |
* Return the {@code Executable} which declares this parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
146 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
147 |
* @return The {@code Executable} declaring this parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
148 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
149 |
public Executable getDeclaringExecutable() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
150 |
return executable; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
151 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
152 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
153 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
154 |
* Get the modifier flags for this the parameter represented by |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
155 |
* this {@code Parameter} object. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
156 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
157 |
* @return The modifier flags for this parameter. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
158 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
159 |
public int getModifiers() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
160 |
return modifiers; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
161 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
162 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
163 |
/** |
17177 | 164 |
* Returns the name of the parameter. If the parameter's name is |
19031
6c9afe6dad33
8020810: Typo in javadoc for Class.toGenericString()
darcy
parents:
18775
diff
changeset
|
165 |
* {@linkplain #isNamePresent() present}, then this method returns |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
166 |
* the name provided by the class file. Otherwise, this method |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
167 |
* synthesizes a name of the form argN, where N is the index of |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
168 |
* the parameter in the descriptor of the method which declares |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
169 |
* the parameter. |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17450
diff
changeset
|
170 |
* |
18775
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
171 |
* @return The name of the parameter, either provided by the class |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
172 |
* file or synthesized if the class file does not provide |
fa61a37ed42b
8016285: Add java.lang.reflect.Parameter.isNamePresent()
emc
parents:
18546
diff
changeset
|
173 |
* a name. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
174 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
175 |
public String getName() { |
25979 | 176 |
// Note: empty strings as parameter names are now outlawed. |
17177 | 177 |
// The .equals("") is for compatibility with current JVM |
178 |
// behavior. It may be removed at some point. |
|
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
179 |
if(name == null || name.equals("")) |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
180 |
return "arg" + index; |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
181 |
else |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
182 |
return name; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
183 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
184 |
|
20506
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
19031
diff
changeset
|
185 |
// Package-private accessor to the real name field. |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
19031
diff
changeset
|
186 |
String getRealName() { |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
19031
diff
changeset
|
187 |
return name; |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
19031
diff
changeset
|
188 |
} |
d826dd5f8e10
8020981: Update methods of java.lang.reflect.Parameter to throw correct exceptions
emc
parents:
19031
diff
changeset
|
189 |
|
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
190 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
191 |
* Returns a {@code Type} object that identifies the parameterized |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
192 |
* type for the parameter represented by this {@code Parameter} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
193 |
* object. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
194 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
195 |
* @return a {@code Type} object identifying the parameterized |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
196 |
* type of the parameter represented by this object |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
197 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
198 |
public Type getParameterizedType() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
199 |
Type tmp = parameterTypeCache; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
200 |
if (null == tmp) { |
27491
1c0081281564
8055063: Parameter#toString() fails w/ AIOOBE for ctr of inner class w/ generic type
emc
parents:
25991
diff
changeset
|
201 |
tmp = executable.getAllGenericParameterTypes()[index]; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
202 |
parameterTypeCache = tmp; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
203 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
204 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
205 |
return tmp; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
206 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
207 |
|
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
27491
diff
changeset
|
208 |
private transient volatile Type parameterTypeCache; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
209 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
210 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
211 |
* Returns a {@code Class} object that identifies the |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
212 |
* declared type for the parameter represented by this |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
213 |
* {@code Parameter} object. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
214 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
215 |
* @return a {@code Class} object identifying the declared |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
216 |
* type of the parameter represented by this object |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
217 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
218 |
public Class<?> getType() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
219 |
Class<?> tmp = parameterClassCache; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
220 |
if (null == tmp) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
221 |
tmp = executable.getParameterTypes()[index]; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
222 |
parameterClassCache = tmp; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
223 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
224 |
return tmp; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
225 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
226 |
|
17450
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
227 |
/** |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
228 |
* Returns an AnnotatedType object that represents the use of a type to |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
229 |
* specify the type of the formal parameter represented by this Parameter. |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
230 |
* |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
231 |
* @return an {@code AnnotatedType} object representing the use of a type |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
232 |
* to specify the type of the formal parameter represented by this |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
233 |
* Parameter |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
234 |
*/ |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
235 |
public AnnotatedType getAnnotatedType() { |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
236 |
// no caching for now |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
237 |
return executable.getAnnotatedParameterTypes()[index]; |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
238 |
} |
0f704861915e
8007073: Implement Core Reflection for Type Annotations on parameters
jfranck
parents:
17177
diff
changeset
|
239 |
|
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
27491
diff
changeset
|
240 |
private transient volatile Class<?> parameterClassCache; |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
241 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
242 |
/** |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
243 |
* Returns {@code true} if this parameter is implicitly declared |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
244 |
* in source code; returns {@code false} otherwise. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
245 |
* |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
246 |
* @return true if and only if this parameter is implicitly |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
247 |
* declared as defined by <cite>The Java™ Language |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
248 |
* Specification</cite>. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
249 |
*/ |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
250 |
public boolean isImplicit() { |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
251 |
return Modifier.isMandated(getModifiers()); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
252 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
253 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
254 |
/** |
15655
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
255 |
* Returns {@code true} if this parameter is neither implicitly |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
256 |
* nor explicitly declared in source code; returns {@code false} |
d9ab4d9ee4f2
8007405: Update java.lang.reflect API to replace SYNTHESIZED with MANDATED
alanb
parents:
15534
diff
changeset
|
257 |
* otherwise. |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
258 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
259 |
* @jls 13.1 The Form of a Binary |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
260 |
* @return true if and only if this parameter is a synthetic |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
261 |
* construct as defined by |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
262 |
* <cite>The Java™ Language Specification</cite>. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
263 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
264 |
public boolean isSynthetic() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
265 |
return Modifier.isSynthetic(getModifiers()); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
266 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
267 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
268 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
269 |
* Returns {@code true} if this parameter represents a variable |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
270 |
* argument list; returns {@code false} otherwise. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
271 |
* |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
272 |
* @return {@code true} if an only if this parameter represents a |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
273 |
* variable argument list. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
274 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
275 |
public boolean isVarArgs() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
276 |
return executable.isVarArgs() && |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
277 |
index == executable.getParameterCount() - 1; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
278 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
279 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
280 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
281 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
282 |
* {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
283 |
* @throws NullPointerException {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
284 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
285 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
286 |
Objects.requireNonNull(annotationClass); |
15511
8f45487ac694
8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents:
15294
diff
changeset
|
287 |
return annotationClass.cast(declaredAnnotations().get(annotationClass)); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
288 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
289 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
290 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
291 |
* {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
292 |
* @throws NullPointerException {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
293 |
*/ |
15659
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
294 |
@Override |
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
295 |
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
296 |
Objects.requireNonNull(annotationClass); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
297 |
|
21316
ca0a7cd228c9
8004912: Repeating annotations - getAnnotationsByType(Class<T>) is not working as expected for few inheritance scenarios
alundblad
parents:
20506
diff
changeset
|
298 |
return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
299 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
300 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
301 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
302 |
* {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
303 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
304 |
public Annotation[] getDeclaredAnnotations() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
305 |
return executable.getParameterAnnotations()[index]; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
306 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
307 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
308 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
309 |
* @throws NullPointerException {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
310 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
311 |
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
312 |
// Only annotations on classes are inherited, for all other |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
313 |
// objects getDeclaredAnnotation is the same as |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
314 |
// getAnnotation. |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
315 |
return getAnnotation(annotationClass); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
316 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
317 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
318 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
319 |
* @throws NullPointerException {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
320 |
*/ |
15659
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
321 |
@Override |
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
322 |
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) { |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
323 |
// Only annotations on classes are inherited, for all other |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
324 |
// objects getDeclaredAnnotations is the same as |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
325 |
// getAnnotations. |
15659
e575dab44ff5
8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents:
15655
diff
changeset
|
326 |
return getAnnotationsByType(annotationClass); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
327 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
328 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
329 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
330 |
* {@inheritDoc} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
331 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
332 |
public Annotation[] getAnnotations() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
333 |
return getDeclaredAnnotations(); |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
334 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
335 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
336 |
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations; |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
337 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
338 |
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
339 |
if(null == declaredAnnotations) { |
22581
e868cde95050
8032779: Update code in java.lang to use newer language features
psandoz
parents:
21316
diff
changeset
|
340 |
declaredAnnotations = new HashMap<>(); |
e868cde95050
8032779: Update code in java.lang to use newer language features
psandoz
parents:
21316
diff
changeset
|
341 |
for (Annotation a : getDeclaredAnnotations()) |
e868cde95050
8032779: Update code in java.lang to use newer language features
psandoz
parents:
21316
diff
changeset
|
342 |
declaredAnnotations.put(a.annotationType(), a); |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
343 |
} |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
344 |
return declaredAnnotations; |
17177 | 345 |
} |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
346 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
diff
changeset
|
347 |
} |