Class ClassVisitorFactory<T>

  • Type Parameters:
    T - The type of the mapped class visitor.

    @Enhance
    public abstract class ClassVisitorFactory<T>
    extends java.lang.Object
    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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String DELEGATE
      The name of the delegate field containing an equivalent visitor.
      private static java.lang.String LABELS
      The name of a map with labels that have been translated previously.
      private java.lang.Class<?> type
      The type of the represented class visitor wrapper.
      private static java.lang.String WRAP
      The name of the method that wraps a translated visitor, including a null check.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ClassVisitorFactory​(java.lang.Class<?> type)
      Creates a new factory.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private static <T> T doPrivileged​(java.security.PrivilegedAction<T> action)
      A proxy for java.security.AccessController#doPrivileged that is activated if available.
      java.lang.Class<?> getType()
      Returns the ClassVisitor type that this factory represents.
      static <S> ClassVisitorFactory<S> of​(java.lang.Class<S> classVisitor)
      Returns a class visitor factory for the supplied ClassVisitor type.
      static <S> ClassVisitorFactory<S> of​(java.lang.Class<S> classVisitor, ByteBuddy byteBuddy)
      Returns a class visitor factory for the supplied ClassVisitor type.
      private static DynamicType toAttributeWrapper​(DynamicType.Builder<?> builder, java.lang.Class<?> source, java.lang.Class<?> target, TypeDescription sourceWrapper, TypeDescription targetWrapper)
      Creates a wrapper type for an Attribute to pass attribues along a visitor chain.
      private static MethodCall.ArgumentLoader.Factory toConvertedParameter​(TypeDescription source, java.lang.Class<?> target, java.lang.String method, int offset, boolean virtual)
      Creates an argument loader for a method parameter that requires conversion.
      private static DynamicType.Builder<?> toMethodVisitorBuilder​(ByteBuddy byteBuddy, java.lang.Class<?> sourceVisitor, java.lang.Class<?> targetVisitor, java.lang.Class<?> sourceTypePath, java.lang.Class<?> targetTypePath, java.lang.Class<?> sourceLabel, java.lang.Class<?> targetLabel, java.lang.Class<?> sourceType, java.lang.Class<?> targetType, java.lang.Class<?> sourceHandle, java.lang.Class<?> targetHandle, java.lang.Class<?> sourceConstantDynamic, java.lang.Class<?> targetConstantDynamic)
      Creates a builder for a method visitor type.
      private static DynamicType.Builder<?> toVisitorBuilder​(ByteBuddy byteBuddy, java.lang.Class<?> sourceVisitor, java.lang.Class<?> targetVisitor, java.lang.Class<?> sourceTypePath, java.lang.Class<?> targetTypePath, Implementation appendix)
      Creates a builder for a visitor type.
      abstract org.objectweb.asm.ClassVisitor unwrap​(T classVisitor)
      Unwraps an instance of the supplied class visitor as a ClassVisitor.
      abstract T wrap​(org.objectweb.asm.ClassVisitor classVisitor)
      Wraps a ClassVisitor within an instance of the supplied class visitor type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DELEGATE

        private static final java.lang.String DELEGATE
        The name of the delegate field containing an equivalent visitor.
        See Also:
        Constant Field Values
      • LABELS

        private static final java.lang.String LABELS
        The name of a map with labels that have been translated previously.
        See Also:
        Constant Field Values
      • WRAP

        private static final java.lang.String WRAP
        The name of the method that wraps a translated visitor, including a null check.
        See Also:
        Constant Field Values
      • type

        private final java.lang.Class<?> type
        The type of the represented class visitor wrapper.
    • Constructor Detail

      • ClassVisitorFactory

        protected ClassVisitorFactory​(java.lang.Class<?> type)
        Creates a new factory.
        Parameters:
        type - The type of the represented class visitor wrapper.
    • Method Detail

      • getType

        public java.lang.Class<?> getType()
        Returns the ClassVisitor type that this factory represents.
        Returns:
        The ClassVisitor type that this factory represents.
      • of

        public static <S> ClassVisitorFactory<S> of​(java.lang.Class<S> classVisitor)
        Returns a class visitor factory for the supplied ClassVisitor type.
        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

        public static <S> ClassVisitorFactory<S> of​(java.lang.Class<S> classVisitor,
                                                    ByteBuddy byteBuddy)
        Returns a class visitor factory for the supplied ClassVisitor type.
        Type Parameters:
        S - The type of the class visitor to map to.
        Parameters:
        classVisitor - The type of the translated ClassVisitor.
        byteBuddy - The Byte Buddy instance to use.
        Returns:
        A factory for wrapping ClassVisitors in Byte Buddy's and the supplied package namespace.
      • doPrivileged

        @Enhance
        private static <T> T doPrivileged​(java.security.PrivilegedAction<T> action)
        A proxy for java.security.AccessController#doPrivileged that 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,
                                                               java.lang.Class<?> sourceVisitor,
                                                               java.lang.Class<?> targetVisitor,
                                                               @MaybeNull
                                                               java.lang.Class<?> sourceTypePath,
                                                               @MaybeNull
                                                               java.lang.Class<?> targetTypePath,
                                                               Implementation appendix)
                                                        throws java.lang.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 - The TypePath source type.
        targetTypePath - The TypePath target type.
        appendix - The implementation to append to the constructor.
        Returns:
        The created builder.
        Throws:
        java.lang.Exception - If an exception occurs.
      • toMethodVisitorBuilder

        private static DynamicType.Builder<?> toMethodVisitorBuilder​(ByteBuddy byteBuddy,
                                                                     java.lang.Class<?> sourceVisitor,
                                                                     java.lang.Class<?> targetVisitor,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> sourceTypePath,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> targetTypePath,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> sourceLabel,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> targetLabel,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> sourceType,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> targetType,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> sourceHandle,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> targetHandle,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> sourceConstantDynamic,
                                                                     @MaybeNull
                                                                     java.lang.Class<?> targetConstantDynamic)
                                                              throws java.lang.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 - The TypePath source type.
        targetTypePath - The TypePath target type.
        sourceLabel - The Label source type.
        targetLabel - The Label target type.
        sourceType - The Type source type.
        targetType - The Type target type.
        sourceHandle - The Handle source type.
        targetHandle - The Handle target type.
        sourceConstantDynamic - The ConstantDynamic source type.
        targetConstantDynamic - The ConstantDynamic target type.
        Returns:
        The created builder.
        Throws:
        java.lang.Exception - If an exception occurs.
      • toConvertedParameter

        private static MethodCall.ArgumentLoader.Factory toConvertedParameter​(TypeDescription source,
                                                                              java.lang.Class<?> target,
                                                                              java.lang.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 offset
        virtual - true if the invoked method is virtual.
        Returns:
        An appropriate argument loader factory.
      • toAttributeWrapper

        private static DynamicType toAttributeWrapper​(DynamicType.Builder<?> builder,
                                                      java.lang.Class<?> source,
                                                      java.lang.Class<?> target,
                                                      TypeDescription sourceWrapper,
                                                      TypeDescription targetWrapper)
                                               throws java.lang.Exception
        Creates a wrapper type for an Attribute to pass attribues along a visitor chain.
        Parameters:
        builder - The builder to use for the wrapper type.
        source - The Attribute type in the original namespace.
        target - The Attribute type in the targeted namespace.
        sourceWrapper - The wrapper type for the Attribute type in the original namespace.
        targetWrapper - The wrapper type for the Attribute type in the targeted namespace.
        Returns:
        The created dynamic type.
        Throws:
        java.lang.Exception - If the dynamic type cannot be built.
      • wrap

        public abstract T wrap​(org.objectweb.asm.ClassVisitor classVisitor)
        Wraps a ClassVisitor within 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

        public abstract org.objectweb.asm.ClassVisitor unwrap​(T classVisitor)
        Unwraps an instance of the supplied class visitor as a ClassVisitor.
        Parameters:
        classVisitor - The class visitor to unwrap.
        Returns:
        A class visitor that unwraps the supplied class visitor.