2
|
1 |
/*
|
|
2 |
* Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.jdi;
|
|
27 |
|
|
28 |
import java.util.List;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* A static or instance method in the target VM. See {@link TypeComponent}
|
|
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 |
public interface Method extends TypeComponent, Locatable, Comparable<Method> {
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Returns a text representation of the return type,
|
|
46 |
* as specified in the declaration of this method.
|
|
47 |
* <P>
|
|
48 |
* This type name is always available even if
|
|
49 |
* the type has not yet been created or loaded.
|
|
50 |
*
|
|
51 |
* @return a String containing the return type name.
|
|
52 |
*/
|
|
53 |
String returnTypeName();
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Returns the return type,
|
|
57 |
* as specified in the declaration of this method.
|
|
58 |
* <P>
|
|
59 |
* Note: if the return type of this method is a reference type (class,
|
|
60 |
* interface, or array) and it has not been created or loaded
|
|
61 |
* by the declaring type's class loader - that is,
|
|
62 |
* {@link TypeComponent#declaringType <CODE>declaringType()</CODE>}
|
|
63 |
* <CODE>.classLoader()</CODE>,
|
|
64 |
* then ClassNotLoadedException will be thrown.
|
|
65 |
* Also, a reference type may have been loaded but not yet prepared,
|
|
66 |
* in which case the type will be returned
|
|
67 |
* but attempts to perform some operations on the returned type
|
|
68 |
* (e.g. {@link ReferenceType#fields() fields()}) will throw
|
|
69 |
* a {@link ClassNotPreparedException}.
|
|
70 |
* Use {@link ReferenceType#isPrepared()} to determine if
|
|
71 |
* a reference type is prepared.
|
|
72 |
*
|
|
73 |
* @see Type
|
|
74 |
* @see Field#type() Field.type() - for usage examples
|
|
75 |
* @return the return {@link Type} of this method.
|
|
76 |
* @throws ClassNotLoadedException if the type has not yet been
|
|
77 |
* created or loaded
|
|
78 |
* through the appropriate class loader.
|
|
79 |
*/
|
|
80 |
Type returnType() throws ClassNotLoadedException;
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Returns a list containing a text representation of the type
|
|
84 |
* of each formal parameter of this method.
|
|
85 |
* <P>
|
|
86 |
* This list is always available even if
|
|
87 |
* the types have not yet been created or loaded.
|
|
88 |
*
|
|
89 |
* @return a {@link java.util.List List} of {@link String},
|
|
90 |
* one List element for each parameter of this method.
|
|
91 |
* Each element represents the type of a formal parameter
|
|
92 |
* as specified at compile-time.
|
|
93 |
* If the formal parameter was declared with an ellipsis, then
|
|
94 |
* it is represented as an array of the type before the ellipsis.
|
|
95 |
*
|
|
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 <CODE>declaringType()</CODE>}
|
|
108 |
* <CODE>.classLoader()</CODE>,
|
|
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</code> if the method is declared abstract;
|
|
135 |
* false otherwise.
|
|
136 |
*/
|
|
137 |
boolean isAbstract();
|
|
138 |
|
|
139 |
/**
|
|
140 |
* Determine if this method is synchronized.
|
|
141 |
*
|
|
142 |
* @return <code>true</code> if the method is declared synchronized;
|
|
143 |
* false otherwise.
|
|
144 |
*/
|
|
145 |
boolean isSynchronized();
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Determine if this method is native.
|
|
149 |
*
|
|
150 |
* @return <code>true</code> if the method is declared native;
|
|
151 |
* false otherwise.
|
|
152 |
*/
|
|
153 |
boolean isNative();
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Determine if this method accepts a variable number of arguments.
|
|
157 |
*
|
|
158 |
* @return <code>true</code> if the method accepts a variable number
|
|
159 |
* of arguments, false otherwise.
|
|
160 |
*
|
|
161 |
* @since 1.5
|
|
162 |
*/
|
|
163 |
boolean isVarArgs();
|
|
164 |
|
|
165 |
/**
|
|
166 |
* Determine if this method is a bridge method. Bridge
|
|
167 |
* methods are defined in the
|
|
168 |
* <a href="http://java.sun.com/docs/books/jls">
|
|
169 |
* "Java<sup><font size=-2>TM</font></sup>
|
|
170 |
* Language Specification, 3rd Edition.</a>
|
|
171 |
*
|
|
172 |
* @return <code>true</code> if the method is a bridge method,
|
|
173 |
* false otherwise.
|
|
174 |
*
|
|
175 |
* @since 1.5
|
|
176 |
*/
|
|
177 |
boolean isBridge();
|
|
178 |
|
|
179 |
/**
|
|
180 |
* Determine if this method is a constructor.
|
|
181 |
*
|
|
182 |
* @return <code>true</code> if the method is a constructor;
|
|
183 |
* false otherwise.
|
|
184 |
*/
|
|
185 |
boolean isConstructor();
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Determine if this method is a static initializer.
|
|
189 |
*
|
|
190 |
* @return <code>true</code> if the method is a static initializer;
|
|
191 |
* false otherwise.
|
|
192 |
*/
|
|
193 |
boolean isStaticInitializer();
|
|
194 |
|
|
195 |
/**
|
|
196 |
* Determine if this method is obsolete.
|
|
197 |
*
|
|
198 |
* @return <code>true</code> if this method has been made obsolete by a
|
|
199 |
* {@link VirtualMachine#redefineClasses} operation.
|
|
200 |
*
|
|
201 |
* @since 1.4
|
|
202 |
*/
|
|
203 |
boolean isObsolete();
|
|
204 |
|
|
205 |
/**
|
|
206 |
* Returns a list containing a {@link Location} object for
|
|
207 |
* each executable source line in this method.
|
|
208 |
* <P>
|
|
209 |
* This method is equivalent to
|
|
210 |
* <code>allLineLocations(vm.getDefaultStratum(),null)</code> -
|
|
211 |
* see {@link #allLineLocations(String,String)}
|
|
212 |
* for more information.
|
|
213 |
*
|
|
214 |
* @return a List of all source line {@link Location} objects.
|
|
215 |
*
|
|
216 |
* @throws AbsentInformationException if there is no line
|
|
217 |
* number information for this (non-native, non-abstract)
|
|
218 |
* method.
|
|
219 |
*/
|
|
220 |
List<Location> allLineLocations() throws AbsentInformationException;
|
|
221 |
|
|
222 |
/**
|
|
223 |
* Returns a list containing a {@link Location} object for
|
|
224 |
* each executable source line in this method.
|
|
225 |
* <P>
|
|
226 |
* Each location maps a source line to a range of code
|
|
227 |
* indices.
|
|
228 |
* The beginning of the range can be determined through
|
|
229 |
* {@link Location#codeIndex}.
|
|
230 |
* The returned list is ordered by code index
|
|
231 |
* (from low to high).
|
|
232 |
* <P>
|
|
233 |
* The returned list may contain multiple locations for a
|
|
234 |
* particular line number, if the compiler and/or VM has
|
|
235 |
* mapped that line to two or more disjoint code index ranges.
|
|
236 |
* <P>
|
|
237 |
* If the method is native or abstract, an empty list is
|
|
238 |
* returned.
|
|
239 |
* <P>
|
|
240 |
* Returned list is for the specified <i>stratum</i>
|
|
241 |
* (see {@link Location} for a description of strata).
|
|
242 |
*
|
|
243 |
* @param stratum The stratum to retrieve information from
|
|
244 |
* or <code>null</code> for the {@link ReferenceType#defaultStratum()}
|
|
245 |
*
|
|
246 |
* @param sourceName Return locations only within this
|
|
247 |
* source file or <code>null</code> to return locations.
|
|
248 |
*
|
|
249 |
* @return a List of all source line {@link Location} objects.
|
|
250 |
*
|
|
251 |
* @throws AbsentInformationException if there is no line
|
|
252 |
* number information for this (non-native, non-abstract)
|
|
253 |
* method. Or if <i>sourceName</i> is non-<code>null</code>
|
|
254 |
* and source name information is not present.
|
|
255 |
*
|
|
256 |
* @since 1.4
|
|
257 |
*/
|
|
258 |
List<Location> allLineLocations(String stratum, String sourceName)
|
|
259 |
throws AbsentInformationException;
|
|
260 |
|
|
261 |
/**
|
|
262 |
* Returns a List containing all {@link Location} objects
|
|
263 |
* that map to the given line number.
|
|
264 |
* <P>
|
|
265 |
* This method is equivalent to
|
|
266 |
* <code>locationsOfLine(vm.getDefaultStratum(), null,
|
|
267 |
* lineNumber)</code> -
|
|
268 |
* see {@link
|
|
269 |
* #locationsOfLine(java.lang.String,java.lang.String,int)}
|
|
270 |
* for more information.
|
|
271 |
*
|
|
272 |
* @param lineNumber the line number
|
|
273 |
*
|
|
274 |
* @return a List of {@link Location} objects that map to
|
|
275 |
* the given line number.
|
|
276 |
*
|
|
277 |
* @throws AbsentInformationException if there is no line
|
|
278 |
* number information for this method.
|
|
279 |
*/
|
|
280 |
List<Location> locationsOfLine(int lineNumber) throws AbsentInformationException;
|
|
281 |
|
|
282 |
/**
|
|
283 |
* Returns a List containing all {@link Location} objects
|
|
284 |
* that map to the given line number and source name.
|
|
285 |
* <P>
|
|
286 |
* Returns a list containing each {@link Location} that maps
|
|
287 |
* to the given line. The returned list will contain a
|
|
288 |
* location for each disjoint range of code indices that have
|
|
289 |
* been assigned to the given line by the compiler and/or
|
|
290 |
* VM. Each returned location corresponds to the beginning of
|
|
291 |
* this range. An empty list will be returned if there is no
|
|
292 |
* executable code at the specified line number; specifically,
|
|
293 |
* native and abstract methods will always return an empty
|
|
294 |
* list.
|
|
295 |
* <p>
|
|
296 |
* Returned list is for the specified <i>stratum</i>
|
|
297 |
* (see {@link Location} for a description of strata).
|
|
298 |
*
|
|
299 |
* @param stratum the stratum to use for comparing line number
|
|
300 |
* and source name, or null to use the default
|
|
301 |
* stratum
|
|
302 |
* @param sourceName the source name containing the
|
|
303 |
* line number, or null to match all
|
|
304 |
* source names
|
|
305 |
* @param lineNumber the line number
|
|
306 |
*
|
|
307 |
* @return a List of {@link Location} objects that map to
|
|
308 |
* the given line number.
|
|
309 |
*
|
|
310 |
* @throws AbsentInformationException if there is no line
|
|
311 |
* number information for this method.
|
|
312 |
* Or if <i>sourceName</i> is non-<code>null</code>
|
|
313 |
* and source name information is not present.
|
|
314 |
*
|
|
315 |
* @since 1.4
|
|
316 |
*/
|
|
317 |
List<Location> locationsOfLine(String stratum, String sourceName,
|
|
318 |
int lineNumber)
|
|
319 |
throws AbsentInformationException;
|
|
320 |
|
|
321 |
/**
|
|
322 |
* Returns a {@link Location} for the given code index.
|
|
323 |
*
|
|
324 |
* @return the {@link Location} corresponding to the
|
|
325 |
* given code index or null if the specified code index is not a
|
|
326 |
* valid code index for this method (native and abstract methods
|
|
327 |
* will always return null).
|
|
328 |
*/
|
|
329 |
Location locationOfCodeIndex(long codeIndex);
|
|
330 |
|
|
331 |
/**
|
|
332 |
* Returns a list containing each {@link LocalVariable} declared
|
|
333 |
* in this method. The list includes any variable declared in any
|
|
334 |
* scope within the method. It may contain multiple variables of the
|
|
335 |
* same name declared within disjoint scopes. Arguments are considered
|
|
336 |
* local variables and will be present in the returned list.
|
|
337 |
*
|
|
338 |
* If local variable information is not available, values of
|
|
339 |
* actual arguments to method invocations can be obtained
|
|
340 |
* by using the method {@link StackFrame#getArgumentValues()}
|
|
341 |
*
|
|
342 |
* @return the list of {@link LocalVariable} objects which mirror
|
|
343 |
* local variables declared in this method in the target VM.
|
|
344 |
* If there are no local variables, a zero-length list is returned.
|
|
345 |
* @throws AbsentInformationException if there is no variable
|
|
346 |
* information for this method.
|
|
347 |
* Generally, local variable information is not available for
|
|
348 |
* native or abstract methods (that is, their argument name
|
|
349 |
* information is not available), thus they will throw this exception.
|
|
350 |
*/
|
|
351 |
List<LocalVariable> variables() throws AbsentInformationException;
|
|
352 |
|
|
353 |
/**
|
|
354 |
* Returns a list containing each {@link LocalVariable} of a
|
|
355 |
* given name in this method.
|
|
356 |
* Multiple variables can be returned
|
|
357 |
* if the same variable name is used in disjoint
|
|
358 |
* scopes within the method.
|
|
359 |
*
|
|
360 |
* @return the list of {@link LocalVariable} objects of the given
|
|
361 |
* name.
|
|
362 |
* If there are no matching local variables, a zero-length list
|
|
363 |
* is returned.
|
|
364 |
* @throws AbsentInformationException if there is no variable
|
|
365 |
* information for this method.
|
|
366 |
* Generally, local variable information is not available for
|
|
367 |
* native or abstract methods (that is, their argument name
|
|
368 |
* information is not available), thus they will throw this exception.
|
|
369 |
*/
|
|
370 |
List<LocalVariable> variablesByName(String name)
|
|
371 |
throws AbsentInformationException;
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Returns a list containing each {@link LocalVariable} that is
|
|
375 |
* declared as an argument of this method.
|
|
376 |
*
|
|
377 |
* If local variable information is not available, values of
|
|
378 |
* actual arguments to method invocations can be obtained
|
|
379 |
* by using the method {@link StackFrame#getArgumentValues()}
|
|
380 |
*
|
|
381 |
* @return the list of {@link LocalVariable} arguments.
|
|
382 |
* If there are no arguments, a zero-length list is returned.
|
|
383 |
* @throws AbsentInformationException if there is no variable
|
|
384 |
* information for this method.
|
|
385 |
* Generally, local variable information is not available for
|
|
386 |
* native or abstract methods (that is, their argument name
|
|
387 |
* information is not available), thus they will throw this exception.
|
|
388 |
*/
|
|
389 |
List<LocalVariable> arguments() throws AbsentInformationException;
|
|
390 |
|
|
391 |
/**
|
|
392 |
* Returns an array containing the bytecodes for this method.
|
|
393 |
* <P>
|
|
394 |
* Not all target virtual machines support this operation.
|
|
395 |
* Use {@link VirtualMachine#canGetBytecodes()}
|
|
396 |
* to determine if the operation is supported.
|
|
397 |
*
|
|
398 |
* @return the array of bytecodes; abstract and native methods
|
|
399 |
* will return a zero-length array.
|
|
400 |
* @throws java.lang.UnsupportedOperationException if
|
|
401 |
* the target virtual machine does not support
|
|
402 |
* the retrieval of bytecodes.
|
|
403 |
*/
|
|
404 |
byte[] bytecodes();
|
|
405 |
|
|
406 |
/**
|
|
407 |
* Returns the {@link Location} of this method, if there
|
|
408 |
* is executable code associated with it.
|
|
409 |
*
|
|
410 |
* @return the {@link Location} of this mirror, or null if
|
|
411 |
* this is an abstract method; native methods will return a
|
|
412 |
* Location object whose codeIndex is -1.
|
|
413 |
*/
|
|
414 |
Location location();
|
|
415 |
|
|
416 |
/**
|
|
417 |
* Compares the specified Object with this method for equality.
|
|
418 |
*
|
|
419 |
* @return true if the Object is a method and if both
|
|
420 |
* mirror the same method (declared in the same class or interface, in
|
|
421 |
* the same VM).
|
|
422 |
*/
|
|
423 |
boolean equals(Object obj);
|
|
424 |
|
|
425 |
/**
|
|
426 |
* Returns the hash code value for this Method.
|
|
427 |
*
|
|
428 |
* @return the integer hash code
|
|
429 |
*/
|
|
430 |
int hashCode();
|
|
431 |
}
|