§5.4.2 Base guards

The intention behind base guards is to prevent lifting of a callin-target if a guard evaluates to false and thus refuses to invoke the callin bound role method. Using base guards it is easier to prevent any side-effects caused by a callin binding, because lifting could cause side-effects at two levels:

Both kinds of side-effects can be avoided using a base guard which prevents unnecessary lifting.

Any guard (5.4.1 (b)-(e)) can be turned into a base guard by adding the modifier base as in:

protected class MyRole playedBy MyBase
  base when (base.value > MyTeam.this.threshold)
{
    class body declarations
}

However, different scoping rules apply for the identifiers that can be used in a base guard:

(a) Base object reference

In all base guard predicates the special identifier base can be used to denote the base object that is about to be lifted.

(b) Method binding guards

A base method binding guard may access parameters as passed to the base method. Parameter mappings are not considered.
Additionally, for after callin bindings, the identifier result may be used to refer to the result of the base method (if any).

Note:

In order to achieve the same effect of accessing the base method's result, a regular binding guard (not a base guard) must use a suitable parameter mapping (see §4.4.(c)).

(c) Method guards

In contrast to regular method guards, a base guard attached to a role method cannot access any method parameters. See the next item (d) for values that are actually in scope.

(d) Role level guards

Role level base guards may use these values:

  • The base instance using the special identifier base.
  • The team instance using a qualified this references (MyTeam.this).

(e) Team level guards

Team level base guards have the same scope as role level base guards (d). However, the type of the role instance is not known here, i.e., here base has the static type java.lang.Object.

(f) Unbound roles

In contrast to regular guards, base guards cannot be attached to unbound role classes nor to their methods.
Only team level base guards are independent of role binding.

Overview: Guard predicates