Griffon 1.2.0

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

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

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

Handles generation of code for the @ResourcesAware annotation.

Generally, it adds (if needed) a ResourceLocator field and the required methods from ResourceHandler.

Authors:
Andres Almiray


Field Summary
private static ClassNode INPUT_STREAM_TYPE

private static Logger LOG

private static String METHOD_GET_RESOURCES

private static String METHOD_GET_RESOURCE_AS_STREAM

private static String METHOD_GET_RESOURCE_AS_URL

private static String NAME

private static ClassNode RESOURCES_AWARE_TYPE

private static ClassNode RESOURCE_HANDLER_TYPE

private static ClassNode RESOURCE_LOCATOR_TYPE

private static ClassNode URL_TYPE

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

 
Method Summary
static void addResourceLocatorIfNeeded(SourceUnit source, ClassNode classNode)

static void apply(ClassNode declaringClass)

Adds the necessary field and methods to support resource locating.

static boolean hasResourcesAwareAnnotation(AnnotatedNode node)

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

protected static boolean needsResourceLocator(ClassNode declaringClass, SourceUnit sourceUnit)

Snoops through the declaring class and all parents looking for methods

  • URL getResourceAsURL(String)
  • InputStream getResourceAsStream(String)
  • List>URL< getResources(String)
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

INPUT_STREAM_TYPE

private static final ClassNode INPUT_STREAM_TYPE


LOG

private static final Logger LOG


METHOD_GET_RESOURCES

private static final String METHOD_GET_RESOURCES


METHOD_GET_RESOURCE_AS_STREAM

private static final String METHOD_GET_RESOURCE_AS_STREAM


METHOD_GET_RESOURCE_AS_URL

private static final String METHOD_GET_RESOURCE_AS_URL


NAME

private static final String NAME


RESOURCES_AWARE_TYPE

private static final ClassNode RESOURCES_AWARE_TYPE


RESOURCE_HANDLER_TYPE

private static final ClassNode RESOURCE_HANDLER_TYPE


RESOURCE_LOCATOR_TYPE

private static final ClassNode RESOURCE_LOCATOR_TYPE


URL_TYPE

private static final ClassNode URL_TYPE


 
Constructor Detail

ResourcesAwareASTTransformation

ResourcesAwareASTTransformation()


 
Method Detail

addResourceLocatorIfNeeded

public static void addResourceLocatorIfNeeded(SourceUnit source, ClassNode classNode)


apply

public static void apply(ClassNode declaringClass)
Adds the necessary field and methods to support resource locating.

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

Also adds support methods: public URL getResourceAsURL(String)
public InputStream getResourceAsStream(String)
public List>URL< getResources(String)

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


hasResourcesAwareAnnotation

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


needsResourceLocator

protected static boolean needsResourceLocator(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