Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] getting the object from a joinpoint

Getting the newly constructed object is a bit tricky and I didn't know
how to do it until I read "Eclipse AspectJ", by Adrian Colyer, et al.
(highly recommended).

First, the object isn't returned by execution() PCDs, even in the case
of around advice and proceed(). However, call() will return the new
object. So the following should work

after () returning (Object o): call (MyClass.new()) {
    System.out.println ("Class = " + o.getClass().getName());
}

or in your case:

after() returning (Object o): ConstCall() {
    System.out.println ("Class = " + o.getClass().getName());
}


On 2/13/06, mfirrincieli@xxxxxxxxxxxxxxxxx
<mfirrincieli@xxxxxxxxxxxxxxxxx> wrote:
> mmm
> basically what i have to do is start up different tasks when different kinds of
> classes are instantiated...
> that's why i have a generic
>
>  pointcut ConstrCall(): !within(MyAspect) && call(myPackage.*.new(..));
>
> pointcut that executes whenere any new() call (within myPackage is called).
>
> so inside my aspect i need to be able to tell what kind of new is being called.
>
>
> -m
>
> > mfirrincieli@xxxxxxxxxxxxxxxxx wrote:
> > > i'm join-pointing a *.new() kind of call, and i'm getting mad cause then
> > what
> > > i'd have to do is getting the object called... and i can't seem to make it
> > > possibile by using thisJoinPoint object.
> > >
> > > for example if i have
> > >
> > > MyClass c = new MyClass();
> > >
> > > i do capture that in my aspect, but i'd also like to get the kind of
> > object
> > > instantiated by new.
> >
> > Not sure if I understood your question correctly but proceed() returns an
> > object, and in the case of a constructor that's the new object:
> >
> > Object around(Object arg): CapturedConstructor(arg) && !within(Cache)
> > {
> >     ...
> >     createdObject = proceed(arg);
> >     ...
> > }
> >
> > Holger
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
>
>
>
>
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


--
Dean Wampler
http://www.aspectprogramming.com
http://www.newaspects.com
http://www.contract4j.org


Back to the top