Imagine that, in an application I'm developing, there is a need to sort each of the returning objects, from any method with these characteristics:
- the method is inside the package my.sorted or any of its subpackages
- the returning object implements the List interface
- the method has the @Sorted annotation
I want to create an Aspect called SortingAspect in which implements:
- A pointcut for the desired points of interruption
- An advice to perform the intended functionality
With this case I came to this code:
MyClass:
public class MyClass {
@Sorted
public List<Integer> myFunction(){
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(20);
list.add(3);
list.add(-4);
list.add(5);
list.add(200);
list.add(34);
return list;
}
}
Sorted.
public @interface Sorted {
}
SortedAspect:
@Aspect
public class SortingAspect {
@Pointcut ("call(* my.sorted..* (..)) && @annotation(Sorted)")
public void sortFuncPointCut() {}
@Around("sortFuncPointCut()")
public List<Integer> sortAdvice(ProceedingJoinPoint pjp) throws Throwable {
List<Integer> list = (List<Integer>)pjp.proceed();
Collections.sort(list);
return list;
}
}
Problem: The problem is that the @Around is not catch any Poincut and I can not understand why.