Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] About join points for local variables.

Hey Ron,

Thanks a lot!

Firstly, let me make sure I understand your solution to object reference via parameters.

So by using the before advice:

before(): execution(* A.m1(B))

I can know the control is just entering the called method m1, and in the object graph I should add an edge from the callee (target object of type A) to the argument just passed in (which is an instance of type B).

Then by using the after advice:

after():  execution(* A.m1(B))

The edge added previously should be deleted since the parameter is out of its scope. Is this correct?


Secondly, for local variables: how could I update the object graph in the following cases?

class A
{
 public void m1()
 {
  // do something ...
  
  B b = new B();
  // b may be passed to other objects
  // some uses of b
  
  C c = b.getC();
  
  // some uses of c
 }
}

Here at the call site B b = new B(); I can add an edge from the creating object (of type A) to the created object (of type B). Since we are not able to trap local variable assignment, how would I delete this edge if b is assigned another value ( e.g. null), or if this method exits? Call site C c = b.getC(); is another case where I should add an edge from the enclosing object to the returned object. The same deletion problem exists.

Please feel free to point out any misunderstandings and thank you very much for your time!

Sunny



On 4/6/06, Ron DiFrango <rdifrango@xxxxxxxxxxxxxxxxxxx> wrote:
Sunny,

If a local variable is an object, you could trap the creation of the object via something like:

call(*.new(..))

The you could use standard reflection to see which object you are in.

For parameters into methods you, can use generic around advice:

aspect Logging {
    before(): within(com.bigboxco..* ) && execution(public * *(..)) {
        System.err.println("entering: " + thisJoinPoint);
        System.err.println("  w/args: " + thisJoinPoint.getArgs());
        System.err.println ("      at: " + thisJoinPoint.getSourceLocation());
    }
}

See the JavaDoc for the runtime API:

http://www.eclipse.org/aspectj/doc/released/runtime-api/index.html

Ron

________________________________

From: aspectj-users-bounces@xxxxxxxxxxx on behalf of Sunny
Sent: Thu 4/6/2006 1:10 PM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] About join points for local variables.


Dear Folks,

After reading the AspectJ FAQ No. 21: "Why can't AspectJ pick out local variables (or array elements or ...)?"

I have the following question:

What I would like to do is to dynamically maintain an object graph (directed), where nodes represent runtime objects and directed edges denote reference relationships between objects. Apparently an object can refer to other objects not only through its fields, but also through its local variables or parameters. Without join point for local/parameters, how would I accurately obtain the current system state info (in terms of relationships between objects)?

Is there any other way that I can achieve the same goal? I appreciate your help!

Sunny

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




Back to the top