T
he syntax you were initially trying to use is valid:
execution( (@Foo *) *(..)) { }
So from that point of view the docs are correct, in a method pattern the
return value can be an annotation pattern. This example means a method
whose return type is annotated with Foo, so it would match the method here:
@Foo
class SomeType {}
public SomeType giveMeOne() {}
And just to mention this whilst on the topic, if you were on Java8 you
could write
@Target(ElementType.TYPE_USE)
@interface Foo {}
class SomeType {}
public @Foo SomeType giveMeOne() {}
And the @Foo will actually be applying to the 'SomeType' type reference,
not to the method. I haven't decided how to fit type_use type annotations
into the AspectJ matching yet.
Andy
On 6 May 2013 11:43, Jay Roberts <[email protected]> wrote:
> Thanks for the responses - I didn't dig into it deep enough to realize
> that Java isn't supporting annotations on return types (I'm assuming that
> this is the issue….).
>
> Just to be clear, and we are Java 7, there is no way to write/annotate a
> Java method annotating the return type and that even if there were, Aspectj
> doesn't support this.
>
> I would say that perhaps the MethodPattern spec in the documentation is a
> little ambiguous, then, as it has TypePattern (for return value of method)
> and one of the patterns for this is AnnotationPattern.
>
> Maybe a MethodReturnTypePattern would exclude the AnnotatedPattern from
> TypePattern?
>
> Thanks for all the quick responses!
>
> Jay
>
>
>
> On May 6, 2013, at 2:25 PM, Andy Clement <[email protected]> wrote:
>
> Hi Jay,
>
> You actually have an annotated method there, not an annotated return
> value. So this will match:
>
> @Around( "execution(@ImmutableCollection * *(..))")
>
> *UNLESS* you are on Java8 and are exploiting type annotations?? If you are
> then I should say AspectJ does not yet support type annotations.
>
> cheers,
> Andy
>
>
>
> On 6 May 2013 10:32, Jay Roberts <[email protected]> wrote:
>
>> I have a simple test case that isn't working, but it seems like it
>> should, could use a bit of help.
>>
>> I have:
>>
>> public class TestReturnAnnotation{
>> public Object object=null;
>> public @ImmutableCollection Object getObject(){
>> return object;
>> }
>> }
>>
>>
>> And from the advice:
>>
>> @Around( "execution( (@ImmutableCollection *) *(..))")
>>
>> This compiles ok, but the advice does not get applied to
>> TestReturnAnnotation.getObject(). Looking at the spec for MethodPattern,
>> it seems like it should, but I'm obviously missing something. FWIW, in the
>> aspect, I have another advice
>>
>> @Around( "set(@ImmutableCollection * *) && args(newVal) && target(t)")
>>
>> That is working fine. Can I have two @Around in the same @Aspect class?
>>
>> Thanks!
>>
>> Jay Roberts
>>
>> _______________________________________________
>> aspectj-users mailing list
>> [email protected]
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users