|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Help with defining a point cutHi 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 cutOn 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 cutThanks 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:
_______________________________________________ aspectj-users mailing list aspectj-users@... https://dev.eclipse.org/mailman/listinfo/aspectj-users |
|
|
Re: Help with defining a point cutOn 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 cutThanks 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:
_______________________________________________ aspectj-users mailing list aspectj-users@... https://dev.eclipse.org/mailman/listinfo/aspectj-users |
|
|
|
|
|
Re: Help with defining a point cutOn 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 cutThanks,
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:
_______________________________________________ aspectj-users mailing list aspectj-users@... https://dev.eclipse.org/mailman/listinfo/aspectj-users |
|
|
Re: Help with defining a point cutIt worked !!! Thanks a lot !!!
On Mon, Apr 27, 2009 at 10:57 AM, Elad Sofer <elad.sofer@...> wrote:
_______________________________________________ aspectj-users mailing list aspectj-users@... https://dev.eclipse.org/mailman/listinfo/aspectj-users |
| Free embeddable forum powered by Nabble | Forum Help |