Help with defining a point cut

View: New views
9 Messages — Rating Filter:   Alert me  

Help with defining a point cut

by elad sofer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

First i apologize if this kind of question have been asked in the past, if it was i could not find it.

I am a newbie to AspectJ and the problem we are trying to solve is this:
There is a legacy code that we want to be able to connect to an automatic testing application (ROBOT).

This framework requires (recommended at least) that every swing component has the name attibute set.
I am looking for a way to do this with an aspect, that will "catch" the swing object at some phase and call the setName method.

It is also important that the name pattern should match (<Type>_<MemberName>) to allow to easily write tests which means i need to be able to get the member and it's parent.

I have been trying for several days now and came up with nothing too bright - whatever i tried had a flaw.

Any assistance would be appreciated.
Elad.

Re: Help with defining a point cut

by Jochen Wuttke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Apr 26, 2009, at 6:55 PM, elad sofer wrote:

>
> Hi all,
>
> First i apologize if this kind of question have been asked in the  
> past, if
> it was i could not find it.
>
> I am a newbie to AspectJ and the problem we are trying to solve is  
> this:
> There is a legacy code that we want to be able to connect to an  
> automatic
> testing application (ROBOT).
>
> This framework requires (recommended at least) that every swing  
> component
> has the name attibute set.
> I am looking for a way to do this with an aspect, that will "catch"  
> the
> swing object at some phase and call the setName method.

Catching the object at some phase, I'd recommend the constructor. So  
something like:

after (Component c) returning:  
execution( javax.swing.Component.new(..)) && this(c) {
        c.setName( <put your desired name here> );
}

Not sure if this() works with constructors, but something like that  
should do the trick.
How to generate the name passed to setName() is up to you, since I  
don't quite understand your requirements there.

Jochen


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

Re: Help with defining a point cut

by elad sofer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the reply,

The thing is that a join point after the Ctor is not suffiecient since i need to have the following name pattern <Type>_<MemberName>, this means that if i have a JLabel within class A and it is initialized in the declerative part i do not have access to the instance of A that holds the JLabel, and this is needed to be able to match the member name using reflection (or is it not ?).

I have tried catching the setVisible but apperantly it is not always called.

Any more advice will be great.

Elad.

On Sun, Apr 26, 2009 at 8:48 PM, Jochen Wuttke <jochen.wuttke@...> wrote:

On Apr 26, 2009, at 6:55 PM, elad sofer wrote:


Hi all,

First i apologize if this kind of question have been asked in the past, if
it was i could not find it.

I am a newbie to AspectJ and the problem we are trying to solve is this:
There is a legacy code that we want to be able to connect to an automatic
testing application (ROBOT).

This framework requires (recommended at least) that every swing component
has the name attibute set.
I am looking for a way to do this with an aspect, that will "catch" the
swing object at some phase and call the setName method.

Catching the object at some phase, I'd recommend the constructor. So something like:

after (Component c) returning: execution( javax.swing.Component.new(..)) && this(c) {
       c.setName( <put your desired name here> );
}

Not sure if this() works with constructors, but something like that should do the trick.
How to generate the name passed to setName() is up to you, since I don't quite understand your requirements there.

Jochen



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


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

Re: Help with defining a point cut

by Jochen Wuttke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Apr 27, 2009, at 7:08 AM, Elad Sofer wrote:

> Thanks for the reply,
>
> The thing is that a join point after the Ctor is not suffiecient  
> since i need to have the following name pattern <Type>_<MemberName>,  
> this means that if i have a JLabel within class A and it is  
> initialized in the declerative part i do not have access to the  
> instance of A that holds the JLabel, and this is needed to be able  
> to match the member name using reflection (or is it not ?).

I'm still not sure what you mean when you say <Type>_<MemberName>. Is  
it something like this;

class A {

        private JLabel myPrivateLabel;

        A() {

                myPrivateLabel = new JLabel();
        }

        //methods

}

