Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: "Can define an AspectJ with a hasmethod Pointcut for...?"

Thanks Ramnivas Laddad, Eric Bodden, Andy Clement, and Bhaskar Maddala!!! for the useful comments!!

 Just clarifying to Andy Clement,

  > Is there a real problem withusing an interface in this way in your case?

    A: No, in fact I just wanted to know all available possibilities.  As  I thought in a different solution, I just make sure If it was possible in AspectJ!

On Dec 20, 2007 1:47 PM, < aspectj-users-request@xxxxxxxxxxx> wrote:
Send aspectj-users mailing list submissions to
       aspectj-users@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
        https://dev.eclipse.org/mailman/listinfo/aspectj-users
or, via email, send a message with subject or body 'help' to
       aspectj-users-request@xxxxxxxxxxx

You can reach the person managing the list at
       aspectj-users-owner@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of aspectj-users digest..."


Today's Topics:

  1. "Can define an AspectJ with a hasmethod Pointcut  for...?"
     (Henrique Mostaert)
  2. Re: "Can define an AspectJ with a hasmethod Pointcut      for...?"
     (Ramnivas Laddad)
  3. Type Patterns in declare statements (neil loughran)
  4. Re: Serialization aspect problem (Eric Bodden)
  5. Re: Re: "Help with hasmethod() and hasfield()     pointcuts"
     (Andy Clement)


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

Message: 1
Date: Thu, 20 Dec 2007 00:17:49 -0200
From: "Henrique Mostaert" < henrique.mr@xxxxxxxxx>
Subject: [aspectj-users] "Can define an AspectJ with a hasmethod
       Pointcut        for...?"
To: aspectj-users <aspectj-users@xxxxxxxxxxx >
Message-ID:
       <673df86b0712191817i438e3c21x31b8ee690f97c49c@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset="iso-8859-1"

Hello all,

 This issue started in the previous topic *"Help with hasmethod() and
hasfield() pointcuts".< http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08654.html>
*In this way, I mentioned the real point that I really want in my last
commentary in this previous topic. So, I decided to put it in a new topic in
order to give more discussion about.

 He we go :

    (1) My main question now is:

     Consider the following example:

         class C {

          public void x(){}
        }

        aspect C{

            // Verify if the method "public void x(){}" exists in Class C
(using the hasmethod() pointcut), and if exists, (our case), inserts a
method into C using the inter-type declaration like:

            public boolean C.checkSomeProperties(){}
       }

     QUESTION: Is there a way to provide this behavior in AspectJ without
using an Interface as intermediate ??


  Regards!!



--
Henrique Mostaert, Departamento de Sistemas Computacionais, UPE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://dev.eclipse.org/mailman/listinfo/aspectj-users/attachments/20071219/18ff8f63/attachment.html

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

Message: 2
Date: Wed, 19 Dec 2007 21:43:09 -0500
From: "Ramnivas Laddad" < ramnivas@xxxxxxxxxxxxxxx>
Subject: Re: [aspectj-users] "Can define an AspectJ with a hasmethod
       Pointcut        for...?"
To: aspectj-users@xxxxxxxxxxx
Message-ID:
       <ef9c6b3b0712191843r695bbad0q9cc9fe092f72b059@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset="iso-8859-1"

Since hasmethod() may be used only in 'declare parents' statements, you
cannot avoid using an interface as an intermediary. One this you can do is
use a *private* interface as an intermediary in the aspect. This will
prevent the interface being exposed to other types in the system.

-Ramnivas

On Dec 19, 2007 9:17 PM, Henrique Mostaert <henrique.mr@xxxxxxxxx> wrote:

> Hello all,
>
>   This issue started in the previous topic *"Help with hasmethod() and
> hasfield() pointcuts".< http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08654.html>
> *In this way, I mentioned the real point that I really want in my last
> commentary in this previous topic. So, I decided to put it in a new topic in
> order to give more discussion about.
>
>   He we go :
>
>      (1) My main question now is:
>
>       Consider the following example:
>
>           class C {
>
>            public void x(){}
>          }
>
>          aspect C{
>
>              // Verify if the method "public void x(){}" exists in Class C
> (using the hasmethod() pointcut), and if exists, (our case), inserts a
> method into C using the inter-type declaration like:
>
>              public boolean C.checkSomeProperties(){}
>         }
>
>       QUESTION: Is there a way to provide this behavior in AspectJ without
> using an Interface as intermediate ??
>
>
>    Regards!!
>
>
>
> --
> Henrique Mostaert, Departamento de Sistemas Computacionais, UPE
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://dev.eclipse.org/mailman/listinfo/aspectj-users/attachments/20071219/aa66f99d/attachment.html

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

Message: 3
Date: Thu, 20 Dec 2007 15:24:38 -0000
From: "neil loughran" < loughran@xxxxxxxxxxxxxxxx>
Subject: [aspectj-users] Type Patterns in declare statements
To: <aspectj-users@xxxxxxxxxxx >
Message-ID: <00bd01c8431c$6f0960d0$1a28220a@STUDENT6510>
Content-Type: text/plain;       charset="us-ascii"

