Dealing with super

As a final feature, we add the mechanism for invoking the implementation of a method in the superclass 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' | ...

We add a validator rule that checks the correct super usage:

public static val WRONG_SUPER_USAGE =
  ISSUE_CODE_PREFIX + "WrongSuperUsage"

@Check def void checkSuper(SJSuper s) {
  if (s.eContainingFeature !=
        SmallJavaPackage.eINSTANCE ...

Get Implementing Domain-Specific Languages with Xtext and Xtend - Second Edition 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.