Groovy Documentation

## groovy.beans
[Groovy] Class ListenerListASTTransformation

    java.lang.Object
      groovy.beans.ListenerListASTTransformation

All Implemented Interfaces:
  ASTTransformation, org.objectweb.asm.Opcodes

    @GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
    class ListenerListASTTransformation
    extends java.lang.Object

Handles generation of code for the `@ListenerList` annotation.

Generally, it adds the needed add<Listener>, remove<Listener> and get<Listener>s methods to support the Java Beans API.

Additionally it adds corresponding fire<Event> methods.

Authors:
  Alexander Klein
  Hamlet D'Arcy

Method Summary

`void`

`addAddListener(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, java.lang.String name, java.lang.Object synchronize)`

Adds the add<Listener> method like:

     synchronized void add${name.capitalize}(${listener.name} listener) {
         if (listener == null)
             return
         if (${field.name} == null)
            ${field.name} = []
         ${field.name}.add(listener)
     }

`void`

`addFireMethods(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, GenericsType[] types, boolean synchronize, MethodNode method)`

Adds the fire<Event> methods like:

     void fire${fireMethod.capitalize()}(${parameterList.join(', ')}) {
         if (${field.name} !

`void`

`addGetListeners(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, java.lang.String name, java.lang.Object synchronize)`

Adds the get<Listener>s method like:

     synchronized ${name.capitalize}[] get${name.capitalize}s() {
         def __result = []
         if (${field.name} !

`void`

`addRemoveListener(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, java.lang.String name, java.lang.Object synchronize)`

Adds the remove<Listener> method like:

     synchronized void remove${name.capitalize}(${listener.name} listener) {
         if (listener == null)
             return
         if (${field.name} == null)
             ${field.name} = []
         ${field.name}.remove(listener)
     }

`void` | `visit(ASTNode[] nodes, SourceUnit source)`

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### addAddListener

    void addAddListener(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, java.lang.String name, java.lang.Object synchronize)

  Adds the add<Listener> method like:

       synchronized void add${name.capitalize}(${listener.name} listener) {
           if (listener == null)
               return
           if (${field.name} == null)
              ${field.name} = []
           ${field.name}.add(listener)
       }

### addFireMethods

    void addFireMethods(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, GenericsType[] types, boolean synchronize, MethodNode method)

  Adds the fire<Event> methods like:

       void fire${fireMethod.capitalize()}(${parameterList.join(', ')}) {
           if (${field.name} != null) {
               def __list = new ArrayList(${field.name})
               __list.each { listener ->
                   listener.$eventMethod(${evt})
               }
           }
       }

### addGetListeners

    void addGetListeners(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, java.lang.String name, java.lang.Object synchronize)

  Adds the get<Listener>s method like:

       synchronized ${name.capitalize}[] get${name.capitalize}s() {
           def __result = []
           if (${field.name} != null)
               __result.addAll(${field.name})
           return __result as ${name.capitalize}[]
       }

### addRemoveListener

    void addRemoveListener(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, java.lang.String name, java.lang.Object synchronize)

  Adds the remove<Listener> method like:

       synchronized void remove${name.capitalize}(${listener.name} listener) {
           if (listener == null)
               return
           if (${field.name} == null)
               ${field.name} = []
           ${field.name}.remove(listener)
       }

### visit

    void visit(ASTNode[] nodes, SourceUnit source)

Groovy Documentation