Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] target() pointcut designator cannot be used in declare statement

Nick,

You could use within(LogAware+) to find any join points within a type that extends LogAware. Likewise, for using declare warning you can uset within(Action+) instead of target(Action).

A few additional points:
1) Since you are matching execution join points, using within(LogAware+) will match most of the cases you would care about. It doesn't mean the exact same thing as this(LogAware) because it doesn't match execution join points in any base classes that don't implement LogAware (it also won't include inter-type declared methods on types that implement LogAware (*)). For example:
class BaseAction { void helper() {...} }
class MyAction extends BaseAction implements LogAware { ... }

For executions of the method helper() where this is an instance of MyAction:

execution(* *(..)) && within(LogAware+) won't match 

But execution(* *(..)) && this(LogAware) would

2) The AspectJ 1.1.1 implementation was broken. "... if a pointcut cannot be entirely statically 
evaluated then it will behave as if it has matched and the error or warning message will be produced..." - Andrew Clement

You can read more of the discussion on the thread "Use of non-statically resolvable pointcut designators in declare error/warning." in the AspectJ-dev mailing list, if you're interested

3) I talked about this(LogAware), because I think that's more clear than target for execution join points (although the two are equivalent).

4) There is more information on the limitations of statically determinable pointcuts in AspectJ at http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq.html#q:knowWhenAspectsAffectClasses
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/printable.html#d0e6555

Ron

(*) To get inter-type declared methods and constructors also, you'd want to use:
    within(LogAware+) || withincode(* LogAware+.*(..)) || withincode(LogAware+.new(..))

Ron Bodkin
Chief Technology Officer
New Aspects of Software
o: (415) 824-4690
m: (415) 509-2895

> ------------Original Message------------
> From: Nick Airey <nick_subscriptions@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, May-11-2004 7:31 PM
> Subject: [aspectj-users] target() pointcut designator cannot be used in declare statement
> 
> 
> Hi gurus, 
> 
> I have a simple logger aspect that logs entry and
> exits to methods on Action classes which also
> implement an interface "LogAware". At runtime, the
> "this" instance is cast to the LogAware interface in
> order to get access to the instance's logger class.
> Note that I want to use the instance's logger, not the
> aspect's logger.
> 
> 
> The problem:
> 
> It used to compile and work under aspectj 1.1.1, but
> since I updated to eclipse 3.0M8 and aspectj, 1.1.8, I
> now get a compile error: "target() pointcut designator
> cannot be used in declare statement" on the
> "implementsLogAware()" pointcut.
> 
> 
> Any suggestions about how to proceed would be very
> welcome.
> 
> Nick.
> 
> 
> 
> public interface LogAware {
> 	Log getLogger();
> }
> 
> 
> public aspect ActionsLoggerAspect {
> 
> 	// pointcut defining all action classes
> 	public pointcut packageFilter():
> within(com.mycompany.webtier.actions.*Action);
> 
> 	// pointcut defining all methods on class, excluding
> constructors
> 	public pointcut classFilter(): execution(!static *
> *(..));
> 
> 	public pointcut contextMethods() : execution(public
> Log getLogger()) || execution(public *
> getSessionContext());
> 
> 	// define the methods to be logged
> 	public pointcut loggedMethod(): packageFilter() &&
> classFilter() && !contextMethods();
> 
> 	// pointcut identifying classes which implement
> interface "LogAware"
> 	public pointcut implementsLogAware():
> target(LogAware);
> 
> 	// pointcut identifying classes which extends
> "Action"
> 	public pointcut implementsAction(): target(Action);
> 
> 	// define the methods to be logged
> 	public pointcut validClass(): implementsAction() &&
> implementsLogAware();
> 
> 	// advice causing a compiler to signal error if the
> class with a logged method method doesn't implement
> LogAware
> 	declare error: loggedMethod() && !validClass():
> "Logged method present without implementing interface
> LogAware";
> 
> 	// run this aspect code before the method 
> 	before(Action action): validClass() && loggedMethod()
> && this(action) {
> 		Log log = ((LogAware)action).getLogger();
> 		if (log.isDebugEnabled()) {
> 			log.debug(">>>
> "+thisJoinPointStaticPart.getSignature().toShortString());
> 	
> 		}
> 	}
> 	
> 	// run this aspect code after the method 
> 	after(Action action): validClass() && loggedMethod()
> && this(action) {
> 		Log log = ((LogAware)action).getLogger();
> 		if (log.isDebugEnabled()) {
> 			log.debug("<<<
> "+thisJoinPointStaticPart.getSignature().toShortString());
> 	
> 		}
> 	}
> }
> 
> 
> Find local movie times and trailers on Yahoo! Movies.
> http://au.movies.yahoo.com
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 


Back to the top