Skip to main content

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



Macneil,

I assume the reason for this discussion is the desire to create fields
whose visibility is restricted to the methods that need them. This can be
done today as inner aspects are supported however you must use an
inter-type declaration to add the method as well as the field it is
accessing. Moving to a code branch level is not possible as no such join
point is supported by AspectJ.

import java.util.Random;

public class MyClass {

      private static aspect InnerAspect1 {

            private static Random MyClass.rgen = new Random();

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

      private static aspect InnerAspect2 {

            private boolean MyClass.flag = false;   // only the f
member-function uses the

            void MyClass.f() {
                  if (flag) {
                  }
            }
      }

      public static void main (String[] args) {
            rand(1,2);
            new MyClass().f();
      }
}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



Back to the top