Bug 345515 - Pass information from match side to new annotation in declare statement
Summary: Pass information from match side to new annotation in declare statement
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-11 23:47 EDT by howard.adam CLA
Modified: 2011-05-12 15:27 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description howard.adam CLA 2011-05-11 23:47:36 EDT
I have discovered a pattern in my JPA mappings that I would like to codify. A simple example follows:

    @OneToMany(fetch=FetchType.EAGER)
    @Sort(type=SortType.NATURAL)
    private SortedSet<Item> items;

I would like to create a single annotation called SortedOneToMany that I can apply to the above set:

    public @interface SortedOneToMany {
        FetchType fetch() default EAGER;
        SortType sort() default NATURAL;
        Class comparator() default void.class;
    }

I have written the following aspect to "attach" the JPA annotations whenever it sees my annotation:

    public aspect SortedOneToManyAspect {
        declare @field: @SortedOneToMany * * : @OneToMany(fetch=FetchType.EAGER);
        declare @field: @SortedOneToMany * * : @Sort(type=SortType.NATURAL);
    }

But I don't know how can I access the values of the SortedOneToMany annotation parameters and use them when defining the OneToMany and Sort annotations. There may be cases where I want to change one of the default values like so:

    @SortedOneToMany(sort=SortType.COMPARATOR,comparator=ItemComparator.class)
    private SortedSet<Item> items;

So how can I pass the annotation values from SortedOneToMany to the Sort annotation?

Hypothetical syntax from Andy Clement:

declare @field:
    @SortedOneToMany(sort=SortType.COMPARATOR,comparator={1}) * * :
    @Sort(type=SortType.COMPARATOR,comparator={1});