Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Weaving anonymous inner class

>From a post a while ago on this list - there may be others, you should
try a search at

http://www.eclipse.org/search/search.cgi?cmd=Search%21&form=extended&ps=10&m=all&t=5&ul=%2Fmhonarc%2Flists%2Faspectj-users&wm=wrd&t=News&t=Mail

Here is one I found:
---
Trying to target a specific anonymous inner class is problematic. Using a
name is inappropriate (by definition) because it is generated by the
compiler. If another anonymous inner class is added higher up the source
code the name of the class you are interested in will change e.g. $1 to $2.

---
In my particular example, this works:

public aspect X {
  // will select only the println() called within the inner class
   before(): call(* println(..)) && within(C) && within(Runnable+) {}
}

class C {
  public static void main(String[] args) {
    System.out.println("not this one");
    new Runnable() {
      public void run() {
        System.out.println("but this one");
      }
    };
  }
}

but i dont know if that will work in your situation.

Andy

On 26/10/2007, Dehua Zhang <dehua.zhang@xxxxxxxxxxxxxx> wrote:
>
> But, can we weave the anonymous inner class only?
> For example, I only want to match the println in the run method.
>
> --
> Dehua (Andy) Zhang
> Sable Research Group, McGill University
> Montréal, Québec, Canada
> http://www.cs.mcgill.ca/~dzhang25
>
>
>
>
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx on behalf of Andy Clement
> Sent: Fri 10/26/2007 03:28
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Weaving anonymous inner class
>
> AspectJ will always weave the anonymous inner classes.  You would have
> to actively specify something in your pointcuts to stop it doing it.
>
> public aspect X {
>   before(): call(* println(..)) {}
> }
>
> class C {
>         public static void main(String[] args) {
>                 new Runnable() {
>                         public void run() {
>                                 System.out.println("hello");
>                         }};
>         }
> }
>
> $ ajc -showWeaveInfo C.java X.aj
> Join point 'method-call(void
> java.io.PrintStream.println(java.lang.String))' in Type 'C$1'
> (C.java:5) advised by before advice from 'X' (X.aj:3)
>
> Andy.
>
>
> On 26/10/2007, Hendrik Gani <s2116865@xxxxxxxxxxxxxxxxxxx> wrote:
> > Hi,
> >
> > Does anyone know how we can weave an anonymous inner class in aspectj
> > (if it is possible at all)?
> >
> > Is it possible to tell aspectj to weave all the methods of a class
> > including those that belong to its inner classes?
> >
> > Thanks heaps,
> >
> > Hendrik
> >
> >
> >
> > _______________________________________________
> > 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
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top