Was just wondering if it is possible to use some kind of type pattern within
declare parents statements?

For example given the following class that I want to serialise

class Foo {
private Bar a;
private Far b;

...
}

Can I write the following in a single statement by somehow just referring to
Foo i.e. Foo and all members in Foo..?

declare parents: Foo implements Serializable;
declare parents: Bar implements Serializable;
declare parents: Far implements Serializable;

I know I can also write

declare parents: (Foo || Bar || Far) implements Serializable;

but was just wondering if there were some additional
operators/designators/tricks/idioms I could utilise for expressing "Foo and
all members within Foo" without resorting to the above.  I think such a
facility would be extremely useful and powerful.

Thanks

Neil Loughran







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

Message: 4
Date: Wed, 19 Dec 2007 18:06:53 +0100
From: "Eric Bodden" < eric.bodden@xxxxxxxxxxxxxx>
Subject: Re: [aspectj-users] Serialization aspect problem
To: aspectj-users@xxxxxxxxxxx
Message-ID:
       <804e3c660712190906p1e792778tde020307175379e0@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset=ISO-8859-1

Hi, Neil.

"f" is a local variable. It's scope is restricted to the advice
declaration. If you want to store the serialized object somewhere you
have to either do this manually (How otherwise would AJ know where to
store f?) or, depending on the context, you may use an around-advice
and return f from that advice to pass it back to the calling context.

Eric

On 19/12/2007, neil loughran < loughran@xxxxxxxxxxxxxxxx> wrote:
> Hi all
>
> I'm trying to figure out what exactly is wrong with my pointcut/advice for a
> serialisation aspect.
>
> The code below is fairly simple but captures the problem I have.  Basically
> I create an object of type Foo and set Foo.x to Foobar. My aspect has two
> advice.. one for capturing instantiation of Foo and the other for capturing
> setX on Foo objects.
>
> On instantiation of Foo, I attempt to load a serialised file ( Foo.ser).  If
> it doesn't exist then an exception is thrown but the program carries on as
> usual.  When I setX the second advice serializes the Foo object as file
> Foo.ser.
>
> Therefore when I run the program a second time I expect the Foo.ser file to
> load and the contents loaded to the Foo object.  However, for some reason I
> can't seem to show the loaded value in FooDriver only in the aspect.
> Therefore, I am assuming my first advice is incorrectly written and the
> loaded content is lost outside of the aspect.  I have tried a few different
> varieties of around/after returning advice to no avail.
>
> Can anyone spot the mistake in the first advice... it's driving me nuts!
>
> Many thanks
> Neil Loughran
>
>
>
> import java.io.*;
>
> class FooDriver  {
>     public static void main(String args[])  {
>         Foo f = new Foo();
>         System.out.println("[FooDriver] x = "+f.getX()); // always null!!?
>
>         f.setX("Foobar");
>     }
> }
>
> class Foo  {
>     public String x;
>     public void setX(String _x)  {
>         x = _x;
>     }
>
>     public String getX() {
>                 return x;
>         }
> }
>
> aspect MyAspect  {
>     declare parents: Foo implements Serializable;
>     String filename = "Foo.ser";
>
>     // problematic advice?
>     after(Foo f): this(f) && execution (Foo.new())  {
>         try  {
>             f = (Foo) SerializeObject.load(filename);
>             System.out.println("[MyAspect] x = "+f.getX()); // works fine
> here!
>         }
>
>         catch(Exception e)  {
>             System.out.println("File not found "+ e);
>         }
>     }
>
>     after(Foo f): this(f) && execution(public void Foo.setX (String))  {
>         System.out.println("Setting");
>         try  {
>             SerializeObject.save(f,filename);
>         }
>
>         catch(IOException e)  {
>             System.out.println("File not found "+ e);
>         }
>     }
> }
>
> class SerializeObject  {
>     public static void save(Object obj, String filename) throws IOException
> {
>           System.out.println("Saving file: "+filename);
>         ObjectOutputStream objstream = new ObjectOutputStream(new
> FileOutputStream(filename));
>         objstream.writeObject (obj);
>         objstream.close();
>     }
>
>     public static Object load(String filename) throws Exception  {
>         System.out.println("Loading file: "+filename);
>         ObjectInputStream objstream = new ObjectInputStream(new
> FileInputStream(filename));
>         Object obj = objstream.readObject();
>         objstream.close();
>         return obj;
>     }
> }
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


--
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada


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

Message: 5
Date: Wed, 19 Dec 2007 23:44:59 +0000
From: "Andy Clement" < andrew.clement@xxxxxxxxx>
Subject: Re: [aspectj-users] Re: "Help with hasmethod() and hasfield()
       pointcuts"
To: aspectj-users@xxxxxxxxxxx
Message-ID:
       <689d61aa0712191544x529e4acdq6b94301743ee0143@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset=ISO-8859-1

No, you need the intermediate interface.  Is there a real problem with
using an interface in this way in your case?  In the code it will only
manifest as an extra interface implemented by the target class 'C' -
will that cause you any problems?

