Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] A few questions from a new user

> 1. How can I get the new value after an array field is read? In the 

There is no join point for array-element-[read|write], sorry.

> 2. I am having trouble in obtaining the caller's class if a 
> method call is made within the caller's static method.

This is a function of reflection.  Your approach is the best available.
But you can narrow the pointcut to specific static method or type:

  withincode(static void m()) && call(void run())

> 3. How can I catch the program termination event? 

Program termination differs for different programs, so you'll have to
define that first, and then write the aspect for it.  Also, don't 
forget Java has a shutdown hook.  

Wes

------------Original Message------------
From: Sunny <sunfire001@xxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Mon, Mar-20-2006 11:14 AM
Subject: [aspectj-users] A few questions from a new user
Dear All,
I am sorry if this is not the right place to ask such questions. I just adopted AspectJ to implement a project. I got a few problems and hope to get some help.
1. How can I get the new value after an array field is read? In the following class A for example, I would like to know 
what changes have been made to the array contents after each array access. It seems that the array access happens BEFORE 
the new value is assigned, so I can only get the old contents each time the field get event occurs. 

public class A
{
 Object[] objArr = new Object[10];
 
  public void call1()
 {
   objArr[0] = new String("1");
   objArr[1] = new String("2");
   objArr[2] = new String("3");  
 }
}

2. I am having trouble in obtaining the caller's class if a method call is made within the caller's static method. For example:
public class A
{
 public static void call1()
 {
  B.changeField();
 }
}
public class B {
 public static void changeField()
 {
  System.out.println("from B");
 } 
}
How can I know the caller is class A? I tried the following pointcut: 
pointcut staticMethodCall() : call(static * *.*(..));
after() : staticMethodCall()
{
 Class calleeClass = thisJoinPoint.getSignature().getDeclaringType();
        Object caller = thisJoinPoint.getThis();
 if (caller == null)
  caller = thisJoinPoint.getSourceLocation().getWithinType();
}
Here I used thisJoinPoint.getSourceLocation().getWithinType(); But what if I test a program where no source code is available? Can I still call thisJoinPoint.getSourceLocation()? 
3. How can I catch the program termination event? For a program containing a main() method, I could possibly solve this by monitoring this method using the call designator and after returning advice. But let's again suppose we have a program in binary form (like jar file), I may not know which method is the entry/termination point. So how can I get notification upon the termination of the program? 
I appreciate any advice and code snippet!
Thank you,
SunnyDay

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



Back to the top