History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2823
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Peter Niederwieser
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

Improve annotation declaration syntax

Created: 13/May/08 04:01 PM   Updated: 14/May/08 09:50 AM
Component/s: syntax
Affects Version/s: 1.6-beta-1
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide
Given the following annotation type declaration in Java:

public @interface Timeout { int value(); TimeUnit unit(); }

In Java I can write:
@Timeout(5, unit = TimeUnit.SECONDS)

The Groovy equivalent is slightly more verbose:
@Timeout(value = 5, unit = TimeUnit.SECONDS)

Groovy should also allow the former style.

Additionally, Jochen has suggested to allow the following styles (see http://www.nabble.com/Annotation-syntax%3A-Java-vs.-Groovy-to17217160.html):
@Timeout(5, unit: TimeUnit.SECONDS)
@Timeout(value: 5, unit: TimeUnit.SECONDS)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Dierk Koenig - 14/May/08 05:32 AM
Guillaume Laforge schrieb:
> On Wed, May 14, 2008 at 12:06 PM, Jochen Theodorou <blackdrag@gmx.org> wrote:
>> Dierk König schrieb:
>>> | @Timeout(value:5, unit:TimeUnit.SECONDS)
>>> | | and of course this:
>>> | | @Timeout(5, unit:TimeUnit.SECONDS)
>>>
>>> and it would be typically Groovy to also allow
>>>

@Timeout value:5, unit:TimeUnit.SECONDS

>> hehe, very true.. how about filling an issue for this too?
>
> Can there be an ambiguity when annotations are nested inside annotations?

in that case you have to use (), it is the same as with method calls inside method calls

bye blackdrag


Mike Dillon - 14/May/08 09:50 AM
I think there might be an edge case for the "value:" syntax when setValue takes a Map. In that case, shouldn't this work like a normal Groovy method declared to take map? If that's the case, then something like this is ambiguous:
public @interface Foo {
    Map value
    def unit
}

@Foo(value: [a: 1, b: 2], unit: TimeUnit.SECONDS)

Should "value" and "unit" be keys of the Map or should the map parameter end up in "value" and the TimeUnit parameter end up in "unit"? Is there a special case for putting a key named "value" into a Map-typed value?

@Foo(value: [value: [a: 1, b: 2], unit: TimeUnit.SECONDS])