Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding a library to an Xbase DSL
Adding a library to an Xbase DSL [message #1767309] Tue, 04 July 2017 14:49 Go to next message
Marco Ullrich is currently offline Marco UllrichFriend
Messages: 14
Registered: December 2016
Location: Bayreuth
Junior Member
Hello everyone,

I want to add a library to an Xbase-DSL to provide some additional functions / classes.
I already did this in a non-Xbase-DSL, following the approach suggested in the book "Implementing Domain-Specific Languages with Xtext and Xtend" (great read btw!) and it worked out of the box.
It suggests to added a lib.mydsl-file into the source folder of the x.y.mydsl-Plugin and the content of this file (e.g. some pre-defined functions or classes /entities) will be available at runtime.

However, when I do this, using Xbase, it does not work and I dont know why (maybe it is not indexed / added to the scope?) and where to start looking for a solution.

What I did so far:
Using the domainmodel-example i created a file lib.dmodel with the following content:
entity a{}

and added it to the package "org.eclipse.xtext.example.domainmodel" ( the package is exported by the plugin by default).

Then I started a runtime-eclipse-application and created a test plugin-project and added a dependency to the org.eclipse.xtext.example.domainmodel plugin.

But when i create a test.dmodel file, entity a is not available.
entity b extends a //Missing supertype a
{}


How can I make this work in Xbase?
Or is there a better way to provide some library functions / library types for an Xbase DSL?

Best regards,
Marco
Re: Adding a library to an Xbase DSL [message #1767311 is a reply to message #1767309] Tue, 04 July 2017 14:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i cannot reproduce this

are you sure you did it right?
you need to add a dependency from the project (plugin) that contains the entity b to the plugin (i assume this is org.eclipse.xtext.example.domainmodel)

btw i would create a separate plugin like org.eclipse.xtext.example.domainmodel.lib for that purpose


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding a library to an Xbase DSL [message #1767312 is a reply to message #1767311] Tue, 04 July 2017 15:10 Go to previous messageGo to next message
Marco Ullrich is currently offline Marco UllrichFriend
Messages: 14
Registered: December 2016
Location: Bayreuth
Junior Member
Hi Christian,
thank you for your help! (:
I will add it to a library-plugin as soon as I get it working that way.
I think I got it right (I simply added the file and the dependencies as mentioned above).
Did I missed a step?

Here are the Manifest.MF`s
of the org.eclipse.xtext.example.domainmodel-Plugin (the DSL-Plugin)
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Xtext Domainmodel Example
Bundle-Vendor: Eclipse Xtext
Bundle-Version: 2.12.0.qualifier
Bundle-SymbolicName: org.eclipse.xtext.example.domainmodel; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.xtext,
 org.eclipse.xtext.xbase,
 org.eclipse.equinox.common;bundle-version="3.5.0",
 org.eclipse.emf.ecore,
 org.eclipse.xtext.xbase.lib,
 org.antlr.runtime,
 org.eclipse.xtext.util,
 org.eclipse.xtend.lib,
 org.eclipse.emf.common,
 org.eclipse.xtext.common.types,
 org.objectweb.asm;bundle-version="[5.0.1,6.0.0)";resolution:=optional
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: dmodel.lang,
 org.eclipse.xtext.example.domainmodel,
 org.eclipse.xtext.example.domainmodel.domainmodel,
 org.eclipse.xtext.example.domainmodel.domainmodel.impl,
 org.eclipse.xtext.example.domainmodel.domainmodel.util,
 org.eclipse.xtext.example.domainmodel.formatting2,
 org.eclipse.xtext.example.domainmodel.jvmmodel,
 org.eclipse.xtext.example.domainmodel.parser.antlr,
 org.eclipse.xtext.example.domainmodel.parser.antlr.internal,
 org.eclipse.xtext.example.domainmodel.scoping,
 org.eclipse.xtext.example.domainmodel.serializer,
 org.eclipse.xtext.example.domainmodel.services,
 org.eclipse.xtext.example.domainmodel.validation
Import-Package: org.apache.log4j


And the runtime-plugin (DmodelTest):
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DmodelTest
Bundle-SymbolicName: DmodelTest
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.xtext.xbase.lib;bundle-version="2.12.0",
 org.eclipse.xtext.example.domainmodel;bundle-version="2.12.0"


Re: Adding a library to an Xbase DSL [message #1767313 is a reply to message #1767312] Tue, 04 July 2017 15:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes this looks fine. maybe eclipse does some wired caching of the domain model plugin. can you delete your runtime workspace folder and try again?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding a library to an Xbase DSL [message #1767341 is a reply to message #1767313] Tue, 04 July 2017 19:00 Go to previous messageGo to next message
Marco Ullrich is currently offline Marco UllrichFriend
Messages: 14
Registered: December 2016
Location: Bayreuth
Junior Member
Deleting the runtime-workspace did the trick!
Thank you Christian!

But entity a is missing in the generated java code, is this a common behavior?
Do I have to create entity a manually in the inferrer?
I expected that entity a would now be part of the EMF-Modelinstance and would be handeled like entity b.


Re: Adding a library to an Xbase DSL [message #1767343 is a reply to message #1767341] Tue, 04 July 2017 19:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no,

it will be filtered in org.eclipse.xtext.builder.BuilderParticipant.getRelevantDeltas(IBuildContext)

=> you would need to subclass BuilderParticipant, adapt that method, and bind the subclass as IXtextBuilderParticipant


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Ambiguous grammar
Next Topic:Using linked .jar libraries in code generator
Goto Forum:
  


Current Time: Tue Apr 23 14:11:03 GMT 2024

Powered by FUDForum. Page generated in 0.05550 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top