Java Reference
In-Depth Information
The implicit first parameter represents the element instance, so we can use
the “member syntax” to seemingly invoke an extension on the instance. This
gives us more of the feeling that we're truly extending the underlying metamodel.
This is an equivalent example to the first:
myFeature.setterName();
Remember that even though we're seemingly extending the metamodel, these
extensions are not available using reflection and cannot be used for specializa-
tion of metamodel operations. During evaluation, an operation matched in the
metamodel takes precedence in execution.
Type Inference
It's not strictly required that a return type be declared because the type can be
inferred from the expression and depends on its context of use. For example,
consider this expression:
asList( Object o) : {o};
When invoking this extension and passing an Integer, as shown next, it has
the static type List[Integer] . So the use of upTo() is statically type safe.
asList(55).get(0).upTo(60);
Recursion
One exception to the rule regarding type declaration is with recursive expres-
sions. Because the type cannot be inferred, it must be stated explicitly, as shown
in this example:
String fullyQualifiedName(JavaPackage p) :
p.eSuperPackage == null ? p.name :
fullyQualifiedName(p.eSuperPackage) + '.'
+ p.name
;
Consider another example from GMF's xpt::editor::palette::Utils
extensions:
Search WWH ::




Custom Search