edu.rit.classfile
Class SynthesizedMethodDescription

java.lang.Object
  extended by edu.rit.classfile.SubroutineReference
      extended by edu.rit.classfile.SubroutineDescription
          extended by edu.rit.classfile.SynthesizedSubroutineDescription
              extended by edu.rit.classfile.SynthesizedMethodDescription

public class SynthesizedMethodDescription
extends SynthesizedSubroutineDescription

Class SynthesizedMethodDescription is used to synthesize a subroutine description for some actual non-abstract method. To synthesize a non-abstract method:

  1. Create an instance of class SynthesizedMethodDescription, specifying the class and the method name.

  2. Modify the method's access mode, static mode, final mode, synchronized mode, and strict floating point mode if necessary.

  3. Specify the method's return type, if any.

  4. Add the method's argument types in order, if any.

  5. Add the method's thrown exceptions in order, if any.

  6. Add the method's bytecode instructions in order.

  7. Add the method's exception handlers in order if necessary.

  8. Set the method's max_stack and max_locals values.

Or:

  1. Create an instance of class SynthesizedMethodDescription, specifying the class and the method name.

  2. Modify the method's access mode, static mode, final mode, synchronized mode, and strict floating point mode if necessary.

  3. Specify the method descriptor, if the method does not return void or if the method has arguments.

  4. Add the method's thrown exceptions in order, if any.

  5. Add the method's bytecode instructions in order.

  6. Add the method's exception handlers in order if necessary.

  7. Set the method's max_stack and max_locals values.

Or:

  1. Create an instance of class SynthesizedMethodDescription, specifying the class, the method name, and the method descriptor, if the method does not return void or if the method has arguments.

  2. Modify the method's access mode, static mode, final mode, synchronized mode, and strict floating point mode if necessary.

  3. Add the method's thrown exceptions in order, if any.

  4. Add the method's bytecode instructions in order.

  5. Add the method's exception handlers in order if necessary.

  6. Set the method's max_stack and max_locals values.

In the documentation below, the term "described method" means "the synthesized method described by this synthesized method description object."

To synthesize an abstract method, see class SynthesizedAbstractMethodDescription.


Constructor Summary
SynthesizedMethodDescription(SynthesizedClassDescription theClassDescription, String theMethodName)
          Construct a new synthesized method description object with the given name.
SynthesizedMethodDescription(SynthesizedClassDescription theClassDescription, String theMethodName, String theMethodDescriptor)
          Construct a new synthesized method description object with the given name and method descriptor.
 
Method Summary
 void addArgumentType(TypeReference theArgumentType)
          Add an argument to this described method.
 void addExceptionHandler(Location theStartLocation, Location theEndLocation, Location theHandlerLocation, ClassReference theCatchType)
          Add an exception handler to the described method's list of exception handlers.
 void addInstruction(Instruction theInstruction)
          Adds the given instruction to the described method's list of bytecode instructions.
 void addThrownException(ClassReference theExceptionClass)
          Add a thrown exception to this described method.
 void increaseMaxLocals(int theMaxLocals)
          Increase the described method's max_locals item if necessary.
 void increaseMaxStack(int theMaxStack)
          Increase the described method's max_stack item if necessary.
 void setFinal(boolean isFinal)
          Specify whether the described method is final, that is, may not be overridden.
 void setMaxLocals(int theMaxLocals)
          Specify the described method's max_locals item.
 void setMaxStack(int theMaxStack)
          Specify the described method's max_stack item.
 void setMethodDescriptor(String theMethodDescriptor)
          Specify the described method's method descriptor.
 void setPackageScoped()
          Specify that the described method has default access (also known as package scoped), that is, may be accessed only from inside its defining package or inside its defining class.
 void setPrivate()
          Specify that the described method is private, that is, may be accessed only from inside its defining class.
 void setProtected()
          Specify that the described method is protected, that is, may be accessed only from inside its defining package, inside its defining class, or inside subclasses of its defining class.
 void setPublic()
          Specify that the described method is public, that is, may be accessed from inside and outside its defining package.
 void setReturnType(TypeReference theReturnType)
          Specify the described method's return type.
 void setStatic(boolean isStatic)
          Specify whether the described method is static.
 void setStrictfp(boolean isStrictfp)
          Specify whether the described method uses strict floating point mode.
 void setSynchronized(boolean isSynchronized)
          Specify whether the described method is synchronized, that is, the monitor must be locked upon invocation and unlocked upon return.
 
