32 * for general information about Field and Method mirrors.
33 *
34 * @see ObjectReference
35 * @see ReferenceType
36 *
37 * @author Robert Field
38 * @author Gordon Hirsch
39 * @author James McIlree
40 * @since 1.3
41 */
42 @jdk.Exported
43 public interface Method extends TypeComponent, Locatable, Comparable<Method> {
44
45 /**
46 * Returns a text representation of the return type,
47 * as specified in the declaration of this method.
48 * <P>
49 * This type name is always available even if
50 * the type has not yet been created or loaded.
51 *
52 * @return a String containing the return type name.
53 */
54 String returnTypeName();
55
56 /**
57 * Returns the return type,
58 * as specified in the declaration of this method.
59 * <P>
60 * Note: if the return type of this method is a reference type (class,
61 * interface, or array) and it has not been created or loaded
62 * by the declaring type's class loader - that is,
63 * {@link TypeComponent#declaringType <CODE>declaringType()</CODE>}
64 * <CODE>.classLoader()</CODE>,
65 * then ClassNotLoadedException will be thrown.
66 * Also, a reference type may have been loaded but not yet prepared,
67 * in which case the type will be returned
68 * but attempts to perform some operations on the returned type
69 * (e.g. {@link ReferenceType#fields() fields()}) will throw
70 * a {@link ClassNotPreparedException}.
71 * Use {@link ReferenceType#isPrepared()} to determine if
72 * a reference type is prepared.
73 *
74 * @see Type
75 * @see Field#type() Field.type() - for usage examples
76 * @return the return {@link Type} of this method.
77 * @throws ClassNotLoadedException if the type has not yet been
78 * created or loaded
79 * through the appropriate class loader.
80 */
81 Type returnType() throws ClassNotLoadedException;
82
83 /**
84 * Returns a list containing a text representation of the type
85 * of each formal parameter of this method.
86 * <P>
87 * This list is always available even if
88 * the types have not yet been created or loaded.
89 *
90 * @return a {@link java.util.List List} of {@link String},
91 * one List element for each parameter of this method.
92 * Each element represents the type of a formal parameter
93 * as specified at compile-time.
94 * If the formal parameter was declared with an ellipsis, then
95 * it is represented as an array of the type before the ellipsis.
96 *
97 */
98 List<String> argumentTypeNames();
99
100 /**
101 * Returns a list containing the type
102 * of each formal parameter of this method.
103 * <P>
104 * Note: if there is any parameter whose type
105 * is a reference type (class, interface, or array)
106 * and it has not been created or loaded
107 * by the declaring type's class loader - that is,
108 * {@link TypeComponent#declaringType <CODE>declaringType()</CODE>}
109 * <CODE>.classLoader()</CODE>,
110 * then ClassNotLoadedException will be thrown.
111 * Also, a reference type may have been loaded but not yet prepared,
112 * in which case the list will be returned
113 * but attempts to perform some operations on the type
114 * (e.g. {@link ReferenceType#fields() fields()}) will throw
115 * a {@link ClassNotPreparedException}.
116 * Use {@link ReferenceType#isPrepared()} to determine if
117 * a reference type is prepared.
118 *
119 * @see Type
120 * @return return a {@link java.util.List List} of {@link Type},
121 * one List element for each parameter of this method.
122 * Each element represents the type of a formal parameter
123 * as specified at compile-time.
124 * If the formal parameter was declared with an ellipsis, then
125 * it is represented as an array of the type before the ellipsis.
126 *
127 * @throws ClassNotLoadedException if the type has not yet been loaded
128 * through the appropriate class loader.
129 */
130 List<Type> argumentTypes() throws ClassNotLoadedException;
131
132 /**
133 * Determine if this method is abstract.
134 *
135 * @return <code>true</code> if the method is declared abstract;
136 * false otherwise.
137 */
138 boolean isAbstract();
139
140 /**
141 * Determine if this method is a default method
142 *
143 * @return <code>true</code> if the method is declared default;
144 * false otherwise
145 *
146 * @since 1.8
147 */
148 default boolean isDefault() {
149 throw new UnsupportedOperationException();
150 }
151
152 /**
153 * Determine if this method is synchronized.
154 *
155 * @return <code>true</code> if the method is declared synchronized;
156 * false otherwise.
157 */
158 boolean isSynchronized();
159
160 /**
161 * Determine if this method is native.
162 *
163 * @return <code>true</code> if the method is declared native;
164 * false otherwise.
165 */
166 boolean isNative();
167
168 /**
169 * Determine if this method accepts a variable number of arguments.
170 *
171 * @return <code>true</code> if the method accepts a variable number
172 * of arguments, false otherwise.
173 *
174 * @since 1.5
175 */
176 boolean isVarArgs();
177
178 /**
179 * Determine if this method is a bridge method. Bridge
180 * methods are defined in
181 * <cite>The Java™ Language Specification</cite>.
182 *
183 * @return <code>true</code> if the method is a bridge method,
184 * false otherwise.
185 *
186 * @since 1.5
187 */
188 boolean isBridge();
189
190 /**
191 * Determine if this method is a constructor.
192 *
193 * @return <code>true</code> if the method is a constructor;
194 * false otherwise.
195 */
196 boolean isConstructor();
197
198 /**
199 * Determine if this method is a static initializer.
200 *
201 * @return <code>true</code> if the method is a static initializer;
202 * false otherwise.
203 */
204 boolean isStaticInitializer();
205
206 /**
207 * Determine if this method is obsolete.
208 *
209 * @return <code>true</code> if this method has been made obsolete by a
210 * {@link VirtualMachine#redefineClasses} operation.
211 *
212 * @since 1.4
213 */
214 boolean isObsolete();
215
216 /**
217 * Returns a list containing a {@link Location} object for
218 * each executable source line in this method.
219 * <P>
220 * This method is equivalent to
221 * <code>allLineLocations(vm.getDefaultStratum(),null)</code> -
222 * see {@link #allLineLocations(String,String)}
223 * for more information.
224 *
225 * @return a List of all source line {@link Location} objects.
226 *
227 * @throws AbsentInformationException if there is no line
228 * number information for this (non-native, non-abstract)
229 * method.
230 */
231 List<Location> allLineLocations() throws AbsentInformationException;
232
233 /**
234 * Returns a list containing a {@link Location} object for
235 * each executable source line in this method.
236 * <P>
237 * Each location maps a source line to a range of code
238 * indices.
239 * The beginning of the range can be determined through
240 * {@link Location#codeIndex}.
241 * The returned list is ordered by code index
242 * (from low to high).
243 * <P>
244 * The returned list may contain multiple locations for a
245 * particular line number, if the compiler and/or VM has
246 * mapped that line to two or more disjoint code index ranges.
247 * <P>
248 * If the method is native or abstract, an empty list is
249 * returned.
250 * <P>
251 * Returned list is for the specified <i>stratum</i>
252 * (see {@link Location} for a description of strata).
253 *
254 * @param stratum The stratum to retrieve information from
255 * or <code>null</code> for the {@link ReferenceType#defaultStratum()}
256 *
257 * @param sourceName Return locations only within this
258 * source file or <code>null</code> to return locations.
259 *
260 * @return a List of all source line {@link Location} objects.
261 *
262 * @throws AbsentInformationException if there is no line
263 * number information for this (non-native, non-abstract)
264 * method. Or if <i>sourceName</i> is non-<code>null</code>
265 * and source name information is not present.
266 *
267 * @since 1.4
268 */
269 List<Location> allLineLocations(String stratum, String sourceName)
270 throws AbsentInformationException;
271
272 /**
273 * Returns a List containing all {@link Location} objects
274 * that map to the given line number.
275 * <P>
276 * This method is equivalent to
277 * <code>locationsOfLine(vm.getDefaultStratum(), null,
278 * lineNumber)</code> -
279 * see {@link
280 * #locationsOfLine(java.lang.String,java.lang.String,int)}
281 * for more information.
282 *
283 * @param lineNumber the line number
284 *
285 * @return a List of {@link Location} objects that map to
286 * the given line number.
287 *
288 * @throws AbsentInformationException if there is no line
289 * number information for this method.
290 */
291 List<Location> locationsOfLine(int lineNumber) throws AbsentInformationException;
292
293 /**
294 * Returns a List containing all {@link Location} objects
295 * that map to the given line number and source name.
296 * <P>
297 * Returns a list containing each {@link Location} that maps
298 * to the given line. The returned list will contain a
303 * executable code at the specified line number; specifically,
304 * native and abstract methods will always return an empty
305 * list.
306 * <p>
307 * Returned list is for the specified <i>stratum</i>
308 * (see {@link Location} for a description of strata).
309 *
310 * @param stratum the stratum to use for comparing line number
311 * and source name, or null to use the default
312 * stratum
313 * @param sourceName the source name containing the
314 * line number, or null to match all
315 * source names
316 * @param lineNumber the line number
317 *
318 * @return a List of {@link Location} objects that map to
319 * the given line number.
320 *
321 * @throws AbsentInformationException if there is no line
322 * number information for this method.
323 * Or if <i>sourceName</i> is non-<code>null</code>
324 * and source name information is not present.
325 *
326 * @since 1.4
327 */
328 List<Location> locationsOfLine(String stratum, String sourceName,
329 int lineNumber)
330 throws AbsentInformationException;
331
332 /**
333 * Returns a {@link Location} for the given code index.
334 *
335 * @return the {@link Location} corresponding to the
336 * given code index or null if the specified code index is not a
337 * valid code index for this method (native and abstract methods
338 * will always return null).
339 */
340 Location locationOfCodeIndex(long codeIndex);
341
342 /**
343 * Returns a list containing each {@link LocalVariable} declared
419 * is executable code associated with it.
420 *
421 * @return the {@link Location} of this mirror, or null if
422 * this is an abstract method; native methods will return a
423 * Location object whose codeIndex is -1.
424 */
425 Location location();
426
427 /**
428 * Compares the specified Object with this method for equality.
429 *
430 * @return true if the Object is a method and if both
431 * mirror the same method (declared in the same class or interface, in
432 * the same VM).
433 */
434 boolean equals(Object obj);
435
436 /**
437 * Returns the hash code value for this Method.
438 *
439 * @return the integer hash code
440 */
441 int hashCode();
442 }
|
32 * for general information about Field and Method mirrors.
33 *
34 * @see ObjectReference
35 * @see ReferenceType
36 *
37 * @author Robert Field
38 * @author Gordon Hirsch
39 * @author James McIlree
40 * @since 1.3
41 */
42 @jdk.Exported
43 public interface Method extends TypeComponent, Locatable, Comparable<Method> {
44
45 /**
46 * Returns a text representation of the return type,
47 * as specified in the declaration of this method.
48 * <P>
49 * This type name is always available even if
50 * the type has not yet been created or loaded.
51 *
52 * @return a {@code String} containing the return type name.
53 */
54 String returnTypeName();
55
56 /**
57 * Returns the return type,
58 * as specified in the declaration of this method.
59 * <P>
60 * Note: if the return type of this method is a reference type (class,
61 * interface, or array) and it has not been created or loaded
62 * by the declaring type's class loader - that is,
63 * {@link TypeComponent#declaringType declaringType()}
64 * {@code .classLoader()},
65 * then ClassNotLoadedException will be thrown.
66 * Also, a reference type may have been loaded but not yet prepared,
67 * in which case the type will be returned
68 * but attempts to perform some operations on the returned type
69 * (e.g. {@link ReferenceType#fields() fields()}) will throw
70 * a {@link ClassNotPreparedException}.
71 * Use {@link ReferenceType#isPrepared()} to determine if
72 * a reference type is prepared.
73 *
74 * @see Type
75 * @see Field#type() Field.type() - for usage examples
76 * @return the return {@link Type} of this method.
77 * @throws ClassNotLoadedException if the type has not yet been
78 * created or loaded
79 * through the appropriate class loader.
80 */
81 Type returnType() throws ClassNotLoadedException;
82
83 /**
84 * Returns a list containing a text representation of the type
85 * of each formal parameter of this method.
86 * <P>
87 * This list is always available even if
88 * the types have not yet been created or loaded.
89 *
90 * @return a {@link java.util.List List} of {@link String},
91 * one List element for each parameter of this method.
92 * Each element represents the type of a formal parameter
93 * as specified at compile-time.
94 * If the formal parameter was declared with an ellipsis, then
95 * it is represented as an array of the type before the ellipsis.
96 */
97 List<String> argumentTypeNames();
98
99 /**
100 * Returns a list containing the type
101 * of each formal parameter of this method.
102 * <P>
103 * Note: if there is any parameter whose type
104 * is a reference type (class, interface, or array)
105 * and it has not been created or loaded
106 * by the declaring type's class loader - that is,
107 * {@link TypeComponent#declaringType declaringType()}
108 * {@code .classLoader()},
109 * then ClassNotLoadedException will be thrown.
110 * Also, a reference type may have been loaded but not yet prepared,
111 * in which case the list will be returned
112 * but attempts to perform some operations on the type
113 * (e.g. {@link ReferenceType#fields() fields()}) will throw
114 * a {@link ClassNotPreparedException}.
115 * Use {@link ReferenceType#isPrepared()} to determine if
116 * a reference type is prepared.
117 *
118 * @see Type
119 * @return return a {@link java.util.List List} of {@link Type},
120 * one List element for each parameter of this method.
121 * Each element represents the type of a formal parameter
122 * as specified at compile-time.
123 * If the formal parameter was declared with an ellipsis, then
124 * it is represented as an array of the type before the ellipsis.
125 *
126 * @throws ClassNotLoadedException if the type has not yet been loaded
127 * through the appropriate class loader.
128 */
129 List<Type> argumentTypes() throws ClassNotLoadedException;
130
131 /**
132 * Determine if this method is abstract.
133 *
134 * @return {@code true} if the method is declared abstract;
135 * {@code false} otherwise.
136 */
137 boolean isAbstract();
138
139 /**
140 * Determine if this method is a default method
141 *
142 * @return {@code true} if the method is declared default;
143 * {@code false} otherwise.
144 *
145 * @since 1.8
146 */
147 default boolean isDefault() {
148 throw new UnsupportedOperationException();
149 }
150
151 /**
152 * Determine if this method is synchronized.
153 *
154 * @return {@code true} if the method is declared synchronized;
155 * {@code false} otherwise.
156 */
157 boolean isSynchronized();
158
159 /**
160 * Determine if this method is native.
161 *
162 * @return {@code true} if the method is declared native;
163 * {@code false} otherwise.
164 */
165 boolean isNative();
166
167 /**
168 * Determine if this method accepts a variable number of arguments.
169 *
170 * @return {@code true} if the method accepts a variable number
171 * of arguments, {@code false} otherwise.
172 *
173 * @since 1.5
174 */
175 boolean isVarArgs();
176
177 /**
178 * Determine if this method is a bridge method. Bridge
179 * methods are defined in
180 * <cite>The Java™ Language Specification</cite>.
181 *
182 * @return {@code true} if the method is a bridge method,
183 * {@code false} otherwise.
184 *
185 * @since 1.5
186 */
187 boolean isBridge();
188
189 /**
190 * Determine if this method is a constructor.
191 *
192 * @return {@code true} if the method is a constructor;
193 * {@code false} otherwise.
194 */
195 boolean isConstructor();
196
197 /**
198 * Determine if this method is a static initializer.
199 *
200 * @return {@code true} if the method is a static initializer;
201 * {@code false} otherwise.
202 */
203 boolean isStaticInitializer();
204
205 /**
206 * Determine if this method is obsolete.
207 *
208 * @return {@code true} if this method has been made obsolete by a
209 * {@link VirtualMachine#redefineClasses} operation.
210 *
211 * @since 1.4
212 */
213 boolean isObsolete();
214
215 /**
216 * Returns a list containing a {@link Location} object for
217 * each executable source line in this method.
218 * <P>
219 * This method is equivalent to
220 * {@code allLineLocations(vm.getDefaultStratum(),null)} -
221 * see {@link #allLineLocations(String,String)}
222 * for more information.
223 *
224 * @return a List of all source line {@link Location} objects.
225 *
226 * @throws AbsentInformationException if there is no line
227 * number information for this (non-native, non-abstract)
228 * method.
229 */
230 List<Location> allLineLocations() throws AbsentInformationException;
231
232 /**
233 * Returns a list containing a {@link Location} object for
234 * each executable source line in this method.
235 * <P>
236 * Each location maps a source line to a range of code
237 * indices.
238 * The beginning of the range can be determined through
239 * {@link Location#codeIndex}.
240 * The returned list is ordered by code index
241 * (from low to high).
242 * <P>
243 * The returned list may contain multiple locations for a
244 * particular line number, if the compiler and/or VM has
245 * mapped that line to two or more disjoint code index ranges.
246 * <P>
247 * If the method is native or abstract, an empty list is
248 * returned.
249 * <P>
250 * Returned list is for the specified <i>stratum</i>
251 * (see {@link Location} for a description of strata).
252 *
253 * @param stratum The stratum to retrieve information from
254 * or {@code null} for the {@link ReferenceType#defaultStratum()}
255 *
256 * @param sourceName Return locations only within this
257 * source file or {@code null} to return locations.
258 *
259 * @return a List of all source line {@link Location} objects.
260 *
261 * @throws AbsentInformationException if there is no line
262 * number information for this (non-native, non-abstract)
263 * method. Or if <i>sourceName</i> is non-{@code null}
264 * and source name information is not present.
265 *
266 * @since 1.4
267 */
268 List<Location> allLineLocations(String stratum, String sourceName)
269 throws AbsentInformationException;
270
271 /**
272 * Returns a List containing all {@link Location} objects
273 * that map to the given line number.
274 * <P>
275 * This method is equivalent to
276 * {@code locationsOfLine(vm.getDefaultStratum(), null,
277 * lineNumber)} -
278 * see {@link
279 * #locationsOfLine(java.lang.String,java.lang.String,int)}
280 * for more information.
281 *
282 * @param lineNumber the line number
283 *
284 * @return a List of {@link Location} objects that map to
285 * the given line number.
286 *
287 * @throws AbsentInformationException if there is no line
288 * number information for this method.
289 */
290 List<Location> locationsOfLine(int lineNumber) throws AbsentInformationException;
291
292 /**
293 * Returns a List containing all {@link Location} objects
294 * that map to the given line number and source name.
295 * <P>
296 * Returns a list containing each {@link Location} that maps
297 * to the given line. The returned list will contain a
302 * executable code at the specified line number; specifically,
303 * native and abstract methods will always return an empty
304 * list.
305 * <p>
306 * Returned list is for the specified <i>stratum</i>
307 * (see {@link Location} for a description of strata).
308 *
309 * @param stratum the stratum to use for comparing line number
310 * and source name, or null to use the default
311 * stratum
312 * @param sourceName the source name containing the
313 * line number, or null to match all
314 * source names
315 * @param lineNumber the line number
316 *
317 * @return a List of {@link Location} objects that map to
318 * the given line number.
319 *
320 * @throws AbsentInformationException if there is no line
321 * number information for this method.
322 * Or if <i>sourceName</i> is non-{@code null}
323 * and source name information is not present.
324 *
325 * @since 1.4
326 */
327 List<Location> locationsOfLine(String stratum, String sourceName,
328 int lineNumber)
329 throws AbsentInformationException;
330
331 /**
332 * Returns a {@link Location} for the given code index.
333 *
334 * @return the {@link Location} corresponding to the
335 * given code index or null if the specified code index is not a
336 * valid code index for this method (native and abstract methods
337 * will always return null).
338 */
339 Location locationOfCodeIndex(long codeIndex);
340
341 /**
342 * Returns a list containing each {@link LocalVariable} declared
418 * is executable code associated with it.
419 *
420 * @return the {@link Location} of this mirror, or null if
421 * this is an abstract method; native methods will return a
422 * Location object whose codeIndex is -1.
423 */
424 Location location();
425
426 /**
427 * Compares the specified Object with this method for equality.
428 *
429 * @return true if the Object is a method and if both
430 * mirror the same method (declared in the same class or interface, in
431 * the same VM).
432 */
433 boolean equals(Object obj);
434
435 /**
436 * Returns the hash code value for this Method.
437 *
438 * @return the integer hash code.
439 */
440 int hashCode();
441 }
|