Additional Xbase features
In this section, we will show a few additional Xbase features, and we will apply them to the Xbase Entities DSL we implemented so far.
Annotations
Xbase provides support for Java-like annotations. This support is not enabled in the standard Xbase grammar. If you want to use Xbase annotations in your DSL, then you must use org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
as the super grammar:
grammar org.example.xbase.entities.Entities with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
Now, you can use the Xbase grammar rules for annotations. In this example, we will add annotations to entities and attributes:
Entity: annotations+=XAnnotation* 'entity' name=ID ('extends' superType=JvmParameterizedTypeReference)? '{' attributes += Attribute* operations += Operation* '}'; Attribute: annotations+=XAnnotation* 'attr' (type=JvmTypeReference)? name=ID ('=' initexpression=XExpression...