Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: "Help with hasmethod() and hasfield() pointcuts"

Hi,

Currently, you would need to do this to achieve what you want:

interface MyInterface {}

aspect X {

  public void MyInterface.m() {}

  declare parents: within(C) && hasmethod(public void x(..))
implements MyInterface;

}

The intertype declaration on m() means classes that implement
MyInterface will get the implementation you specify, so class C, if it
has a method called x() will get method m() too.

Andy.

On 19/12/2007, 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
>
>


Back to the top