Support java-style annotations

Description

Support for declaring annotations similar to Java:

@classAnnotation class MyClass { @simpleAnnotation @valuedAnnotation("value") @complexAnnotation({ complex : { key:1 } }) public function something( @argAnnotation someArg ) { } } // represents metadata for the above class { annotations: { classAnnotation: true } ,functions : [ { name : "something" ,annotations : { simpleAnnotation : true ,valuedAnnotation : "value" ,complexAnnotation : { complex : { key : 1 } } } ,arguments : [ { name : "someArg" ,annotations : { argAnnotation : true } } ] } ] }

Activity

Show:

David Reynaud 2 November 2017 at 14:07

+1 for the support actual Java class annotations (that affect generated code) as well as CFML annotations that affect metadata.

It is very important to keep a large code compatibility with ACF. We have tons of functions using JAVA annotations which prevents migration to Lucee.

Sean Corfield 16 September 2015 at 20:33

FWIW, I'm strongly in favor but feel we need to support actual Java class annotations (that affect generated code) as well as CFML annotations that affect metadata.

For example, If we could annotate CFC methods with @com.newrelic.api.agent.Trace for example, calls to them could be automatically tracked in New Relic transaction traces – and this is something that's come up several times recently on Twitter and Slack.

Brad Wood 16 September 2015 at 19:41

The TAG likes this in concept and would like to start a discussion in the Lang forum to further define what this looks like.

Kai Koenig 15 September 2015 at 22:42

Ok, thanks , that helps quite a bit re understanding your idea and use case.

Jesse Shaffer 15 September 2015 at 21:24

A couple of points about this.

I agree with the one point - Java annotations are quite, heavy... You have to define an annotation type before being able to use it.

What I'm envisioning is leaving the comment annotations where they are, but add "real" annotations so they generate metadata that would end up in getMetaData(thing).annotations.<@annotation>

Here's a real-world example of a CFC definition that I'm working with:

component { // currently I have to use something like this: /** * @client.validators.1 {type:"exists"} * @client.validators.2 {type:"length", min:3} */ // would prefer something like: @Client({ validators: [ {type:"exists"} ,{type:"length", min:3} ] }) // or @ClientValidation({type:"exists"}) @ClientValidation({type:"length", min:3}) property string PersonName; }

Currently, I have to read the metadata, parse the strings and convert them into structs of usable data. I would instead prefer to have getMetaData("my.Component") return (based on the above example):

{ annotations: {} // no class annotations ,functions : [] ,properties:[ { name:"PersonName" ,type:"String" ,annotations:{ // the @Client({...}) version Client: { validators: [ {type:"exists"} ,{type:"length", min:3} ] } // the @ClientValidation({...}) version ClientValidation: [ {type:"exists"} ,{type:"length", min:3} ] } } ] }

In addition to the above, support for "real" annotations should be available at the following levels:

  • class

  • function

  • property

  • argument

This should not change the existing comment annotations at all - as those go directly into the metadata for the given objects. Just to re-iterate, the annotations specified by "real" annotations go into the "annotations" collection under the metadata for whatever it is assigned to.

Hopefully that explains the idea better. I've been out of the loop a bit also, so I don't know the climate concerning this lately, but I would like to see this implemented for CFC's as well as Lucee classes - I see no reason not to as it only augments existing functionality.

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 12 June 2015 at 17:18
Updated 2 November 2017 at 14:07

Flag notifications