Class AsmUtil

java.lang.Object
io.quarkus.deployment.util.AsmUtil

public class AsmUtil extends Object
A collection of ASM and Jandex utilities.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Map<Character,String>
     
    static final List<org.objectweb.asm.Type>
     
    static final Map<org.objectweb.asm.Type,org.objectweb.asm.Type>
     
    static final List<org.objectweb.asm.Type>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.objectweb.asm.Type
    autobox(org.objectweb.asm.Type primitive)
     
    static void
    boxIfRequired(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.Type jandexType)
    Calls the right boxing method for the given Jandex Type if it is a primitive.
    static void
    copyParameterNames(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.MethodInfo method)
    Copy the parameter names to the given MethodVisitor, unless we don't have parameter name info
    static String
    getDescriptor(org.jboss.jandex.MethodInfo method, Function<String,String> typeArgMapper)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use MethodInfo.descriptor(Function)
    static String
    getDescriptor(org.jboss.jandex.Type type, Function<String,String> typeArgMapper)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use Type.descriptor(Function)
    static int
    getLoadOpcode(org.jboss.jandex.Type jandexType)
    Returns the bytecode instruction to load the given Jandex Type.
    static int
    getParameterSize(org.jboss.jandex.Type paramType)
    Returns the number of underlying bytecode parameters taken by the given Jandex parameter Type.
    static org.jboss.jandex.Type[]
    getParameterTypes(String methodDescriptor)
    Returns the Jandex Types of the parameters of the given method descriptor.
    static int
    getReturnInstruction(String typeDescriptor)
    Returns a return bytecode instruction suitable for the given return type descriptor.
    static int
    getReturnInstruction(org.jboss.jandex.Type jandexType)
    Returns a return bytecode instruction suitable for the given return Jandex Type.
    static String
    getSignature(org.jboss.jandex.MethodInfo method, Function<String,String> typeArgMapper)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use MethodInfo.genericSignature(Function)
    static String
    getSignature(org.jboss.jandex.Type type, Function<String,String> typeArgMapper)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use GenericSignature.forType(Type, Function, StringBuilder)
    static String
    getSignatureIfRequired(org.jboss.jandex.MethodInfo method)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use GenericSignature.genericSignatureIfRequired()
    static String
    getSignatureIfRequired(org.jboss.jandex.MethodInfo method, Function<String,String> typeArgMapper)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use GenericSignature.genericSignatureIfRequired(Function)
    static void
    printValueOnStderr(org.objectweb.asm.MethodVisitor mv, Runnable valuePusher)
    Prints the value pushed on the stack (must be an Object) by the given valuePusher to STDERR.
    static void
    unboxIfRequired(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.Type jandexType)
    Calls the right unboxing method for the given Jandex Type if it is a primitive.
    static void
    unboxIfRequired(org.objectweb.asm.MethodVisitor mv, org.objectweb.asm.Type type)
    Calls the right unboxing method for the given Jandex Type if it is a primitive.
    static void
    visitLdc(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.Type jandexType)
    Invokes the proper LDC Class Constant instructions for the given Jandex Type.

    Methods inherited from class java.lang.Object

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

    • PRIMITIVES

      public static final List<org.objectweb.asm.Type> PRIMITIVES
    • WRAPPERS

      public static final List<org.objectweb.asm.Type> WRAPPERS
    • WRAPPER_TO_PRIMITIVE

      public static final Map<org.objectweb.asm.Type,org.objectweb.asm.Type> WRAPPER_TO_PRIMITIVE
    • PRIMITIVE_DESCRIPTOR_TO_PRIMITIVE_CLASS_LITERAL

      public static final Map<Character,String> PRIMITIVE_DESCRIPTOR_TO_PRIMITIVE_CLASS_LITERAL
  • Constructor Details

    • AsmUtil

      public AsmUtil()
  • Method Details

    • autobox

      public static org.objectweb.asm.Type autobox(org.objectweb.asm.Type primitive)
    • getSignatureIfRequired

      @Deprecated(since="3.1", forRemoval=true) public static String getSignatureIfRequired(org.jboss.jandex.MethodInfo method)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use GenericSignature.genericSignatureIfRequired()
    • getSignatureIfRequired

      @Deprecated(since="3.1", forRemoval=true) public static String getSignatureIfRequired(org.jboss.jandex.MethodInfo method, Function<String,String> typeArgMapper)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use GenericSignature.genericSignatureIfRequired(Function)
    • getSignature

      @Deprecated(since="3.1", forRemoval=true) public static String getSignature(org.jboss.jandex.MethodInfo method, Function<String,String> typeArgMapper)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use MethodInfo.genericSignature(Function)
    • getDescriptor

      @Deprecated(since="3.1", forRemoval=true) public static String getDescriptor(org.jboss.jandex.MethodInfo method, Function<String,String> typeArgMapper)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use MethodInfo.descriptor(Function)
    • getDescriptor

      @Deprecated(since="3.1", forRemoval=true) public static String getDescriptor(org.jboss.jandex.Type type, Function<String,String> typeArgMapper)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Type.descriptor(Function)
    • getSignature

      @Deprecated(since="3.1", forRemoval=true) public static String getSignature(org.jboss.jandex.Type type, Function<String,String> typeArgMapper)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use GenericSignature.forType(Type, Function, StringBuilder)
    • getReturnInstruction

      public static int getReturnInstruction(String typeDescriptor)
      Returns a return bytecode instruction suitable for the given return type descriptor. This will return specialised return instructions IRETURN, LRETURN, FRETURN, DRETURN, RETURN for primitives/void, and ARETURN otherwise;
      Parameters:
      typeDescriptor - the return type descriptor.
      Returns:
      the correct bytecode return instruction for that return type descriptor.
    • getReturnInstruction

      public static int getReturnInstruction(org.jboss.jandex.Type jandexType)
      Returns a return bytecode instruction suitable for the given return Jandex Type. This will return specialised return instructions IRETURN, LRETURN, FRETURN, DRETURN, RETURN for primitives/void, and ARETURN otherwise;
      Parameters:
      jandexType - the return Jandex Type.
      Returns:
      the correct bytecode return instruction for that return type descriptor.
    • visitLdc

      public static void visitLdc(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.Type jandexType)
      Invokes the proper LDC Class Constant instructions for the given Jandex Type. This will properly create LDC instructions for array types, class/parameterized classes, and primitive types by loading their equivalent TYPE constants in their box types, as well as type variables (using the first bound or Object) and Void.
      Parameters:
      mv - The MethodVisitor on which to visit the LDC instructions
      jandexType - the Jandex Type whose Class Constant to load.
    • boxIfRequired

      public static void boxIfRequired(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.Type jandexType)
      Calls the right boxing method for the given Jandex Type if it is a primitive.
      Parameters:
      mv - The MethodVisitor on which to visit the boxing instructions
      jandexType - The Jandex Type to box if it is a primitive.
    • getLoadOpcode

      public static int getLoadOpcode(org.jboss.jandex.Type jandexType)
      Returns the bytecode instruction to load the given Jandex Type. This returns the specialised bytecodes ILOAD, DLOAD, FLOAD and LLOAD for primitives, or ALOAD otherwise.
      Parameters:
      jandexType - The Jandex Type whose load instruction to return.
      Returns:
      The bytecode instruction to load the given Jandex Type.
    • unboxIfRequired

      public static void unboxIfRequired(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.Type jandexType)
      Calls the right unboxing method for the given Jandex Type if it is a primitive.
      Parameters:
      mv - The MethodVisitor on which to visit the unboxing instructions
      jandexType - The Jandex Type to unbox if it is a primitive.
    • unboxIfRequired

      public static void unboxIfRequired(org.objectweb.asm.MethodVisitor mv, org.objectweb.asm.Type type)
      Calls the right unboxing method for the given Jandex Type if it is a primitive.
      Parameters:
      mv - The MethodVisitor on which to visit the unboxing instructions
      type - The Jandex Type to unbox if it is a primitive.
    • getParameterTypes

      public static org.jboss.jandex.Type[] getParameterTypes(String methodDescriptor)
      Returns the Jandex Types of the parameters of the given method descriptor.
      Parameters:
      methodDescriptor - a method descriptor
      Returns:
      the list of Jandex Type objects representing the parameters of the given method descriptor.
    • getParameterSize

      public static int getParameterSize(org.jboss.jandex.Type paramType)
      Returns the number of underlying bytecode parameters taken by the given Jandex parameter Type. This will be 2 for doubles and longs, 1 otherwise.
      Parameters:
      paramType - the Jandex parameter Type
      Returns:
      the number of underlying bytecode parameters required.
    • printValueOnStderr

      public static void printValueOnStderr(org.objectweb.asm.MethodVisitor mv, Runnable valuePusher)
      Prints the value pushed on the stack (must be an Object) by the given valuePusher to STDERR.
      Parameters:
      mv - The MethodVisitor to forward printing to.
      valuePusher - The function to invoke to push an Object to print on the stack.
    • copyParameterNames

      public static void copyParameterNames(org.objectweb.asm.MethodVisitor mv, org.jboss.jandex.MethodInfo method)
      Copy the parameter names to the given MethodVisitor, unless we don't have parameter name info
      Parameters:
      mv - the visitor to copy to
      method - the method to copy from