I would like to filter return values of methods which have a @Filter annotation and return a Collection, an Array or a Map by a certain predicate.
I tried something like:
@Pointcut("execution(@example.annotations.Filter * *(..)) "
+ "&& @annotation(filter) ")
public void filterOperation(final Filter filter) {
/* ... */
}
But I get syntax errors if I add execution((java.util.Collection+ || java.util.Map+) * * (..)) to the PointCut above.
How would a solution look like, preferable one where I could error out if some method was annotated with @Filter but would not return a collection?
Did you tried to use
execution((java.util.Collection+ || java.util.Map+) *.* (..))?Or you can use:
You can handle return value the following way:
But I suppose it will be better to use separate advices for
Maps andCollections: