Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] AW: Pointcut on a constructor with a custom@Annotation

Rather than the dynamic @target() you can also use static typepattern:

  call((@Annotation *).new(..))

e.g.,
--------------------------------------

---- ACon.java

@interface I {}
@I class C {}
aspect A { declare warning : call((@I *).new(..)) : "I new call"; }
public class ACon {
  public static void main(String[] a) {
    new C();
  }
}

----- $ aspectj-1.5 -1.5 ACon.java
C:\home\wes\work\src\ACon.java:7 [warning] I new call
new C();
^^^^^^^
        constructor-call(void C.<init>())
        see also: C:\home\wes\work\src\ACon.java:4::0

1 warning

--------------------------------------

When debugging pointcuts, it's fastest to use declare-error
to verify the static part.

hth - wes

> ------------Original Message------------
> From: "Ron Bodkin" <rbodkin@xxxxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Thu, Apr-20-2006 11:53 AM
> Subject: RE: [aspectj-users] AW: Pointcut on a constructor with a custom@Annotation
>
> Hi Moritz,
> 
> Please take a look at this FAQ entry:
> http://www.eclipse.org/aspectj/doc/released/faq.html#q:adviseconstructors 
> 
> Basically, you can't use @target for the call to a constructor: there 
> isn't
> one. You could use @target for execution of the constructor or you 
> could
> bind the returned object with after returning advice and then use 
> reflection
> to test for an annotation on the object.
> 
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Moritz Post
> Sent: Thursday, April 20, 2006 11:39 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: [aspectj-users] AW: Pointcut on a constructor with a
> custom@Annotation
> 
> Hallo Again
> 
> Sorry, I hit send accidentally. :(
>  
> > Hallo Mailingliste
> > 
> > I am struggling to create a proper pointcut on a constructor. I want 
> to
> > catch all creations of an object which is annotated with a custom
> > annotation. Like:
> > 
> > @MyAnnotation
> > public class TheClass {
> > 
> >   public TheClass {
> >   }
> > 
> > }
> > 
> > So whenever a classlass is instantiated I want to get the instance of 
> that
> class (having the MyAnnotation annotation).
> > Therefore I developed the following Pointcut:
> 
> So I continue here with the mentioned pointcut:
> 
> @AfterReturning(pointcut = "call(* .new(..)) && @target(MyAnnotation)",
> returning = "obj")
>   public void objectCreation() {
>   }
>  
> The problem here is, that the combination of the call(* .new(..)) and 
> the
> @target(MyAnnotation) does not work. I can either remove the @target 
> and it
> works fine or I can remove the call(..) and let the @target be the key. 
> But
> together those two do not work.
> 
> Am I doing something completely wrong? Or is there another suggested 
> way to
> intercept a newly created object?
> 
> Any help is appreciated
> 
> Regards
> Moritz Post
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top