rune (2) [Avatar] Offline
Hello, and complements on a great book! Love the in Action series in general really.

I am using AspectJ for design enforcement here, and declaring errors and warnings for the ajc to throw at compile-time. Among the things I would like to detect is when any static reference is done to a class instead of an interface, and declare a warning/error for that. In particular, I am aiming to enforce Constrained Java as explained in this paper:

Is this possible at all? I have tried things like:

public pointcut violateCJPS():
withincode( * no.rune.processor..*.*(..) ) &&
if( ! thisJoinPoint.getSignature().getDeclaringType().isInterface() );

declare warning: violateCJPS(): "Violating Constrained Java Package Space.";

But I think I am not at the right track because I get an compiler error saying that the if() pointcut designator cannot be used in declare statement.

So to sum it up, I want to make a pointcut which matches interfaces only. Possible? Thank you in advance! smilie
ramnivas (171) [Avatar] Offline
Re: Matching interfaces

The if() pointcut is a runtime-determinable pointcut. You can use only the statically determinable pointcut for static crosscutting. Unfortunately, you seem to have a need to determine if a certain type is an interface and that is not possible with current AspectJ.

agou (7) [Avatar] Offline
Re: Matching interfaces
p.97 "Note that since these declarations affect compile-time behavior, you must use only statically determinable pointcuts in the declaration."

So in other words you want to do something dynamically using a static crosscutting. I had a similar problem where I wanted to capture join points that were only inside classes and not aspects ( )

But I am only a beginner. Maybe Ramnivas has some ideas!
rune (2) [Avatar] Offline
Re: Matching interfaces
Thanks for quick replies! It was as I suspected then. Crossing my fingers for future AspectJ updates.