Class MethodGen

  • All Implemented Interfaces:
    java.lang.Cloneable, NamedAndTyped

    public class MethodGen
    extends FieldGenOrMethodGen
    Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local variables and attributes, whereas the 'LocalVariableTable' and 'LineNumberTable' attributes will be set automatically for the code. Use stripAttributes() if you don't like this. While generating code it may be necessary to insert NOP operations. You can use the 'removeNOPs' method to get rid off them. The resulting method object can be obtained via the 'getMethod()' method.
    See Also:
    InstructionList, Method
    • Constructor Detail

      • MethodGen

        public MethodGen​(int accessFlags,
                         Type returnType,
                         Type[] argTypes,
                         java.lang.String[] argNames,
                         java.lang.String methodName,
                         java.lang.String className,
                         InstructionList il,
                         ConstantPoolGen cp)
        Declare method. If the method is non-static the constructor automatically declares a local variable '$this' in slot 0. The actual code is contained in the 'il' parameter, which may further manipulated by the user. But they must take care not to remove any instruction (handles) that are still referenced from this object. For example one may not add a local variable and later remove the instructions it refers to without causing havoc. It is safe however if you remove that local variable, too.
        Parameters:
        accessFlags - access qualifiers
        returnType - method type
        argTypes - argument types
        argNames - argument names (if this is null, default names will be provided for them)
        methodName - name of method
        className - class name containing this method (may be null, if you don't care)
        il - instruction list associated with this method, may be null only for abstract or native methods
        cp - constant pool
      • MethodGen

        public MethodGen​(Method method,
                         java.lang.String className,
                         ConstantPoolGen cp)
        Instantiate from existing method.
        Parameters:
        method - method
        className - class name containing this method
        cp - constant pool