Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Language feature: inner aspects

I'd like to see inner aspects much in the way Java allows inner classes.
The primary use that motivates this feature would be for inner-type
declarations. Specifically, I would like to write things like

  static int rand(int n, int m) {
    static Random MyClass.rgen = new Random();
    return n + Math.abs(rgen.nextInt()) % (m - n + 1);
  }

and

  void f() {
    boolean MyClass.flag = 0;   // only the f member-function uses the
                                // "flag" field; so say so explicitly
    ... compute using this new member
  }

in both cases, the members flag and rgen will be aspect private and
accessible only to the method that declares these inner inter-type
declarations. For more generality and better locality these declarations
can even have tighter scoping so that perhaps only one branch in a method
will have access to the member. You can imagine initialization semantics
similar to C for this feature.

I think allowing inner inter-type declarations will improve locality and
lend for higher control over what objects/methods can access what. Inner
pointcuts and advice could be useful, though the only example I could
think of where that would really come in handy would be when the advice
should only be active when in the cflow of the scope that contains the
advice. (An implicit && cflow in other words, plus the locality advantages
mentioned before.)

I would not imagine the implementation of these features would be tricky
except for changing the grammar and producing $1 classes much as the Java
complier does for anonymous inner-classes. Having less syntactic heavyness
might also help coding on the fly and introducing examples in tutorials,
and only when things start to become less clear would you "put these into
a separate aspect," just as we do with subroutining.

Thanks,
Macneil


Back to the top