BindableASTTransformation (Groovy 5.0.8)

Package: groovy.beans

## [Java] Class BindableASTTransformation

- groovy.beans.BindableASTTransformation

- All Implemented Interfaces and Traits:
    ASTTransformation, org.objectweb.asm.Opcodes

      @GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
      public class BindableASTTransformation
      extends Object
      implements ASTTransformation, org.objectweb.asm.Opcodes

  Handles generation of code for the `@Bindable` annotation when `@Vetoable` is not present.

  Generally, it adds (if needed) a PropertyChangeSupport field and the needed add/removePropertyChangeListener methods to support the listeners.

  It also generates the setter and wires the setter through the PropertyChangeSupport.

  If a Vetoable annotation is detected it does nothing and lets the VetoableASTTransformation handle all the changes.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected static ClassNode` | `boundClassNode` |

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `addPropertyChangeSupport(ClassNode declaringClass)` Adds the necessary field and methods to support property change support.
    `` | `protected Statement` | `createBindableStatement(PropertyNode propertyNode, Expression fieldExpression)` Creates a statement body similar to: `this.firePropertyChange("field", field, field = value)`
    `` | `protected void` | `createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)` Creates a setter method with the given body.
    `` | `public static boolean` | `hasBindableAnnotation(AnnotatedNode node)` Convenience method to see if an annotated node is `@Bindable`.
    `` | `protected boolean` | `needsPropertyChangeSupport(ClassNode declaringClass, SourceUnit sourceUnit)` Snoops through the declaring class and all parents looking for methods `void addPropertyChangeListener(PropertyChangeListener)`, `void removePropertyChangeListener(PropertyChangeListener)`, and `void firePropertyChange(String, Object, Object)`.
    `` | `public void` | `visit(ASTNode[] nodes, SourceUnit source)` Handles the bulk of the processing, mostly delegating to other methods.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### protected static final ClassNode boundClassNode

  - ### Method Detail

    - #### protected void addPropertyChangeSupport(ClassNode declaringClass)

      Adds the necessary field and methods to support property change support.

      Adds a new field:

           protected final java.beans.PropertyChangeSupport this$PropertyChangeSupport = new java.beans.PropertyChangeSupport(this)"

      Also adds support methods:

           public void addPropertyChangeListener(java.beans.PropertyChangeListener)
           public void addPropertyChangeListener(String, java.beans.PropertyChangeListener)
           public void removePropertyChangeListener(java.beans.PropertyChangeListener)
           public void removePropertyChangeListener(String, java.beans.PropertyChangeListener)
           public java.beans.PropertyChangeListener[] getPropertyChangeListeners()

      Parameters:
        `declaringClass` - the class to which we add the support field and methods

    - #### protected Statement createBindableStatement(PropertyNode propertyNode, Expression fieldExpression)

      Creates a statement body similar to: `this.firePropertyChange("field", field, field = value)`

      Parameters:
        `propertyNode` - the field node for the property
        `fieldExpression` - a field expression for setting the property value
      Returns:
        the created statement

    - #### protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)

      Creates a setter method with the given body.

      Parameters:
        `declaringClass` - the class to which we will add the setter
        `propertyNode` - the field to back the setter
        `setterName` - the name of the setter
        `setterBlock` - the statement representing the setter block

    - #### public static boolean hasBindableAnnotation(AnnotatedNode node)

      Convenience method to see if an annotated node is `@Bindable`.

      Parameters:
        `node` - the node to check
      Returns:
        true if the node is bindable

    - #### protected boolean needsPropertyChangeSupport(ClassNode declaringClass, SourceUnit sourceUnit)

      Snoops through the declaring class and all parents looking for methods `void addPropertyChangeListener(PropertyChangeListener)`, `void removePropertyChangeListener(PropertyChangeListener)`, and `void firePropertyChange(String, Object, Object)`. If any are defined all must be defined or a compilation error results.

      Parameters:
        `declaringClass` - the class to search
        `sourceUnit` - the source unit, for error reporting. `@NotNull`.
      Returns:
        true if property change support should be added

    - #### @Override
      public void visit(ASTNode[] nodes, SourceUnit source)

      Handles the bulk of the processing, mostly delegating to other methods.

      Parameters:
        `nodes` - the ast nodes
        `source` - the source unit for the nodes