Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Pointcut to calls to a specific field

Hi there,

how can I define a pointcut picking out calls to specific field? 

  ...
  this.children.add(someObj);
  ...

definitions like

  pointcut add(MyContainer container, Object child) :
      call(boolean Collection.add(Object)) && this(container) &&
args(child);

also match

  ...
  Collection c = new ArrayList();
  c.add(someObject);
  ...

So I came up with the following solution:

  pointcut add(MyContainer container, Object child, Collection c) :
      call(boolean Collection.add(Object)) && this(container) &&
args(child) && target(c);

  after(MyContainer container, Object child, Collection c) :
add(container, child, c) {
      if (c != container.children)
          return;
      ...
  }

Has somebody found a better solution? Some definition limiting the
pointcut only to a specified field or something alike?

Thanks for any ideas,
Bruno Feurer



Back to the top