[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ews.eclipse.technology.aspectj] Re: Newbie help with @target and declare

Par wrote:
Hi,

I'd like to declare an error when someone calls the constructor on specific objects. There is a nice example in the Quick Ref that say that you do like this:

declare error: call(Singleton.new(..)) : "Bad"

But what if I whant this behavour on classes with a specific annotation? I tried:

declare error: call(*.new(..)) && @target(MyAnnotation)

but the compiler say that @target cannot be used in a declare statement. Any suggestions anyone?

Thanks




The reason is that @target matches depending on whether or not the runtime type that is the targe of the call has the given annotation (and we can't know the runtime type until runtime...)


You can use the following idiom instead, which matches based on the static (declared) type of the receiver:

declare error: call( (@MyAnnotation *).new(..) ) : "Bad"

(@MyAnnotation *) is simply a type pattern that matches any type with "MyAnnotation".