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:
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, aString
or aClass
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
JavaConstant.Simple.Dispatcher
A dispatcher to representjava.lang.constant.ConstantDesc
.protected static class
JavaConstant.Simple.OfTrivialValue<S>
Represents a trivial constant value that represents itself.protected static class
JavaConstant.Simple.OfTypeDescription
Represents 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.OfClassDesc
CLASS_DESC
A dispatcher for interaction withjava.lang.constant.ClassDesc
.protected static JavaConstant.Simple.Dispatcher
CONSTANT_DESC
A dispatcher for interaction withjava.lang.constant.ClassDesc
.protected static JavaConstant.Simple.Dispatcher.OfDirectMethodHandleDesc
DIRECT_METHOD_HANDLE_DESC
A dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc
.protected static JavaConstant.Simple.Dispatcher.OfDirectMethodHandleDesc.ForKind
DIRECT_METHOD_HANDLE_DESC_KIND
A dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc
.protected static JavaConstant.Simple.Dispatcher.OfDynamicConstantDesc
DYNAMIC_CONSTANT_DESC
A dispatcher for interaction withjava.lang.constant.DirectMethodHandleDesc
.protected static JavaConstant.Simple.Dispatcher.OfMethodHandleDesc
METHOD_HANDLE_DESC
A dispatcher for interaction withjava.lang.constant.MethodHandleDesc
.protected static JavaConstant.Simple.Dispatcher.OfMethodTypeDesc
METHOD_TYPE_DESC
A dispatcher for interaction withjava.lang.constant.MethodTypeDesc
.private TypeDescription
typeDescription
A description of the type of the constant.protected T
value
The represented constant pool value.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Simple(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> T
doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.boolean
equals(java.lang.Object object)
TypeDescription
getTypeDescription()
Returns a description of the type of the represented instance or at least a stub.T
getValue()
Returns the represented value.int
hashCode()
static JavaConstant
of(TypeDescription typeDescription)
Returns a Java constant representation for aTypeDescription
.static JavaConstant
ofDescription(java.lang.Object value, java.lang.ClassLoader classLoader)
Creates a Java constant value from ajava.lang.constant.ConstantDesc
.static JavaConstant
ofDescription(java.lang.Object value, ClassFileLocator classFileLocator)
Creates a Java constant value from ajava.lang.constant.ConstantDesc
.static JavaConstant
ofDescription(java.lang.Object value, TypePool typePool)
Creates a Java constant value from ajava.lang.constant.ConstantDesc
.static JavaConstant
ofLoaded(java.lang.Object value)
Resolves a loaded Java value to a Java constant representation.java.lang.String
toString()
static JavaConstant
wrap(java.lang.Object value)
Wraps a value representing a loaded or unloaded constant asJavaConstant
instance.static java.util.List<JavaConstant>
wrap(java.util.List<?> values)
Wraps a list of either loaded or unloaded constant representations asJavaConstant
instances.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
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#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.
-
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.
-
ofDescription
public static JavaConstant ofDescription(java.lang.Object value, java.lang.ClassLoader classLoader)
Creates a Java constant value from ajava.lang.constant.ConstantDesc
.- Parameters:
value
- Thejava.lang.constant.ConstantDesc
to 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.ConstantDesc
to 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.ConstantDesc
to 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 asJavaConstant
instance.- 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 asJavaConstant
instances.- 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 the represented instance or at least a stub.- Specified by:
getTypeDescription
in interfaceJavaConstant
- Returns:
- A description of the type of the represented instance or at least a stub.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-