[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] help on pointcuts weaving

 
My java class lies in the default package and looks like this,
 
public class testSockets {

 /**
  * @param args
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {

  String ip = null;
  InetAddress result = null;
  InetAddress testAddress = null;
  InetAddress addr = InetAddress.getByName("www.google" + ".com");
  Socket s = new Socket(addr, 80);
  result = s.getInetAddress().getLocalHost();
  System.out.println("value of ip ::" + result);
  ip = result.getHostAddress();
  System.out.println("value of ip ::" + ip);

 }

}

 

The pointcuts and advice  I used to weave in the aspects are,

pointcut name2():
  call(public * Socket.getInetAddress.getLocalHost(..)) || withincode(public * testSockets.*(..));

 before() : name2() {
  System.out.println("able to weavee");
 }

The aspects are getting weaved in now.

The decompiled class file[testSockets .class] looks like this

import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;

public class testSockets
{

    public testSockets()
    {
    }

    public static void main(String args[])
        throws Exception
    {
        String ip = null;
        InetAddress result = null;
        InetAddress testAddress = null;
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        InetAddress addr = InetAddress.getByName("www.google.com");
        byte byte0 = 80;
        InetAddress inetaddress = addr;
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        Socket s = new Socket(inetaddress, byte0);
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        s.getInetAddress();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        result = InetAddress.getLocalHost();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        String s1 = "value of ip ::";
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        System.out.println(s1 + result);
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        ip = result.getHostAddress();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        String s2 = "value of ip ::";
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        TestAspect.aspectOf().ajc$before$TestAspect$1$66a23648();
        System.out.println(s2 + ip);
    }
}

I would like to know why the advice is getting weaved in at so many places,when the Socket.getInetAdress.getLocalHost() is called only once.

 

Neeraja.