Andy.

On 19/12/2007, Henrique Mostaert <henrique.mr@xxxxxxxxx> wrote:
> Dear Bhaskar Maddala,
>
>   Thanks for the solution!!! In fact, the real scenario that I concerned,
> would be  if  possible:
>
>   a class  C  with a metod x(), an AspectC that verifies if the methd x()
> exists in Class C using the hasmethod pointcut, and then if true inserting a
> method into C using the inter-type declaration, for example: public boolean
> C.checkSomething() { } instead of using an interface as an intermediate.
>
> regards!
>
> On Dec 19, 2007 4:46 PM, <aspectj-users-request@xxxxxxxxxxx
> > wrote:
> > Send aspectj-users mailing list submissions to
> >         aspectj-users@xxxxxxxxxxx
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > or, via email, send a message with subject or body 'help' to
> >        aspectj-users-request@xxxxxxxxxxx
> >
> > You can reach the person managing the list at
> >         aspectj-users-owner@xxxxxxxxxxx
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of aspectj-users digest..."
> >
> >
> > Today's Topics:
> >
> >   1. Re: "Help with hasmethod() and hasfield() pointcuts"
> >      (Henrique Mostaert)
> >   2. Re: Serialization aspect problem (Bhaskar Maddala)
> >   3. Re: Re: "Help with hasmethod() and hasfield()     pointcuts"
> >      (Bhaskar Maddala)
> >
> >
> >
> ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Wed, 19 Dec 2007 16:31:52 -0200
> > From: "Henrique Mostaert" < henrique.mr@xxxxxxxxx>
> > Subject: [aspectj-users] Re: "Help with hasmethod() and hasfield()
> >        pointcuts"
> > To: aspectj-users@xxxxxxxxxxx
> > Message-ID:
> >
> < 673df86b0712191031k4a56b4acs747a390a5b3c3667@xxxxxxxxxxxxxx>
> >
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Dear Andy Clement,
> >
> >  Thanks for the help!!
> >
> >  Moreover, Is there a way to use the hasmethod pointcut in another context
> > besides declare parents??
> >
> >  I want it in a situation to verify for example If a Class C has the
> method
> > x() then inserts a method t() using the inter-type declarations...
> >
> >  Is possible?
> >
> > On Dec 19, 2007 3:00 PM,
> < aspectj-users-request@xxxxxxxxxxx> wrote:
> >
> > > Send aspectj-users mailing list submissions to
> > >        aspectj-users@xxxxxxxxxxx
> > >
> > > To subscribe or unsubscribe via the World Wide Web, visit
> > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > or, via email, send a message with subject or body 'help' to
> > >        aspectj-users-request@xxxxxxxxxxx
> > >
> > > You can reach the person managing the list at
> > >         aspectj-users-owner@xxxxxxxxxxx
> > >
> > > When replying, please edit your Subject line so it is more specific
> > > than "Re: Contents of aspectj-users digest..."
> > >
> > >
> > > Today's Topics:
> > >
> > >   1. "Help with hasmethod() and hasfield() pointcuts"
> > >      (Henrique Mostaert)
> > >   2. Re: "Help with hasmethod() and hasfield() pointcuts"
> > >      (Andy Clement)
> > >   3. Serialization aspect problem (neil loughran)
> > >
> > >
> > >
> ----------------------------------------------------------------------
> > >
> > > Message: 1
> > > Date: Wed, 19 Dec 2007 10:45:14 -0200
> > > From: "Henrique Mostaert" <henrique.mr@xxxxxxxxx>
> > > Subject: [aspectj-users] "Help with hasmethod() and hasfield()
> > >        pointcuts"
> > > To: aspectj-users <aspectj-users@xxxxxxxxxxx>
> > > Message-ID:
> > >        <
> 673df86b0712190445n28c4cc0es87f5227d97741aa9@xxxxxxxxxxxxxx>
> > > Content-Type: text/plain; charset="iso-8859-1"
> > >
> > > Hello all,
> > >
> > >  Could someone give me some instructions in order to use hasmethod() and
> > > hasfield() pointcuts?
> > >
> > >  I activated the option in AJDT 1.4 with AspectJ 5 to "allow hasmethod()
> > > and hasfield() type patterns in declare parents and declare @type".
> But,
> > > it
> > > doesn't work. The AJDT plugin doesn't recognize these pointcuts leading
> to
> > > compile time error. So, Could someone explain me why this happens?
> > >
> > >  Moreover, If someone could also show me how to allow these pointcuts
> > > Through ajc compiler options. (I didn't find the this option, only
> through
> > > eclipse and it does not work ).
> > >
> > > Regards!
> > >
> > > --
> > > Henrique Mostaert
> > > -------------- next part --------------
> > > An HTML attachment was scrubbed...
> > > URL:
> > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users/attachments/20071219/586e5f6b/attachment.html
> > >
> > > ------------------------------
> > >
> > > Message: 2
> > > Date: Wed, 19 Dec 2007 14:49:48 +0000
> > > From: "Andy Clement" < andrew.clement@xxxxxxxxx >
> > > Subject: Re: [aspectj-users] "Help with hasmethod() and hasfield()
> > >        pointcuts"
> > > To: aspectj-users@xxxxxxxxxxx
> > > Message-ID:
> > >
> <689d61aa0712190649o21a9ed7ds529ff0e4f1e2c3ff@xxxxxxxxxxxxxx >
> > > Content-Type: text/plain; charset=ISO-8859-1
> > >
> > > Hi, here you go:
> > >
> > > --- A.java ----- 8< -----
> > > public class A {
> > >  public static void main(String[]argv) {
> > >  }
> > > }
> > >
> > > aspect X {
> > >  declare parents: hasmethod(public void main(..)) implements
> > > java.io.Serializable;
> > > }
> > > -----8<------
> > > $ ajc -1.5 -showWeaveInfo -XhasMember A.java
> > > Extending interface set for type 'A' ( A.java) to include
> > > 'java.io.Serializable ' (A.java)
> > >
> > > $ javap A
> > > Compiled from "A.java"
> > > public class A extends java.lang.Object implements java.io.Serializable{
> > >    public A();
> > >    public static void main( java.lang.String[]);
> > > }
> > >
> > > I'm not sure why flicking the option on in AJDT is not working for you.
> > >
> > > Andy.
> > >
> > > On 19/12/2007, Henrique Mostaert < henrique.mr@xxxxxxxxx> wrote:
> > > > Hello all,
> > > >
> > > >   Could someone give me some instructions in order to use hasmethod()
> > > and
> > > > hasfield() pointcuts?
> > > >
> > > >   I activated the option in AJDT 1.4 with AspectJ 5 to "allow
> > > hasmethod()
> > > > and hasfield() type patterns in declare parents and declare @type".
> > >  But, it
> > > > doesn't work. The AJDT plugin doesn't recognize these pointcuts
> leading
> > > to
> > > > compile time error. So, Could someone explain me why this happens?
> > > >
> > > >  Moreover, If someone could also show me how to allow these pointcuts
> > > > Through ajc compiler options. (I didn't find the this option, only
> > > through
> > > > eclipse and it does not work ).
> > > >
> > > > Regards!
> > > >
> > > > --
> > > > Henrique Mostaert
> > > >
> > > >
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > > >
> > >
> > >
> > > ------------------------------
> > >
> > > Message: 3
> > > Date: Wed, 19 Dec 2007 15:59:22 -0000
> > > From: "neil loughran" < loughran@xxxxxxxxxxxxxxxx>
> > > Subject: [aspectj-users] Serialization aspect problem
> > > To: < aspectj-users@xxxxxxxxxxx >
> > > Message-ID:
> <004b01c84258$1f499390$1a28220a@STUDENT6510>
> > > Content-Type: text/plain;       charset="us-ascii"
> > >
> > > Hi all
> > >
> > > I'm trying to figure out what exactly is wrong with my pointcut/advice
> for
> > > a
> > > serialisation aspect.
> > >
> > > The code below is fairly simple but captures the problem I have.
> > >  Basically
> > > I create an object of type Foo and set Foo.x to Foobar. My aspect has
> two
> > > advice.. one for capturing instantiation of Foo and the other for
> > > capturing
> > > setX on Foo objects.
> > >
> > > On instantiation of Foo, I attempt to load a serialised file ( Foo.ser).
> > >  If
> > > it doesn't exist then an exception is thrown but the program carries on
> as
> > > usual.  When I setX the second advice serializes the Foo object as file
> > > Foo.ser.
> > >
> > > Therefore when I run the program a second time I expect the Foo.ser file
> > > to
> > > load and the contents loaded to the Foo object.  However, for some
> reason
> > > I
> > > can't seem to show the loaded value in FooDriver only in the aspect.
> > > Therefore, I am assuming my first advice is incorrectly written and the
> > > loaded content is lost outside of the aspect.  I have tried a few
> > > different
> > > varieties of around/after returning advice to no avail.
> > >
> > > Can anyone spot the mistake in the first advice... it's driving me nuts!
> > >
> > > Many thanks
> > > Neil Loughran
> > >
> > >
> > >
> > > import java.io.*;
> > >
> > > class FooDriver  {
> > >    public static void main(String args[])  {
> > >        Foo f = new Foo();
> > >        System.out.println("[FooDriver] x = "+f.getX()); // always
> null!!?
> > >
> > >        f.setX("Foobar");
> > >    }
> > > }
> > >
> > > class Foo  {
> > >    public String x;
> > >    public void setX(String _x)  {
> > >        x = _x;
> > >    }
> > >
> > >    public String getX() {
> > >                return x;
> > >        }
> > > }
> > >
> > > aspect MyAspect  {
> > >    declare parents: Foo implements Serializable;
> > >    String filename = "Foo.ser";
> > >
> > >    // problematic advice?
> > >    after(Foo f): this(f) && execution (Foo.new())  {
> > >        try  {
> > >            f = (Foo) SerializeObject.load (filename);
> > >            System.out.println("[MyAspect] x = "+f.getX()); // works fine
> > > here!
> > >        }
> > >
> > >        catch(Exception e)  {
> > >            System.out.println("File not found "+ e);
> > >        }
> > >    }
> > >
> > >    after(Foo f): this(f) && execution(public void Foo.setX(String))  {
> > >        System.out.println("Setting");
> > >        try  {
> > >             SerializeObject.save(f,filename);
> > >        }
> > >
> > >        catch(IOException e)  {
> > >            System.out.println("File not found "+ e);
> > >        }
> > >    }
> > > }
> > >
> > > class SerializeObject  {
> > >    public static void save(Object obj, String filename) throws
> IOException
> > > {
> > >          System.out.println("Saving file: "+filename);
> > >        ObjectOutputStream objstream = new ObjectOutputStream(new
> > > FileOutputStream(filename));
> > >        objstream.writeObject(obj);
> > >        objstream.close ();
> > >    }
> > >
> > >    public static Object load(String filename) throws Exception  {
> > >         System.out.println("Loading file: "+filename);
> > >        ObjectInputStream objstream = new ObjectInputStream(new
> > > FileInputStream(filename));
> > >        Object obj = objstream.readObject();
> > >         objstream.close();
> > >        return obj;
> > >    }
> > > }
> > >
> > >
> > >
> > > ------------------------------
> > >
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> > >
> > > End of aspectj-users Digest, Vol 34, Issue 37
> > > *********************************************
> > >
> >
> >
> >
> > --
> > Henrique Mostaert, Departamento de Sistemas Computacionais, UPE
> > http://www.dsc.upe.br/~hemr
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL:
> https://dev.eclipse.org/mailman/listinfo/aspectj-users/attachments/20071219/e3534f10/attachment.html
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Wed, 19 Dec 2007 13:33:15 -0500
> > From: "Bhaskar Maddala" < maddalab@xxxxxxxxx>
> > Subject: Re: [aspectj-users] Serialization aspect problem
> > To: aspectj-users@xxxxxxxxxxx
> > Message-ID:
> >
> <508d7a910712191033v77b67e28wb75aefb548876aa4@xxxxxxxxxxxxxx>
> > Content-Type: text/plain; charset=ISO-8859-1
> >
> > A modified aspect that works
> >
> > public aspect SerializationAspect
> > {
> >   declare parents: Foo implements Serializable;
> >   String filename = "Foo.ser ";
> >
> >   // problematic advice? - no longer problematic
> >   after(Foo f): this(f) && execution( Foo.new())  {
> >       try  {
> >           Foo f1 = (Foo) SerializeObject.load (filename);
> >           System.out.println("[MyAspect] x = "+f1.getX()); // works fine
> here!
> >           f.setX(f1.getX()); // it's all about the references.....
> >       }
> >
> >       catch(Exception e)  {
> >           System.out.println("File not found "+ e);
> >       }
> >   }
> >
> >   after(Foo f): this(f) && execution(public void Foo.setX(String)) &&
> > !within(SerializationAspect) {
> >       System.out.println("Setting");
> >       try  {
> >           SerializeObject.save(f,filename);
> >       }
> >
> >       catch(IOException e)  {
> >           System.out.println ("File not found "+ e);
> >       }
> >   }
> > }
> >
> > Thanks
> > Bhaskar
> >
> >
> > On Dec 19, 2007 10:59 AM, neil loughran <loughran@xxxxxxxxxxxxxxxx> wrote:
> > > Hi all
> > >
> > > I'm trying to figure out what exactly is wrong with my pointcut/advice
> for a
> > > serialisation aspect.
> > >
> > > The code below is fairly simple but captures the problem I have.
> Basically
> > > I create an object of type Foo and set Foo.x to Foobar. My aspect has
> two
> > > advice.. one for capturing instantiation of Foo and the other for
> capturing
> > > setX on Foo objects.
> > >
> > > On instantiation of Foo, I attempt to load a serialised file ( Foo.ser).
>  If
> > > it doesn't exist then an exception is thrown but the program carries on
> as
> > > usual.  When I setX the second advice serializes the Foo object as file
> > > Foo.ser.
> > >
> > > Therefore when I run the program a second time I expect the Foo.ser file
> to
> > > load and the contents loaded to the Foo object.  However, for some
> reason I
> > > can't seem to show the loaded value in FooDriver only in the aspect.
> > > Therefore, I am assuming my first advice is incorrectly written and the
> > > loaded content is lost outside of the aspect.  I have tried a few
> different
> > > varieties of around/after returning advice to no avail.
> > >
> > > Can anyone spot the mistake in the first advice... it's driving me nuts!
> > >
> > > Many thanks
> > > Neil Loughran
> > >
> > >
> > >
> > > import java.io.*;
> > >
> > > class FooDriver  {
> > >     public static void main(String args[])  {
> > >         Foo f = new Foo();
> > >         System.out.println("[FooDriver] x = "+f.getX()); // always
> null!!?
> > >
> > >         f.setX("Foobar");
> > >     }
> > > }
> > >
> > > class Foo  {
> > >     public String x;
> > >     public void setX(String _x)  {
> > >         x = _x;
> > >     }
> > >
> > >     public String getX() {
> > >                 return x;
> > >         }
> > > }
> > >
> > > aspect MyAspect  {
> > >     declare parents: Foo implements Serializable;
> > >     String filename = "Foo.ser";
> > >
> > >     // problematic advice?
> > >     after(Foo f): this(f) && execution (Foo.new())  {
> > >         try  {
> > >             f = (Foo) SerializeObject.load(filename);
> > >             System.out.println ("[MyAspect] x = "+f.getX()); // works
> fine
> > > here!
> > >         }
> > >
> > >         catch(Exception e)  {
> > >             System.out.println ("File not found "+ e);
> > >         }
> > >     }
> > >
> > >     after(Foo f): this(f) && execution(public void Foo.setX (String))  {
> > >         System.out.println("Setting");
> > >         try  {
> > >             SerializeObject.save(f,filename);
> > >         }
> > >
> > >         catch(IOException e)  {
> > >             System.out.println("File not found "+ e);
> > >         }
> > >     }
> > > }
> > >
> > > class SerializeObject  {
> > >     public static void save(Object obj, String filename) throws
> IOException
> > > {
> > >           System.out.println("Saving file: "+filename);
> > >         ObjectOutputStream objstream = new ObjectOutputStream(new
> > > FileOutputStream(filename));
> > >         objstream.writeObject (obj);
> > >         objstream.close();
> > >     }
> > >
> > >     public static Object load(String filename) throws Exception  {
> > >         System.out.println("Loading file: "+filename);
> > >         ObjectInputStream objstream = new ObjectInputStream(new
> > > FileInputStream(filename));
> > >         Object obj = objstream.readObject();
> > >         objstream.close();
> > >         return obj;
> > >     }
> > > }
> > >
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> >
> >
> > ------------------------------
> >
> > Message: 3
> > Date: Wed, 19 Dec 2007 13:46:27 -0500
> > From: "Bhaskar Maddala" <maddalab@xxxxxxxxx>
> > Subject: Re: [aspectj-users] Re: "Help with hasmethod() and hasfield()
> >        pointcuts"
> > To: aspectj-users@xxxxxxxxxxx
> > Message-ID:
> >        <
> 508d7a910712191046l3c95f9b3if08cd889e91c41ae@xxxxxxxxxxxxxx>
> > Content-Type: text/plain; charset=ISO-8859-1
> >
> > >  I want it in a situation to verify for example If a Class C has the
> method
> > > x() then inserts a method t() using the inter-type declarations...
> >
> > but isn't that a declare parents use case? Put another way, on which
> > type is the method t declared?
> >
> > Here is an attempt at a solution, not certain though if this is what
> > you were looking for (using previous example)
> >
> > public class A {
> >  public static void main(String[]argv) {
> >  }
> >
> >  public void x(){}
> > }
> >
> > interface T{
> >        void t();
> > }
> >
> > aspect X {
> >  declare parents: hasmethod(public void main(..)) implements
> > java.io.Serializable;
> >
> >  public void T.t() { System.out.println("t");}
> >
> >  declare parents: hasmethod(public void x(..)) extends T;
> > }
> >
> > ..\bin\ajc -classpath ..\lib\aspectjrt.jar -1.5 -showWeaveInfo
> > -XhasMember A.java
> >
> > Type 'T' (A.java) has intertyped method from 'X' (A.java:'void T.t()')
> >
> > Extending interface set for type 'A' (A.java) to include
> > 'java.io.Serializable ' (A.java)
> >
> > Extending interface set for type 'A' ( A.java) to include 'T' (A.java)
> >
> > Type 'A' (A.java) has intertyped method from 'X' (A.java:'void T.t()')
> >
> >
> >
> >
> > On Dec 19, 2007 1:31 PM, Henrique Mostaert < henrique.mr@xxxxxxxxx> wrote:
> > > Dear Andy Clement,
> > >
> > >  Thanks for the help!!
> > >
> > >  Moreover, Is there a way to use the hasmethod pointcut in another
> context
> > > besides declare parents??
> > >
> > >  I want it in a situation to verify for example If a Class C has the
> method
> > > x() then inserts a method t() using the inter-type declarations...
> > >
> > >  Is possible?
> > >
> > > On Dec 19, 2007 3:00 PM,
> <aspectj-users-request@xxxxxxxxxxx> wrote:
> > > > Send aspectj-users mailing list submissions to
> > > >         aspectj-users@xxxxxxxxxxx
> > > >
> > > > To subscribe or unsubscribe via the World Wide Web, visit
> > > >
> > > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > or, via email, send a message with subject or body 'help' to
> > > >        aspectj-users-request@xxxxxxxxxxx
> > > >
> > > > You can reach the person managing the list at
> > > >         aspectj-users-owner@xxxxxxxxxxx
> > > >
> > > > When replying, please edit your Subject line so it is more specific
> > > > than "Re: Contents of aspectj-users digest..."
> > > >
> > > >
> > > > Today's Topics:
> > > >
> > > >   1. "Help with hasmethod() and hasfield() pointcuts"
> > > >      (Henrique Mostaert)
> > > >   2. Re: "Help with hasmethod() and hasfield() pointcuts"
> > > >      (Andy Clement)
> > > >   3. Serialization aspect problem (neil loughran)
> > > >
> > > >
> > > >
> ----------------------------------------------------------------------
> > > >
> > > > Message: 1
> > > > Date: Wed, 19 Dec 2007 10:45:14 -0200
> > > > From: "Henrique Mostaert" < henrique.mr@xxxxxxxxx>
> > > > Subject: [aspectj-users] "Help with hasmethod() and hasfield()
> > > >        pointcuts"
> > > > To: aspectj-users < aspectj-users@xxxxxxxxxxx>
> > > > Message-ID:
> > > >
> <673df86b0712190445n28c4cc0es87f5227d97741aa9@xxxxxxxxxxxxxx
> >
> > > > Content-Type: text/plain; charset="iso-8859-1"
> > > >
> > > >
> > > > Hello all,
> > > >
> > > >  Could someone give me some instructions in order to use hasmethod()
> and
> > > > hasfield() pointcuts?
> > > >
> > > >  I activated the option in AJDT 1.4 with AspectJ 5 to "allow
> hasmethod()
> > > > and hasfield() type patterns in declare parents and declare @type".
> But,
> > > it
> > > > doesn't work. The AJDT plugin doesn't recognize these pointcuts
> leading to
> > > > compile time error. So, Could someone explain me why this happens?
> > > >
> > > >  Moreover, If someone could also show me how to allow these pointcuts
> > > > Through ajc compiler options. (I didn't find the this option, only
> through
> > > > eclipse and it does not work ).
> > > >
> > > > Regards!
> > > >
> > > > --
> > > > Henrique Mostaert
> > > > -------------- next part --------------
> > > > An HTML attachment was scrubbed...
> > > > URL:
> > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users/attachments/20071219/586e5f6b/attachment.html
> > > >
> > > > ------------------------------
> > > >
> > > > Message: 2
> > > > Date: Wed, 19 Dec 2007 14:49:48 +0000
> > > > From: "Andy Clement" < andrew.clement@xxxxxxxxx>
> > > > Subject: Re: [aspectj-users] "Help with hasmethod() and hasfield()
> > > >        pointcuts"
> > > > To: aspectj-users@xxxxxxxxxxx
> > > > Message-ID:
> > > >
> < 689d61aa0712190649o21a9ed7ds529ff0e4f1e2c3ff@xxxxxxxxxxxxxx
> >
> > > > Content-Type: text/plain; charset=ISO-8859-1
> > > >
> > > >
> > > >
> > > >
> > > > Hi, here you go:
> > > >
> > > > --- A.java ----- 8< -----
> > > > public class A {
> > > >  public static void main(String[]argv) {
> > > >  }
> > > > }
> > > >
> > > > aspect X {
> > > >  declare parents: hasmethod(public void main(..)) implements
> > > > java.io.Serializable ;
> > > > }
> > > > -----8<------
> > > > $ ajc -1.5 -showWeaveInfo -XhasMember A.java
> > > > Extending interface set for type 'A' (A.java) to include
> > > > 'java.io.Serializable ' (A.java)
> > > >
> > > > $ javap A
> > > > Compiled from "A.java"
> > > > public class A extends java.lang.Object implements
> java.io.Serializable{
> > > >    public A();
> > > >    public static void main( java.lang.String[]);
> > > > }
> > > >
> > > > I'm not sure why flicking the option on in AJDT is not working for
> you.
> > > >
> > > > Andy.
> > > >
> > > > On 19/12/2007, Henrique Mostaert < henrique.mr@xxxxxxxxx> wrote:
> > > > > Hello all,
> > > > >
> > > > >   Could someone give me some instructions in order to use
> hasmethod()
> > > and
> > > > > hasfield() pointcuts?
> > > > >
> > > > >   I activated the option in AJDT 1.4 with AspectJ 5 to "allow
> > > hasmethod()
> > > > > and hasfield() type patterns in declare parents and declare @type".
> > > But, it
> > > > > doesn't work. The AJDT plugin doesn't recognize these pointcuts
> leading
> > > to
> > > > > compile time error. So, Could someone explain me why this happens?
> > > > >
> > > > >  Moreover, If someone could also show me how to allow these
> pointcuts
> > > > > Through ajc compiler options. (I didn't find the this option, only
> > > through
> > > > > eclipse and it does not work ).
> > > > >
> > > > > Regards!
> > > > >
> > > > > --
> > > > > Henrique Mostaert
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > aspectj-users mailing list
> > > > > aspectj-users@xxxxxxxxxxx
> > > > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > >
> > > > >
> > > >
> > > >
> > > > ------------------------------
> > > >
> > > > Message: 3
> > > > Date: Wed, 19 Dec 2007 15:59:22 -0000
> > > > From: "neil loughran" <loughran@xxxxxxxxxxxxxxxx >
> > > > Subject: [aspectj-users] Serialization aspect problem
> > > > To: < aspectj-users@xxxxxxxxxxx>
> > > > Message-ID:
> <004b01c84258$1f499390$1a28220a@STUDENT6510>
> > > > Content-Type: text/plain;       charset="us-ascii"
> > > >
> > > > Hi all
> > > >
> > > > I'm trying to figure out what exactly is wrong with my pointcut/advice
> for
> > > a
> > > > serialisation aspect.
> > > >
> > > > The code below is fairly simple but captures the problem I have.
> > > Basically
> > > > I create an object of type Foo and set Foo.x to Foobar. My aspect has
> two
> > > > advice.. one for capturing instantiation of Foo and the other for
> > > capturing
> > > > setX on Foo objects.
> > > >
> > > > On instantiation of Foo, I attempt to load a serialised file (
> Foo.ser).
> > > If
> > > > it doesn't exist then an exception is thrown but the program carries
> on as
> > > > usual.  When I setX the second advice serializes the Foo object as
> file
> > > > Foo.ser.
> > > >
> > > > Therefore when I run the program a second time I expect the Foo.ser
> file
> > > to
> > > > load and the contents loaded to the Foo object.  However, for some
> reason
> > > I
> > > > can't seem to show the loaded value in FooDriver only in the aspect.
> > > > Therefore, I am assuming my first advice is incorrectly written and
> the
> > > > loaded content is lost outside of the aspect.  I have tried a few
> > > different
> > > > varieties of around/after returning advice to no avail.
> > > >
> > > > Can anyone spot the mistake in the first advice... it's driving me
> nuts!
> > > >
> > > > Many thanks
> > > > Neil Loughran
> > > >
> > > >
> > > >
> > > > import java.io.*;
> > > >
> > > > class FooDriver  {
> > > >    public static void main(String args[])  {
> > > >        Foo f = new Foo();
> > > >        System.out.println("[FooDriver] x = "+f.getX()); // always
> null!!?
> > > >
> > > >        f.setX("Foobar");
> > > >    }
> > > > }
> > > >
> > > > class Foo  {
> > > >    public String x;
> > > >    public void setX(String _x)  {
> > > >        x = _x;
> > > >    }
> > > >
> > > >    public String getX() {
> > > >                return x;
> > > >        }
> > > > }
> > > >
> > > > aspect MyAspect  {
> > > >    declare parents: Foo implements Serializable;
> > > >    String filename = "Foo.ser";
> > > >
> > > >    // problematic advice?
> > > >    after(Foo f): this(f) && execution ( Foo.new())  {
> > > >        try  {
> > > >            f = (Foo) SerializeObject.load(filename);
> > > >             System.out.println("[MyAspect] x = "+f.getX()); // works
> fine
> > > > here!
> > > >        }
> > > >
> > > >        catch(Exception e)  {
> > > >             System.out.println("File not found "+ e);
> > > >        }
> > > >    }
> > > >
> > > >    after(Foo f): this(f) && execution(public void Foo.setX (String))  {
> > > >        System.out.println("Setting");
> > > >        try  {
> > > >            SerializeObject.save (f,filename);
> > > >        }
> > > >
> > > >        catch(IOException e)  {
> > > >            System.out.println("File not found "+ e);
> > > >        }
> > > >    }
> > > > }
> > > >
> > > > class SerializeObject  {
> > > >    public static void save(Object obj, String filename) throws
> IOException
> > > > {
> > > >          System.out.println("Saving file: "+filename);
> > > >        ObjectOutputStream objstream = new ObjectOutputStream(new
> > > > FileOutputStream(filename));
> > > >        objstream.writeObject(obj);
> > > >        objstream.close();
> > > >    }
> > > >
> > > >    public static Object load(String filename) throws Exception  {
> > > >        System.out.println("Loading file: "+filename);
> > > >        ObjectInputStream objstream = new ObjectInputStream(new
> > > > FileInputStream(filename));
> > > >        Object obj = objstream.readObject();
> > > >        objstream.close();
> > > >        return obj;
> > > >    }
> > > > }
> > > >
> > > >
> > > >
> > > > ------------------------------
> > > >
> > > >
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > >
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > > >
> > > > End of aspectj-users Digest, Vol 34, Issue 37
> > > > *********************************************
> > > >
> > >
> > >
> > >
> > > --
> > > Henrique Mostaert, Departamento de Sistemas Computacionais, UPE
> > > http://www.dsc.upe.br/~hemr
> > > _______________________________________________
> > > 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
> >
> >
> > End of aspectj-users Digest, Vol 34, Issue 38
> > *********************************************
> >
>
>
>
> --
>
> Henrique Mostaert, Departamento de Sistemas Computacionais, UPE
> http://www.dsc.upe.br/~hemr
> _______________________________________________
> 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


End of aspectj-users Digest, Vol 34, Issue 42
*********************************************



--
Henrique Mostaert, Departamento de Sistemas e Computação, UPE

Back to the top