Function Annotations in Components

Railo allows you to add metadata to functions and arguments, by writing a specific syntax in the comments before the function that they relate to. By adding, for example @MyMetaData "This is the metadata for my function" you can add that metadata to the information that is returned from the getComponentMetaData().

This metadata can then be used for code generators, parsers etc, without having to affect the actual running code. An example below how they can be used in the following CFC:

component {
/**
This is the main hint
@mymetadata "This is an added item of metadata"
@nameVariable.description "this is the description of the name argument"
**/
function getName(String nameVariable){
return "sampleName";
}
}

You can now print out the metadata from the functions by using the getComponentMetadata() function and getting the functions key from the structure:

annot = new cfcs.Annotation();
metadata = getComponentMetadata(annot);
dump(metadata.functions);

You will then see the following: