Package net.bytebuddy.utility
Class JavaConstant.Simple<T>
- java.lang.Object
-
- net.bytebuddy.utility.JavaConstant.Simple<T>
-
- Type Parameters:
T- The represented type.
- All Implemented Interfaces:
ConstantValue,JavaConstant
- Direct Known Subclasses:
JavaConstant.Simple.OfTrivialValue,JavaConstant.Simple.OfTypeDescription
- Enclosing interface:
- JavaConstant
public abstract static class JavaConstant.Simple<T> extends java.lang.Object implements JavaConstant
Represents a simple Java constant, either a primitive constant, aStringor aClass.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceJavaConstant.Simple.DispatcherA dispatcher to representjava.lang.constant.ConstantDesc.protected static classJavaConstant.Simple.OfTrivialValue<S>Represents a trivial constant value that represents itself.protected static classJavaConstant.Simple.OfTypeDescriptionRepresents a type constant.-
Nested classes/interfaces inherited from interface net.bytebuddy.utility.JavaConstant
JavaConstant.Dynamic, JavaConstant.MethodHandle, JavaConstant.MethodType, JavaConstant.Simple<T>, JavaConstant.Visitor<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected static JavaConstant.Simple.Dispatcher.OfClassDescCLASS_DESCA dispatcher for interaction withjava.lang.constant.ClassDesc.protected static JavaConstant.Simple.DispatcherCONSTANT_DESCA dispatcher for interaction withjava.lang.constant.ClassDesc.protected static JavaConstant.Simple.Dispatcher.OfDirectMethodHandleDescDIRECT_METHOD_HANDLE_DESCA dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc.protected static JavaConstant.Simple.Dispatcher.OfDirectMethodHandleDesc.ForKindDIRECT_METHOD_HANDLE_DESC_KINDA dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc.protected static JavaConstant.Simple.Dispatcher.OfDynamicConstantDescDYNAMIC_CONSTANT_DESCA dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc.protected static JavaConstant.Simple.Dispatcher.OfMethodHandleDescMETHOD_HANDLE_DESCA dispatcher for interaction withjava.lang.constant.MethodHandleDesc.protected static JavaConstant.Simple.Dispatcher.OfMethodTypeDescMETHOD_TYPE_DESCA dispatcher for interaction withjava.lang.constant.MethodTypeDesc.private TypeDescriptiontypeDescriptionA description of the type of the constant.protected TvalueThe represented constant pool value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSimple(T value, TypeDescription typeDescription)Creates a simple Java constant.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.booleanequals(java.lang.Object object)TypeDescriptiongetTypeDescription()Returns a description of the type of this constant.TgetValue()Returns the represented value.inthashCode()static JavaConstantof(TypeDescription typeDescription)Returns a Java constant representation for aTypeDescription.static JavaConstantofAsm(TypePool typePool, java.lang.Object value)Resolves an ASM constant to aJavaConstant.static JavaConstantofDescription(java.lang.Object value, java.lang.ClassLoader classLoader)Creates a Java constant value from ajava.lang.constant.ConstantDesc.static JavaConstantofDescription(java.lang.Object value, ClassFileLocator classFileLocator)Creates a Java constant value from ajava.lang.constant.ConstantDesc.static JavaConstantofDescription(java.lang.Object value, TypePool typePool)Creates a Java constant value from ajava.lang.constant.ConstantDesc.static JavaConstantofLoaded(java.lang.Object value)Resolves a loaded Java value to a Java constant representation.protected static JavaConstantofLoadedOrNull(java.lang.Object value)Resolves a loaded Java value to a Java constant representation.java.lang.StringtoString()static JavaConstantwrap(java.lang.Object value)Wraps a value representing a loaded or unloaded constant asJavaConstantinstance.static java.util.List<JavaConstant>wrap(java.util.List<?> values)Wraps a list of either loaded or unloaded constant representations asJavaConstantinstances.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.bytebuddy.utility.ConstantValue
toStackManipulation
-
Methods inherited from interface net.bytebuddy.utility.JavaConstant
accept, toDescription
-
-
-
-
Field Detail
-
CONSTANT_DESC
protected static final JavaConstant.Simple.Dispatcher CONSTANT_DESC
A dispatcher for interaction withjava.lang.constant.ClassDesc.
-
CLASS_DESC
protected static final JavaConstant.Simple.Dispatcher.OfClassDesc CLASS_DESC
A dispatcher for interaction withjava.lang.constant.ClassDesc.
-
METHOD_TYPE_DESC
protected static final JavaConstant.Simple.Dispatcher.OfMethodTypeDesc METHOD_TYPE_DESC
A dispatcher for interaction withjava.lang.constant.MethodTypeDesc.
-
METHOD_HANDLE_DESC
protected static final JavaConstant.Simple.Dispatcher.OfMethodHandleDesc METHOD_HANDLE_DESC
A dispatcher for interaction withjava.lang.constant.MethodHandleDesc.
-
DIRECT_METHOD_HANDLE_DESC
protected static final JavaConstant.Simple.Dispatcher.OfDirectMethodHandleDesc DIRECT_METHOD_HANDLE_DESC
A dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc.
-
DIRECT_METHOD_HANDLE_DESC_KIND
protected static final JavaConstant.Simple.Dispatcher.OfDirectMethodHandleDesc.ForKind DIRECT_METHOD_HANDLE_DESC_KIND
A dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc.
-
DYNAMIC_CONSTANT_DESC
protected static final JavaConstant.Simple.Dispatcher.OfDynamicConstantDesc DYNAMIC_CONSTANT_DESC
A dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc.
-
value
protected final T value
The represented constant pool value.
-
typeDescription
private final TypeDescription typeDescription
A description of the type of the constant.
-
-
Constructor Detail
-
Simple
protected Simple(T value, TypeDescription typeDescription)
Creates a simple Java constant.- Parameters:
value- The represented constant pool value.typeDescription- A description of the type of the constant.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
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.
-
ofAsm
public static JavaConstant ofAsm(TypePool typePool, java.lang.Object value)
Resolves an ASM constant to aJavaConstant.- Parameters:
typePool- The type pool to resolve type descriptions with.value- The ASM constant value.- Returns:
- An appropriate
JavaConstant.
-
ofLoaded
public static JavaConstant ofLoaded(java.lang.Object value)
Resolves a loaded Java value to a Java constant representation.- Parameters:
value- The value to represent.- Returns:
- An appropriate Java constant representation.
-
ofLoadedOrNull
@MaybeNull protected static JavaConstant ofLoadedOrNull(java.lang.Object value)
Resolves a loaded Java value to a Java constant representation.- Parameters:
value- The value to represent.- Returns:
- An appropriate Java constant representation or
nullif the supplied argument is not a compile-time constant.
-
ofDescription
public static JavaConstant ofDescription(java.lang.Object value, @MaybeNull java.lang.ClassLoader classLoader)
Creates a Java constant value from ajava.lang.constant.ConstantDesc.- Parameters:
value- Thejava.lang.constant.ConstantDescto represent.classLoader- The class loader to use for resolving type information from the supplied value.- Returns:
- An appropriate Java constant representation.
-
ofDescription
public static JavaConstant ofDescription(java.lang.Object value, ClassFileLocator classFileLocator)
Creates a Java constant value from ajava.lang.constant.ConstantDesc.- Parameters:
value- Thejava.lang.constant.ConstantDescto represent.classFileLocator- The class file locator to use for resolving type information from the supplied value.- Returns:
- An appropriate Java constant representation.
-
ofDescription
public static JavaConstant ofDescription(java.lang.Object value, TypePool typePool)
Creates a Java constant value from ajava.lang.constant.ConstantDesc.- Parameters:
value- Thejava.lang.constant.ConstantDescto represent.typePool- The type pool to use for resolving type information from the supplied value.- Returns:
- An appropriate Java constant representation.
-
of
public static JavaConstant of(TypeDescription typeDescription)
Returns a Java constant representation for aTypeDescription.- Parameters:
typeDescription- The type to represent as a constant.- Returns:
- An appropriate Java constant representation.
-
wrap
public static JavaConstant wrap(java.lang.Object value)
Wraps a value representing a loaded or unloaded constant asJavaConstantinstance.- Parameters:
value- The value to wrap.- Returns:
- A wrapped Java constant.
-
wrap
public static java.util.List<JavaConstant> wrap(java.util.List<?> values)
Wraps a list of either loaded or unloaded constant representations asJavaConstantinstances.- Parameters:
values- The values to wrap.- Returns:
- A list of wrapped Java constants.
-
getValue
public T getValue()
Returns the represented value.- Returns:
- The represented value.
-
getTypeDescription
public TypeDescription getTypeDescription()
Returns a description of the type of this constant.- Specified by:
getTypeDescriptionin interfaceConstantValue- Returns:
- A description of the type of this constant.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(@MaybeNull java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-