[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] help on pointcuts weaving
|
First, I dont understand why you call getLocalHost() this way. It's a static method.
You can(should) call it as InetAddress.getLocalHost().
Second, for your example,
pointcut name2():
call (public * java.net.InetAddress.getLocalHost())
&&
withincode(public * testSockets.*(..));
Last, if you want to capture the call chain like o.foo().bar(), you probably need TraceMatch in abc http://abc.comlab.ox.ac.uk.
--
Dehua 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 Neeraja Maniyani
Sent: Thu 6/26/2008 05:06
To: aspectj-users@xxxxxxxxxxx
Subject: [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.