As a final feature, we add the mechanism for invoking the implementation of a method in the superclass by using the keyword super
. Note that super
should be used only as the receiver of a member selection expression, that is, it cannot be passed as the argument of a method. Following the practice "loose grammar, strict validation", we do not impose this at the grammar level. Thus, we add the rule for super
as a terminal expression:
SJTerminalExpression returns SJExpression:
...
{SJSuper} 'super' | ...
and we add a validator rule that checks the correct super
usage:
@Check def void checkSuper(SJSuper s) { if (s.eContainingFeature != SmallJavaPackage::eINSTANCE.SJMemberSelection_Receiver) error("'super' can be used only as member selection receiver", null, WRONG_SUPER_USAGE) }
Thanks to the way we implemented the scope provider, in order to make members of the superclass visible when the receiver expression is super
, we only need to provide a type for...