Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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


Back to the top