Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] cflow joinpoint confusion


Hi,

I had found a workaround this issue earlier, but once again with some new refactorings I am getting into trouble using both withincode, call, target and args together in an advice. From my understanding of AspectJ I should get what I expect but unfortunately nothing is being captured. Here is the problem:

 

I have a class Database with method close as follows:

 

public class Database {

 

  void close(int closemode) throws HsqlException {

        HsqlException he = null;

        setState(DATABASE_CLOSING);
        sessionManager.closeAllSessions();
        sessionManager.clearAll();

//some code to refactor
....//more code in close

}

 

}

 

I want to refactor code in the Database.close method that occurs after sessionManager.clearAll( ) code. So, I create pointcuts as follows:

 

pointcut thisDB(Database d): this(d);

pointcut clearAllcall() : call(void SessionManager.clearAll());

pointcut inClose(int closemode): args(closemode) && withincode(void close(int ));

 

and then have the following advice:

 

 after(Database d, int closemode): thisDB(d) && inClose(closemode) && clearAllcall() {
        d.logger.closeLog(closemode);
    }

 

 I would hope that it would crosscut after the clearAll() call in close method, but it does not crosscut anywhere. Can someone please tell me what am I doing wrong?

 

Thanks a lot.

Sincerely,

Irum Godil.


pope <alexandru.popescu@xxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[quote Irum Godil::on 1/30/2005 11:41 PM]
| Hi,
|
| I have the following code structure:
|
| public class Test {
| public static int callx() {
| return Test2.returnInt();
| }
|
| public static int callAgain() {
| returnTest2.returnInt();
| }
| }
|
|
| public class Test2 {
| public static int returnInt() {
| return 2;
| }
| }
|
| I would like to capture the call to Test2.returnInt() from the function Test.callx() For that I
wrote the following pointcuts and advice:
|
|
| pointcut exec() : withincode(public static int callx());
| pointcut callx() : call(public static int returnInt());
|
| int around() : cflow(exec()) && callx() {
| System.out.println("Passed around it");
| return -1;
| }
|
| Since I am doing cflow(exec()) && callx() I would assume that only one call to "returnInt()" i.e.
the one inside function "callx()" would be captured. But AspectJ captures both the calls to
"returnInt( ) " i.e the one in "callx( )" and in "callAgain( )".
|
| Can someone please tell me what am I doing wrong and how can I capture only one pointcut i.e. the
one inside of callx( ).
|
| Thanks a lot in advance for all your help.
|
| Irum Godil.
|
|
|
| ---------------------------------
| Do you Yahoo!?
| Yahoo! Mail - You care about security. So do we.

A simple solution would be to use withincode(public static int callx()) && call(public static int
returnInt()).


- --
:pope
[the_mindstorm]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFB/VexTTDTje0R2dgRAjsQAJ40luTTJvlji50x4G0gWV2cAjlz+wCfZk9f
Rs4TrBFFNNG/plz3BmXiYmA=
=sI+4
-----END PGP SIGNATURE-----
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!

Back to the top