[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Annotations injection on types based onmethods annotations

There is an experimental AspectJ feature, hasmember type patterns, which
lets you write a type pattern for types that have a member with a given
signature. With this feature, you actually can match for types that have
annotations on methods as desired. 

Back in January Adrian posted this about it:

"But...AspectJ 5 contains an undocumented experimental X option :
-XhasMember. It enables the compiler to support hasmethod(method_pattern)
and hasfield(field_pattern) type patterns - but only within declare
statements. It's experimental and undocumented because it may change, and
because it doesn't yet take into account ITDs. Caveat emptor. "

Consider the following example code. If you compile it with -XhasMember it
does what you want:

package immut;

public aspect LiftImmutability {
	declare @type: hasmethod(@Immutable * *(..)): @Container;

aspect TestWarning {
	declare warning : staticinitialization(@Container *) : "container

@interface Immutable {}
@interface Container {}

class Annotated {
	@Immutable void m1() {}

>ajc -1.5 -XhasMember immut\LiftImmutability.aj
C:\devel\scratch\hasMember\immut\LiftImmutability.aj:15 [warning] container

class Annotated {
        staticinitialization(void immut.Annotated.<clinit>())
        see also: C:\devel\scratch\hasMember\immut\LiftImmutability.aj:8::0

1 warning

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Wes Isberg
Sent: Sunday, September 10, 2006 10:18 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Annotations injection on types based onmethods

I can't think of a way to do that.


shows that you can say something like

  declare @type : org.xyz.model..* : @BusinessDomain ;

But it takes a type pattern ("org.xyz.model..*").


On Sat, 09 Sep 2006 20:08:15 +0100
 Paulo Alexandre Corigo Zenida <paulo.zenida@xxxxxxxx>
> Hi all,
> I have searched for examples on google and tried lots of
> ways but I did not have success.
> Therefore, I would like to ask to the community of
> AspectJ if it is possible to do ITD
> for annotations on types, based on the type methods. I
> would like to make a type T be
> annotated with an annotation MyAnnotation based on
> annotated methods for that type T.. I
> would like to write something like:
> declare @type : (@MyAnnotation * *..`.(..)) :
> MyAnnotation;
> Is this possible to achieve with AspectJ?
> Thanks for your interest,
> Paulo Zenida
> Mensagem enviada usando o IMP (Internet Messaging
> Program).
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users

aspectj-users mailing list