Annotation Interface Accessor


@Target(METHOD) @Retention(RUNTIME) public @interface Accessor
Defines an accessor method in a mixin, the method can be a getter (must return the field type and take no arguments) or a setter (must take an argument of the field type and return void). The annotated method must be abstract.

The target field for an accessor can be specified as part of the decorated method name (eg. setFoo or getFoo to provide accessors for a target field foo) or specified in the annotation value.

Accessors provide a simple way of gaining access to internal class members in a target class without needing to resort to access transformers, and without the usual need to Shadow a target field. This can both greatly simplify mixins which only contain accessors, and provide for faster development than with access transformers since no re-decompile is needed to put the changes into effect.

Accessors can be used in regular mixins as a convenient way to generate getters and setters. They can also be used to create "Accessor Mixins" which are special mixins defined as interfaces which must only contain Accessor and Invoker methods. Unlike normal mixins however, Accessor Mixins are accessible via user code and thus no surrogate "Duck" interface is required to expose the generated methods, the mixin itself acts as its own Duck.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    By default, the annotation processor will attempt to locate an obfuscation mapping for all Accessor methods since it is anticipated that in general the target field of a Accessor annotation will be an obfuscated field in the target class.
    Normally the target field name is inflected by examining the annotated method name.
  • Element Details

    • value

      String value
      Normally the target field name is inflected by examining the annotated method name. If the annotated method starts with "get", "set" or "is" followed by a capital letter, then the prefix is stripped and the remainder of the method name is used as the target field name.

      However sometimes it maye be desirable to name an accessor method differently to the target field name. In this case you may specify the field using its name.

      Returns:
      name for the target field, or empty string to inflect using the annotated method name
      Default:
      ""
    • remap

      boolean remap
      By default, the annotation processor will attempt to locate an obfuscation mapping for all Accessor methods since it is anticipated that in general the target field of a Accessor annotation will be an obfuscated field in the target class. However since it is possible that the target is not obfuscated, it may be desirable to suppress the compiler warning which would be generated. Setting this value to false will cause the annotation processor to skip remapping for this annotation.
      Returns:
      True to instruct the annotation processor to search for obfuscation mappings for this annotation
      Default:
      true