Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] inherits from?

> I'm interested in writing a pointcut that matches all methods that call
> setSize(Dimension);
> from any subclass of java.awt.Component.

interesting...

You can pick out calls _to_ non-static methods of Component
or its subclasses using

   target(Component) && call({methodSignature})

But no pointcut can directly pick out the join point for a call
to, or the execution of, a method enclosing another join point
(in this case, a call to setSize(Dimension)).

However, the withincode() PCD can pick out a join point whose
static shadow is within the body of specified constructors or
methods, so you can use it to restrict the affected join points.
If you want a list of the containing methods for code spelunking,
you could use the IDE support to find the methods containing such
call join points as those affected by advice on that join point.

(related: The call() PCD can pick out a method or constructor call
join point, but does not pick out the (enclosing) method of the
join point.  The this() PCD can pick out a join point where the
instance is of a given type (but thus won't pick out calls from
a static context).  For call join points, this() picks out the
caller; for execution join points, this() picks out the callee,
so there is no way to get the caller from an execution join
point.)

Also, I suspect you don't just want any

   setSize(Dimension)

(there are 11 in JDK 1.4) but implementations of

  Component.setSize(Dimension)

and you might also want to pick out calls to

  Component.setBounds(int, int, int, int)

So perhaps what you mean is this:

   /** calls to Component instance methods setSize or
     * setBounds from within methods of Component
     */
   pointcut changeSize(Dimension dim) :
       (call(void setSize(Dimension))
           || call(void setBounds(int, int, int, int)))
       && withincode(* Component+.*(..))
       && target(Component) && args(dim)

But our implementation of AspectJ requires that the
weaver have access to the code for the method call, so
this won't pick up calls from within Sun code when you
are only weaving your own code.  While you can use
the execution(..) PCD to pick out method executions for
setSize(..) in your own code (even if it was called by
Sun code), you can't identify the caller from the
execution join point.

And btw, that's how I think through pointcuts:

- the (kind(s) of) join point I'm after
- constrained staticly by within, etc.
- constrained dynamically by target, args, cflow, etc.
- surfacing the required context from the join point
- considering any implementation limitations

Wes

Anagnost, Ted (MED, GEMS-IT) wrote:
Hello,

I'm interested in writing a pointcut that matches all methods that call
setSize(Dimension);
from any subclass of java.awt.Component.
So far I have:

pointcut changeSize(Dimension dim) : call(void *.setSize(Dimension)) && args(dim);

How do I specify only to match subclasses of java.awt.Component?

Thanks,

Ted



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top