@GroovyASTTransformation(phase=CompilePhase.CANONICALIZATION)
@SuppressWarnings(value="ParameterCount")
class ListenerListASTTransformation
extends Object
implements ASTTransformation, org.objectweb.asm.Opcodes
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.
| Constructor and description |
|---|
ListenerListASTTransformation() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
addAddListener(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field, ClassNode listener, String name, Object synchronize)Adds the add<Listener> method like: |
|
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, String name, 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, String name, 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)The method is invoked when an AST Transformation is active. For local transformations, it is invoked once each time the local annotation is encountered. For global transformations, it is invoked once for every source unit, which is typically a source file.
|
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)
}
Adds the fire<Event> methods like:
void fire${fireMethod.capitalize()}(${parameterList.join(', ')}) {
if (${field.name} != null) {
def __list = new ArrayList(${field.name})
for (listener in __list) {
listener.$eventMethod(${evt})
}
}
}
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}[]
}
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)
}
The method is invoked when an AST Transformation is active. For local transformations, it is invoked once each time the local annotation is encountered. For global transformations, it is invoked once for every source unit, which is typically a source file.
nodes - The ASTnodes when the call was triggered. Element 0 is the AnnotationNode that triggered this
annotation to be activated. Element 1 is the AnnotatedNode decorated, such as a MethodNode or ClassNode. For
global transformations it is usually safe to ignore this parameter.source - The source unit being compiled. The source unit may contain several classes. For global transformations,
information about the AST can be retrieved from this object.Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.