APIdia Launch Partner
Top Description Fields Methods
java.lang.classfile

public non-sealed Interface ClassTransform

extends ClassFileTransform<ClassTransform, ClassElement, ClassBuilder>
Known Direct Subinterfaces
jdk.internal.classfile.components.ClassRemapper, jdk.internal.classfile.impl.TransformImpl.UnresolvedClassTransform
Annotations
@FunctionalInterface
Imports
java.lang.classfile.attribute.CodeAttribute, java.util.function.Consumer, .Predicate, .Supplier, jdk.internal.classfile.impl.TransformImpl

A transformation on streams of ClassElement.

Refer to ClassFileTransform for general guidance and caution around the use of transforms for structures in the class file format.

Since
24
See Also
ClassModel, ClassFile#transformClass(ClassModel, ClassTransform)

Field Summary

Modifier and TypeField and Description
public static final ClassTransform
ACCEPT_ALL

A class transform that passes all elements to the builder.

Method Summary

Modifier and TypeMethod and Description
public default ClassTransform
andThen(ClassTransform t)

Implements java.lang.classfile.ClassFileTransform.andThen.

Chain this transform with another; elements presented to the builder of this transform will become the input to the next transform.

public static ClassTransform

Returns:

the class transform
dropping
(Predicate<ClassElement>
the predicate that determines which elements to drop
filter
)

Creates a class transform that passes each element through to the builder, except for those that the supplied Predicate returns true for.

public static ClassTransform

Returns:

the class transform
endHandler
(Consumer<ClassBuilder>
the function to call when transformation is complete
finisher
)

Creates a class transform that passes each element through to the builder, and calls the specified function when transformation is complete.

public static ClassTransform

Returns:

the stateful class transform
ofStateful
(Supplier<ClassTransform>
a Supplier that produces a fresh transform object for each traversal
supplier
)

Creates a stateful class transform from a Supplier.

public static ClassTransform

Returns:

the class transform
transformingFields
(FieldTransform
the field transform
xform
)

Creates a class transform that transforms FieldModel elements with the supplied field transform, passing other elements through to the builder.

public static ClassTransform

Returns:

the class transform
transformingMethodBodies
(Predicate<MethodModel>
a predicate that determines which methods to transform
filter
,
CodeTransform
the code transform
xform
)

Creates a class transform that transforms the CodeAttribute (method body) of MethodModel elements with the supplied code transform for methods that the supplied Predicate returns true for, passing other elements through to the builder.

public static ClassTransform

Returns:

the class transform
transformingMethodBodies
(CodeTransform
the code transform
xform
)

Creates a class transform that transforms the CodeAttribute (method body) of MethodModel elements with the supplied code transform, passing other elements through to the builder.

public static ClassTransform

Returns:

the class transform
transformingMethods
(Predicate<MethodModel>
a predicate that determines which methods to transform
filter
,
MethodTransform
the method transform
xform
)

Creates a class transform that transforms MethodModel elements with the supplied method transform for methods that the supplied Predicate returns true for, passing other elements through to the builder.

public static ClassTransform

Returns:

the class transform
transformingMethods
(MethodTransform
the method transform
xform
)

Creates a class transform that transforms MethodModel elements with the supplied method transform, passing other elements through to the builder.

Inherited from java.lang.classfile.ClassFileTransform:
acceptatEndatStart

Field Detail

ACCEPT_ALLback to summary
public static final ClassTransform ACCEPT_ALL

A class transform that passes all elements to the builder.

Method Detail

andThenback to summary
public default ClassTransform andThen(ClassTransform t)

Implements java.lang.classfile.ClassFileTransform.andThen.

Doc from java.lang.classfile.ClassFileTransform.andThen.

Chain this transform with another; elements presented to the builder of this transform will become the input to the next transform.

This method is implemented by the Class-File API. Users usually don't have sufficient access to Class-File API functionalities to override this method correctly for generic downstream transforms.

Implementation Specification

The default implementation returns this class transform chained with another class transform from the argument. Chaining of two transforms requires to involve a chained builder serving as a target builder for this transform and also as a source of elements for the downstream transform.

Annotations
@Override
droppingback to summary
public static ClassTransform dropping(Predicate<ClassElement> filter)

Creates a class transform that passes each element through to the builder, except for those that the supplied Predicate returns true for.

Parameters
filter:Predicate<ClassElement>

the predicate that determines which elements to drop

Returns:ClassTransform

the class transform

endHandlerback to summary
public static ClassTransform endHandler(Consumer<ClassBuilder> finisher)

Creates a class transform that passes each element through to the builder, and calls the specified function when transformation is complete.

Parameters
finisher:Consumer<ClassBuilder>

the function to call when transformation is complete

Returns:ClassTransform

the class transform

ofStatefulback to summary
public static ClassTransform ofStateful(Supplier<ClassTransform> supplier)

Creates a stateful class transform from a Supplier. The supplier will be invoked for each transformation.

Parameters
supplier:Supplier<ClassTransform>

a Supplier that produces a fresh transform object for each traversal

Returns:ClassTransform

the stateful class transform

transformingFieldsback to summary
public static ClassTransform transformingFields(FieldTransform xform)

Creates a class transform that transforms FieldModel elements with the supplied field transform, passing other elements through to the builder.

Parameters
xform:FieldTransform

the field transform

Returns:ClassTransform

the class transform

transformingMethodBodiesback to summary
public static ClassTransform transformingMethodBodies(Predicate<MethodModel> filter, CodeTransform xform)

Creates a class transform that transforms the CodeAttribute (method body) of MethodModel elements with the supplied code transform for methods that the supplied Predicate returns true for, passing other elements through to the builder.

Parameters
filter:Predicate<MethodModel>

a predicate that determines which methods to transform

xform:CodeTransform

the code transform

Returns:ClassTransform

the class transform

transformingMethodBodiesback to summary
public static ClassTransform transformingMethodBodies(CodeTransform xform)

Creates a class transform that transforms the CodeAttribute (method body) of MethodModel elements with the supplied code transform, passing other elements through to the builder.

Parameters
xform:CodeTransform

the code transform

Returns:ClassTransform

the class transform

transformingMethodsback to summary
public static ClassTransform transformingMethods(Predicate<MethodModel> filter, MethodTransform xform)

Creates a class transform that transforms MethodModel elements with the supplied method transform for methods that the supplied Predicate returns true for, passing other elements through to the builder.

Parameters
filter:Predicate<MethodModel>

a predicate that determines which methods to transform

xform:MethodTransform

the method transform

Returns:ClassTransform

the class transform

transformingMethodsback to summary
public static ClassTransform transformingMethods(MethodTransform xform)

Creates a class transform that transforms MethodModel elements with the supplied method transform, passing other elements through to the builder.

Parameters
xform:MethodTransform

the method transform

Returns:ClassTransform

the class transform