Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] capturing methods without a call to another method

Thankyou Nick,
The solution you suggested was really helpful, but if i implemented this, it
would mean that i have to re-cast the Object[] returned by around advice to its
respective type on assignment to a variable/call to the method. Is there any way
through which i can capture a pointcut like Object.clone() inside another
pointcut like my method signature? or if it all it isn't possible, can i atleast
list all the methods that match this signature? for ex. a method with the
signature (*[] *(..))? The problem being, initially i don't want to use Aspects
in production environment, so the below method wouldn't fit well.

Regards,
Rohith.

----- Original Message ----- 
From: "Nicholas Lesiecki" <ndlesiecki@xxxxxxxxx>
To: <aspectj-users@xxxxxxxxxxx>
Sent: Thursday, August 12, 2004 10:36 PM
Subject: Re: [aspectj-users] capturing methods without a call to another method


> It's very easy to enforce your policy with around advice:
>
> //[warning: uncompiled]
> Object[] around() : execution(*[] *(..)){
> Object[] original = proceed();
> return original.clone();
> }
>
> However, this advice runs the risk of double-cloning if the method
> already clones the array. Also, a method could allocate a local array
> which you might not want cloned...
>
> As to detection, well, that's a bit more difficult, since you would
> have to keep state about whether a given array had had clone called on
> it at some point during the cflow of a method. You might be able to do
> this with a percflow() aspect, but the question you would want to ask
> is: why not just enforce the policy automatically with advice (as
> above)?
>
> Cheers,
> Nick
>
>
> On Aug 12, 2004, at 8:30 AM, Rohith Ajjampur wrote:
>
> > Hello all,
> >
> > I am trying to implement a policy of cloning an array before retuning
> > a refence
> > to it in a method across an API, here is my test code with an aspect:
> >
> > public aspect HelloWorldAspect {
> >     pointcut hello(): !within(HelloWorldAspect);
> >
> >     pointcut method(): execution(*[] *(..));
> >
> >     pointcut cloning(): call(* java.lang.Object.clone());
> >
> >     before(): cflow(method()) && cloning() && hello() {
> >         print("Before : ", thisEnclosingJoinPointStaticPart);
> >     }
> >
> >     after(): cflow(method())&& cloning() && hello() {
> >         print("After : ", thisEnclosingJoinPointStaticPart);
> >     }
> > }
> >
> > public class World {
> >  private Integer[] intArray = new Integer[2];
> >
> >     public Integer[] returnArrayWithCloning() {
> >      for (int i = 0; i < intArray.length; i++) {
> >         intArray[i] = new Integer(i++);
> >      }
> >      return (Integer[])intArray.clone();
> >     }
> >
> >     public Integer[] returnArrayWithoutCloning() {
> >      return intArray;
> >     }
> > }
> >
> > With the above pointcuts and advices i get all the calls to the method
> > World.returnArrayWithCloning(), that is quiet clear, but i would like
> > to get a
> > list of all the methods that return an array without calling its
> > clone() method.
> > Please suggest me how to get this result.
> >
> > Regards,
> > Rohith.
> >
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> Nicholas Lesiecki
> Software Craftsman, specializing in J2EE,
> Agile Methods, and aspect-oriented programming
>
> Books:
> * Mastering AspectJ: http://tinyurl.com/66vf
> * Java Tools for Extreme Programming: http://tinyurl.com/66vt
>
> Articles on AspectJ:
> * http://tinyurl.com/66vu and http://tinyurl.com/66vv
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>



Back to the top