I just can't find out why my pointcut is not working. Compiler does not give any warnings, so I cannot explain why it is not working. I'm using aspectjrt 1.7.2 and aspectjtools 1.7.0 in a maven javafx application.
My aspect looks like this
public privileged aspect MovieAspect perthis(MovieInit()) {
pointcut MovieInit(): execution(Movie.new(..));
pointcut reloadMainPanelView(): cflow(execution(void main.views.MainFrame.MainPanel.fillMainPanel(..)));
before(ArrayList tar): target(tar) && reloadMainPanelView() && call(void java.util.ArrayList.clear())
&& !within(MovieAspect) {
System.out.println("test");
}
my MovieAspect is located in package main.models
And here a little explanation of what is actually happening within my code
when my gui loads I initialize the MainFrame class. Just before that another aspect loads all movie-objects. And then when the MainFrame initializes the views for the movie-objects in the MainPanel it first clears its view-objects and reloads them. Because I added all those views as listener to the corresponding movie-object I need to remove them again. Of course I could do just before calling the clear-method of the ArrayList but I really would like to know why the pointcut is not working. The MovieAspect-objects do get instantiated, I tested this with the MovieInit() pointcut.
does anyone have a clue, why this pointcut does not work? actually all pointcuts on outer classes in the same package or not do not work except for those in class Movie.
hope someone can help.
EDIT:
this is a catch to all constructors of the movie-class but it doesn't matter. After hours of research I found the solution. This text explains this behaviour
4.3.4 Implicit limiting of join points
Using the per-object or per-control-flow association has the side effect of implicitly limiting the advice in the aspect to only join points that match the scope of an aspect instance. The scope of an aspect instance is the set of join points that have an aspect instance associated with them. For example, for the percflow() association, the scope of an aspect instance is all the join points occurring inside the control flow of the specified pointcut. This means that even if a pointcut specified for an advice matches a join point, the advice to that join point won’t apply unless the join point also matches the scope of the aspect. This side effect often surprises developers when they refactor an aspect to create reusable parts and need to use per- associations. The aspect association implies that advice in an aspect will apply to join points only if:
■ For perthis() associations, the join point’s execution object matches the aspect instance’s associated object.
■ For pertarget() associations, the join point’s target object matches the aspect’s associated object.
■ For percflow() associations, the join point is in the control flow of the aspect’s associated control flow.
■ For percflowbelow() associations, the join point is below the control flow of the aspect’s associated control flow.