Annotation Interface Constant


@Target({}) @Retention(RUNTIME) public @interface Constant
Annotation for specifying the injection point for an ModifyConstant injector. Leaving all values unset causes the injection point to match all constants with the same type as the ModifyConstant handler's return type.

To match a specific constant, specify the appropriate value for the appropriate argument. Specifying values of different types will cause an error to be raised by the injector.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Available options for the expandZeroConditions() setting.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specify a type literal to match
    double
    Specify a double constant to match
    Whilst most constants can be located in the compiled method with relative ease, there exists a special case when a zero is used in a conditional expression.
    float
    Specify a float constant to match
    int
    Specify an integer constant to match, includes byte and short values.
    boolean
     
    long
    Specify a long constant to match
    boolean
    Causes this injector to match ACONST_NULL (null object) literals
    int
    Ordinal offset.
    This specifies the ID of the slice to use for this query.
    Specify a String constant to match
  • Element Details

    • nullValue

      boolean nullValue
      Causes this injector to match ACONST_NULL (null object) literals
      Returns:
      true to match null
      Default:
      false
    • intValue

      int intValue
      Specify an integer constant to match, includes byte and short values.

      Special note for referencing 0 (zero) which forms part of a comparison expression: See the expandZeroConditions() option below.

      Returns:
      integer value to match
      Default:
      0
    • floatValue

      float floatValue
      Specify a float constant to match
      Returns:
      float value to match
      Default:
      0.0f
    • longValue

      long longValue
      Specify a long constant to match
      Returns:
      long value to match
      Default:
      0L
    • doubleValue

      double doubleValue
      Specify a double constant to match
      Returns:
      double value to match
      Default:
      0.0
    • stringValue

      String stringValue
      Specify a String constant to match
      Returns:
      string value to match
      Default:
      ""
    • classValue

      Class<?> classValue
      Specify a type literal to match
      Returns:
      type literal to match
      Default:
      java.lang.Object.class
    • ordinal

      int ordinal
      Ordinal offset. Many InjectionPoints will return every opcode matching their criteria, specifying ordinal allows a particular opcode to be identified from the returned list. The default value of -1 does not alter the behaviour and returns all matching opcodes. Specifying a value of 0 or higher returns only the requested opcode (if one exists: for example specifying an ordinal of 4 when only 2 opcodes are matched by the InjectionPoint is not going to work particularly well!)
      Returns:
      ordinal value for supported InjectionPoint types
      Default:
      -1
    • slice

      String slice
      This specifies the ID of the slice to use for this query.

      For more details see the Slice.id()

      Returns:
      the slice identifier, or empty string to use the default slice
      Default:
      ""
    • expandZeroConditions

      Constant.Condition[] expandZeroConditions
      Whilst most constants can be located in the compiled method with relative ease, there exists a special case when a zero is used in a conditional expression. For example:
      if (x >= 0)

      This special case occurs because java includes explicit instructions for this type of comparison, and thus the compiled code might look more like this:

      if (x.isGreaterThanOrEqualToZero())

      Of course if we know that the constant we are searching for is part of a comparison, then we can explicitly search for the isGreaterThanOrEqualToZero and convert it back to the original form in order to redirect it just like any other constant access.

      To enable this behaviour, you may specify one or more values for this argument based on the type of expression you wish to expand. Since the Java compiler is wont to compile certain expressions as the inverse of their source-level counterparts (eg. compiling a do this if greater than structure to a ignore this if less than or equal structure); specifying a particular expression type implicitly includes the inverse expression as well.

      It is worth noting that the effect on ordinals may be hard to predict, and thus care should be taken to ensure that the selected injection points match the expected locations.

      Specifying this option has the following effects:

      • Matching conditional opcodes in the target method are identified for injection candidacy.
      • An intValue of 0 is implied and does not need to be explicitly defined.
      • However, explicitly specifying an intValue of 0 will cause this selector to also match explicit 0 constants in the method body as well.
      Default:
      {}
    • log

      boolean log
      Returns:
      true to enable verbose debug logging for this injection point
      Default:
      false