peaSquared (1) [Avatar] Offline
#1
Greetings,

I need to craft a pointcut to identify code which does not adhere to a design pattern. Here is the pattern:

1. Assume an interface is defined as follows:

public interface MyProcessor{
public void process();
}

2. Assume a marker annotation has been defined called "OkToIgnore".


3. Classes implementing the MyProcessor inteface must follow the these rules:

a) The process() method must be defined on this class (and each subclass) individually (cannot rely on superclass to provide implementation)
b) Every public attribute (defined directly on the class in question -- the one implementing the interface) as well as every private attribute with a public or protected accessor method (again, defined directly on the class implementing the interface) must satisfy one of the following:
i) The attribute is marked with the "OkToIgnore" annotation.
ii) The attribute (if public) or the public getter must be called/accessed within the scope of the "process()" method defined on this class.

If one of (a) or (b) is not satisfied, then I want to fail compilation or log a message or some similar action to be implemented in the advice. The action is not that important as I am simply struggling with defining the pointcut.

Note that the same rules must also apply to subclasses of any class implementing the interface -- but these subclasses must define the process() method themselves and must "process" their own attributes defined directly on themselves.

Is this even possible? If so, any help on how to define the best pointcut for this scenario would be greatly appreciated! I am open to any reasonable refactoring that might need to be done to enable this sort of checking as well if that would help. I'd prefer not to have to refactor or add extra code to the classes if at all possible though.

I look forward to your help with this challenge !!!! Thanks in advance!

Peter
ramnivas (171) [Avatar] Offline
#2
Re: Need advice on how to craft a pointcut ... a real challenge :)
I see that this query has already replied to on the aspectj-user mailing list.

In any case, this can't be implemented. As explained in chapter 11, you cannot detect an absence of a pointcut using AspectJ's declare error and warning construct.

-Ramnivas