If it is, then I assume you want to set the name in the JLabel to  
"A_myPrivateLabel"?
If that's the case you can change the "execution" join-point to  
"call", that at least gives you access to the current instance of "A".  
Catching the member name requires an additional bit of advice at every  
field assignment where you can check the type and remember the name if  
necessary.

If all this is not what you meant, I think you should give a code  
example.

Jochen

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

Re: Help with defining a point cut

by elad sofer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks again,

What i mean by my pattern (refering to your code example), is that i need to set the name of myPrivateLabel to "JLabel_myPrivateLabel". I was not able to do that since our code sometimes looks like this:

class A {

       private JLabel myPrivateLabel = new JLabel();
       private JLabel anotherPrivateLabel;

       A() {
               anotherPrivateLabel = new JLabel();
       }
       //methods
}

I need to be able to handle both cases and dont really understand how.

BTW - i am using annotations to define my aspects.

Thanks for you patience.
Elad.



On Mon, Apr 27, 2009 at 9:57 AM, Jochen Wuttke <jochen.wuttke@...> wrote:

On Apr 27, 2009, at 7:08 AM, Elad Sofer wrote:

Thanks for the reply,

The thing is that a join point after the Ctor is not suffiecient since i need to have the following name pattern <Type>_<MemberName>, this means that if i have a JLabel within class A and it is initialized in the declerative part i do not have access to the instance of A that holds the JLabel, and this is needed to be able to match the member name using reflection (or is it not ?).

I'm still not sure what you mean when you say <Type>_<MemberName>. Is it something like this;

class A {

       private JLabel myPrivateLabel;

       A() {

               myPrivateLabel = new JLabel();
       }

       //methods

}

If it is, then I assume you want to set the name in the JLabel to "A_myPrivateLabel"?
If that's the case you can change the "execution" join-point to "call", that at least gives you access to the current instance of "A". Catching the member name requires an additional bit of advice at every field assignment where you can check the type and remember the name if necessary.

If all this is not what you meant, I think you should give a code example.


Jochen

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


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

Parent Message unknown RE: Help with defining a point cut

by Victor Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You could do this via reflection, your test method needs
to iterate through the fields on the object under test
and if they are of a relevant type set it's name (and
possibly go through it's members if it's a container?)


-----Original Message-----
From: aspectj-users-bounces@...
[mailto:aspectj-users-bounces@...] On Behalf Of Elad Sofer
Sent: 27 April 2009 08:19
To: aspectj-users@...
Subject: Re: [aspectj-users] Help with defining a point cut


Thanks again,

What i mean by my pattern (refering to your code example), is that i
need to set the name of myPrivateLabel to "JLabel_myPrivateLabel". I was
not able to do that since our code sometimes looks like this:

class A {

       private JLabel myPrivateLabel = new JLabel();
       private JLabel anotherPrivateLabel;

       A() {
               anotherPrivateLabel = new JLabel();
       }
       //methods
}

I need to be able to handle both cases and dont really understand how.

BTW - i am using annotations to define my aspects.

Thanks for you patience.
Elad.




On Mon, Apr 27, 2009 at 9:57 AM, Jochen Wuttke <jochen.wuttke@...>
wrote:


On Apr 27, 2009, at 7:08 AM, Elad Sofer wrote:


Thanks for the reply,

The thing is that a join point after the Ctor is not suffiecient since i
need to have the following name pattern <Type>_<MemberName>, this means
that if i have a JLabel within class A and it is initialized in the
declerative part i do not have access to the instance of A that holds
the JLabel, and this is needed to be able to match the member name using
reflection (or is it not ?).



I'm still not sure what you mean when you say <Type>_<MemberName>. Is it
something like this;

class A {

       private JLabel myPrivateLabel;

       A() {

               myPrivateLabel = new JLabel();
       }

       //methods

}

If it is, then I assume you want to set the name in the JLabel to
"A_myPrivateLabel"?
If that's the case you can change the "execution" join-point to "call",
that at least gives you access to the current instance of "A". Catching
the member name requires an additional bit of advice at every field
assignment where you can check the type and remember the name if
necessary.

If all this is not what you meant, I think you should give a code
example.


