Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Fw: aspectj capturing currently executing object

Unfortunately the source code line is not captured in the joinpoint object, nor is the entire source encoded in the class file so that the relevant snippet could be extracted at runtime. You'd have to read the relevant source file and pull out the text you need.

cheers,
Andy


On 2 July 2013 06:28, Krishna Jasty <krishna.jasty@xxxxxxx> wrote:
Hi,
 
Is there a way in aspect to read the source line as it is.
Say for example. My Java class code
 
  public static void main(String[] args)throws IOException,SQLException
{
     Vector testvector = new Vector();
      testvector.add("abc");
 }
 
I want to read the source line Vector testvector= new Vector();
When i use
SourceLocation sl =thisJoinPointStaticPart
.getSourceLocation();
 
Which is giving me the file details and line number details but not the source line read ..
 
Thanks,
 



-----Forwarded by Krishna Jasty/BLR/TCS on 07/02/2013 06:40PM -----
To: aspectj-users@xxxxxxxxxxx
From: Krishna Jasty/BLR/TCS
Date: 06/27/2013 03:41PM
Subject: aspectj capturing currently executing object


Hi Users,

Go through the following steps once.
 
1) My Java class code
 
  public static void main(String[] args)throws IOException,SQLException
{
     Vector testvector = new Vector();
      testvector.add("abc");
   }
 
 
2) Aspect Implementation
 
 pointcut allConstructors() : call( * java.util..add(..));
 Object around() : allConstructors() {
 Object[] objarr = thisJoinPoint.getArgs();
 for (int i = 0; i < objarr.length; i++)
{
  System.out.println("object is..."+objarr[i]);//This will give me tha value "abc"
 }
 
Similarly if i want to get the object testvector and i want to perform the testvector.size() operation on it.
How to capture this testvector object, if i use this or getTarget() which is returning null.
Please suggest the way to make it possible.
 
Thanks,
Krishnachaitanya Jasty

=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top