Path: blob/master/src/jdk.jdi/share/classes/com/sun/jdi/Method.java
41159 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jdi;2627import java.util.List;2829/**30* A static or instance method in the target VM. See {@link TypeComponent}31* for general information about Field and Method mirrors.32*33* @see ObjectReference34* @see ReferenceType35*36* @author Robert Field37* @author Gordon Hirsch38* @author James McIlree39* @since 1.340*/41public interface Method extends TypeComponent, Locatable, Comparable<Method> {4243/**44* Returns a text representation of the return type,45* as specified in the declaration of this method.46* <P>47* This type name is always available even if48* the type has not yet been created or loaded.49*50* @return a {@code String} containing the return type name.51*/52String returnTypeName();5354/**55* Returns the return type,56* as specified in the declaration of this method.57* <P>58* Note: if the return type of this method is a reference type (class,59* interface, or array) and it has not been created or loaded60* by the declaring type's class loader - that is,61* {@link TypeComponent#declaringType declaringType()}62* {@code .classLoader()},63* then ClassNotLoadedException will be thrown.64* Also, a reference type may have been loaded but not yet prepared,65* in which case the type will be returned66* but attempts to perform some operations on the returned type67* (e.g. {@link ReferenceType#fields() fields()}) will throw68* a {@link ClassNotPreparedException}.69* Use {@link ReferenceType#isPrepared()} to determine if70* a reference type is prepared.71*72* @see Type73* @see Field#type() Field.type() - for usage examples74* @return the return {@link Type} of this method.75* @throws ClassNotLoadedException if the type has not yet been76* created or loaded77* through the appropriate class loader.78*/79Type returnType() throws ClassNotLoadedException;8081/**82* Returns a list containing a text representation of the type83* of each formal parameter of this method.84* <P>85* This list is always available even if86* the types have not yet been created or loaded.87*88* @return a {@link java.util.List List} of {@link String},89* one List element for each parameter of this method.90* Each element represents the type of a formal parameter91* as specified at compile-time.92* If the formal parameter was declared with an ellipsis, then93* it is represented as an array of the type before the ellipsis.94*/95List<String> argumentTypeNames();9697/**98* Returns a list containing the type99* of each formal parameter of this method.100* <P>101* Note: if there is any parameter whose type102* is a reference type (class, interface, or array)103* and it has not been created or loaded104* by the declaring type's class loader - that is,105* {@link TypeComponent#declaringType declaringType()}106* {@code .classLoader()},107* then ClassNotLoadedException will be thrown.108* Also, a reference type may have been loaded but not yet prepared,109* in which case the list will be returned110* but attempts to perform some operations on the type111* (e.g. {@link ReferenceType#fields() fields()}) will throw112* a {@link ClassNotPreparedException}.113* Use {@link ReferenceType#isPrepared()} to determine if114* a reference type is prepared.115*116* @see Type117* @return return a {@link java.util.List List} of {@link Type},118* one List element for each parameter of this method.119* Each element represents the type of a formal parameter120* as specified at compile-time.121* If the formal parameter was declared with an ellipsis, then122* it is represented as an array of the type before the ellipsis.123*124* @throws ClassNotLoadedException if the type has not yet been loaded125* through the appropriate class loader.126*/127List<Type> argumentTypes() throws ClassNotLoadedException;128129/**130* Determine if this method is abstract.131*132* @return {@code true} if the method is declared abstract;133* {@code false} otherwise.134*/135boolean isAbstract();136137/**138* Determine if this method is a default method139*140* @return {@code true} if the method is declared default;141* {@code false} otherwise.142*143* @since 1.8144*/145default boolean isDefault() {146throw new UnsupportedOperationException();147}148149/**150* Determine if this method is synchronized.151*152* @return {@code true} if the method is declared synchronized;153* {@code false} otherwise.154*/155boolean isSynchronized();156157/**158* Determine if this method is native.159*160* @return {@code true} if the method is declared native;161* {@code false} otherwise.162*/163boolean isNative();164165/**166* Determine if this method accepts a variable number of arguments.167*168* @return {@code true} if the method accepts a variable number169* of arguments, {@code false} otherwise.170*171* @since 1.5172*/173boolean isVarArgs();174175/**176* Determine if this method is a bridge method. Bridge177* methods are defined in178* <cite>The Java Language Specification</cite>.179*180* @return {@code true} if the method is a bridge method,181* {@code false} otherwise.182*183* @since 1.5184*/185boolean isBridge();186187/**188* Determine if this method is a constructor.189*190* @return {@code true} if the method is a constructor;191* {@code false} otherwise.192*/193boolean isConstructor();194195/**196* Determine if this method is a static initializer.197*198* @return {@code true} if the method is a static initializer;199* {@code false} otherwise.200*/201boolean isStaticInitializer();202203/**204* Determine if this method is obsolete.205*206* @return {@code true} if this method has been made obsolete by a207* {@link VirtualMachine#redefineClasses} operation.208*209* @since 1.4210*/211boolean isObsolete();212213/**214* Returns a list containing a {@link Location} object for215* each executable source line in this method.216* <P>217* This method is equivalent to218* {@code allLineLocations(vm.getDefaultStratum(),null)} -219* see {@link #allLineLocations(String,String)}220* for more information.221*222* @return a List of all source line {@link Location} objects.223*224* @throws AbsentInformationException if there is no line225* number information for this (non-native, non-abstract)226* method.227*/228List<Location> allLineLocations() throws AbsentInformationException;229230/**231* Returns a list containing a {@link Location} object for232* each executable source line in this method.233* <P>234* Each location maps a source line to a range of code235* indices.236* The beginning of the range can be determined through237* {@link Location#codeIndex}.238* The returned list is ordered by code index239* (from low to high).240* <P>241* The returned list may contain multiple locations for a242* particular line number, if the compiler and/or VM has243* mapped that line to two or more disjoint code index ranges.244* <P>245* If the method is native or abstract, an empty list is246* returned.247* <P>248* Returned list is for the specified <i>stratum</i>249* (see {@link Location} for a description of strata).250*251* @param stratum The stratum to retrieve information from252* or {@code null} for the {@link ReferenceType#defaultStratum()}253*254* @param sourceName Return locations only within this255* source file or {@code null} to return locations.256*257* @return a List of all source line {@link Location} objects.258*259* @throws AbsentInformationException if there is no line260* number information for this (non-native, non-abstract)261* method. Or if <i>sourceName</i> is non-{@code null}262* and source name information is not present.263*264* @since 1.4265*/266List<Location> allLineLocations(String stratum, String sourceName)267throws AbsentInformationException;268269/**270* Returns a List containing all {@link Location} objects271* that map to the given line number.272* <P>273* This method is equivalent to274* {@code locationsOfLine(vm.getDefaultStratum(), null,275* lineNumber)} -276* see {@link277* #locationsOfLine(java.lang.String,java.lang.String,int)}278* for more information.279*280* @param lineNumber the line number281*282* @return a List of {@link Location} objects that map to283* the given line number.284*285* @throws AbsentInformationException if there is no line286* number information for this method.287*/288List<Location> locationsOfLine(int lineNumber) throws AbsentInformationException;289290/**291* Returns a List containing all {@link Location} objects292* that map to the given line number and source name.293* <P>294* Returns a list containing each {@link Location} that maps295* to the given line. The returned list will contain a296* location for each disjoint range of code indices that have297* been assigned to the given line by the compiler and/or298* VM. Each returned location corresponds to the beginning of299* this range. An empty list will be returned if there is no300* executable code at the specified line number; specifically,301* native and abstract methods will always return an empty302* list.303* <p>304* Returned list is for the specified <i>stratum</i>305* (see {@link Location} for a description of strata).306*307* @param stratum the stratum to use for comparing line number308* and source name, or null to use the default309* stratum310* @param sourceName the source name containing the311* line number, or null to match all312* source names313* @param lineNumber the line number314*315* @return a List of {@link Location} objects that map to316* the given line number.317*318* @throws AbsentInformationException if there is no line319* number information for this method.320* Or if <i>sourceName</i> is non-{@code null}321* and source name information is not present.322*323* @since 1.4324*/325List<Location> locationsOfLine(String stratum, String sourceName,326int lineNumber)327throws AbsentInformationException;328329/**330* Returns a {@link Location} for the given code index.331*332* @return the {@link Location} corresponding to the333* given code index or null if the specified code index is not a334* valid code index for this method (native and abstract methods335* will always return null).336*/337Location locationOfCodeIndex(long codeIndex);338339/**340* Returns a list containing each {@link LocalVariable} declared341* in this method. The list includes any variable declared in any342* scope within the method. It may contain multiple variables of the343* same name declared within disjoint scopes. Arguments are considered344* local variables and will be present in the returned list.345*346* If local variable information is not available, values of347* actual arguments to method invocations can be obtained348* by using the method {@link StackFrame#getArgumentValues()}349*350* @return the list of {@link LocalVariable} objects which mirror351* local variables declared in this method in the target VM.352* If there are no local variables, a zero-length list is returned.353* @throws AbsentInformationException if there is no variable354* information for this method.355* Generally, local variable information is not available for356* native or abstract methods (that is, their argument name357* information is not available), thus they will throw this exception.358*/359List<LocalVariable> variables() throws AbsentInformationException;360361/**362* Returns a list containing each {@link LocalVariable} of a363* given name in this method.364* Multiple variables can be returned365* if the same variable name is used in disjoint366* scopes within the method.367*368* @return the list of {@link LocalVariable} objects of the given369* name.370* If there are no matching local variables, a zero-length list371* is returned.372* @throws AbsentInformationException if there is no variable373* information for this method.374* Generally, local variable information is not available for375* native or abstract methods (that is, their argument name376* information is not available), thus they will throw this exception.377*/378List<LocalVariable> variablesByName(String name)379throws AbsentInformationException;380381/**382* Returns a list containing each {@link LocalVariable} that is383* declared as an argument of this method.384*385* If local variable information is not available, values of386* actual arguments to method invocations can be obtained387* by using the method {@link StackFrame#getArgumentValues()}388*389* @return the list of {@link LocalVariable} arguments.390* If there are no arguments, a zero-length list is returned.391* @throws AbsentInformationException if there is no variable392* information for this method.393* Generally, local variable information is not available for394* native or abstract methods (that is, their argument name395* information is not available), thus they will throw this exception.396*/397List<LocalVariable> arguments() throws AbsentInformationException;398399/**400* Returns an array containing the bytecodes for this method.401* <P>402* Not all target virtual machines support this operation.403* Use {@link VirtualMachine#canGetBytecodes()}404* to determine if the operation is supported.405*406* @return the array of bytecodes; abstract and native methods407* will return a zero-length array.408* @throws java.lang.UnsupportedOperationException if409* the target virtual machine does not support410* the retrieval of bytecodes.411*/412byte[] bytecodes();413414/**415* Returns the {@link Location} of this method, if there416* is executable code associated with it.417*418* @return the {@link Location} of this mirror, or null if419* this is an abstract method; native methods will return a420* Location object whose codeIndex is -1.421*/422Location location();423424/**425* Compares the specified Object with this method for equality.426*427* @return true if the Object is a method and if both428* mirror the same method (declared in the same class or interface, in429* the same VM).430*/431boolean equals(Object obj);432433/**434* Returns the hash code value for this Method.435*436* @return the integer hash code.437*/438int hashCode();439}440441442