Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] ITD syntax

Ramnivas,

I actually like the idea of using a "declare" statement to define where the ITD applies a lot. One of the benefits I see is the ability to selectively define which classes that implement an interface receive the default code. Using annotations to define if the default implementation is inherited, or even to define which of several default implementations is used, could be much simpler and more readable than the only way I can think of to do that now, which is to have multiple interfaces. For instance I could have a definition with a syntax similar to yours:

declare parents: !@NoInherit ITDInterface+ inherits ITDDefaultImpl;

and now I have a way to turn off default inheritance, or I could have the opposite and use an annotation to only turn it on at certain points. Or I might have more than one class implementing defaults.....

declare parents: !@FastImpl ITDInterface+ inherits ITDDefaultImpl;

declare parents: @FastImpl ITDInterface+ inherits ITDFastimpl;

It's concise, powerful, readable, it keeps the implementing code in plain java. I think that would be pretty cool.

On Dec 4, 2008, at 11:39 AM, Ramnivas Laddad wrote:

I like this proposal.

Here is an alternative syntax suggestion that
- addresses Dave's use case
- addresses a use case that is easy to implement in @AspectJ but not
in code style
- avoids new keywords

public aspect ITDAspect{

   /* don't have define the class here, don't need to make it private;
       but defining it that way matches Dave's example
  */
   private static class ITDDefaultImpl {
       private String string;

       public String getString(){
           return string;
       }

       public void setString(String string){
           this.string = string;
       }
   }

   /* declare that ITDInterface should be introduced with
       all fields and methods in ITDDefaultImpl
       Not sure about the choice of using "extends"
       (trying to avoid new keyword)
       Alternatives: declare implements? declare default?
   */
   declare extends: ITDInterface, ITDDefaultImpl;
}

This makes a common use case implemented by the following @AspectJ
snippet available in the code style syntax. Essentially, I get to
reuse the implementation available from an existing class.

@DeclareParents(value="com.myco.domain.*",
                            defaultImpl= ITDDefaultImpl.class)
ITDInterface something;

How does this sound?

-Ramnivas

On Wed, Dec 3, 2008 at 9:40 PM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
I could be wrong but I think I recall someone talking about something
like this a while ago - possibly Ramnivas.  Although having just
trawled through our enhancement requests, I only found this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=240011 which is about
saving typing but isn't quite the same thing.  What you propose is
interesting, what do others think?

cheers,
Andy.

2008/12/3 Dave Whittaker <dave@xxxxxxxxxx>

I've been wondering recently.... is there a reason that ITDs are defined the way they are? I don't know how others tend to use them, but for me I'm pretty likely to have an aspect that contains ITD fields and methods that apply to a single interface within a given aspect. This makes me wonder why we have a syntax like:

public aspect ITDAspect{

      private String ITDInterface.string;

      public String ITDInterface.getString(){
              return string;
      }

      public void ITDInterface.setString(String string){
              this.string = string;
      }

}

Instead of:

public aspect ITDAspect{

      intertype(ITDInterface){


              private String string;

              public String getString(){
                      return string;
              }

              public void setString(String string){
                      this.string = string;
              }

      }
}

Or something similar. Something that involved less typing, consolidated code that is defined for another type and looked more like plain java code (not to mention more like other AJ definitions in this case....). At the very least it would allow for something that I've wanted many times: cut and paste between classes and ITDs without having to post process with some sort of wacky regex. Am I missing a reason why it's desirable or even necessary to type out the full interface name on each line?
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

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



Back to the top