Note that there are some explanatory texts on larger screens.

plurals
  1. POCapturing calls made from within the cflow of a constructor
    primarykey
    data
    text
    <p>I am struggling to create an aspectj pointcut because I can't figure out how to limit a pointcut to calls from an object's constructor to its own methods (but <em>exclude</em> calls to methods on other instances of the same class).</p> <p>Background:</p> <p>I have an application with objects that need to notify their "watchers" whenever the object's data changes. To implement this I have methods decorated with a @NotifiableChange annotation, and an aspect that triggers the notification process after these method calls complete. </p> <p>The difficulty is that I do NOT want to trigger notifications during object construction, only when methods are called AFTER construction. I.e. calls from objectA's constructor to objectA's own methods should not be included in the pointcut. However, calls to objectB's methods made during the course of objectA's constructor <em>should</em> be included in the pointcut.</p> <p>I've completely tied myself in knots trying all varieties of withincode, within, cflow, this and target but just can't create the right pointcut. This is what I have now: (DataChangeNotifier is the interface implemented by the relevant classes)</p> <pre><code>pointcut callsWithinConstructors(DataChangeNotifier notifierObject): // call to a notifiable method call(@NotifiableChange * *(..)) //on this object &amp;&amp; this(notifierObject) //in the execution of a constructor &amp;&amp; withincode(DataChangeNotifier+.new(..)); // cut any method with any parameters with this annotation pointcut notifiable(DataChangeNotifier notifierObject): call(@NotifiableChange * DataChangeNotifier+.*(..)) &amp;&amp; target(notifierObject) //but not from the constructors (because there should be no notifications during construction) &amp;&amp; !cflow(callsWithinConstructors(DataChangeNotifier+)) //and not from the method that gets called by notifiers - this method is handled below &amp;&amp; !withincode(* DataChangeNotifier+.listenedDataHasChanged(..)); </code></pre> <p>but it seems the first pointcut is excluding ALL method calls that take place within the constructor, not just those to its own methods. </p> <p>Please help - I'm going crazy!</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload