Dealing with super

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 ...

Get Implementing Domain-Specific Languages with Xtext and Xtend now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.