Top Description Fields Constructors Methods
net.bytebuddy.utility.visitor

public abstract Class MetadataAwareClassVisitor

extends ClassVisitor
Class Inheritance
Known Direct Subclasses
net.bytebuddy.dynamic.scaffold.TypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor, net.bytebuddy.dynamic.scaffold.TypeWriter.Default.ForInlining.WithDecorationOnly.DecorationClassVisitor, net.bytebuddy.dynamic.scaffold.TypeWriter.Default.ForCreation.CreationClassVisitor
Imports
net.bytebuddy.utility.nullability.MaybeNull, net.bytebuddy.jar.asm.*

A class visitor that traces invocations of visitation methods and notifies if a nest host or outer class was not visited.

Field Summary

Modifier and TypeField and Description
private boolean
triggerAttributes

true if the attribute visitation is not yet completed.

private boolean
triggerNestHost

true if the nest host was not yet visited.

private boolean
triggerOuterClass

true if the outer class was not yet visited.

Inherited from net.bytebuddy.jar.asm.ClassVisitor:
apicv

Constructor Summary

AccessConstructor and Description
protected
MetadataAwareClassVisitor(int
The API version.
api
,
ClassVisitor
The class visitor to delegate to.
classVisitor
)

Creates a metadata aware class visitor.

Method Summary

Modifier and TypeMethod and Description
private void
considerTriggerAfterAttributes()

Considers triggering the after attribute visitation.

private void
considerTriggerNestHost()

Considers triggering a nest host visitation.

private void
considerTriggerOuterClass()

Considers triggering an outer class visitation.

protected void
onAfterAttributes()

Invoked if the attribute visitation is about to complete.

protected void
onNestHost()

Invoked if the nest host was not visited.

protected void
onOuterType()

Invoked if the outer class was not visited.

protected AnnotationVisitor

Returns:

An annotation visitor or null if the annotation should be ignored.
onVisitAnnotation
(String
The annotation type's descriptor.
descriptor
,
boolean
true if the annotation is visible at runtime.
visible
)

An order-sensitive invocation of ClassVisitor#visitAnnotation(String, boolean).

protected void
onVisitAttribute(Attribute
The attribute to visit.
attribute
)

An order-sensitive invocation of ClassVisitor#visitAttribute(Attribute).

protected void
onVisitEnd()

An order-sensitive invocation of ClassVisitor#visitEnd().

protected FieldVisitor

Returns:

A field visitor to visit the field or null to ignore it.
onVisitField
(int
The field's modifiers.
modifiers
,
String
The field's internal name.
internalName
,
String
The field type's descriptor.
descriptor
,
String
The field's generic signature or null if the field is not generic.
signature
,
Object
The field's default value or null if no such value exists.
value
)

An order-sensitive invocation of ClassVisitor#visitField(int, String, String, String, Object).

protected void
onVisitInnerClass(String
The internal name of the inner class.
internalName
,
String
The internal name of the outer class or null for a member class.
outerName
,
String
The inner class's simple name or null for an anonymous class.
innerName
,
int
The inner class's source code modifiers.
modifiers
)

An order-sensitive invocation of ClassVisitor#visitInnerClass(String, String, String, int).

protected MethodVisitor

Returns:

A method visitor to visit the method or null to ignore it.
onVisitMethod
(int
The method's modifiers.
modifiers
,
String
The method's internal name.
internalName
,
String
The field type's descriptor.
descriptor
,
String
The method's generic signature or null if the method is not generic.
signature
,
String[]
The method's declared exceptions or null if no exceptions are declared.
exception
)

An order-sensitive invocation of ClassVisitor#visitMethod(int, String, String, String, String[]).

protected void
onVisitNestHost(String
The internal name of the nest host.
nestHost
)

An order-sensitive invocation of ClassVisitor#visitNestHost(String).

protected void
onVisitNestMember(String
The internal name of the nest member.
nestMember
)

An order-sensitive invocation of ClassVisitor#visitNestMember(String).

protected void
onVisitOuterClass(String
The outer class's internal name.
owner
,
String
The outer method's name or null if it does not exist.
name
,
String
The outer method's descriptor or null if it does not exist.
descriptor
)

