12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package java.lang.reflect;
26
27 import java.lang.annotation.*;
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.Set;
31 import java.util.Objects;
32 import sun.reflect.annotation.AnnotationSupport;
33
34 /**
35 * Information about method parameters.
36 *
37 * A {@code Parameter} provides information about method parameters,
38 * including its name and modifiers. It also provides an alternate
39 * means of obtaining attributes for the parameter.
40 *
41 * @since 1.8
42 */
43 public final class Parameter implements AnnotatedElement {
44
45 private final String name;
46 private final int modifiers;
47 private final Executable executable;
48 private final int index;
49
50 /**
51 * Package-private constructor for {@code Parameter}.
155 *
156 * @jls 8.4.1 Formal Parameters
157 * @see <a
158 * href="{@docRoot}/java.base/java/lang/reflect/package-summary.html#LanguageJvmModel">Java
159 * programming language and JVM modeling in core reflection</a>
160 */
161 public int getModifiers() {
162 return modifiers;
163 }
164
165 /**
166 * {@return an unmodifiable set of the {@linkplain AccessFlag
167 * access flags} for the parameter represented by this object,
168 * possibly empty}
169 *
170 * @see #getModifiers()
171 * @jvms 4.7.24 The MethodParameters Attribute
172 * @since 20
173 */
174 public Set<AccessFlag> accessFlags() {
175 return AccessibleObject.reflectionFactory.parseAccessFlags(getModifiers(),
176 AccessFlag.Location.METHOD_PARAMETER, getDeclaringExecutable().getDeclaringClass());
177 }
178
179 /**
180 * Returns the name of the parameter. If the parameter's name is
181 * {@linkplain #isNamePresent() present}, then this method returns
182 * the name provided by the class file. Otherwise, this method
183 * synthesizes a name of the form argN, where N is the index of
184 * the parameter in the descriptor of the method which declares
185 * the parameter.
186 *
187 * @return The name of the parameter, either provided by the class
188 * file or synthesized if the class file does not provide
189 * a name.
190 */
191 public String getName() {
192 // Note: empty strings as parameter names are now outlawed.
193 // The .isEmpty() is for compatibility with current JVM
194 // behavior. It may be removed at some point.
195 if(name == null || name.isEmpty())
196 return "arg" + index;
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package java.lang.reflect;
26
27 import java.lang.annotation.*;
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.Set;
31 import java.util.Objects;
32
33 import jdk.internal.reflect.AccessFlagSet;
34 import sun.reflect.annotation.AnnotationSupport;
35
36 /**
37 * Information about method parameters.
38 *
39 * A {@code Parameter} provides information about method parameters,
40 * including its name and modifiers. It also provides an alternate
41 * means of obtaining attributes for the parameter.
42 *
43 * @since 1.8
44 */
45 public final class Parameter implements AnnotatedElement {
46
47 private final String name;
48 private final int modifiers;
49 private final Executable executable;
50 private final int index;
51
52 /**
53 * Package-private constructor for {@code Parameter}.
157 *
158 * @jls 8.4.1 Formal Parameters
159 * @see <a
160 * href="{@docRoot}/java.base/java/lang/reflect/package-summary.html#LanguageJvmModel">Java
161 * programming language and JVM modeling in core reflection</a>
162 */
163 public int getModifiers() {
164 return modifiers;
165 }
166
167 /**
168 * {@return an unmodifiable set of the {@linkplain AccessFlag
169 * access flags} for the parameter represented by this object,
170 * possibly empty}
171 *
172 * @see #getModifiers()
173 * @jvms 4.7.24 The MethodParameters Attribute
174 * @since 20
175 */
176 public Set<AccessFlag> accessFlags() {
177 return AccessFlagSet.ofValidated(AccessFlagSet.METHOD_PARAMETER_FLAGS, modifiers);
178 }
179
180 /**
181 * Returns the name of the parameter. If the parameter's name is
182 * {@linkplain #isNamePresent() present}, then this method returns
183 * the name provided by the class file. Otherwise, this method
184 * synthesizes a name of the form argN, where N is the index of
185 * the parameter in the descriptor of the method which declares
186 * the parameter.
187 *
188 * @return The name of the parameter, either provided by the class
189 * file or synthesized if the class file does not provide
190 * a name.
191 */
192 public String getName() {
193 // Note: empty strings as parameter names are now outlawed.
194 // The .isEmpty() is for compatibility with current JVM
195 // behavior. It may be removed at some point.
196 if(name == null || name.isEmpty())
197 return "arg" + index;
|