This tutorial shows you, how you can reference Vorto Models from your custom Xtext DSL Eclipse Plugins.
In this demo, we are going to create a DSL with which you can describe an IoT system aggregating Vorto Information Models.
- Open Eclipse IDE
- Download Vorto DSL Plugins and install it as an archive in your Eclipse IDE
- Restart your Eclipse
- Create a new DSL Xtext Project
File > New > Other > Xtext > Xtext Project
-
Choose a projectname and language name
-
Specify a file extension for your language, e.g. mysdl
-
Click on Finish.
After the wizard is finished, it will create five projects for you.
Your Project Browser would look something like this:
- org.xtext.example.mydsl (core language plugin)
- org.xtext.example.mydsl.ide
- org.xtext.example.mydsl.ui
- org.xtext.example.mydsl.tests
- org.xtext.example.mydsl.ui.tests
We are primarily interested in the core language plugin, e.g. org.xtext.example.mydsl.
-
Open the core language plugin and find the *.xtext grammar file
-
Replace the content with the following grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals import "http://www.eclipse.org/vorto/metamodel/InformationModel" as im generate myDsl "http://www.xtext.org/example/mydsl/MyDsl" Root: 'namespace' namespace = QualifiedName 'version' version = VERSION (references += ModelReference)* 'system' name = ID '{' (model += Model)* '}'; Model: name = ID 'as' type = [im::InformationModel | QualifiedName]; QualifiedName: ID ('.' ID)* ; terminal VERSION : ('0'..'9')* '.' ('0'..'9')* '.' ('0'..'9')*('-'ID)?; ModelReference : 'using' importedNamespace=QualifiedName';'version=VERSION ;
As you can notice, it imports the Vorto Information Model Ecore and use it from your own DSL grammar.
-
Open the *.mwe2 Workflow file and add a reference to the Vorto Model Ecore files. Since we only use Vorto Information Models from our DSL, we just reference those.
... language = StandardLanguage { ... referencedResource = "platform:/resource/org.eclipse.vorto.core/model/InformationModel.genmodel" referencedResource = "platform:/resource/org.eclipse.vorto.core/model/Model.genmodel" ... }
-
Open the MANIFEST.MF file and add the following dependencies (under required bundles):
org.eclipse.vorto.core;bundle-version="0.10.0", org.eclipse.vorto.editor;bundle-version="0.10.0", org.eclipse.vorto.editor.infomodel;bundle-version="0.10.0"
If you are behind proxy, you would need to download ANTLR SDK manually, using the following Update Site: http://download.itemis.com/updates/. Once done so, please restart the IDE and continue with the following steps:
- Find the GenerateMyDsl.mwe2 Workflow file in the core plugin project.
- Right-click on the file and Run it. This will generate all necessary Xtext source code in order to run your language as an Eclipse Plugin
Now your language is all set. It's time to test it.
- Right-click on the core plugin project (e.g. org.xtext.example.mydsl) and run it in a new Eclipse Workbench. A new Eclipse Workbench instance starts up for your language. It automatically loads all Vorto Eclipse Plugins as well as your DSL plugins.
- Create a new simple project
- Add a new Vorto Information Model file to the project or download it from the Vorto Repository
Here is an example of a Vorto Information Model securitycamera.infomodel:
namespace org.mycompany.demo
version 1.0.0
displayname "Security Camera"
infomodel SecurityCamera {
// should contain function blocks, but omitting in this example
}
-
Add a new file for your DSL. The autocompletion editor feature kicks in and suggests you the SecurityCamera Information Model to choose for a reference:
Example:
namespace org.mycompany.demo version 1.0.0 using org.mycompany.demo.SecurityCamera;1.0.0 system SmartBuilding { cameraFirstFloor as SecurityCamera cameraSecondFloor as SecurityCamera }
Congratulations! You have just created a simple Xtext language project which references Vorto Information Models.