APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.constant

public final Class ConstantUtils

extends Object
Class Inheritance
Annotations
@AOTSafeClassInitializer
Imports
jdk.internal.vm.annotation.AOTSafeClassInitializer, .Stable, sun.invoke.util.Wrapper, java.lang.constant.ClassDesc, .ConstantDesc, .ConstantDescs, .MethodTypeDesc, java.lang.invoke.MethodType, java.util.Set, jdk.internal.access.JavaLangAccess, .SharedSecrets

Helper methods for the implementation of java.lang.constant.

Field Summary

Modifier and TypeField and Description
public static final ClassDesc
public static ClassDesc
public static final ClassDesc[]
public static final ConstantDesc[]
EMPTY_CONSTANTDESC

an empty constant descriptor

private static final JavaLangAccess
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
public static final int
private static final Set<String>

Constructor Summary

AccessConstructor and Description
private
ConstantUtils()

No instantiation

Method Summary

Modifier and TypeMethod and Description
public static int
arrayDepth(String descriptorString, int off)

Retrieves the array depth on a trusted descriptor.

pack-priv static IllegalArgumentException
public static ClassDesc
binaryNameToDesc(String
a binary name
binaryName
)

Creates a ClassDesc from a pre-validated binary name for a class or interface type.

public static String
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.

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

public static String
public static PrimitiveClassDescImpl
forPrimitiveType(String descriptor, int offset)

public static ClassDesc
internalNameToDesc(String
a binary name
internalName
)

Creates a ClassDesc from a pre-validated internal name for a class or interface type.

public static String
pack-priv static String
pack-priv static IllegalArgumentException
private static IllegalArgumentException
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.

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.

public static ClassDesc
parseReferenceTypeDesc(String
a field descriptor string for a class or interface type
descriptor
)

Creates a ClassDesc from a descriptor string for a class or interface type or an array type.

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.

public static ClassDesc
referenceClassDesc(String
a field descriptor string for a class or interface type
descriptor
)

Creates a ClassDesc from a pre-validated descriptor string for a class or interface type or an array type.

pack-priv static ClassDesc
resolveClassDesc(String descriptor, int start, int len)

pack-priv static int

Returns:

the length of the descriptor, or 0 if it is not a descriptor
skipOverFieldSignature
(String
the descriptor string
descriptor
,
int
the starting index into the string
start
,
int
the ending index within the string
end
)

Validates that the characters at [start, end) within the provided string describe a valid field type descriptor.

public static void
public static String

Returns:

the class name passed if valid
validateBinaryClassName
(String
the class name
name
)

Validates the correctness of a binary class name.

public static String

Returns:

the package name passed if valid
validateBinaryPackageName
(String
the package name
name
)

Validates the correctness of a binary package name.

public static void
private static String

Returns:

the name passed if valid
validateClassOrPackageName
(String
the name
name
,
boolean
true means / is the separator char (internal form); otherwise . is the separator char
slashSeparator
,
boolean
true means the empty string is a valid name
allowEmpty
)

Validates the correctness of a class or interface name or a package name.

public static String

Returns:

the class name passed if valid
validateInternalClassName
(String
the class name
name
)

Validates the correctness of an internal class name.

public static String

Returns:

the package name passed if valid
validateInternalPackageName
(String
the package name
name
)

Validates the correctness of an internal package name.

public static String

Returns:

the name passed if valid
validateMemberName
(String
the name of the member
name
,
boolean method)

Validates a member name

public static String

Returns:

the module name passed if valid
validateModuleName
(String
the module name
name
)

Validates the correctness of a module name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CD_module_infoback to summary
public static final ClassDesc CD_module_info
CD_Object_arrayback to summary
public static ClassDesc CD_Object_array
Annotations
@Stable
EMPTY_CLASSDESCback to summary
public static final ClassDesc[] EMPTY_CLASSDESC
EMPTY_CONSTANTDESCback to summary
public static final ConstantDesc[] EMPTY_CONSTANTDESC

an empty constant descriptor

JLAback to summary
private static final JavaLangAccess JLA
JVM_SIGNATURE_ARRAYback to summary
private static final char JVM_SIGNATURE_ARRAY
JVM_SIGNATURE_BOOLEANback to summary
private static final char JVM_SIGNATURE_BOOLEAN
JVM_SIGNATURE_BYTEback to summary
private static final char JVM_SIGNATURE_BYTE
JVM_SIGNATURE_CHARback to summary
private static final char JVM_SIGNATURE_CHAR
JVM_SIGNATURE_CLASSback to summary
private static final char JVM_SIGNATURE_CLASS
JVM_SIGNATURE_DOUBLEback to summary
private static final char JVM_SIGNATURE_DOUBLE
JVM_SIGNATURE_FLOATback to summary
private static final char JVM_SIGNATURE_FLOAT
JVM_SIGNATURE_INTback to summary
private static final char JVM_SIGNATURE_INT
JVM_SIGNATURE_LONGback to summary
private static final char JVM_SIGNATURE_LONG
JVM_SIGNATURE_SHORTback to summary
private static final char JVM_SIGNATURE_SHORT
JVM_SIGNATURE_VOIDback to summary
private static final char JVM_SIGNATURE_VOID
MAX_ARRAY_TYPE_DESC_DIMENSIONSback to summary
public static final int MAX_ARRAY_TYPE_DESC_DIMENSIONS
pointyNamesback to summary
private static final Set<String> pointyNames