Jochen

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




______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


This e-mail and any attachments are for the intended addressee(s) only
and may contain confidential and/or privileged material. If you are not a
named addressee, do not use, retain or disclose such information.
This email is not guaranteed to be free from viruses and does not bind
Serco in any contract or obligation.
Serco Limited. Registered in England and Wales. No: 242246
Registered Office: Serco House,16 Bartley Wood Business Park, Hook,
Hampshire RG27 9UY United Kingdom.

Help cut carbon...please don’t print this e-mail unless you really need to.
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: Help with defining a point cut

by Jochen Wuttke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Apr 27, 2009, at 9:19 AM, Elad Sofer wrote:

> Thanks again,
>
> What i mean by my pattern (refering to your code example), is that i  
> need to set the name of myPrivateLabel to "JLabel_myPrivateLabel". I  
> was not able to do that since our code sometimes looks like this:
>
> class A {
>
>        private JLabel myPrivateLabel = new JLabel();
>        private JLabel anotherPrivateLabel;
>
>        A() {
>                anotherPrivateLabel = new JLabel();
>        }
>        //methods
> }
>
> I need to be able to handle both cases and dont really understand how.

OK, I think I see the problem now. Try what I suggested before:

- use the set() join-point to capture all assignments to type  
javax.swing.Component (or whatever it is you are interested in)
- grab the name of the assigned field from the locally available info  
(dunno how, but should be straightforward with something like target()  
or thisJoinPoint())
- use reflection to read out the rest of the info you need to build  
the name
- call setName() (by reflection)

Jochen

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

Re: Help with defining a point cut

by elad sofer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks,

I will try this one, it sounds good. :)
Will let you know if it worked.

Elad.


On Mon, Apr 27, 2009 at 10:54 AM, Jochen Wuttke <jochen.wuttke@...> wrote:

On Apr 27, 2009, at 9:19 AM, Elad Sofer wrote:

Thanks again,

What i mean by my pattern (refering to your code example), is that i need to set the name of myPrivateLabel to "JLabel_myPrivateLabel". I was not able to do that since our code sometimes looks like this:

class A {

      private JLabel myPrivateLabel = new JLabel();
      private JLabel anotherPrivateLabel;

      A() {
              anotherPrivateLabel = new JLabel();
      }
      //methods
}

I need to be able to handle both cases and dont really understand how.

OK, I think I see the problem now. Try what I suggested before:

- use the set() join-point to capture all assignments to type javax.swing.Component (or whatever it is you are interested in)
- grab the name of the assigned field from the locally available info (dunno how, but should be straightforward with something like target() or thisJoinPoint())
- use reflection to read out the rest of the info you need to build the name
- call setName() (by reflection)


Jochen

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


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

Re: Help with defining a point cut

by elad sofer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It worked !!! Thanks a lot !!!

On Mon, Apr 27, 2009 at 10:57 AM, Elad Sofer <elad.sofer@...> wrote:
Thanks,

I will try this one, it sounds good. :)
Will let you know if it worked.

Elad.



On Mon, Apr 27, 2009 at 10:54 AM, Jochen Wuttke <jochen.wuttke@...> wrote:

On Apr 27, 2009, at 9:19 AM, Elad Sofer wrote:

Thanks again,

What i mean by my pattern (refering to your code example), is that i need to set the name of myPrivateLabel to "JLabel_myPrivateLabel". I was not able to do that since our code sometimes looks like this:

class A {

      private JLabel myPrivateLabel = new JLabel();
      private JLabel anotherPrivateLabel;

      A() {
              anotherPrivateLabel = new JLabel();
      }
      //methods
}

I need to be able to handle both cases and dont really understand how.

OK, I think I see the problem now. Try what I suggested before:

- use the set() join-point to capture all assignments to type javax.swing.Component (or whatever it is you are interested in)
- grab the name of the assigned field from the locally available info (dunno how, but should be straightforward with something like target() or thisJoinPoint())
- use reflection to read out the rest of the info you need to build the name
- call setName() (by reflection)


Jochen

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



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