Package com.tonic.builder
Class MethodBuilder
- java.lang.Object
-
- com.tonic.builder.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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AnnotationBuilder<MethodBuilder>annotate(String type)Opens an annotation on this method; callAnnotationBuilder.end()to return here.AnnotationBuilder<MethodBuilder>annotateParameter(int index, String type)Opens an annotation on one parameter; callAnnotationBuilder.end()to return here.CodeBuildercode()Opens the method body, creating the code builder on first call and returning the same one afterwards.ClassBuilderend()Closes this method.MethodBuilderexceptions(String... exceptionTypes)Adds types to the Exceptions attribute emitted for this method.MethodBuildermaxLocals(int maxLocals)Overrides the computed max_locals of the Code attribute.MethodBuildermaxStack(int maxStack)Overrides the computed max_stack of the Code attribute.
-
-
-
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
-
annotate
public AnnotationBuilder<MethodBuilder> annotate(String type)
Opens an annotation on this method; callAnnotationBuilder.end()to return here.- Parameters:
type- the annotation type, as an internal or descriptor name- Returns:
- the annotation builder
-
annotateParameter
public AnnotationBuilder<MethodBuilder> annotateParameter(int index, String type)
Opens an annotation on one parameter; callAnnotationBuilder.end()to return here.- Parameters:
index- 0-based parameter positiontype- 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
-
-