Other languages

Skip to end of metadata
Go to start of metadata

Here we introduce some handy BaseLanguage extensions

Checked dots

Language: jetbrains.mps.baseLanguage.checkedDots

A Checked Dot Expression is an dot expression extended with null checks on the operand.

If the operand is null, the value of the whole checked dot expression becomes null, otherwise it evaluates to the value of corresponding dot expression.

Ways to create a Checked Dot Expression
  • The Make dot expression checked intention
  • Enter "?" after dot, e.g. customer.?address.?street
  • Left transform of operation with "?"

You can transform checked dot expressions to the usual dot expressions using the Make dot expression not checked intention

Overloaded operators

Language: jetbrains.mps.baseLanguage.overloadedOperators

This language provides a way to overload binary operators.

Overloaded operator declarations are stored in an OverloadedOperatorContainer.

If there are several overloaded versions for one operator the most relevant is chosen.

Note that if an overloaded operators' usage is in the other model than its declaration, overloadedOperators language should be added to "languages engaged on generation" of usage's model.

Examples

Overloading plus operator for class Complex:

 

Also, you can define your own custom operators. Assume we want to create a binary boolean operator for strings, which tells if one string contains another:

 

Now, we can simply use this operator:


Custom constructors (since 1.5.1)

Language: jetbrains.mps.baseLanguage.constructors

Custom constructors provide a simple way to create complex objects. They are stored in a special root node - CustomConstructorsContainer.

Example

Assume we need a faster way to create rectangle.


Now, let's create a rectangle:

Previous Next

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.