# Annotation Type Bind

@Retention(CLASS) @Target(FIELD) public @interface Bind

Pairs a `@Bindable` field with the component it should mirror.

`name` is the value the target component returns from `Component#getName()`. `attr` picks the attribute to write: text, UIID, selected state, visible / hidden, the icon name, or the component name itself.

One-way bindings push from the model to the component on `Binders.bind`. Two-way bindings additionally listen for user input on text fields, text areas, and check boxes so changes flow back into the model.

##### Accessor resolution

The annotation processor decides how to read and write the field in this order:

1. Explicit accessor names -- `@Bind(getter="getX", setter="setX")`. Use this when the JavaBeans naming convention doesn't match (a fluent setter, a renamed boolean, ...).
2. JavaBeans accessors when both `getter` and `setter` are blank: `getFoo()` / `isFoo()` for the getter, `setFoo(T)` for the setter. Detected from the project's compiled bytecode -- no runtime reflection.
3. Direct public-field access as a last resort. The processor fails the build with a clear error when the field is private and no usable accessor exists.

For two-way bindings the build-time processor instruments the resolved setter to call `Binders.notifyChanged(this)` at every return point. Application code can mutate the model through the setter from anywhere and the bound component refreshes automatically; see `Annotation-Component-Binding.asciidoc` for the loop-guard details.

- ## Required Element Summary

  Required Elements
  Modifier and Type
  Required Element
  Description
  `String`
  `name`
  `Component#getName()` of the target component.

- ## Optional Element Summary

  Optional Elements
  Modifier and Type
  Optional Element
  Description
  `BindAttr`
  `attr`
  Which property of the component the field mirrors.
  `String`
  `getter`
  Explicit getter method name.
  `String`
  `setter`
  Explicit setter method name.
  `boolean`
  `twoWay`
  When false the binding is one-way (model -> component only).

- ## Element Details

  - ### name

    String name
    `Component#getName()` of the target component.

  - ### attr

    BindAttr attr
    Which property of the component the field mirrors. Default: `TEXT`.
    Default:
      `TEXT`

  - ### twoWay

    boolean twoWay
    When false the binding is one-way (model -> component only). Default `true` for `TEXT` against editable components and for `SELECTED`; for all other attributes the binding is implicitly one-way regardless of this flag.
    Default:
      `true`

  - ### getter

    String getter
    Explicit getter method name. Default: empty -- the processor uses JavaBeans `get<Field>` / `is<Field>` discovery, then falls back to direct public-field access.
    Default:
      `""`

  - ### setter

    String setter
    Explicit setter method name. Default: empty -- the processor uses JavaBeans `set<Field>` discovery, then falls back to direct public-field assignment. The resolved setter (whether explicit or detected) is instrumented for two-way bindings.
    Default:
      `""`