Methods inherited from class edu.rit.classfile.SubroutineDescription
getCodeLength, getExceptionHandlers, getInstructions, getMaxLocals, getMaxStack, getThrownExceptions, isAbstract, isFinal, isNative, isPackageScoped, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized
 
Methods inherited from class edu.rit.classfile.SubroutineReference
equals, getArgumentTypes, getArgumentWordCount, getClassReference, getMethodDescriptor, getMethodName, getReturnType, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SynthesizedMethodDescription

public SynthesizedMethodDescription(SynthesizedClassDescription theClassDescription,
                                    String theMethodName)
                             throws ListFullException
Construct a new synthesized method description object with the given name. Initially, the described method is public, is not static, is not final, is not synchronized, does not use strict floating point mode, has a return type of void, has no arguments, throws no exceptions, has no instructions, has max_stack = 0, and has max_locals = 0. As a side effect, the new synthesized method description object is added to the given synthesized class description object.

Parameters:
theClassDescription - Class containing this method.
theMethodName - Method name.
Throws:
NullPointerException - (unchecked exception) Thrown if theClassDescription is null or theMethodName is null.
IllegalArgumentException - (unchecked exception) Thrown if theMethodName is zero length.
ListFullException - Thrown if theClassDescription's subroutine list is full (i.e., contains 65535 subroutines).

SynthesizedMethodDescription

public SynthesizedMethodDescription(SynthesizedClassDescription theClassDescription,
                                    String theMethodName,
                                    String theMethodDescriptor)
                             throws ListFullException
Construct a new synthesized method description object with the given name and method descriptor. Initially, the described method is public, is not static, is not final, is not synchronized, does not use strict floating point mode, has a return type and arguments as specified by theMethodDescriptor, throws no exceptions, has no instructions, has max_stack = 0, and has max_locals = 0. As a side effect, the new synthesized method description object is added to the given synthesized class description object.

Parameters:
theClassDescription - Class containing this method.
theMethodName - Method name.
theMethodDescriptor - Method descriptor in the format specified by Section 4.3.3 of the Java Virtual Machine Specification, Second Edition.
Throws:
NullPointerException - (unchecked exception) Thrown if theClassDescription is null or theMethodName is null or theMethodDescriptor is null.
IllegalArgumentException - (unchecked exception) Thrown if theMethodName is zero length. Thrown if theMethodDescriptor does not obey the syntax of a method descriptor. Thrown if the number of arguments in theMethodDescriptor exceeds the limit (254).
ListFullException - Thrown if theClassDescription's subroutine list is full (i.e., contains 65535 subroutines).
Method Detail

setPublic

public void setPublic()
Specify that the described method is public, that is, may be accessed from inside and outside its defining package.


setPrivate

public void setPrivate()
Specify that the described method is private, that is, may be accessed only from inside its defining class.


setProtected

public void setProtected()
Specify that the described method is protected, that is, may be accessed only from inside its defining package, inside its defining class, or inside subclasses of its defining class.


setPackageScoped

public void setPackageScoped()
Specify that the described method has default access (also known as package scoped), that is, may be accessed only from inside its defining package or inside its defining class.


setStatic

public void setStatic(boolean isStatic)
Specify whether the described method is static.

Parameters:
isStatic - True if the described method is static, false otherwise.

setFinal

public void setFinal(boolean isFinal)
Specify whether the described method is final, that is, may not be overridden.

Parameters:
isFinal - True if the described method is final, false otherwise.

setSynchronized

public void setSynchronized(boolean isSynchronized)
Specify whether the described method is synchronized, that is, the monitor must be locked upon invocation and unlocked upon return.

Parameters:
isSynchronized - True if the described method is synchronized, false otherwise.

setStrictfp

public void setStrictfp(boolean isStrictfp)
Specify whether the described method uses strict floating point mode.

Parameters:
isStrictfp - True to use strict floating point mode, false not to use strict floating point mode.

setReturnType

public void setReturnType(TypeReference theReturnType)
Specify the described method's return type.

Parameters:
theReturnType - Type reference for the return type, or null if the referenced method returns void.

addArgumentType

public void addArgumentType(TypeReference theArgumentType)
                     throws ListFullException
Add an argument to this described method.

Parameters:
theArgumentType - Argument's type reference.
Throws:
NullPointerException - (unchecked exception) Thrown if theArgumentType is null.
ListFullException - Thrown if adding theArgumentType would cause the described method's argument word count to exceed the limit (254).

setMethodDescriptor

public void setMethodDescriptor(String theMethodDescriptor)
Specify the described method's method descriptor.

