Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/jdi/Method.java
38831 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*/41@jdk.Exported42public interface Method extends TypeComponent, Locatable, Comparable<Method> {4344/**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 if49* the type has not yet been created or loaded.50*51* @return a String containing the return type name.52*/53String returnTypeName();5455/**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 loaded61* 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 returned67* but attempts to perform some operations on the returned type68* (e.g. {@link ReferenceType#fields() fields()}) will throw69* a {@link ClassNotPreparedException}.70* Use {@link ReferenceType#isPrepared()} to determine if71* a reference type is prepared.72*73* @see Type74* @see Field#type() Field.type() - for usage examples75* @return the return {@link Type} of this method.76* @throws ClassNotLoadedException if the type has not yet been77* created or loaded78* through the appropriate class loader.79*/80Type returnType() throws ClassNotLoadedException;8182/**83* Returns a list containing a text representation of the type84* of each formal parameter of this method.85* <P>86* This list is always available even if87* 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 parameter92* as specified at compile-time.93* If the formal parameter was declared with an ellipsis, then94* it is represented as an array of the type before the ellipsis.95*96*/97List<String> argumentTypeNames();9899/**100* Returns a list containing the type101* of each formal parameter of this method.102* <P>103* Note: if there is any parameter whose type104* is a reference type (class, interface, or array)105* and it has not been created or loaded106* 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 returned112* but attempts to perform some operations on the type113* (e.g. {@link ReferenceType#fields() fields()}) will throw114* a {@link ClassNotPreparedException}.115* Use {@link ReferenceType#isPrepared()} to determine if116* a reference type is prepared.117*118* @see Type119* @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 parameter122* as specified at compile-time.123* If the formal parameter was declared with an ellipsis, then124* it is represented as an array of the type before the ellipsis.125*126* @throws ClassNotLoadedException if the type has not yet been loaded127* through the appropriate class loader.128*/129List<Type> argumentTypes() throws ClassNotLoadedException;130131/**132* Determine if this method is abstract.133*134* @return <code>true</code> if the method is declared abstract;135* false otherwise.136*/137boolean isAbstract();138139/**140* Determine if this method is a default method141*142* @return <code>true</code> if the method is declared default;143* false otherwise144*145* @since 1.8146*/147default boolean isDefault() {148throw new UnsupportedOperationException();149}150151/**152* Determine if this method is synchronized.153*154* @return <code>true</code> if the method is declared synchronized;155* false otherwise.156*/157boolean isSynchronized();158159/**160* Determine if this method is native.161*162* @return <code>true</code> if the method is declared native;163* false otherwise.164*/165boolean isNative();166167/**168* Determine if this method accepts a variable number of arguments.169*170* @return <code>true</code> if the method accepts a variable number171* of arguments, false otherwise.172*173* @since 1.5174*/175boolean isVarArgs();176177/**178* Determine if this method is a bridge method. Bridge179* methods are defined in180* <cite>The Java™ Language Specification</cite>.181*182* @return <code>true</code> if the method is a bridge method,183* false otherwise.184*185* @since 1.5186*/187boolean isBridge();188189/**190* Determine if this method is a constructor.191*192* @return <code>true</code> if the method is a constructor;193* false otherwise.194*/195boolean isConstructor();196197/**198* Determine if this method is a static initializer.199*200* @return <code>true</code> if the method is a static initializer;201* false otherwise.202*/203boolean isStaticInitializer();204205/**206* Determine if this method is obsolete.207*208* @return <code>true</code> if this method has been made obsolete by a209* {@link VirtualMachine#redefineClasses} operation.210*211* @since 1.4212*/213boolean isObsolete();214215/**216* Returns a list containing a {@link Location} object for217* each executable source line in this method.218* <P>219* This method is equivalent to220* <code>allLineLocations(vm.getDefaultStratum(),null)</code> -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 line227* number information for this (non-native, non-abstract)228* method.229*/230List<Location> allLineLocations() throws AbsentInformationException;231232/**233* Returns a list containing a {@link Location} object for234* each executable source line in this method.235* <P>236* Each location maps a source line to a range of code237* indices.238* The beginning of the range can be determined through239* {@link Location#codeIndex}.240* The returned list is ordered by code index241* (from low to high).242* <P>243* The returned list may contain multiple locations for a244* particular line number, if the compiler and/or VM has245* mapped that line to two or more disjoint code index ranges.246* <P>247* If the method is native or abstract, an empty list is248* 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 from254* or <code>null</code> for the {@link ReferenceType#defaultStratum()}255*256* @param sourceName Return locations only within this257* source file or <code>null</code> to return locations.258*259* @return a List of all source line {@link Location} objects.260*261* @throws AbsentInformationException if there is no line262* number information for this (non-native, non-abstract)263* method. Or if <i>sourceName</i> is non-<code>null</code>264* and source name information is not present.265*266* @since 1.4267*/268List<Location> allLineLocations(String stratum, String sourceName)269throws AbsentInformationException;270271/**272* Returns a List containing all {@link Location} objects273* that map to the given line number.274* <P>275* This method is equivalent to276* <code>locationsOfLine(vm.getDefaultStratum(), null,277* lineNumber)</code> -278* see {@link279* #locationsOfLine(java.lang.String,java.lang.String,int)}280* for more information.281*282* @param lineNumber the line number283*284* @return a List of {@link Location} objects that map to285* the given line number.286*287* @throws AbsentInformationException if there is no line288* number information for this method.289*/290List<Location> locationsOfLine(int lineNumber) throws AbsentInformationException;291292/**293* Returns a List containing all {@link Location} objects294* that map to the given line number and source name.295* <P>296* Returns a list containing each {@link Location} that maps297* to the given line. The returned list will contain a298* location for each disjoint range of code indices that have299* been assigned to the given line by the compiler and/or300* VM. Each returned location corresponds to the beginning of301* this range. An empty list will be returned if there is no302* executable code at the specified line number; specifically,303* native and abstract methods will always return an empty304* 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 number310* and source name, or null to use the default311* stratum312* @param sourceName the source name containing the313* line number, or null to match all314* source names315* @param lineNumber the line number316*317* @return a List of {@link Location} objects that map to318* the given line number.319*320* @throws AbsentInformationException if there is no line321* number information for this method.322* Or if <i>sourceName</i> is non-<code>null</code>323* and source name information is not present.324*325* @since 1.4326*/327List<Location> locationsOfLine(String stratum, String sourceName,328int lineNumber)329throws AbsentInformationException;330331/**332* Returns a {@link Location} for the given code index.333*334* @return the {@link Location} corresponding to the335* given code index or null if the specified code index is not a336* valid code index for this method (native and abstract methods337* will always return null).338*/339Location locationOfCodeIndex(long codeIndex);340341/**342* Returns a list containing each {@link LocalVariable} declared343* in this method. The list includes any variable declared in any344* scope within the method. It may contain multiple variables of the345* same name declared within disjoint scopes. Arguments are considered346* local variables and will be present in the returned list.347*348* If local variable information is not available, values of349* actual arguments to method invocations can be obtained350* by using the method {@link StackFrame#getArgumentValues()}351*352* @return the list of {@link LocalVariable} objects which mirror353* local variables declared in this method in the target VM.354* If there are no local variables, a zero-length list is returned.355* @throws AbsentInformationException if there is no variable356* information for this method.357* Generally, local variable information is not available for358* native or abstract methods (that is, their argument name359* information is not available), thus they will throw this exception.360*/361List<LocalVariable> variables() throws AbsentInformationException;362363/**364* Returns a list containing each {@link LocalVariable} of a365* given name in this method.366* Multiple variables can be returned367* if the same variable name is used in disjoint368* scopes within the method.369*370* @return the list of {@link LocalVariable} objects of the given371* name.372* If there are no matching local variables, a zero-length list373* is returned.374* @throws AbsentInformationException if there is no variable375* information for this method.376* Generally, local variable information is not available for377* native or abstract methods (that is, their argument name378* information is not available), thus they will throw this exception.379*/380List<LocalVariable> variablesByName(String name)381throws AbsentInformationException;382383/**384* Returns a list containing each {@link LocalVariable} that is385* declared as an argument of this method.386*387* If local variable information is not available, values of388* actual arguments to method invocations can be obtained389* by using the method {@link StackFrame#getArgumentValues()}390*391* @return the list of {@link LocalVariable} arguments.392* If there are no arguments, a zero-length list is returned.393* @throws AbsentInformationException if there is no variable394* information for this method.395* Generally, local variable information is not available for396* native or abstract methods (that is, their argument name397* information is not available), thus they will throw this exception.398*/399List<LocalVariable> arguments() throws AbsentInformationException;400401/**402* Returns an array containing the bytecodes for this method.403* <P>404* Not all target virtual machines support this operation.405* Use {@link VirtualMachine#canGetBytecodes()}406* to determine if the operation is supported.407*408* @return the array of bytecodes; abstract and native methods409* will return a zero-length array.410* @throws java.lang.UnsupportedOperationException if411* the target virtual machine does not support412* the retrieval of bytecodes.413*/414byte[] bytecodes();415416/**417* Returns the {@link Location} of this method, if there418* is executable code associated with it.419*420* @return the {@link Location} of this mirror, or null if421* this is an abstract method; native methods will return a422* Location object whose codeIndex is -1.423*/424Location location();425426/**427* Compares the specified Object with this method for equality.428*429* @return true if the Object is a method and if both430* mirror the same method (declared in the same class or interface, in431* the same VM).432*/433boolean equals(Object obj);434435/**436* Returns the hash code value for this Method.437*438* @return the integer hash code439*/440int hashCode();441}442443444