< prev index next >

src/java.base/share/classes/java/lang/reflect/Parameter.java

Print this page

 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 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.Objects;
 31 import sun.reflect.annotation.AnnotationSupport;
 32 
 33 /**
 34  * Information about method parameters.
 35  *
 36  * A {@code Parameter} provides information about method parameters,
 37  * including its name and modifiers.  It also provides an alternate
 38  * means of obtaining attributes for the parameter.
 39  *
 40  * @since 1.8
 41  */
 42 public final class Parameter implements AnnotatedElement {
 43 
 44     private final String name;
 45     private final int modifiers;
 46     private final Executable executable;
 47     private final int index;
 48 
 49     /**

144     /**
145      * {@return the {@code Executable} declaring this parameter}
146      */
147     public Executable getDeclaringExecutable() {
148         return executable;
149     }
150 
151     /**
152      * {@return the Java language {@linkplain Modifier modifiers} for
153      * the parameter represented by this object}
154      *
155      * @jls 8.4.1 Formal Parameters
156      * @see <a
157      * href="{@docRoot}/java.base/java/lang/reflect/package-summary.html#LanguageJvmModel">Java
158      * programming language and JVM modeling in core reflection</a>
159      */
160     public int getModifiers() {
161         return modifiers;
162     }
163 














164     /**
165      * Returns the name of the parameter.  If the parameter's name is
166      * {@linkplain #isNamePresent() present}, then this method returns
167      * the name provided by the class file. Otherwise, this method
168      * synthesizes a name of the form argN, where N is the index of
169      * the parameter in the descriptor of the method which declares
170      * the parameter.
171      *
172      * @return The name of the parameter, either provided by the class
173      *         file or synthesized if the class file does not provide
174      *         a name.
175      */
176     public String getName() {
177         // Note: empty strings as parameter names are now outlawed.
178         // The .isEmpty() is for compatibility with current JVM
179         // behavior.  It may be removed at some point.
180         if(name == null || name.isEmpty())
181             return "arg" + index;
182         else
183             return name;

 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 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     /**

145     /**
146      * {@return the {@code Executable} declaring this parameter}
147      */
148     public Executable getDeclaringExecutable() {
149         return executable;
150     }
151 
152     /**
153      * {@return the Java language {@linkplain Modifier modifiers} for
154      * the parameter represented by this object}
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 AccessFlag.maskToAccessFlags(getModifiers(),
176                                             AccessFlag.Location.METHOD_PARAMETER);
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;
197         else
198             return name;
< prev index next >