jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-2823

Support map style annotation attribute declaration syntax

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.6-beta-1
  • Fix Version/s: None
  • Component/s: syntax
  • Labels:
    None

Description

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)

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Dierk Koenig added a comment - 14/May/08 5: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

Show
Dierk Koenig added a comment - 14/May/08 5: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
Hide
Permalink
Mike Dillon added a comment - 14/May/08 9: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])
Show
Mike Dillon added a comment - 14/May/08 9: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])
Hide
Permalink
Peter Niederwieser added a comment - 26/May/09 9:04 AM - edited

I was wrong - "@Timeout(5, unit = TimeUnit.SECONDS)" is not possible in Java. So this part of the issue should probably be dropped.

Show
Peter Niederwieser added a comment - 26/May/09 9:04 AM - edited I was wrong - "@Timeout(5, unit = TimeUnit.SECONDS)" is not possible in Java. So this part of the issue should probably be dropped.
Hide
Permalink
Paul King added a comment - 17/Jun/09 6:56 AM

slightly reword summary to reflect current intent of issue

Show
Paul King added a comment - 17/Jun/09 6:56 AM slightly reword summary to reflect current intent of issue

People

  • Assignee:
    Unassigned
    Reporter:
    Peter Niederwieser
Vote (0)
Watch (3)

Dates

  • Created:
    13/May/08 4:01 PM
    Updated:
    10/Jan/11 4:30 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.