Class MethodConstant
- java.lang.Object
-
- net.bytebuddy.implementation.bytecode.constant.MethodConstant
-
- All Implemented Interfaces:
StackManipulation
- Direct Known Subclasses:
MethodConstant.ForConstructor
,MethodConstant.ForMethod
public abstract class MethodConstant extends java.lang.Object implements StackManipulation
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.-
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.bytecode.StackManipulation
StackManipulation.Compound, StackManipulation.Illegal, StackManipulation.Size, StackManipulation.Trivial
-
-
Field Summary
Fields Modifier and Type Field Description 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
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.StackManipulation
cached()
Returns a cached version of this method constant as specified byMethodConstant.CachedMethod
andMethodConstant.CachedConstructor
.static MethodConstant.CanCache
forMethod(MethodDescription.InDefinedShape methodDescription)
Creates a stack manipulation that loads a method constant onto the operand stack.boolean
isValid()
Determines if this stack manipulation is valid.protected abstract StackManipulation
preparation()
Returns a stack manipulation that loads the values that are required for loading a method constant onto the operand stack.
-
-
-
Field Detail
-
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
-
forMethod
public static MethodConstant.CanCache forMethod(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.
-
isValid
public boolean isValid()
Description copied from interface:StackManipulation
Determines if this stack manipulation is valid.- Specified by:
isValid
in interfaceStackManipulation
- Returns:
- If
false
, this manipulation cannot be applied and should throw an exception.
-
apply
public StackManipulation.Size apply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext)
Description copied from interface:StackManipulation
Applies the stack manipulation that is described by this instance.- Specified by:
apply
in interfaceStackManipulation
- 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.
-
preparation
protected abstract StackManipulation preparation()
Returns a stack manipulation that loads the values that are required for loading a method constant onto the operand stack.- Returns:
- A stack manipulation for loading a method or constructor onto the operand stack.
-
accessorMethod
protected abstract MethodDescription 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.
-
cached
public StackManipulation cached()
Returns a cached version of this method constant as specified byMethodConstant.CachedMethod
andMethodConstant.CachedConstructor
.- Returns:
- A cached version of this method constant.
-
-