#Some thoughts on how to build a flexible annotation processor for coldfusion
Introduction
As in Java, there me times when providing additional metadata to a program will be useful. I the case of unit testing, we can provide granular details to the test framework on how to handle methods that exits in tests. This concept was used by javadoc early on by asking developers to place documentation metadata in special comments in source code; the metadata follows specific rules; e.g. @author, @param, @returns, etc. More recently have been built into the Java language and adopted by JUnit 4, TestNG, and others.
Details
But how can we provide flexible annotation processing in ColdFusion when it's not built into the language? Like javadoc, it would be possible to parse ColdFusion code to determine how to execute tests; Elliot Sprehn demonstrated a token parser @cfunited-08.
Another way would be to place an "arbitrary" attribute inside of cffunction. These attributes are effectively ignored by the compiler and processor, but are available as meta data. So, a program can use reflection to get the value of the attribute and subsequently process it as needed.
Examples (ala TestNG):
<cffunction name="testSomething" mxunit="@SlowTest"> ....
<cffunction name="testSomething" mxunit="@Skip"> ....
<cffunction name="testSomething" mxunit="@BeforeTest"> ....
<cffunction name="testSomething" mxunit="@AfterTest"> ....
<cffunction name="testSomething" mxunit="@Group=myGroupName"> ....
Needs
It might be wise to create an annotation processor that defines specific interface requirements for annotation classes. In other words, for each annotation, there would be a corresponding class (cfc) that implements the interface the processor expects; e.g. init(), execute(). This has the benefit of creating a framework for annotations that can be extended.