Package net.bytebuddy.asm
Class TypeReferenceAdjustment
- java.lang.Object
-
- net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
-
- net.bytebuddy.asm.TypeReferenceAdjustment
-
- All Implemented Interfaces:
AsmVisitorWrapper
@Enhance public class TypeReferenceAdjustment extends AsmVisitorWrapper.AbstractBase
Adds an attribute value for all inner classes that are referenced by the instrumented type. Adding such attributes is formally required by the Java virtual machine specification but it is not enforced by the verifier. As a result, many alternative JVM languages do not correctly implement the attribute. By adding this visitor, a type's inner class attribute can be repaired or created by registering this visitor wrapper.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
TypeReferenceAdjustment.TypeReferenceClassVisitor
A class visitor that collects all type references and all inner class references.-
Nested classes/interfaces inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
AsmVisitorWrapper.AbstractBase, AsmVisitorWrapper.Compound, AsmVisitorWrapper.ForDeclaredFields, AsmVisitorWrapper.ForDeclaredMethods, AsmVisitorWrapper.NoOp
-
-
Field Summary
Fields Modifier and Type Field Description private ElementMatcher.Junction<? super TypeDescription>
filter
A filter for excluding types from type reference analysis.private boolean
strict
true
if the visitor should throw an exception if a type reference cannot be located.-
Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TypeReferenceAdjustment(boolean strict, ElementMatcher.Junction<? super TypeDescription> filter)
Creates a type reference adjustment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeReferenceAdjustment
filter(ElementMatcher<? super TypeDescription> filter)
Excludes all matched types from being added as an attribute.static TypeReferenceAdjustment
relaxed()
Creates a strict type reference adjustment that ignores type references that cannot be resolved in the supplied type pool.static TypeReferenceAdjustment
strict()
Creates a strict type reference adjustment that throws an exception if a type reference cannot be resolved in the supplied type pool.org.objectweb.asm.ClassVisitor
wrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)
Applies aClassVisitorWrapper
to the creation of aDynamicType
.-
Methods inherited from class net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
mergeReader, mergeWriter
-
-
-
-
Field Detail
-
strict
private final boolean strict
true
if the visitor should throw an exception if a type reference cannot be located.
-
filter
private final ElementMatcher.Junction<? super TypeDescription> filter
A filter for excluding types from type reference analysis.
-
-
Constructor Detail
-
TypeReferenceAdjustment
protected TypeReferenceAdjustment(boolean strict, ElementMatcher.Junction<? super TypeDescription> filter)
Creates a type reference adjustment.- Parameters:
strict
-true
if the visitor should throw an exception if a type reference cannot be located.filter
- A filter for excluding types from type reference analysis.
-
-
Method Detail
-
strict
public static TypeReferenceAdjustment strict()
Creates a strict type reference adjustment that throws an exception if a type reference cannot be resolved in the supplied type pool.- Returns:
- A strict type reference adjustment.
-
relaxed
public static TypeReferenceAdjustment relaxed()
Creates a strict type reference adjustment that ignores type references that cannot be resolved in the supplied type pool.- Returns:
- A relaxed type reference adjustment.
-
filter
public TypeReferenceAdjustment filter(ElementMatcher<? super TypeDescription> filter)
Excludes all matched types from being added as an attribute.- Parameters:
filter
- A filter for excluding types from the attribute generation.- Returns:
- A new type reference adjustment that uses the supplied filter for excluding types.
-
wrap
public org.objectweb.asm.ClassVisitor wrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)
Applies aClassVisitorWrapper
to the creation of aDynamicType
.- Parameters:
instrumentedType
- The instrumented type.classVisitor
- AClassVisitor
to become the new primary class visitor to which the createdDynamicType
is written to.implementationContext
- The implementation context of the current instrumentation.typePool
- The type pool that was provided for the class creation.fields
- The instrumented type's fields.methods
- The instrumented type's methods non-ignored declared and virtually inherited methods.writerFlags
- The ASMClassWriter
flags to consider.readerFlags
- The ASMClassReader
flags to consider.- Returns:
- A new
ClassVisitor
that usually delegates to theClassVisitor
delivered in the argument.
-
-