Fall 2002 Programming Language Seminar:
Aspect-Oriented Programming with AspectJ

Back to main course page

[ Washington University in St Louis ]
Department of Computer Science

Course Notes: 11 September 2002

Code examples from today's lecture:


Brief review of last time

Types of join points:

  1. execution(constructor)
    This type of join point corresponds to the execution of a constructor.
  2. execution(method)
    The execution of a method.
  3. call(constructor) A call to a constructor (e.g., new Foo())
    This type of join point corresponds to calling a constructor. The join point is at the site of the new command, not the site of the code for the constructor, as in constructor execution join points, above. This has important consequences that we will study later.
  4. call(method)
    This type of join point corresponds to calling a method. This is different than a method execution join point in that it occurs before virtual dispatch -- that is, if B extends A, they both implement method m(), and you call a.m() with local variable a of type A but referencing an object of type B, you have a call join point on A.m() followed by an execution join point on B.m(); however, since the method m() is inherited from the superclass, this execution join point can be picked out with execution(void A.m()). Also, the join point is at the site of the method call, not the site of the code for the method, as in method execution join points. This has important consequences that we will study later.
  5. initialization(constructor)
    initialization of an object
  6. staticinitialization(class)
    static initialization of a class (just after class loading)
  7. get(field)
    The join point corresponding to access of an object or class data member. The containing type given in the field specification is the type containing the field or the type from which the field is requested. For example, if B extends A and A contains an int field f that B inherits (i.e., B doesn't also define a field with the same signature and name), then get(int A.f) will pick out every reference to the field, but get(int B.f) will only pick out those references that occur through a variable statically bound to type B. NOTE: get join points do not occur if a class or object data member is merely assigned and not accessed.
  8. set(field)
    Analogous to the above, but for assigning fields instead of accessing them.
  9. handler(exception)
    The execution of a catch block for the given exception type (but not a subclass).
In general, every join point in AspectJ is one of the above. You use the above (as we already have) as pointcut specifiers to set up a point cut that includes join points of that type.

Other pointcut designators

Other AspectJ pointcut specifiers are listed below. These are not join point types, but may be used in specifying pointcuts that can include any type of join point. (They can also be composed with each other and the above join point types. See below.)

The rest we'll talk about later:

In the above, constructor specifications typically take the form

[ access ] class.new(argument-list)

If no access specifier (public, private, or protected) is specified, then the constructor specification matches a constructor with any level of access. Access specifiers can also be negated with !. Here are some examples:

Foo.new() Specifies the constructor of class Foo that takes no arguments
org.somewhere.Bar.new(int) Specifies the constructor of class org.somewhere.Bar that takes a single int argument
public Main.new(String, String) Specifies the constructor of class Main that is public and takes two String arguments
!private com.example.lang.Expression.new() Specifies the constructor of class com.example.lang.Expression that is not private and takes no arguments
Specifying an access level may seem redundant, but can be very useful when combined with wildcards, as we will see later.

Method specifications are very similar to constructor specifications, but include a return type. They generally take the form

[ access ] [ static ] return-type class.method(argument-list)

Some examples:

void Foo.myMethod() Specifies the void method myMethod() of class Foo that takes no arguments
void org.somewhere.Bar.initialize(int) Specifies the void method initialize() of class org.somewhere.Bar that takes a single int argument
public static boolean Main.compare(String, String) Specifies the method compare() of class Main that is public and static, takes two String arguments, and returns a boolean
!private com.example.lang.Expression com.example.lang.Expression.canon() Specifies the method canon() of class com.example.lang.Expression that is not private, takes no arguments, and returns a com.example.lang.Expression

The rest of the lecture notes from today will be available soon...


Please contact me at mdeters@cse.wustl.edu if you have any questions regarding these notes.

Help on setting up AspectJ
Back to AspectJ Seminar course calendar


Morgan Deters / About me / OpenPGP Public Key / 02 Jan 2006

This page is certified valid HTML 4.01!  This page refers to certified valid CSS!  I support the AnyBrowser campaign