Class ConstantUtils

java.lang.Object
io.smallrye.classfile.extras.constant.ConstantUtils

public final class ConstantUtils extends Object
Helper methods for the implementation of java.lang.constant.
  • Field Details

    • EMPTY_CONSTANTDESC

      public static final ConstantDesc[] EMPTY_CONSTANTDESC
      an empty constant descriptor
    • EMPTY_CLASSDESC

      public static final ClassDesc[] EMPTY_CLASSDESC
    • MAX_ARRAY_TYPE_DESC_DIMENSIONS

      public static final int MAX_ARRAY_TYPE_DESC_DIMENSIONS
      See Also:
    • CD_module_info

      public static final ClassDesc CD_module_info
    • CD_Object_array

      public static ClassDesc CD_Object_array
  • Method Details

    • binaryNameToDesc

      public static ClassDesc binaryNameToDesc(String binaryName)
      Creates a ClassDesc from a pre-validated binary name for a class or interface type. Validated version of ClassDesc.of(String).
      Parameters:
      binaryName - a binary name
    • internalNameToDesc

      public static ClassDesc internalNameToDesc(String internalName)
      Creates a ClassDesc from a pre-validated internal name for a class or interface type. Validated version of
      invalid reference
      ClassDesc#ofInternalName(String)
      .
      Parameters:
      internalName - a binary name
    • classDesc

      public static ClassDesc classDesc(Class<?> type)
      Creates a ClassDesc from a Class object, requires that this class can always be described nominally, i.e. this class is not a hidden class or interface or an array with a hidden component type.
    • referenceClassDesc

      public static ClassDesc referenceClassDesc(Class<?> type)
      Creates a ClassDesc from a Class object representing a non-hidden class or interface or an array type with a non-hidden component type.
    • referenceClassDesc

      public static ClassDesc referenceClassDesc(String descriptor)
      Creates a ClassDesc from a pre-validated descriptor string for a class or interface type or an array type.
      Parameters:
      descriptor - a field descriptor string for a class or interface type
    • methodTypeDesc

      public static MethodTypeDesc methodTypeDesc(MethodType type)
      Creates a MethodTypeDesc from a MethodType object, requires that the type can be described nominally, i.e. all of its return type and parameter types can be described nominally.
    • methodTypeDesc

      public static MethodTypeDesc methodTypeDesc(Class<?> returnType, Class<?>[] parameterTypes)
      Creates a MethodTypeDesc from return class and parameter class objects, requires that all of them can be described nominally. This version is mainly useful for working with Method objects.
    • validateBinaryClassName

      public static String validateBinaryClassName(String name)
      Validates the correctness of a binary class name. In particular checks for the presence of invalid characters, empty name, consecutive, leading, or trailing ..
      Parameters:
      name - the class name
      Returns:
      the class name passed if valid
      Throws:
      IllegalArgumentException - if the class name is invalid
      NullPointerException - if class name is null
    • validateInternalClassName

      public static String validateInternalClassName(String name)
      Validates the correctness of an internal class name. In particular checks for the presence of invalid characters, empty name, consecutive, leading, or trailing /.
      Parameters:
      name - the class name
      Returns:
      the class name passed if valid
      Throws:
      IllegalArgumentException - if the class name is invalid
      NullPointerException - if class name is null
    • validateBinaryPackageName

      public static String validateBinaryPackageName(String name)
      Validates the correctness of a binary package name. In particular checks for the presence of invalid characters, consecutive, leading, or trailing .. Allows empty strings for the unnamed package.
      Parameters:
      name - the package name
      Returns:
      the package name passed if valid
      Throws:
      IllegalArgumentException - if the package name is invalid
      NullPointerException - if the package name is null
    • validateInternalPackageName

      public static String validateInternalPackageName(String name)
      Validates the correctness of an internal package name. In particular checks for the presence of invalid characters, consecutive, leading, or trailing /. Allows empty strings for the unnamed package.
      Parameters:
      name - the package name
      Returns:
      the package name passed if valid
      Throws:
      IllegalArgumentException - if the package name is invalid
      NullPointerException - if the package name is null
    • validateModuleName

      public static String validateModuleName(String name)
      Validates the correctness of a module name. In particular checks for the presence of invalid characters in the name. Empty module name is allowed. Module and Package Names
      Parameters:
      name - the module name
      Returns:
      the module name passed if valid
      Throws:
      IllegalArgumentException - if the module name is invalid
      NullPointerException - if the module name is null
    • validateMemberName

      public static String validateMemberName(String name, boolean method)
      Validates a member name
      Parameters:
      name - the name of the member
      Returns:
      the name passed if valid
      Throws:
      IllegalArgumentException - if the member name is invalid
      NullPointerException - if the member name is null
    • validateClassOrInterface

      public static void validateClassOrInterface(ClassDesc classDesc)
    • validateArrayRank

      public static void validateArrayRank(int rank)
    • arrayDepth

      public static int arrayDepth(String descriptorString, int off)
      Retrieves the array depth on a trusted descriptor. Uses a simple loop with the assumption that most descriptors have 0 or very low array depths.
    • binaryToInternal

      public static String binaryToInternal(String name)
    • internalToBinary

      public static String internalToBinary(String name)
    • dropFirstAndLastChar

      public static String dropFirstAndLastChar(String s)
    • forPrimitiveType

      public static ClassDesc forPrimitiveType(String descriptor, int offset)
    • concat

      public static String concat(String prefix, Object value, String suffix)