Constructor Detail

ConstantUtilsback to summary
private ConstantUtils()

No instantiation

Method Detail

arrayDepthback to summary
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.

badMethodDescriptorback to summary
pack-priv static IllegalArgumentException badMethodDescriptor(String descriptor)
binaryNameToDescback to summary
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:String

a binary name

binaryToInternalback to summary
public static String binaryToInternal(String name)
classDescback to summary
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.

concatback to summary
public static String concat(String prefix, Object value, String suffix)
dropFirstAndLastCharback to summary
public static String dropFirstAndLastChar(String s)
forPrimitiveTypeback to summary
public static PrimitiveClassDescImpl forPrimitiveType(String descriptor, int offset)
internalNameToDescback to summary
public static ClassDesc internalNameToDesc(String internalName)

Creates a ClassDesc from a pre-validated internal name for a class or interface type. Validated version of ClassDesc#ofInternalName(String).

Parameters
internalName:String

a binary name

internalToBinaryback to summary
public static String internalToBinary(String name)
invalidArrayRankMessageback to summary
pack-priv static String invalidArrayRankMessage(int rank)
invalidClassNameback to summary
pack-priv static IllegalArgumentException invalidClassName(String className)
maxArrayTypeDescDimensionsback to summary
private static IllegalArgumentException maxArrayTypeDescDimensions()
methodTypeDescback to summary
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.

methodTypeDescback to summary
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.

parseReferenceTypeDescback to summary
public static ClassDesc parseReferenceTypeDesc(String descriptor)

Creates a ClassDesc from a descriptor string for a class or interface type or an array type.

Parameters
descriptor:String

a field descriptor string for a class or interface type

Exceptions
IllegalArgumentException:
if the descriptor string is not a valid field descriptor string, or does not describe a class or interface type
Java Virtual Machine Specification
4.3.2 Field Descriptors
referenceClassDescback to summary
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.

referenceClassDescback to summary
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:String

a field descriptor string for a class or interface type

Java Virtual Machine Specification
4.3.2 Field Descriptors
resolveClassDescback to summary
pack-priv static ClassDesc resolveClassDesc(String descriptor, int start, int len)
skipOverFieldSignatureback to summary
pack-priv static int skipOverFieldSignature(String descriptor, int start, int end)

Validates that the characters at [start, end) within the provided string describe a valid field type descriptor.

Parameters
descriptor:String

the descriptor string

start:int

the starting index into the string

end:int

the ending index within the string

Returns:int

the length of the descriptor, or 0 if it is not a descriptor

Exceptions
IllegalArgumentException:
if the descriptor string is not valid
validateArrayRankback to summary
public static void validateArrayRank(int rank)
validateBinaryClassNameback to summary
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:String

the class name

Returns:String

the class name passed if valid

Exceptions
IllegalArgumentException:
if the class name is invalid
NullPointerException:
if class name is null
validateBinaryPackageNameback to summary
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:String

the package name

Returns:String

the package name passed if valid

Exceptions
IllegalArgumentException:
if the package name is invalid
NullPointerException:
if the package name is null
validateClassOrInterfaceback to summary
public static void validateClassOrInterface(ClassDesc classDesc)
validateClassOrPackageNameback to summary
private static String validateClassOrPackageName(String name, boolean slashSeparator, boolean allowEmpty)

Validates the correctness of a class or interface name or a package name. In particular checks for the presence of invalid characters, consecutive, leading, or trailing separator char, for both non-internal and internal forms, and the empty string for class or interface names.

Parameters
name:String

the name

slashSeparator:boolean

true means / is the separator char (internal form); otherwise . is the separator char

allowEmpty:boolean

true means the empty string is a valid name

Returns:String

the name passed if valid

Exceptions
IllegalArgumentException:
if the name is invalid
NullPointerException:
if name is null
validateInternalClassNameback to summary
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:String

the class name

Returns:String

the class name passed if valid

Exceptions
IllegalArgumentException:
if the class name is invalid
NullPointerException:
if class name is null
validateInternalPackageNameback to summary
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:String

the package name

Returns:String

the package name passed if valid

Exceptions
IllegalArgumentException:
if the package name is invalid
NullPointerException:
if the package name is null
validateMemberNameback to summary
public static String validateMemberName(String name, boolean method)

Validates a member name

Parameters
name:String

the name of the member

Returns:String

the name passed if valid

Exceptions
IllegalArgumentException:
if the member name is invalid
NullPointerException:
if the member name is null
validateModuleNameback to summary
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. 4.2.3 Module and Package Names

Parameters
name:String

the module name

Returns:String

the module name passed if valid

Exceptions
IllegalArgumentException:
if the module name is invalid
NullPointerException:
if the module name is null