Top Description Methods
java.lang.classfile

public sealed Interface MethodBuilder

extends ClassFileBuilder<MethodElement, MethodBuilder>
Known Direct Subinterfaces
jdk.internal.classfile.impl.TerminalMethodBuilder
Known Direct Implementers
jdk.internal.classfile.impl.ChainedMethodBuilder
Annotations
@PreviewFeature
feature:CLASSFILE_API
Imports
java.util.Optional, java.util.function.Consumer, java.lang.classfile.constantpool.Utf8Entry, jdk.internal.classfile.impl.ChainedMethodBuilder, .TerminalMethodBuilder, java.lang.reflect.AccessFlag, jdk.internal.javac.PreviewFeature

Preview

Second Preview of ClassFile API (JEP 466).

Programs can only use MethodBuilder when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.

A builder for methods. Builders are not created directly; they are passed to handlers by methods such as ClassBuilder#withMethod(Utf8Entry, Utf8Entry, int, Consumer) or to method transforms. The elements of a method can be specified abstractly (by passing a MethodElement to with(ClassFileElement) or concretely by calling the various withXxx methods.
Since
22
See Also
MethodTransform

Method Summary

Modifier and TypeMethod and Description
public Optional<MethodModel>

Returns:

the MethodModel representing the method being transformed, if this method builder represents the transformation of some MethodModel
original
()

Returns the MethodModel representing the method being transformed, if this method builder represents the transformation of some MethodModel.

public MethodBuilder

Returns:

this builder
transformCode
(CodeModel
the method body to be transformed
code
,
CodeTransform
the transform to apply to the method body
transform
)

Build the method body for this method by transforming the body of another method.

public MethodBuilder

Returns:

this builder
withCode
(Consumer<? super CodeBuilder>
a handler receiving a CodeBuilder
code
)

Build the method body for this method.

public default MethodBuilder

Returns:

this builder
withFlags
(int
the access flags, as a bit mask
flags
)

Sets the method access flags.

public default MethodBuilder

Returns:

this builder
withFlags
(AccessFlag...
the access flags, as a bit mask
flags
)

Sets the method access flags.

Inherited from java.lang.classfile.ClassFileBuilder:
acceptcanWriteDirectconstantPooltransformwith

Method Detail

originalback to summary
public Optional<MethodModel> original()

Returns the MethodModel representing the method being transformed, if this method builder represents the transformation of some MethodModel.

Returns:Optional<MethodModel>

the MethodModel representing the method being transformed, if this method builder represents the transformation of some MethodModel

transformCodeback to summary
public MethodBuilder transformCode(CodeModel code, CodeTransform transform)

Build the method body for this method by transforming the body of another method.

Implementation Note

This method behaves as if:

withCode(b -> b.transformCode(code, transform));
withCode(b -> b.transformCode(code, transform));
Parameters
code:CodeModel

the method body to be transformed

transform:CodeTransform

the transform to apply to the method body

Returns:MethodBuilder

this builder

withCodeback to summary
public MethodBuilder withCode(Consumer<? super CodeBuilder> code)

Build the method body for this method.

Parameters
code:Consumer<? super CodeBuilder>

a handler receiving a CodeBuilder

Returns:MethodBuilder

this builder

withFlagsback to summary
public default MethodBuilder withFlags(int flags)

Sets the method access flags.

Parameters
flags:int

the access flags, as a bit mask

Returns:MethodBuilder

this builder

withFlagsback to summary
public default MethodBuilder withFlags(AccessFlag... flags)

Sets the method access flags.

Parameters
flags:AccessFlag[]

the access flags, as a bit mask

Returns:MethodBuilder

this builder