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

User Manual    [Previous]   [Next]   

Top-level Aspects

Aspects in Umple can also be specified at top level (i.e. outside any classes). In this case, a set of classes in which to inject the code must be specified, within curly brackets. Glob patterns can be used to match a set of classes, where an asterisk is the wildcard character.

Example with "after" statement that will inject code in all set functions in all classes

after {*} set* { doSomething(); }

class Student1
{
  name;
}

class Student2
{
  name;
}

class Employer
{
  age;
  String testFunction() {
    return "This is a test function";
  }
}

class Student1 {isA X;}
class Student2 {isA X;}
class Employer {isA X;}
trait X {
  doSomething() {
    System.out.println("Doing something\n");
  }
}
      

Load the above code into UmpleOnline

 

Example that will inject code after two specific methods in all classes starting with Student

after {Student*} setName,testFunction { doSomething(); }
class Student1
{
	name;
}
class Student2
{
	name;
}
class Employer
{
	age;
	String testFunction() {
		return "This is a test function";
	}
}

class Student1 {isA X;}
class Student2 {isA X;}
trait X {
  doSomething() {
    System.out.println("Doing something\n");
  }
}
      

Load the above code into UmpleOnline

 

Syntax


toplevelCodeInjection- : [[toplevelBeforeCode]] | [[toplevelAfterCode]]

toplevelBeforeCode : ( before | [=around] ) {([className])(, [className])*} [[aspectBody]]

toplevelAfterCode : after {
  ([className]
  )
  (, [className]
  )*} [[aspectBody]]