Package org.spongepowered.asm.mixin.injection.points

## Class BeforeFieldAccess

- java.lang.Object
- - org.spongepowered.asm.mixin.injection.InjectionPoint
  - - org.spongepowered.asm.mixin.injection.points.BeforeInvoke
    - - org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess

    public class BeforeFieldAccess
    extends BeforeInvoke

This injection point searches for GETFIELD and PUTFIELD (and static equivalent) opcodes matching its arguments and returns a list of insns immediately prior to matching instructions. It accepts the following parameters from `At`:

target
  A `Target Selector` which identifies the target field.
opcode
  The `opcode` of the field access, must be one of GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
ordinal
  The ordinal position of the field access to match. For example if the field is referenced 3 times and you want to match the 3rd then you can specify an ordinal of 2 (ordinals are zero-indexed). The default value is -1 which supresses ordinal matching
named argument: array
  For matching accesses to an array field element following a GETFIELD or GETSTATIC. Specify `get`, `set` or `length` to match the desired operation.
named argument: fuzz
  When matching array operations using `array` the injection point will by default search up to 8 instructions after the matched field insn. However in some cases the array operation may be further from the matched GETFIELD or GETSTATIC and the amount to search (the "fuzz factor" can be specified using this argument. Likewise to optimise the search against false positives, this value can be specified as a lower value if desired. Has no effect if `array` is not specified.

Example:

> `@At(value = "FIELD", target="field_59_z:I", opcode = Opcodes.GETFIELD)`

Matching array access:

For array fields, it is possible to match field accesses followed by a corresponding array element get, set or length operation. To enable this behaviour specify the `array` named-argument with the desired operation:

> `@At(value = "FIELD", target="myIntArray:[I", opcode = Opcodes.GETFIELD, args = "array=get")`

See `Redirect` for information on array element redirection.

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

### Nested Class Summary

### Nested classes/interfaces inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke

`BeforeInvoke.SearchType`

### Nested classes/interfaces inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint

`InjectionPoint.AtCode, InjectionPoint.Flags, InjectionPoint.RestrictTargetLevel, InjectionPoint.Specifier`

### Field Summary

Fields
`static int` `ARRAY_SEARCH_FUZZ_DEFAULT` Default fuzz factor for searching for array access opcodes

### Fields inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke

`allowPermissive, className, context, logger, mixin, ordinal, target`

### Fields inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint

`DEFAULT_ALLOWED_SHIFT_BY, MAX_ALLOWED_SHIFT_BY`

### Constructor Summary

Constructors
`BeforeFieldAccess​(InjectionPointData data)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected boolean` `addInsn​(org.objectweb.asm.tree.InsnList insns, java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes, org.objectweb.asm.tree.AbstractInsnNode insn)`
`static org.objectweb.asm.tree.AbstractInsnNode` `findArrayNode​(org.objectweb.asm.tree.InsnList insns, org.objectweb.asm.tree.FieldInsnNode fieldNode, int opcode, int searchRange)` Searches for an array access instruction in the supplied instruction list which is within `searchRange` instructions of the supplied field instruction.
`int` `getArrayOpcode()`
`int` `getFuzzFactor()`
`protected boolean` `matchesInsn​(org.objectweb.asm.tree.AbstractInsnNode insn)`

### Methods inherited from class org.spongepowered.asm.mixin.injection.points.BeforeInvoke

`find, find, inspectInsn, log, matchesOrdinal, setLogging`

### Methods inherited from class org.spongepowered.asm.mixin.injection.InjectionPoint

`addMessage, after, and, before, checkPriority, getAtCode, getId, getSlice, getSpecifier, getTargetRestriction, nextNode, or, parse, parse, parse, parse, parse, parse, parse, parse, register, register, setTargetRestriction, shift, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### ARRAY_SEARCH_FUZZ_DEFAULT

    public static final int ARRAY_SEARCH_FUZZ_DEFAULT

Default fuzz factor for searching for array access opcodes

See Also:
  Constant Field Values

### Constructor Detail

#### BeforeFieldAccess

    public BeforeFieldAccess​(InjectionPointData data)

### Method Detail

#### getFuzzFactor

    public int getFuzzFactor()

#### getArrayOpcode

    public int getArrayOpcode()

#### matchesInsn

    protected boolean matchesInsn​(org.objectweb.asm.tree.AbstractInsnNode insn)

Overrides:
  `matchesInsn` in class `BeforeInvoke`

#### addInsn

    protected boolean addInsn​(org.objectweb.asm.tree.InsnList insns,
                              java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes,
                              org.objectweb.asm.tree.AbstractInsnNode insn)

Overrides:
  `addInsn` in class `BeforeInvoke`

#### findArrayNode

    public static org.objectweb.asm.tree.AbstractInsnNode findArrayNode​(org.objectweb.asm.tree.InsnList insns,
                                                                        org.objectweb.asm.tree.FieldInsnNode fieldNode,
                                                                        int opcode,
                                                                        int searchRange)

Searches for an array access instruction in the supplied instruction list which is within `searchRange` instructions of the supplied field instruction. Searching halts if the search range is exhausted, if an `Opcodes.ARRAYLENGTH` opcode is encountered immediately after the specified access, if a matching field access is found, or if the end of the method is reached.

Parameters:
  `insns` - Instruction list to search
  `fieldNode` - Field instruction to search from
  `opcode` - array access opcode to search for
  `searchRange` - search range
Returns:
  matching opcode or `null` if not matched