Class dec.trek.Method

The Method object allows you to manipulate the methods of a class. Also a method can be passed as an argument when the called method’s corresponding parameter is of class Member. This is because Member is the superclass of Field and Method.

The Method class does not have a public constructor. To reach a classfile’s methods, you must use firstMethod() or lastMethod() in the ClassFile class, or override atStartOf(Method) or atEndOf(Method) in the Trek class.

A method consists of statements and local variables. However statements are not explicitly part of a classfile, and local variables may not be. Thus the method needs to be analyzed before you can access its content. This occurs when you first access a statement or local variable with firstStatement, firstLocal, and so on. This analysis is rather involved. In particular, determining the data type of a local variable can require using getClassFile to access other classfiles. But if a classfile is not accessible, the analyzer catches the exception and uses heuristics to make up for the unavailable info.

Method Summary

  • firstLocal – returns the Local object of the first local variable of this method
  • firstStatement – returns the Statement object of the first statement of this method
  • getArgCount – returns the number of arguments defined for this method
  • getClassFile – returns the ClassFile object of the class that this method is part of
  • getExceptionHandlers – returns the exception handlers of this method
  • hasModifier – returns true if this method has any of the specified access modifiers
  • isConstructor – returns true if this method is a constructor
  • lastLocal – returns the Local object of the last local variable of this method
  • lastStatement – returns the Statement object of the last statement of this method
  • next – returns the Method object of the next method of the current classfile
  • prev – returns the Method object of the previous method of the current classfile
  • toArgList – returns the source code for the argument list of this method
  • toName – returns the unqualified name of this method
  • toObjectId – returns the object Id of this method
  • toString – returns the source code for the declaration of this method
  • toThrowsTypes – returns the exceptions specified in this method's throws clause
  • toType – returns the data type of this method’s return value

Fields

public Object userDefined

Field that can be used by an application developer to store arbitrary data about this object during the trek.

Methods

public Local firstLocal()

Returns the Local object of this method’s first local variable. If this method has no locals, null is returned instead. If the method is not static, the first local is always the this variable.

public Statement firstStatement()

Returns the Statement object of this method’s first statement. If this method has no code, null is returned instead.

public int getArgCount()

Returns the number of arguments defined for this method

public ClassFile getClassFile()

Returns the ClassFile object of the class that this method is part of

public ExceptionHandler[] getExceptionHandlers()

Returns this method’s exception handlers. If this method has no exception handlers, null is returned instead. To access the attributes of an exception handler, see the ExceptionHandler class.

public boolean hasModifier(int flags)

Returns true if this method was declared with any of the specified flags.

Parameters:

flags – one or more of the ACC constants defined in the Trek class.

public boolean isConstructor()

Returns true if this method is a constructor.

public Local lastLocal()

Returns the Local object of this method’s last local. If this method has no locals, null is returned instead.

public Statement lastStatement()

Returns the Statement object of this method’s last statement. If this method has no code, null is returned instead.

public Method next()

Returns the Method of the alphabetically next method in this method’s classfile. Returns null if there are no more methods.

public Method prev()

Returns the Method of the alphabetically previous method in this method’s classfile. Returns null if there are no more methods.

public String toArgList()

Returns the source code that defined this method’s argument list.

public String toName()

Returns the unqualified name of this method.

public String toObjectId()

Returns a persistent value that identifies this method. A reference to this method can be acquired by calling getObject on a trek that this method is within.

A method is defined by its argument list as well as its name (because overloading is allowed in Java). Thus an object Id for a method becomes obsolete if either its name or its argument list is changed.

public String toString()

Returns the source statement that defined this method.

public String[] toThrowsTypes()

Returns an array containing the fully qualified name of each exception specified in this method's throws clause. If this method has no throws clause, the returned array's size is 0.

public String toType()

Returns this method’s return type, such as void or int or java.lang.Object.