Class MethodConstant
- java.lang.Object
-
- net.bytebuddy.implementation.bytecode.StackManipulation.AbstractBase
-
- net.bytebuddy.implementation.bytecode.constant.MethodConstant
-
- All Implemented Interfaces:
StackManipulation
- Direct Known Subclasses:
MethodConstant.ForConstructor
,MethodConstant.ForMethod
public abstract class MethodConstant extends StackManipulation.AbstractBase
Represents the creation of aMethod
value which can be created from a given set of constant pool values and can therefore be considered a constant in the broader meaning.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
MethodConstant.CachedConstructor
Represents a cached constructor for aMethodConstant
.protected static class
MethodConstant.CachedMethod
Represents a cached method for aMethodConstant
.static interface
MethodConstant.CanCache
Represents aMethodConstant
that is directly loaded onto the operand stack without caching the value.protected static class
MethodConstant.CanCacheIllegal
Represents a method constant that cannot be represented by Java's reflection API.protected static class
MethodConstant.ForConstructor
Creates aMethodConstant
for loading aConstructor
instance onto the operand stack.protected static class
MethodConstant.ForMethod
Creates aMethodConstant
for loading aMethod
instance onto the operand stack.protected static class
MethodConstant.PrivilegedLookup
Performs a privileged lookup of a method constant by using anjava.security.AccessController
.-
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.bytecode.StackManipulation
StackManipulation.AbstractBase, StackManipulation.Compound, StackManipulation.Illegal, StackManipulation.Simple, StackManipulation.Size, StackManipulation.Trivial
-
-
Field Summary
Fields Modifier and Type Field Description protected static MethodDescription.InDefinedShape
DO_PRIVILEGED
Thejava.security.AccessController#doPrivileged(PrivilegedExceptionAction)
method ornull
if this method is not available on the current VM.protected MethodDescription.InDefinedShape
methodDescription
A description of the method to be loaded onto the stack.
-
Constructor Summary
Constructors Modifier Constructor Description protected
MethodConstant(MethodDescription.InDefinedShape methodDescription)
Creates a new method constant.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract MethodDescription.InDefinedShape
accessorMethod()
Returns the method for loading a declared method or constructor onto the operand stack.StackManipulation.Size
apply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext)
Applies the stack manipulation that is described by this instance.private static MethodDescription.InDefinedShape
doPrivileged()
Resolves thejava.security.AccessController#doPrivileged
method if the security manager is supported on the current VM and if security manager support is not explicitly disabled.boolean
equals(java.lang.Object other)
int
hashCode()
protected abstract StackManipulation
methodName()
Returns a stack manipulation that loads the method name onto the operand stack if this is required.static MethodConstant.CanCache
of(MethodDescription.InDefinedShape methodDescription)
Creates a stack manipulation that loads a method constant onto the operand stack.static MethodConstant.CanCache
ofPrivileged(MethodDescription.InDefinedShape methodDescription)
Creates a stack manipulation that loads a method constant onto the operand stack using anjava.security.AccessController
.protected static java.util.List<StackManipulation>
typeConstantsFor(java.util.List<TypeDescription> parameterTypes)
Returns a list of type constant load operations for the given list of parameters.protected MethodConstant.CanCache
withPrivilegedLookup()
Returns a method constant that uses anjava.security.AccessController
to look up this constant.-
Methods inherited from class net.bytebuddy.implementation.bytecode.StackManipulation.AbstractBase
isValid
-
-
-
-
Field Detail
-
DO_PRIVILEGED
protected static final MethodDescription.InDefinedShape DO_PRIVILEGED
Thejava.security.AccessController#doPrivileged(PrivilegedExceptionAction)
method ornull
if this method is not available on the current VM.
-
methodDescription
protected final MethodDescription.InDefinedShape methodDescription
A description of the method to be loaded onto the stack.
-
-
Constructor Detail
-
MethodConstant
protected MethodConstant(MethodDescription.InDefinedShape methodDescription)
Creates a new method constant.- Parameters:
methodDescription
- The method description for which theMethod
representation should be created.
-
-
Method Detail
-
doPrivileged
private static MethodDescription.InDefinedShape doPrivileged()
Resolves thejava.security.AccessController#doPrivileged
method if the security manager is supported on the current VM and if security manager support is not explicitly disabled.- Returns:
- The
doPrivileged
method ornull
.
-
of
public static MethodConstant.CanCache of(MethodDescription.InDefinedShape methodDescription)
Creates a stack manipulation that loads a method constant onto the operand stack.- Parameters:
methodDescription
- The method to be loaded onto the stack.- Returns:
- A stack manipulation that assigns a method constant for the given method description.
-
ofPrivileged
public static MethodConstant.CanCache ofPrivileged(MethodDescription.InDefinedShape methodDescription)
Creates a stack manipulation that loads a method constant onto the operand stack using anjava.security.AccessController
. If the current VM does not support the access controller API, or ifnet.bytebuddy.securitymanager
is set to false, this method has the same effect asof(MethodDescription.InDefinedShape)
.- Parameters:
methodDescription
- The method to be loaded onto the stack.- Returns:
- A stack manipulation that assigns a method constant for the given method description.
-
typeConstantsFor
protected static java.util.List<StackManipulation> typeConstantsFor(java.util.List<TypeDescription> parameterTypes)
Returns a list of type constant load operations for the given list of parameters.- Parameters:
parameterTypes
- A list of all type descriptions that should be represented as type constant load operations.- Returns:
- A corresponding list of type constant load operations.
-
apply
public StackManipulation.Size apply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext)
Applies the stack manipulation that is described by this instance.- Parameters:
methodVisitor
- The method visitor used to write the method implementation to.implementationContext
- The context of the current implementation.- Returns:
- The changes to the size of the operand stack that are implied by this stack manipulation.
-
withPrivilegedLookup
protected MethodConstant.CanCache withPrivilegedLookup()
Returns a method constant that uses anjava.security.AccessController
to look up this constant.- Returns:
- A method constant that uses an
java.security.AccessController
to look up this constant.
-
methodName
protected abstract StackManipulation methodName()
Returns a stack manipulation that loads the method name onto the operand stack if this is required.- Returns:
- A stack manipulation that loads the method name onto the operand stack if this is required.
-
accessorMethod
protected abstract MethodDescription.InDefinedShape accessorMethod()
Returns the method for loading a declared method or constructor onto the operand stack.- Returns:
- The method for loading a declared method or constructor onto the operand stack.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
-