Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] private calls and within inner classes



Bruno,

You might like to use "declare warning ..." and/or -showWeaveInfo to
determine whether a problem lies in AspectJ or AJDT/Visualiser.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/

Bruno Harbulot <bruno.harbulot@xxxxxxxxxxxx>@eclipse.org on 04/03/2005
17:48:29

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-admin@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    [aspectj-users] private calls and within inner classes


Hello,


I'm trying to intercept calls to private methods (Test.InnerA.runPrivate
and Test.runPrivate) from within a method belonging to an inner class
(Test.InnerB.InnerInnerB). The example is a bit complicated, but
corresponds to some java code which is not mine and that I would like to
advise.

It seems that "withincode" (matching within the code of
Test.InnerB.InnerInnerB.run())  does not match calls to these private
methods. It would have worked with ajc 1.0.6.
Also, surprisingly, it works with the equivalent public method, but the
AJDT visualiser shows indicators (on Test.runPrivate and
Test.runPrivateStatic) as if they were "execution" and not "call"
pointcuts.
I've read the AspectJ 1.1 readme, but the changes to "call" and the
limitations of "withincode" don't seem to explain the problems with this
particular example.

Is there any way I could advise calls to InnerA.runPrivate(..) made from
within InnerB.InnerInnerB.run() (and get hold of the instance of
InnerInnerB)?


Thanks,

Bruno.







Here is the test code:


public class Test {
             public static class InnerA {
                         private static void runPrivate(int a) {
                                     System.out.println("InnerA private:
"+a) ;
                         }
                         public static void runPublic(int a) {
                                     System.out.println("InnerA public:
"+a) ;
                         }
             }

             private static void runPrivateStatic(int a) {
                         System.out.println("runPrivateStatic: "+a) ;
             }

             public static void runPublicStatic(int a) {
                         System.out.println("runPublicStatic: "+a) ;
             }

             private void runPrivate(int a) {
                         System.out.println("runPrivate: "+a) ;
             }

             public static class InnerB {
                         InnerInnerB innerinnerb = new InnerInnerB() ;
                         public class InnerInnerB {

                                     public void run() {
                                                 InnerA.runPrivate(1) ;
                                                 InnerA.runPublic(1) ;
                                                 runPrivateStatic(1) ;
                                                 runPublicStatic(1) ;
                                                 Test t = new Test() ;
                                                 t.runPrivate(1) ;
                                     }
                         }

                         public void run() {
                                     innerinnerb.run() ;
                         }
             }

             public void run() {
                         InnerA.runPrivate(2) ;
                         InnerA.runPublic(2) ;
                         runPrivateStatic(2) ;
                         runPublicStatic(2) ;
                         runPrivate(2) ;
             }

             public static void main(String[] args) {
                         InnerB innerb = new InnerB() ;
                         innerb.run() ;
                         Test t = new Test() ;
                         t.run() ;
             }
}



privileged aspect TestAspect {
             /* Does not match anything with ajc 1.1, but matches with ajc
1.0 */
             void around(Test.InnerB.InnerInnerB iib, int a): call(private
void
Test.InnerA.runPrivate(..)) && args(a) && this(iib) && withincode(*
Test.InnerB.InnerInnerB.run()){
                         proceed(iib, a + 10);
             }

             /* Does not match anything with ajc 1.1, but matches with ajc
1.0 */
             void around(Test.InnerB.InnerInnerB iib, int a): call(void
Test.InnerA.runPrivate(..)) && args(a) && this(iib) && withincode(*
Test.InnerB.InnerInnerB.run()){
                         proceed(iib, a + 20);
             }

             /* Matches */
             void around(Test.InnerB.InnerInnerB iib, int a): call(void
Test.InnerA.runPublic(..)) && args(a) && this(iib) && withincode(*
Test.InnerB.InnerInnerB.run()){
                         proceed(iib, a + 40);
             }

             /* Does not match anything with ajc 1.1, but matches with ajc
1.0 */
             void around(int a): call(private void
Test.runPrivateStatic(..)) &&
args(a) && withincode(* Test.InnerB.InnerInnerB.run()){
                         proceed(a + 100);
             }

             /* Matches */
             void around(int a): call(void Test.runPublicStatic(..)) &&
args(a) &&
withincode(* Test.InnerB.InnerInnerB.run()){
                         proceed(a + 200);
             }

             /* Does not match anything with ajc 1.1, but matches with ajc
1.0 */
             void around(int a): call(void Test.runPrivate(..)) && args(a)
&&
withincode(* Test.InnerB.InnerInnerB.run()){
                         proceed(a + 400);
             }

             /* Matches */
             void around(int a): call(private void
Test.runPrivateStatic(..)) &&
args(a){
                         proceed(a + 1000);
             }

             /* Matches */
             void around(int a): call(void Test.runPublicStatic(..)) &&
args(a) {
                         proceed(a + 2000);
             }

             /* Matches */
             void around(int a): call(void Test.runPrivate(..)) && args(a)
{
                         proceed(a + 4000);
             }
}






Here are the results with ajc 1.1 and a recent AJDT:

InnerA private: 1
InnerA public: 41
runPrivateStatic: 1001
runPublicStatic: 2201
runPrivate: 4001
InnerA private: 2
InnerA public: 2
runPrivateStatic: 1002
runPublicStatic: 2002
runPrivate: 4002





Here are the results with ajc 1.0.6:

InnerA private: 31
InnerA public: 41
runPrivateStatic: 1101
runPublicStatic: 2201
runPrivate: 4401
InnerA private: 2
InnerA public: 2
runPrivateStatic: 1002
runPublicStatic: 2002
runPrivate: 4002


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




Back to the top