An order-sensitive invocation of ClassVisitor#visitOuterClass(String, String, String).

protected void
onVisitPermittedSubclass(String
The internal name of the permitted subclass.
permittedSubclass
)

An order-sensitive invocation of ClassVisitor#visitPermittedSubclass.

protected RecordComponentVisitor

Returns:

The record component visitor or null if the component should not be visited.
onVisitRecordComponent
(String
The record component's name.
name
,
String
The record component's descriptor.
descriptor
,
String
The record component's generic signature or null if the record component's type is non-generic.
signature
)

An order-sensitive invocation of ClassVisitor#visitRecordComponent(String, String, String).

protected AnnotationVisitor

Returns:

An annotation visitor or null if the annotation should be ignored.
onVisitTypeAnnotation
(int
The type reference of the type annotation.
typeReference
,
TypePath
The type path of the type annotation.
typePath
,
String
The descriptor of the annotation type.
descriptor
,
boolean
true if the annotation is visible at runtime.
visible
)

An order-sensitive invocation of ClassVisitor#visitTypeAnnotation(int, TypePath, String, boolean).

public final AnnotationVisitor
visitAnnotation(String
the class descriptor of the annotation class.
descriptor
,
boolean
true if the annotation is visible at runtime.
visible
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitAnnotation.

Visits an annotation of the class.
public final void
visitAttribute(Attribute
an attribute.
attribute
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitAttribute.

Visits a non standard attribute of the class.
public final void
visitEnd()

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitEnd.

Visits the end of the class.
public final FieldVisitor
visitField(int
the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.
modifiers
,
String
the field's name.
internalName
,
String
the field's descriptor (see Type).
descriptor
,
String
the field's signature. May be null if the field's type does not use generic types.
signature
,
Object
the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.
value
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitField.

Visits a field of the class.
public final void
visitInnerClass(String
the internal name of C (see Type#getInternalName()).
name
,
String
the internal name of the class or interface C is a member of (see Type#getInternalName()). Must be null if C is not the member of a class or interface (e.g. for local or anonymous classes).
outerName
,
String
the (simple) name of C. Must be null for anonymous inner classes.
innerName
,
int
the access flags of C originally declared in the source code from which this class was compiled.
modifiers
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitInnerClass.

Visits information about an inner class.
public final MethodVisitor
visitMethod(int
the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
modifiers
,
String
the method's name.
internalName
,
String
the method's descriptor (see Type).
descriptor
,
String
the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
signature
,
String[]
the internal names of the method's exception classes (see Type#getInternalName()). May be null.
exception
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Visits a method of the class.
public final void
visitNestHost(String
the internal name of the host class of the nest (see Type#getInternalName()).
nestHost
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitNestHost.

Visits the nest host class of the class.
public final void
visitNestMember(String
the internal name of a nest member (see Type#getInternalName()).
nestMember
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitNestMember.

Visits a member of the nest.
public final void
visitOuterClass(String
internal name of the enclosing class of the class (see Type#getInternalName()).
owner
,
String
the name of the method that contains the class, or null if the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in an instance initializer, static initializer, instance variable initializer, or class variable initializer).
name
,
String
the descriptor of the method that contains the class, or null if the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in an instance initializer, static initializer, instance variable initializer, or class variable initializer).
descriptor
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitOuterClass.

Visits the enclosing class of the class.
public final void
visitPermittedSubclass(String
the internal name of a permitted subclass (see Type#getInternalName()).
permittedSubclass
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitPermittedSubclass.

Visits a permitted subclasses.
public RecordComponentVisitor
visitRecordComponent(String
the record component name.
name
,
String
the record component descriptor (see Type).
descriptor
,
String
the record component signature. May be null if the record component type does not use generic types.
signature
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitRecordComponent.

Visits a record component of the class.
public final AnnotationVisitor
visitTypeAnnotation(int
a reference to the annotated type. The sort of this type reference must be TypeReference#CLASS_TYPE_PARAMETER, TypeReference#CLASS_TYPE_PARAMETER_BOUND or TypeReference#CLASS_EXTENDS. See TypeReference.
typeReference
,
TypePath
the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be null if the annotation targets 'typeRef' as a whole.
typePath
,
String
the class descriptor of the annotation class.
descriptor
,
boolean
true if the annotation is visible at runtime.
visible
)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitTypeAnnotation.

Visits an annotation on a type in the class signature.
Inherited from net.bytebuddy.jar.asm.ClassVisitor:
getDelegatevisitvisitModulevisitSource

Field Detail

triggerAttributesback to summary
private boolean triggerAttributes

true if the attribute visitation is not yet completed.

triggerNestHostback to summary
private boolean triggerNestHost

true if the nest host was not yet visited.

triggerOuterClassback to summary
private boolean triggerOuterClass

true if the outer class was not yet visited.

Constructor Detail

MetadataAwareClassVisitorback to summary
protected MetadataAwareClassVisitor(int api, ClassVisitor classVisitor)

Creates a metadata aware class visitor.

Parameters
api:int

The API version.

classVisitor:ClassVisitor

The class visitor to delegate to.

Method Detail

considerTriggerAfterAttributesback to summary
private void considerTriggerAfterAttributes()

Considers triggering the after attribute visitation.

considerTriggerNestHostback to summary
private void considerTriggerNestHost()

Considers triggering a nest host visitation.

considerTriggerOuterClassback to summary
private void considerTriggerOuterClass()

Considers triggering an outer class visitation.

onAfterAttributesback to summary
protected void onAfterAttributes()

Invoked if the attribute visitation is about to complete.

onNestHostback to summary
protected void onNestHost()

Invoked if the nest host was not visited.

onOuterTypeback to summary
protected void onOuterType()

Invoked if the outer class was not visited.

onVisitAnnotationback to summary
protected AnnotationVisitor onVisitAnnotation(String descriptor, boolean visible)

An order-sensitive invocation of ClassVisitor#visitAnnotation(String, boolean).

Parameters
descriptor:String

The annotation type's descriptor.

visible:boolean

true if the annotation is visible at runtime.

Returns:AnnotationVisitor

An annotation visitor or null if the annotation should be ignored.

Annotations
@MaybeNull
onVisitAttributeback to summary
protected void onVisitAttribute(Attribute attribute)

An order-sensitive invocation of ClassVisitor#visitAttribute(Attribute).

Parameters
attribute:Attribute

The attribute to visit.

onVisitEndback to summary
protected void onVisitEnd()

An order-sensitive invocation of ClassVisitor#visitEnd().

onVisitFieldback to summary
protected FieldVisitor onVisitField(int modifiers, String internalName, String descriptor, String signature, Object value)

An order-sensitive invocation of ClassVisitor#visitField(int, String, String, String, Object).

Parameters
modifiers:int

The field's modifiers.

internalName:String

The field's internal name.

descriptor:String

The field type's descriptor.

signature:String

The field's generic signature or null if the field is not generic.

value:Object

The field's default value or null if no such value exists.

Returns:FieldVisitor

A field visitor to visit the field or null to ignore it.

Annotations
@MaybeNull
onVisitInnerClassback to summary
protected void onVisitInnerClass(String internalName, String outerName, String innerName, int modifiers)

An order-sensitive invocation of ClassVisitor#visitInnerClass(String, String, String, int).

Parameters
internalName:String

The internal name of the inner class.

outerName:String

The internal name of the outer class or null for a member class.

innerName:String

The inner class's simple name or null for an anonymous class.

modifiers:int

The inner class's source code modifiers.

onVisitMethodback to summary
protected MethodVisitor onVisitMethod(int modifiers, String internalName, String descriptor, String signature, String[] exception)

An order-sensitive invocation of ClassVisitor#visitMethod(int, String, String, String, String[]).

Parameters
modifiers:int

The method's modifiers.

internalName:String

The method's internal name.

descriptor:String

The field type's descriptor.

signature:String

The method's generic signature or null if the method is not generic.

exception:String[]

The method's declared exceptions or null if no exceptions are declared.

Returns:MethodVisitor

A method visitor to visit the method or null to ignore it.

Annotations
@MaybeNull
onVisitNestHostback to summary
protected void onVisitNestHost(String nestHost)

An order-sensitive invocation of ClassVisitor#visitNestHost(String).

Parameters
nestHost:String

The internal name of the nest host.

onVisitNestMemberback to summary
protected void onVisitNestMember(String nestMember)

An order-sensitive invocation of ClassVisitor#visitNestMember(String).

Parameters
nestMember:String

The internal name of the nest member.

onVisitOuterClassback to summary
protected void onVisitOuterClass(String owner, String name, String descriptor)

An order-sensitive invocation of ClassVisitor#visitOuterClass(String, String, String).

Parameters
owner:String

The outer class's internal name.

name:String

The outer method's name or null if it does not exist.

descriptor:String

The outer method's descriptor or null if it does not exist.

onVisitPermittedSubclassback to summary
protected void onVisitPermittedSubclass(String permittedSubclass)

An order-sensitive invocation of ClassVisitor#visitPermittedSubclass.

Parameters
permittedSubclass:String

The internal name of the permitted subclass.

onVisitRecordComponentback to summary
protected RecordComponentVisitor onVisitRecordComponent(String name, String descriptor, String signature)

An order-sensitive invocation of ClassVisitor#visitRecordComponent(String, String, String).

Parameters
name:String

The record component's name.

descriptor:String

The record component's descriptor.

signature:String

The record component's generic signature or null if the record component's type is non-generic.

Returns:RecordComponentVisitor

The record component visitor or null if the component should not be visited.

Annotations
@MaybeNull
onVisitTypeAnnotationback to summary
protected AnnotationVisitor onVisitTypeAnnotation(int typeReference, TypePath typePath, String descriptor, boolean visible)

An order-sensitive invocation of ClassVisitor#visitTypeAnnotation(int, TypePath, String, boolean).

Parameters
typeReference:int

The type reference of the type annotation.

typePath:TypePath

The type path of the type annotation.

descriptor:String

The descriptor of the annotation type.

visible:boolean

true if the annotation is visible at runtime.

Returns:AnnotationVisitor

An annotation visitor or null if the annotation should be ignored.

Annotations
@MaybeNull
visitAnnotationback to summary
public final AnnotationVisitor visitAnnotation(String descriptor, boolean visible)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitAnnotation.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitAnnotation.

Visits an annotation of the class.

Parameters
descriptor:String

the class descriptor of the annotation class.

visible:boolean

true if the annotation is visible at runtime.

Returns:AnnotationVisitor

a visitor to visit the annotation values, or null if this visitor is not interested in visiting this annotation.

Annotations
@Override
@MaybeNull
visitAttributeback to summary
public final void visitAttribute(Attribute attribute)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitAttribute.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitAttribute.

Visits a non standard attribute of the class.

Parameters
attribute:Attribute

an attribute.

Annotations
@Override
visitEndback to summary
public final void visitEnd()

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitEnd.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitEnd.

Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all the fields and methods of the class have been visited.

Annotations
@Override
visitFieldback to summary
public final FieldVisitor visitField(int modifiers, String internalName, String descriptor, String signature, Object value)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitField.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitField.

Visits a field of the class.

Parameters
modifiers:int

the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.

internalName:String

the field's name.

descriptor:String

the field's descriptor (see Type).

signature:String

the field's signature. May be null if the field's type does not use generic types.

value:Object

the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.

Returns:FieldVisitor

a visitor to visit field annotations and attributes, or null if this class visitor is not interested in visiting these annotations and attributes.

Annotations
@Override
@MaybeNull
visitInnerClassback to summary
public final void visitInnerClass(String name, String outerName, String innerName, int modifiers)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitInnerClass.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitInnerClass.

Visits information about an inner class. This inner class is not necessarily a member of the class being visited. More precisely, every class or interface C which is referenced by this class and which is not a package member must be visited with this method. This class must reference its nested class or interface members, and its enclosing class, if any. See the JVMS 4.7.6 section for more details.

Parameters
name:String

the internal name of C (see Type#getInternalName()).

outerName:String

the internal name of the class or interface C is a member of (see Type#getInternalName()). Must be null if C is not the member of a class or interface (e.g. for local or anonymous classes).

innerName:String

the (simple) name of C. Must be null for anonymous inner classes.

modifiers:int

the access flags of C originally declared in the source code from which this class was compiled.

Annotations
@Override
visitMethodback to summary
public final MethodVisitor visitMethod(int modifiers, String internalName, String descriptor, String signature, String[] exception)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitMethod.

Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Parameters
modifiers:int

the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.

internalName:String

the method's name.

descriptor:String

the method's descriptor (see Type).

signature:String

the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.

exception:String[]

the internal names of the method's exception classes (see Type#getInternalName()). May be null.

Returns:MethodVisitor

an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

Annotations
@Override
@MaybeNull
visitNestHostback to summary
public final void visitNestHost(String nestHost)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitNestHost.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitNestHost.

Visits the nest host class of the class. A nest is a set of classes of the same package that share access to their private members. One of these classes, called the host, lists the other members of the nest, which in turn should link to the host of their nest. This method must be called only once and only if the visited class is a non-host member of a nest. A class is implicitly its own nest, so it's invalid to call this method with the visited class name as argument.

Parameters
nestHost:String

the internal name of the host class of the nest (see Type#getInternalName()).

Annotations
@Override
visitNestMemberback to summary
public final void visitNestMember(String nestMember)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitNestMember.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitNestMember.

Visits a member of the nest. A nest is a set of classes of the same package that share access to their private members. One of these classes, called the host, lists the other members of the nest, which in turn should link to the host of their nest. This method must be called only if the visited class is the host of a nest. A nest host is implicitly a member of its own nest, so it's invalid to call this method with the visited class name as argument.

Parameters
nestMember:String

the internal name of a nest member (see Type#getInternalName()).

Annotations
@Override
visitOuterClassback to summary
public final void visitOuterClass(String owner, String name, String descriptor)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitOuterClass.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitOuterClass.

Visits the enclosing class of the class. This method must be called only if this class is a local or anonymous class. See the JVMS 4.7.7 section for more details.

Parameters
owner:String

internal name of the enclosing class of the class (see Type#getInternalName()).

name:String

the name of the method that contains the class, or null if the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in an instance initializer, static initializer, instance variable initializer, or class variable initializer).

descriptor:String

the descriptor of the method that contains the class, or null if the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in an instance initializer, static initializer, instance variable initializer, or class variable initializer).

Annotations
@Override
visitPermittedSubclassback to summary
public final void visitPermittedSubclass(String permittedSubclass)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitPermittedSubclass.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitPermittedSubclass.

Visits a permitted subclasses. A permitted subclass is one of the allowed subclasses of the current class.

Parameters
permittedSubclass:String

the internal name of a permitted subclass (see Type#getInternalName()).

Annotations
@Override
visitRecordComponentback to summary
public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitRecordComponent.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitRecordComponent.

Visits a record component of the class.

Parameters
name:String

the record component name.

descriptor:String

the record component descriptor (see Type).

signature:String

the record component signature. May be null if the record component type does not use generic types.

Returns:RecordComponentVisitor

a visitor to visit this record component annotations and attributes, or null if this class visitor is not interested in visiting these annotations and attributes.

Annotations
@Override
@MaybeNull
visitTypeAnnotationback to summary
public final AnnotationVisitor visitTypeAnnotation(int typeReference, TypePath typePath, String descriptor, boolean visible)

Overrides net.bytebuddy.jar.asm.ClassVisitor.visitTypeAnnotation.

Doc from net.bytebuddy.jar.asm.ClassVisitor.visitTypeAnnotation.

Visits an annotation on a type in the class signature.

Parameters
typeReference:int

a reference to the annotated type. The sort of this type reference must be TypeReference#CLASS_TYPE_PARAMETER, TypeReference#CLASS_TYPE_PARAMETER_BOUND or TypeReference#CLASS_EXTENDS. See TypeReference.

typePath:TypePath

the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be null if the annotation targets 'typeRef' as a whole.

descriptor:String

the class descriptor of the annotation class.

visible:boolean

true if the annotation is visible at runtime.

Returns:AnnotationVisitor

a visitor to visit the annotation values, or null if this visitor is not interested in visiting this annotation.

Annotations
@Override
@MaybeNull