Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Adding getter/setter using AspectJ

Hi Setya,

Well, you can write ITDs but those ITDs aren't parameterizable.

class DomainClass {
  int someProperty;
}

aspect Injector {
  public int DomainClass.getSomeProperty() {
    return someProperty;
  }
  public void DomainClass.setSomeProperty(int someProperty) {
    this.someProperty = someProperty;
  }
}

You can't write a more general definition that says 'for a field that
looks like that, create a method that looks like this'.

Spring Roo uses the ITD mechanism above, it generates the aspects for
many kinds of thing (getters/setters/toString/hashcode/equals/etc) and
then looks after keeping them up to date for you, you don't have to
maintain them yourself, you just work on the domain classes.

It wouldn't be all that difficult to extend AspectJ and define an
annotation that then triggered AspectJ to create accessors
(getters/setters) for any field that has that annotation, I just
haven't had that many users express an interest in AspectJ supporting
it.

cheers
Andy

On 6 July 2011 09:56, Setya <jsetya@xxxxxxxxx> wrote:
> Hi all,
>
> Is it possible to add getter/setter using AspectJ, pretty much like project
> Lombok ?
>
> Thanks & Regards,
>
> Setya
>
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/Adding-getter-setter-using-AspectJ-tp3649371p3649371.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top