Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Newbie questing: how to weave in static methods with a certain return type

Hi Roger,

I've been trying to come up with something, but I don't think i can
get the syntax to do it.

If we could ITD onto type variables, there is possibly an option:

class MyAspect<T extends SuperClass> {}

  static T T.byId(BigDecimcal id) {
    return SuperClass.byId(T.class,id);
  }
}

class MyClass1Aspect extends MyAspect<MyClass1> {}
class MyClass2Aspect extends MyAspect<MyClass2> {}

but that isn't possible right now.  If they weren't static methods you
could do something like this today:

aspect MyAspect2<T> {
  interface I {}
  T I.byId(BigDecimal id) {
    return SuperClass.byId(T.class,id);
  }
  declare parents: T implements I;
}

class MyClass1Aspect extends MyAspect2<MyClass1> {}
class MyClass2Aspect extends MyAspect2<MyClass2> {}

but they are static, so that isn't allowed...

cheers,
Andy

2010/1/28 Roger Gilliar <roger@xxxxxxxxxx>:
> Hi !
> IIs it possible to extract the static definitions in MyClass1 and MyClass2
> into an aspect ?  I know how I can weave in the implementation of an
> interface, but in this case I would need to weave in the return type to. Is
> this even possible ?
> abstract class SuperClass (
> protected static <T> T byId(final Class<T> classType, final BigDecimal id) {
> ..... do something and return new object of type T
> }
> }
>
> class MyClass1 extends SuperClass {
> static MyClass1 byId(BigDecimal id) {
> SuperClass.byId(MyClass1.class, id);
> }
> }
> class MyClass2 extends SuperClass {
> static MyClass2 byId(BigDecimal id) {
> SuperClass.byId(MyClass2.class, id);
> }
>
> }
> Regards
>   Roger
>
>
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top