Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Question about @AspectJ and what it can do

I have been referring to those guides a lot so far :)

Also I believe I am very close to getting the desired behaviour I have been after. I don't think I need @AsepctJ at all.

pointcut testPC1() : @annotation(UndoableJTextField);

pointcut testPC2(String s, int c) : call(javax.swing.JTextField.new(String, int)) && args(s, c);

after(String s, int c) : testPC2(s, c) && testPC1()
{
	System.out.println("undoableJTextField");
}


TestPC1() will match the JComponents everywhere they are used if they have the correct annotation and testPC2() will match wherever I create a new JTextField with those arg types, but I cannot get an intersection of the two. The && does not give me any matches. I am having a hard time finding the right syntax to get that intersection, any suggestions?

________________________________________
From: aspectj-users-bounces@xxxxxxxxxxx [aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Ramnivas Laddad [ramnivas@xxxxxxxxxxxxxxx]
Sent: Thursday, July 01, 2010 11:43 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Question about @AspectJ and what it can do

You might want to read
http://www.eclipse.org/aspectj/doc/released/adk15notebook/index.html
and
http://www.eclipse.org/aspectj/doc/released/progguide/index.html

You might also want to pick a good book on AspectJ :-)

-Ramnivas

On Thu, Jul 1, 2010 at 7:09 AM, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx>> wrote:
The reason I would like to use @aspectj could be because of naiveness when it comes to AspectJ. The main goal I am pursuing is easy to show with some code.

@Undoable
JTextField tf = new JTextField();

@Undoable
JButton tf = new JButton();

I would like to have the aspect get a reference to the new object created and have a clear and compact marker for showing in my code which JComponents are undoable.

You mentioned that I could use a target pointcut, but I am looking at the docs and I still don't get how that one works yet. Would it accomplish what I need?
________________________________________
From: aspectj-users-bounces@xxxxxxxxxxx<mailto:aspectj-users-bounces@xxxxxxxxxxx> [aspectj-users-bounces@xxxxxxxxxxx<mailto:aspectj-users-bounces@xxxxxxxxxxx>] On Behalf Of Ramnivas Laddad [ramnivas@xxxxxxxxxxxxxxx<mailto:ramnivas@xxxxxxxxxxxxxxx>]
Sent: Wednesday, June 30, 2010 9:48 PM
To: aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx>
Subject: Re: [aspectj-users] Question about @AspectJ and what it can do

The code you shown can be mapped to @AspectJ just fine.

As for annotations, in Java (and thus in AspectJ) you cannot put annotations on a call site. Differentiating between JTextField and JButton is easy--all you need  is a target() pointcut.

BTW, is there a reason for pursuing the @AspectJ syntax? The traditional syntax is more powerful and there is nothing that you can do with @AspectJ that you cannot with traditional.

-Ramnivas

On Wed, Jun 30, 2010 at 5:21 PM, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx><mailto:Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx>>> wrote:
In traditional AspectJ I would do something like below. I didn't get one working, but it was something like this.

after(String s) : call(javax.swing.JTextField.new(s)) && args(s) && if(s.equals("textField1") //find out where the JTextfield with text "textField1" is instantiated, and run the code below
{
  //code here (is there a technical term to call the code block in here?)
  undoService.addCallback(new ActionListener()
  {
         public void actionPerformed(ActionEvent ae)
        {
         undoService.addEdit(new UndoableEditDocumentCustom(textField));
         }
  });
}

The point is to find the JTextField with a starting text of "textField1", which is not a good way to identify the JTextField I want, but this is just for proof of concept purposes. Once the correct JTextField is found, execute the code. With annotations, would it be simple to add this code for a specific JComponent? Can the annotation go right on top of the JComponent instantiation code? Can the annotation do some extra processing to know if the JComponent is a JTextField or JButton so I can call specific code for both? Sorry if I am not perfectly clear, I am still really green.
________________________________________
From: aspectj-users-bounces@xxxxxxxxxxx<mailto:aspectj-users-bounces@xxxxxxxxxxx><mailto:aspectj-users-bounces@xxxxxxxxxxx<mailto:aspectj-users-bounces@xxxxxxxxxxx>> [aspectj-users-bounces@xxxxxxxxxxx<mailto:aspectj-users-bounces@xxxxxxxxxxx><mailto:aspectj-users-bounces@xxxxxxxxxxx<mailto:aspectj-users-bounces@xxxxxxxxxxx>>] On Behalf Of Ramnivas Laddad [ramnivas@xxxxxxxxxxxxxxx<mailto:ramnivas@xxxxxxxxxxxxxxx><mailto:ramnivas@xxxxxxxxxxxxxxx<mailto:ramnivas@xxxxxxxxxxxxxxx>>]
Sent: Wednesday, June 30, 2010 5:30 PM
To: aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx><mailto:aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx>>
Subject: Re: [aspectj-users] Question about @AspectJ and what it can do

Can you show what you intent to do with the traditional syntax? That will help in showing if and how it can be mapped to @AspectJ.

-Ramnivas

On Wed, Jun 30, 2010 at 1:47 PM, Kashtan, Daniel <Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx><mailto:Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx>><mailto:Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx><mailto:Daniel.Kashtan@xxxxxxx<mailto:Daniel.Kashtan@xxxxxxx>>>> wrote:
Hey all,

I have AspectJ working real nice right now and I would like to see if @AspectJ can let me do those same things in a slicker fashion. I can illustrate want I am thinking about by showing my function:

undoService.addCallback(new ActionListener()
{
     public void actionPerformed(ActionEvent ae)
     {
     undoService.addEdit(new UndoableEditDocumentCustom(textField));
     }
});

Right now my actionPerformed is hard-wired to send my undoService that particular UndoableEdit for a JTextfield. I'd like to automate the process of adding these edits. Could I possibly add an annotation above my JComponents that would be able to call the code above based on the type of JComponent it is? I think I know how to do this in AspectJ, but I am having a hard time grasping how @AspectJ works, so any suggestions or pointers would be great :)

This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender.
Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx><mailto:aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx>><mailto:aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx><mailto:aspectj-users@xxxxxxxxxxx<mailto:aspectj-users@xxxxxxxxxxx>>>
https://dev.eclipse.org/mailman/listinfo/aspectj-users

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

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



Back to the top