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 aMethodvalue 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 classMethodConstant.CachedConstructorRepresents a cached constructor for aMethodConstant.protected static classMethodConstant.CachedMethodRepresents a cached method for aMethodConstant.static interfaceMethodConstant.CanCacheRepresents aMethodConstantthat is directly loaded onto the operand stack without caching the value.protected static classMethodConstant.CanCacheIllegalRepresents a method constant that cannot be represented by Java's reflection API.protected static classMethodConstant.ForConstructorCreates aMethodConstantfor loading aConstructorinstance onto the operand stack.protected static classMethodConstant.ForMethodCreates aMethodConstantfor loading aMethodinstance onto the operand stack.protected static classMethodConstant.PrivilegedLookupPerforms a privileged lookup of a method constant by using anAccessController.-
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.InDefinedShapemethodDescriptionA description of the method to be loaded onto the stack.
-
Constructor Summary
Constructors Modifier Constructor Description protectedMethodConstant(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.InDefinedShapeaccessorMethod()Returns the method for loading a declared method or constructor onto the operand stack.StackManipulation.Sizeapply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext)Applies the stack manipulation that is described by this instance.booleanequals(java.lang.Object other)inthashCode()booleanisValid()Determines if this stack manipulation is valid.protected abstract StackManipulationmethodName()Returns a stack manipulation that loads the method name onto the operand stack if this is required.static MethodConstant.CanCacheof(MethodDescription.InDefinedShape methodDescription)Creates a stack manipulation that loads a method constant onto the operand stack.static MethodConstant.CanCacheofPrivileged(MethodDescription.InDefinedShape methodDescription)Creates a stack manipulation that loads a method constant onto the operand stack using anAccessController.protected MethodConstant.CanCacheprivileged()Returns a method constant that uses anAccessControllerto look up this constant.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.
-
-
-
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 theMethodrepresentation should be created.
-
-
Method Detail
-
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 anAccessController.- 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.
-
isValid
public boolean isValid()
Determines if this stack manipulation is valid.- Specified by:
isValidin 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)
Applies the stack manipulation that is described by this instance.- Specified by:
applyin 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.
-
privileged
protected MethodConstant.CanCache privileged()
Returns a method constant that uses anAccessControllerto look up this constant.- Returns:
- A method constant that uses an
AccessControllerto 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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
-