Class BeforeConstant

java.lang.Object
org.spongepowered.asm.mixin.injection.InjectionPoint
org.spongepowered.asm.mixin.injection.points.BeforeConstant

public class BeforeConstant extends InjectionPoint
Special injection point which can be defined by an Constant annotation or using the at code CONSTANT.

This injection point searches for LDC and other constant opcodes matching its arguments and returns a list of injection points matching those instructions. When used with At it accepts the following parameters:

ordinal
The ordinal position of the constant opcode to match. The default value is -1 which supresses ordinal matching
named argument: nullValue
To match null literals in the method body, set this to true
named argument: intValue
To match int literals in the method body. See also the expandZeroConditions argument below for concerns when matching conditional zeroes.
named argument: floatValue
To match float literals in the method body.
named argument: longValue
To match long literals in the method body.
named argument: doubleValue
To match double literals in the method body.
named argument: stringValue
To match String literals in the method body.
named argument: classValue
To match Class literals in the method body.
named argument: log
Enable debug logging when searching for matching opcodes.
named argument: expandZeroConditions
See the Constant.expandZeroConditions() option, this argument should be a list of Constant.Condition names

Examples:

   // Find all integer constans with value 4
   @At(value = "CONSTANT", args = "intValue=4")
   // Find the String literal "foo"
   @At(value = "CONSTANT", args = "stringValue=foo"
   // Find integer constants with value 0 and expand conditionals
   @At(
     value = "CONSTANT",
     args = {
       "intValue=0",
       "expandZeroConditions=LESS_THAN_ZERO,GREATER_THAN_ZERO"
     }
   )
   

Note that like all standard injection points, this class matches the insn itself, putting the injection point immediately before the access in question. Use shift specifier to adjust the matched opcode as necessary.

  • Constructor Details

    • BeforeConstant

      public BeforeConstant(IMixinContext context, org.objectweb.asm.tree.AnnotationNode node, String returnType)
    • BeforeConstant

      public BeforeConstant(InjectionPointData data)
  • Method Details

    • find

      public boolean find(String desc, org.objectweb.asm.tree.InsnList insns, Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes)
      Description copied from class: InjectionPoint
      Find injection points in the supplied insn list
      Specified by:
      find in class InjectionPoint
      Parameters:
      desc - Method descriptor, supplied to allow return types and arguments etc. to be determined
      insns - Insn list to search in, the strategy MUST ONLY add nodes from this list to the nodes collection
      nodes - Collection of nodes to populate. Injectors should NOT make any assumptions about the state of this collection and should only call the add() method
      Returns:
      true if one or more injection points were found
    • log

      protected void log(String message, Object... params)