Package net.bytebuddy.asm
Class ClassVisitorFactory<T>
java.lang.Object
net.bytebuddy.asm.ClassVisitorFactory<T>
- Type Parameters:
T- The type of the mapped class visitor.
A factory for wrapping a
ClassVisitor in Byte Buddy's package namespace to a
ClassVisitor in any other namespace. Note that this API does not allow for the
passing of Attributes. which must be filtered or propagated past this translation.
If the supplied visitors do not declare a method that Byte Buddy's version of ASM is aware
of, an UnsupportedOperationException is thrown.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA method to wrap anAttribute.protected static classA method to translate an array of constants from one namespace to another.protected static classA method to translate aConstantDynamicfrom one namespace to another.protected static classA method to translate a constant value from one namespace to another.protected static classA factory for creating a wrapper for aClassVisitor.protected static classA method to translate a stack map frame array from one namespace to another.protected static classA method to translate aHandlefrom one namespace to another.protected static classA method to translate an array ofLabels from one namespace to another.protected static classA method to translate aLabelfrom one namespace to another.protected static classAn appender that performs anull-checked construction.protected static classA method to translate aTypePathtype from one namespace to another. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe name of the delegate field containing an equivalent visitor.private static final StringThe name of a map with labels that have been translated previously.private final Class<?> The type of the represented class visitor wrapper.private static final StringThe name of the method that wraps a translated visitor, including anullcheck. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedClassVisitorFactory(Class<?> type) Creates a new factory. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> TdoPrivileged(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.Class<?> getType()Returns theClassVisitortype that this factory represents.static <S> ClassVisitorFactory<S> Returns a class visitor factory for the suppliedClassVisitortype.static <S> ClassVisitorFactory<S> Returns a class visitor factory for the suppliedClassVisitortype.private static DynamicTypetoAttributeWrapper(DynamicType.Builder<?> builder, Class<?> source, Class<?> target, TypeDescription sourceWrapper, TypeDescription targetWrapper) Creates a wrapper type for anAttributeto pass attribues along a visitor chain.private static MethodCall.ArgumentLoader.FactorytoConvertedParameter(TypeDescription source, Class<?> target, String method, int offset, boolean virtual) Creates an argument loader for a method parameter that requires conversion.private static DynamicType.Builder<?> toMethodVisitorBuilder(ByteBuddy byteBuddy, Class<?> sourceVisitor, Class<?> targetVisitor, Class<?> sourceTypePath, Class<?> targetTypePath, Class<?> sourceLabel, Class<?> targetLabel, Class<?> sourceType, Class<?> targetType, Class<?> sourceHandle, Class<?> targetHandle, Class<?> sourceConstantDynamic, Class<?> targetConstantDynamic) Creates a builder for a method visitor type.private static DynamicType.Builder<?> toVisitorBuilder(ByteBuddy byteBuddy, Class<?> sourceVisitor, Class<?> targetVisitor, Class<?> sourceTypePath, Class<?> targetTypePath, Implementation appendix) Creates a builder for a visitor type.abstract org.objectweb.asm.ClassVisitorUnwraps an instance of the supplied class visitor as aClassVisitor.abstract Twrap(org.objectweb.asm.ClassVisitor classVisitor) Wraps aClassVisitorwithin an instance of the supplied class visitor type.
-
Field Details
-
DELEGATE
The name of the delegate field containing an equivalent visitor.- See Also:
-
LABELS
The name of a map with labels that have been translated previously.- See Also:
-
WRAP
The name of the method that wraps a translated visitor, including anullcheck.- See Also:
-
type
The type of the represented class visitor wrapper.
-
-
Constructor Details
-
ClassVisitorFactory
Creates a new factory.- Parameters:
type- The type of the represented class visitor wrapper.
-
-
Method Details
-
getType
Returns theClassVisitortype that this factory represents.- Returns:
- The
ClassVisitortype that this factory represents.
-
of
Returns a class visitor factory for the suppliedClassVisitortype.- Type Parameters:
S- The type of the class visitor to map to.- Parameters:
classVisitor- The type of the translated class visitor.- Returns:
- A factory for wrapping
ClassVisitors in Byte Buddy's and the supplied package namespace.
-
of
Returns a class visitor factory for the suppliedClassVisitortype.- Type Parameters:
S- The type of the class visitor to map to.- Parameters:
classVisitor- The type of the translatedClassVisitor.byteBuddy- The Byte Buddy instance to use.- Returns:
- A factory for wrapping
ClassVisitors in Byte Buddy's and the supplied package namespace.
-
doPrivileged
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
toVisitorBuilder
private static DynamicType.Builder<?> toVisitorBuilder(ByteBuddy byteBuddy, Class<?> sourceVisitor, Class<?> targetVisitor, @MaybeNull Class<?> sourceTypePath, @MaybeNull Class<?> targetTypePath, Implementation appendix) throws Exception Creates a builder for a visitor type.- Parameters:
byteBuddy- The Byte Buddy instance to use.sourceVisitor- The visitor type to map from.targetVisitor- The visitor type to map to.sourceTypePath- TheTypePathsource type.targetTypePath- TheTypePathtarget type.appendix- The implementation to append to the constructor.- Returns:
- The created builder.
- Throws:
Exception- If an exception occurs.
-
toMethodVisitorBuilder
private static DynamicType.Builder<?> toMethodVisitorBuilder(ByteBuddy byteBuddy, Class<?> sourceVisitor, Class<?> targetVisitor, @MaybeNull Class<?> sourceTypePath, @MaybeNull Class<?> targetTypePath, @MaybeNull Class<?> sourceLabel, @MaybeNull Class<?> targetLabel, @MaybeNull Class<?> sourceType, @MaybeNull Class<?> targetType, @MaybeNull Class<?> sourceHandle, @MaybeNull Class<?> targetHandle, @MaybeNull Class<?> sourceConstantDynamic, @MaybeNull Class<?> targetConstantDynamic) throws Exception Creates a builder for a method visitor type.- Parameters:
byteBuddy- The Byte Buddy instance to use.sourceVisitor- The visitor type to map from.targetVisitor- The visitor type to map to.sourceTypePath- TheTypePathsource type.targetTypePath- TheTypePathtarget type.sourceLabel- TheLabelsource type.targetLabel- TheLabeltarget type.sourceType- TheTypesource type.targetType- TheTypetarget type.sourceHandle- TheHandlesource type.targetHandle- TheHandletarget type.sourceConstantDynamic- TheConstantDynamicsource type.targetConstantDynamic- TheConstantDynamictarget type.- Returns:
- The created builder.
- Throws:
Exception- If an exception occurs.
-
toConvertedParameter
private static MethodCall.ArgumentLoader.Factory toConvertedParameter(TypeDescription source, Class<?> target, String method, int offset, boolean virtual) Creates an argument loader for a method parameter that requires conversion.- Parameters:
source- The source type.target- The target type.method- The name of the method.offset- The parameter offsetvirtual-trueif the invoked method is virtual.- Returns:
- An appropriate argument loader factory.
-
toAttributeWrapper
private static DynamicType toAttributeWrapper(DynamicType.Builder<?> builder, Class<?> source, Class<?> target, TypeDescription sourceWrapper, TypeDescription targetWrapper) throws Exception Creates a wrapper type for anAttributeto pass attribues along a visitor chain.- Parameters:
builder- The builder to use for the wrapper type.source- TheAttributetype in the original namespace.target- TheAttributetype in the targeted namespace.sourceWrapper- The wrapper type for theAttributetype in the original namespace.targetWrapper- The wrapper type for theAttributetype in the targeted namespace.- Returns:
- The created dynamic type.
- Throws:
Exception- If the dynamic type cannot be built.
-
wrap
Wraps aClassVisitorwithin an instance of the supplied class visitor type.- Parameters:
classVisitor- The class visitor to wrap.- Returns:
- A class visitor that wraps the supplied class visitor.
-
unwrap
Unwraps an instance of the supplied class visitor as aClassVisitor.- Parameters:
classVisitor- The class visitor to unwrap.- Returns:
- A class visitor that unwraps the supplied class visitor.
-