In AspectJ classes, interfaces and aspects may be nested inside each other. In terms of nested lexical scope, a new scope is entered each time the keywords class, interface and aspect are entered, and the scope is exited at the closing right brace. In the case of class and interface the scope entered has JAVA mode, whereas for the case of aspect the scope entered has ASPECT mode.
At the bottom of Figure 1 we give the declaration of a nested class called NestedClass. Note that inside the class declaration is in JAVA mode, so the keywords recognized are those corresponding to JAVA mode (i.e. Java keywords plus aspect, privileged and pointcut). Thus, in the example, before and after are considered identifiers, not keywords. Note that this use of inner classes provides a mechanism for referring to variables defined in other classes that may have the same name as keywords in ASPECT mode. In our example we have defined the method getBefore to read the value of OtherClass.before.
The above rule for entering a new lexical scope upon encounter of the keyword class is complicated by the fact that class does not always signal a new class declaration in Java. In particular, it can be used to return a Class object that represents a type, as in C.class (this is useful, for example, to create typed lists, where the intended element type is stored with the list structure). All such uses of the class keyword are preceded by a dot, and class declarations themselves are never preceded by a dot. For that reason, the lexer records whether the last emitted token was a dot; if it is, then the class keyword does not cause a transition to a new lexical scope.