§5.4.1 Regular guards

This group of guards evaluates within the context of a given role. These guards are evaluated after a callin target is lifted and before a callin bound role method is invoked.

(a) Method binding guards

A guard may be attached to a callin method binding as in:

void roleMethod(int ir) <- after void baseMethod(int ib)
  when (ir > MyTeam.this.threshold);

Such a guard only affects the callin binding to which it is attached, i.e., this specific callin binding is only effective, if the predicate evaluates to true.
The following values are within the scope of the predicate expression, and thus can be used to express the condition:

  • The role instance denoted by this.
    Features of the role instance can also be accessed relative to this with or without explicit qualifying this.
  • The team instance denoted by a qualified this reference as in MyTeam.this.
  • If the callin binding includes signatures (as in the example above): Parameters of the role method.
    If parameter mappings are involved, they will be evaluated before evaluating the guard.

(b) Method guards

A method guard is similar to a method binding guard, but it applies to all callin method bindings of this method.
A method guard is declared between the method signature and the method body:

void roleMethod(int ir)
  when (ir > MyTeam.this.threshold) { body statements }

(c) Role level guards

When a guard is specified at the role level, i.e., directly before the class body of a role class, it applies to all callin method bindings of the role class:

protected class MyRole
  when (value > MyTeam.this.threshold)
{
    int value;
    other class body declarations
}

The following values are within the scope of the predicate expression:

  • The role instance denoted by this (explicit or implicit, see above). Thus, in the example value will be interpreted as a field of the enclosing role.
  • The team instance denoted by a qualified this reference as in MyTeam.this

(d) Team level guards

A guard specified in the header of a team class may disable the callin bindings of all contained role classes. The syntax corresponds to the syntax of role level guards.
The only value directly available within team level guard is the team instance (denoted by this) and its features.

Of course all guards can also access any visible static feature of a visible class.

Even if a guard has no direct effect, because, e.g., a role class has no callin bindings (maybe not even a role-base binding), predicates at such abstract levels are useful, because all predicates are inherited by all sub classes (explicit and implicit).