Parameters:
theMethodDescriptor - Method descriptor in the format specified by Section 4.3.3 of the Java Virtual Machine Specification, Second Edition.
Throws:
NullPointerException - (unchecked exception) Thrown if theMethodDescriptor is null.
IllegalStateException - (unchecked exception) Thrown if the method descriptor cannot be set because this method description is already in use.
IllegalArgumentException - (unchecked exception) Thrown if theMethodDescriptor does not obey the syntax of a method descriptor. Thrown if the number of arguments in theMethodDescriptor exceeds the limit (254).

addThrownException

public void addThrownException(ClassReference theExceptionClass)
                        throws ListFullException
Add a thrown exception to this described method.

Parameters:
theExceptionClass - Exception's class reference.
Throws:
NullPointerException - (unchecked exception) Thrown if theExceptionClass is null.
ListFullException - Thrown if the requisite constant pool entries could not be added because the constant pool is full. Also thrown if the described method's thrown exception list is full (i.e., contains 65535 thrown exceptions).

addInstruction

public void addInstruction(Instruction theInstruction)
                    throws ListFullException
Adds the given instruction to the described method's list of bytecode instructions.

Parameters:
theInstruction - Instruction to add.
Throws:
NullPointerException - (unchecked exception) Thrown if theInstruction is null.
ListFullException - Thrown if the requisite constant pool entries could not be added because the described method's class's constant pool is full. Also thrown if adding theInstruction would cause the described method's code length to exceed the maximum allowed value (65534 bytes).

addExceptionHandler

public void addExceptionHandler(Location theStartLocation,
                                Location theEndLocation,
                                Location theHandlerLocation,
                                ClassReference theCatchType)
                         throws ListFullException
Add an exception handler to the described method's list of exception handlers.

Parameters:
theStartLocation - Start location. This is the location of the first instruction in the method's bytecode sequence covered by the exception handler. (The start location is inclusive.)
theEndLocation - End location. This is the location of the next instruction after the last instruction in the method's bytecode sequence covered by the exception handler. (The end location is exclusive.)
theHandlerLocation - Handler location. This is the location of the first instruction in the exception handler itself.
theCatchType - Catch type. This is a class reference to the exception class caught by the exception handler. Null means the exception handler catches all exceptions.
Throws:
NullPointerException - (unchecked exception) Thrown if theStartLocation is null, theEndLocation is null, or theHandlerLocation is null.
IllegalArgumentException - (unchecked exception) Thrown if any of the following is true:
  • theStartLocation, theEndLocation, and theHandlerLocation have not all been added to the described method.
  • theStartLocation is at the same place as or comes after theEndLocation.
ListFullException - Thrown if the requisite constant pool entries could not be added because the described method's class's constant pool was full. Also thrown if the described method's exception handler list is full (i.e., contains 65535 exception handlers).

setMaxStack

public void setMaxStack(int theMaxStack)
                 throws OutOfRangeException
Specify the described method's max_stack item. The max_stack item's value gives the maximum depth of the described method's operand stack at any point during execution of the method.

Parameters:
theMaxStack - max_stack value.
Throws:
OutOfRangeException - Thrown if theMaxStack is not in the range 0 .. 65535.

increaseMaxStack

public void increaseMaxStack(int theMaxStack)
                      throws OutOfRangeException
Increase the described method's max_stack item if necessary. The max_stack item's value gives the maximum depth of the described method's operand stack at any point during execution of the method. If the described method's current max_stack value is less than theMaxStack, the max_stack value is set to theMaxStack, otherwise the max_stack value is unchanged.

Parameters:
theMaxStack - max_stack value.
Throws:
OutOfRangeException - Thrown if theMaxStack is not in the range 0 .. 65535.

setMaxLocals

public void setMaxLocals(int theMaxLocals)
                  throws OutOfRangeException
Specify the described method's max_locals item. The max_locals item's value gives the number of local variables in the local variable array allocated upon invocation of the described method.

Parameters:
theMaxLocals - max_locals value.
Throws:
OutOfRangeException - Thrown if theMaxLocals is not in the range 0 .. 65535.

increaseMaxLocals

public void increaseMaxLocals(int theMaxLocals)
                       throws OutOfRangeException
Increase the described method's max_locals item if necessary. The max_locals item's value gives the number of local variables in the local variable array allocated upon invocation of the described method. If the described method's current max_locals value is less than theMaxLocals, the max_locals value is set to theMaxLocals, otherwise the max_locals value is unchanged.

Parameters:
theMaxLocals - max_locals value.
Throws:
OutOfRangeException - Thrown if theMaxLocals is not in the range 0 .. 65535.


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.