Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] How to provide external pcd definition?

Adrian Colyer said: 

> Firstly, a new utility class: JoinPointMatcher.  JoinPointMatcher is 
> constructed with a string (in the expected usage this is obtained
> from a config file, but it could be generated in the program itself 
> at runtime for extreme use cases) which contains an AspectJ pointcut
> expression, e.g.:
> 
> JoinPointMatcher jpm = 
>    new JoinPointMatcher("within(patterntesting..*)");
>
> At any join point, you can ask JoinPointMatcher whether or 
> not it matches: 
>  if( jpm.matches(thisJoinPoint)) ...

This is very interesting. There seems to be (at least) two ways to think
about it:

 - it's a convenience utility, that operates on JoinPoint objects,
   to help people write certain join point predicates. It currently
   happens to make use of code from the compiler.

 - it's a first step towards supporting behavior reflection ala
   metaobjec protocol in AspectJ. This first step isn't integrated
   into the language, but it has tentative connection to the 
   implementation.

As currently designed, you can take both views. The difference is in
how this plays out in the future. 

With the second approach, you could imagine going farther, and making
first class pointcuts really part of the language. The potential
advantage to doing this would be that in the future, when we have
true VM based weaving, you might get much better performance from
such a scheme than with the first approach. This is because the
implementation would have a better chance at "compiling in" a first
class pointcut when it becomes defined.

In the current approach its going to be a lot more difficult for 
that kind of optimization.

The advantage of the first approach is there is no language change
involved, and some might argue that it makes the immediate performance
costs clear.

Either way, this seems like a good first step.

It seems like it should be fairly straightforward to extend this to
allow getting access to values. So that I might say:

   ptc = Pointcut.parsePointcut("(int x): execution(void Point.setX(int)) && args(x)");

then, when the pointcut matches, it could return some sort of environment
structure that says has the value of x.

But once you do this you may be stuck having to write/refactor a lot of code
rather than being able to conveniently glom onto the existing code in the
weaver.



Back to the top