Griffon 1.2.0

org.codehaus.griffon.ast
[Java] Class EventPublisherASTTransformation

java.lang.Object
  org.codehaus.griffon.ast.AbstractASTTransformation
      org.codehaus.griffon.ast.EventPublisherASTTransformation

@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
public class EventPublisherASTTransformation
extends AbstractASTTransformation

Handles generation of code for the @EventPublisher annotation.

Generally, it adds (if needed) an EventRouter field and the needed add/removeEventListener methods to support the listeners.

Authors:
Andres Almiray


Field Summary
private static String ARGS

private static String ENABLED

private static ClassNode EVENT_HANDLER_TYPE

private static ClassNode EVENT_PUBLISHER_TYPE

private static ClassNode EVENT_ROUTER_TYPE

private static ClassNode GAH_TYPE

private static String LISTENER

private static Logger LOG

private static String NAME

private static ClassNode RUNNABLE_WITH_ARGS_TYPE

 
Fields inherited from class AbstractASTTransformation
APPLICATION_HOLDER_TYPE, COLLECTIONS_CLASS
 
Constructor Summary
EventPublisherASTTransformation()

 
Method Summary
protected static void addEventRouter(ClassNode declaringClass)

Adds the necessary field and methods to support event firing.

static void addEventRouterToClass(SourceUnit source, ClassNode classNode)

static Expression eventRouterInstance()

static boolean hasEventPublisherAnnotation(AnnotatedNode node)

Convenience method to see if an annotated node is @EventPublisher.

protected static boolean needsEventRouter(ClassNode declaringClass, SourceUnit sourceUnit)

Snoops through the declaring class and all parents looking for methods

  • void addEventListener(Object)
  • void addEventListener(String, Closure)
  • void addEventListener(String, RunnableWithArgs)
  • void removeEventListener(Object)
  • void removeEventListener(String, Closure)
  • void removeEventListener(String, RunnableWithArgs)
  • void publishEvent(String, List = [])
  • void publishEventOutsideUI(String, List = [])
  • void publishEventAsync(String, List = [])
  • boolean isEventPublishingEnabled()
  • void setEventPublishingEnabled(boolean)
If any are defined all must be defined or a compilation error results.

void visit(ASTNode[] nodes, SourceUnit source)

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

 
Methods inherited from class AbstractASTTransformation
addError, applicationInstance, checkNodesForAnnotationAndType, emptyMap, makeClassSafe, makeClassSafe, makeClassSafe, newClass
 

Field Detail

ARGS

private static final String ARGS


ENABLED

private static final String ENABLED


EVENT_HANDLER_TYPE

private static final ClassNode EVENT_HANDLER_TYPE


EVENT_PUBLISHER_TYPE

private static final ClassNode EVENT_PUBLISHER_TYPE


EVENT_ROUTER_TYPE

private static final ClassNode EVENT_ROUTER_TYPE


GAH_TYPE

private static final ClassNode GAH_TYPE


LISTENER

private static final String LISTENER


LOG

private static final Logger LOG


NAME

private static final String NAME


RUNNABLE_WITH_ARGS_TYPE

private static final ClassNode RUNNABLE_WITH_ARGS_TYPE


 
Constructor Detail

EventPublisherASTTransformation

EventPublisherASTTransformation()


 
Method Detail

addEventRouter

protected static void addEventRouter(ClassNode declaringClass)
Adds the necessary field and methods to support event firing.

Adds a new field: protected final org.codehaus.griffon.runtime.core.EventRouter this$eventRouter = new org.codehaus.griffon.runtime.core.EventRouter()

Also adds support methods: public void addEventListener(Object)
public void addEventListener(String, Closure)
public void addEventListener(String, RunnableWithArgs)
public void removeEventListener(Object)
public void removeEventListener(String, Closure)
public void removeEventListener(String, RunnableWithArgs)
public void publishEvent(String,List = [])
public void publishEventOutsideUI(String,List = [])
public void publishEventAsync(String,List = [])
public boolean isEventPublishingEnabled()
public void setEventPublishingEnabled(boolean)

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


addEventRouterToClass

public static void addEventRouterToClass(SourceUnit source, ClassNode classNode)


eventRouterInstance

public static Expression eventRouterInstance()


hasEventPublisherAnnotation

public static boolean hasEventPublisherAnnotation(AnnotatedNode node)
Convenience method to see if an annotated node is @EventPublisher.
Parameters:
node - the node to check
Returns:
true if the node is an event publisher


needsEventRouter

protected static boolean needsEventRouter(ClassNode declaringClass, SourceUnit sourceUnit)
Snoops through the declaring class and all parents looking for methodsIf 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


visit

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


 

Groovy Documentation