soot
Class SootMethod

java.lang.Object
  extended by soot.tagkit.AbstractHost
      extended by soot.SootMethod
All Implemented Interfaces:
ClassMember, MethodOrMethodContext, Host, Numberable

public class SootMethod
extends AbstractHost
implements ClassMember, Numberable, MethodOrMethodContext

Soot representation of a Java method. Can be declared to belong to a SootClass. Does not contain the actual code, which belongs to a Body. The getActiveBody() method points to the currently-active body.


Field Summary
static String constructorName
           
static boolean DEBUG
           
protected  MethodSource ms
          Tells this method how to find out where its body lives.
static String staticInitializerName
           
 
Constructor Summary
SootMethod(String name, List parameterTypes, Type returnType)
          Constructs a SootMethod with the given name, parameter types and return type.
SootMethod(String name, List parameterTypes, Type returnType, int modifiers)
          Constructs a SootMethod with the given name, parameter types, return type and modifiers.
SootMethod(String name, List parameterTypes, Type returnType, int modifiers, List<SootClass> thrownExceptions)
          Constructs a SootMethod with the given name, parameter types, return type, and list of thrown exceptions.
 
Method Summary
 void addException(SootClass e)
          Adds the given exception to the list of exceptions thrown by this method.
 void addExceptionIfAbsent(SootClass e)
          Adds the given exception to the list of exceptions thrown by this method unless the exception is already in the list.
 Context context()
           
 int equivHashCode()
          Returns a hash code for this method consistent with structural equality.
 Body getActiveBody()
          Retrieves the active body for this method.
 String getBytecodeParms()
          Returns the parameters part of the signature in the format in which it appears in bytecode.
 String getBytecodeSignature()
          Returns the signature of this method in the format in which it appears in bytecode (eg.
 String getDavaDeclaration()
           
 String getDeclaration()
          Returns the declaration of this method, as used at the top of textual body representations (before the {}'s containing the code for representation.)
 SootClass getDeclaringClass()
          Returns the class which declares the current SootMethod.
 List<SootClass> getExceptions()
          Returns a backed list of the exceptions thrown by this method.
 int getModifiers()
          Gets the modifiers of this method.
 String getName()
          Returns the name of this method.
 int getNumber()
           
 NumberedString getNumberedSubSignature()
           
 int getParameterCount()
          Returns the number of parameters taken by this method.
 Type getParameterType(int n)
          Gets the type of the nth parameter of this method.
 List getParameterTypes()
          Returns a read-only list of the parameter types of this method.
 Type getReturnType()
          Returns the return type of this method.
 String getSignature()
          Returns the Soot signature of this method.
static String getSignature(SootClass cl, String name, List params, Type returnType)
           
 MethodSource getSource()
          Returns the MethodSource of the current SootMethod.
 String getSubSignature()
          Returns the Soot subsignature of this method.
static String getSubSignature(String name, List params, Type returnType)
           
 boolean hasActiveBody()
          Returns true if this method has an active body.
 boolean isAbstract()
          Convenience method returning true if this method is abstract.
 boolean isConcrete()
          Returns true if this method is not phantom, abstract or native, i.e.
 boolean isConstructor()
           
 boolean isDeclared()
          Returns true when some SootClass object declares this SootMethod object.
 boolean isEntryMethod()
           
 boolean isJavaLibraryMethod()
          We rely on the JDK class recognition to decide if a method is JDK method.
 boolean isMain()
           
 boolean isNative()
          Convenience method returning true if this method is native.
 boolean isPhantom()
          Returns true when this SootMethod object is phantom.
 boolean isPrivate()
          Convenience method returning true if this method is private.
 boolean isProtected()
          Convenience method returning true if this method is protected.
 boolean isPublic()
          Convenience method returning true if this method is public.
 boolean isStatic()
          Convenience method returning true if this method is static.
 boolean isSynchronized()
          Convenience method returning true if this method is synchronized.
 SootMethodRef makeRef()
           
 SootMethod method()
           
 void releaseActiveBody()
          Releases the active body associated with this method.
 void removeException(SootClass e)
          Removes the given exception from the list of exceptions thrown by this method.
 Body retrieveActiveBody()
          Returns the active body if present, else constructs an active body and returns that.
 void setActiveBody(Body body)
          Sets the active body for this method.
 void setDeclared(boolean isDeclared)
           
 void setDeclaringClass(SootClass declClass)
          Nomair A.
 void setExceptions(List exceptions)
           
 void setModifiers(int modifiers)
          Sets the modifiers of this method.
 void setName(String name)
          Sets the name of this method.
 void setNumber(int number)
           
 void setParameterTypes(List l)
          Changes the set of parameter types of this method.
 void setPhantom(boolean value)
          Sets the phantom flag on this method.
 void setReturnType(Type t)
          Sets the return type of this method.
 void setSource(MethodSource ms)
          Sets the MethodSource of the current SootMethod.
 boolean throwsException(SootClass e)
          Returns true if this method throws exception e.
 String toString()
          Returns the signature of this method.
 
Methods inherited from class soot.tagkit.AbstractHost
addAllTagsOf, addTag, getTag, getTags, hasTag, removeAllTags, removeTag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

constructorName

public static final String constructorName
See Also:
Constant Field Values

staticInitializerName

public static final String staticInitializerName
See Also:
Constant Field Values

DEBUG

public static boolean DEBUG

ms

protected MethodSource ms
Tells this method how to find out where its body lives.

Constructor Detail

SootMethod

public SootMethod(String name,
                  List parameterTypes,
                  Type returnType)
Constructs a SootMethod with the given name, parameter types and return type.


SootMethod

public SootMethod(String name,
                  List parameterTypes,
                  Type returnType,
                  int modifiers)
Constructs a SootMethod with the given name, parameter types, return type and modifiers.


SootMethod

public SootMethod(String name,
                  List parameterTypes,
                  Type returnType,
                  int modifiers,
                  List<SootClass> thrownExceptions)
Constructs a SootMethod with the given name, parameter types, return type, and list of thrown exceptions.

Method Detail

setSource

public void setSource(MethodSource ms)
Sets the MethodSource of the current SootMethod.


getSource

public MethodSource getSource()
Returns the MethodSource of the current SootMethod.


equivHashCode

public int equivHashCode()
Returns a hash code for this method consistent with structural equality.


getName

public String getName()
Returns the name of this method.


setDeclaringClass

public void setDeclaringClass(SootClass declClass)
Nomair A. Naeem , January 14th 2006 Need it for the decompiler to create a new SootMethod The SootMethod can be created fine but when one tries to create a SootMethodRef there is an error because there is no declaring class set. Dava cannot add the method to the class until after it has ended decompiling the remaining method (new method added is added in the PackManager) It would make sense to setDeclared to true within this method too. However later when the sootMethod is added it checks that the method is not set to declared (isDeclared).


getDeclaringClass

public SootClass getDeclaringClass()
Returns the class which declares the current SootMethod.

Specified by:
getDeclaringClass in interface ClassMember

setDeclared

public void setDeclared(boolean isDeclared)

isDeclared

public boolean isDeclared()
Returns true when some SootClass object declares this SootMethod object.

Specified by:
isDeclared in interface ClassMember

isPhantom

public boolean isPhantom()
Returns true when this SootMethod object is phantom.

Specified by:
isPhantom in interface ClassMember

isConcrete

public boolean isConcrete()
Returns true if this method is not phantom, abstract or native, i.e. this method can have a body.


setPhantom

public void setPhantom(boolean value)
Sets the phantom flag on this method.


setName

public void setName(String name)
Sets the name of this method.


getModifiers

public int getModifiers()
Gets the modifiers of this method.

Specified by:
getModifiers in interface ClassMember
See Also:
Modifier

setModifiers

public void setModifiers(int modifiers)
Sets the modifiers of this method.

Specified by:
setModifiers in interface ClassMember
See Also:
Modifier

getReturnType

public Type getReturnType()
Returns the return type of this method.


setReturnType

public void setReturnType(Type t)
Sets the return type of this method.


getParameterCount

public int getParameterCount()
Returns the number of parameters taken by this method.


getParameterType

public Type getParameterType(int n)
Gets the type of the nth parameter of this method.


getParameterTypes

public List getParameterTypes()
Returns a read-only list of the parameter types of this method.


setParameterTypes

public void setParameterTypes(List l)
Changes the set of parameter types of this method.


getActiveBody

public Body getActiveBody()
Retrieves the active body for this method.


retrieveActiveBody

public Body retrieveActiveBody()
Returns the active body if present, else constructs an active body and returns that. If you called Scene.v().loadClassAndSupport() for a class yourself, it will not be an application class, so you cannot get retrieve its active body. Please call setApplicationClass() on the relevant class.


setActiveBody

public void setActiveBody(Body body)
Sets the active body for this method.


hasActiveBody

public boolean hasActiveBody()
Returns true if this method has an active body.


releaseActiveBody

public void releaseActiveBody()
Releases the active body associated with this method.


addExceptionIfAbsent

public void addExceptionIfAbsent(SootClass e)
Adds the given exception to the list of exceptions thrown by this method unless the exception is already in the list.


addException

public void addException(SootClass e)
Adds the given exception to the list of exceptions thrown by this method.


removeException

public void removeException(SootClass e)
Removes the given exception from the list of exceptions thrown by this method.


throwsException

public boolean throwsException(SootClass e)
Returns true if this method throws exception e.


setExceptions

public void setExceptions(List exceptions)

getExceptions

public List<SootClass> getExceptions()
Returns a backed list of the exceptions thrown by this method.


isStatic

public boolean isStatic()
Convenience method returning true if this method is static.

Specified by:
isStatic in interface ClassMember

isPrivate

public boolean isPrivate()
Convenience method returning true if this method is private.

Specified by:
isPrivate in interface ClassMember

isPublic

public boolean isPublic()
Convenience method returning true if this method is public.

Specified by:
isPublic in interface ClassMember

isProtected

public boolean isProtected()
Convenience method returning true if this method is protected.

Specified by:
isProtected in interface ClassMember

isAbstract

public boolean isAbstract()
Convenience method returning true if this method is abstract.


isNative

public boolean isNative()
Convenience method returning true if this method is native.


isSynchronized

public boolean isSynchronized()
Convenience method returning true if this method is synchronized.


isMain

public boolean isMain()
Returns:
yes if this is the main method

isConstructor

public boolean isConstructor()
Returns:
yes, if this function is a constructor.

isEntryMethod

public boolean isEntryMethod()
Returns:
yes, if this is a class initializer or main function.

isJavaLibraryMethod

public boolean isJavaLibraryMethod()
We rely on the JDK class recognition to decide if a method is JDK method.


getBytecodeParms

public String getBytecodeParms()
Returns the parameters part of the signature in the format in which it appears in bytecode.


getBytecodeSignature

public String getBytecodeSignature()
Returns the signature of this method in the format in which it appears in bytecode (eg. [Ljava/lang/Object instead of java.lang.Object[]).


getSignature

public String getSignature()
Returns the Soot signature of this method. Used to refer to methods unambiguously.


getSignature

public static String getSignature(SootClass cl,
                                  String name,
                                  List params,
                                  Type returnType)

getSubSignature

public String getSubSignature()
Returns the Soot subsignature of this method. Used to refer to methods unambiguously.


getSubSignature

public static String getSubSignature(String name,
                                     List params,
                                     Type returnType)

getNumberedSubSignature

public NumberedString getNumberedSubSignature()

toString

public String toString()
Returns the signature of this method.

Overrides:
toString in class Object

getDavaDeclaration

public String getDavaDeclaration()

getDeclaration

public String getDeclaration()
Returns the declaration of this method, as used at the top of textual body representations (before the {}'s containing the code for representation.)


getNumber

public final int getNumber()
Specified by:
getNumber in interface Numberable

setNumber

public final void setNumber(int number)
Specified by:
setNumber in interface Numberable

method

public SootMethod method()
Specified by:
method in interface MethodOrMethodContext

context

public Context context()
Specified by:
context in interface MethodOrMethodContext

makeRef

public SootMethodRef makeRef()