Class MethodBuilder


  • public class MethodBuilder
    extends Object
    Fluent builder for one method of a ClassBuilder, holding its code, thrown types, frame sizes, and annotations until the enclosing class is built.
    • Method Detail

      • code

        public CodeBuilder code()
        Opens the method body, creating the code builder on first call and returning the same one afterwards.
        Returns:
        the code builder for this method
      • annotateParameter

        public AnnotationBuilder<MethodBuilder> annotateParameter​(int index,
                                                                  String type)
        Opens an annotation on one parameter; call AnnotationBuilder.end() to return here.
        Parameters:
        index - 0-based parameter position
        type - the annotation type, as an internal or descriptor name
        Returns:
        the annotation builder
        Throws:
        IllegalArgumentException - if the position is not valid for this method's descriptor
      • exceptions

        public MethodBuilder exceptions​(String... exceptionTypes)
        Adds types to the Exceptions attribute emitted for this method.
        Parameters:
        exceptionTypes - internal names of the declared thrown types
        Returns:
        this builder
      • maxStack

        public MethodBuilder maxStack​(int maxStack)
        Overrides the computed max_stack of the Code attribute.
        Parameters:
        maxStack - the operand stack size to write
        Returns:
        this builder
      • maxLocals

        public MethodBuilder maxLocals​(int maxLocals)
        Overrides the computed max_locals of the Code attribute.
        Parameters:
        maxLocals - the local slot count to write
        Returns:
        this builder
      • end

        public ClassBuilder end()
        Closes this method.
        Returns:
        the enclosing class builder