list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

Code Injection Pattern Matching

When creating before and after statements, you can arrange for the code to be injected into certain methods that match a pattern. You can use * as a wildcard, and ! as an exclusion operator. The following examples will both generate the same code.

Another example of pattern matching for code injection can be found on the page on pooled state machines, where the same code is injected into all the event methods matching a certain pattern

You can specify that code should be injected only into generated methods by specifying the word 'generated' after before or after. Similarly you can specify only custom methods using the keyword 'custom'. The keyword 'all' indicates to inject the code into all matching methods.

Example


class Student
{
  const Boolean DEBUG = true;
  firstName;
  lastName;
  cityOfBirth;
  before get*Name { 
    if ( DEBUG) { System.out.println("accessing the name"); }
  }
}
      

Load the above code into UmpleOnline

 

Another Example


class Student
{
  const Boolean DEBUG = true;
  firstName;
  lastName;
  cityOfBirth;
  before get*,!getCityOfBirth { 
    if ( DEBUG) { System.out.println("accessing the name"); }
  }
}

      

Load the above code into UmpleOnline