Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtend code generation: include library
Xtend code generation: include library [message #1804551] Thu, 28 March 2019 12:45 Go to next message
Eclipse UserFriend
Hello,

I am using Xtend to generate Java code based on a program written in my DSL. Alongside this generated Java code, I would like to include a library (two Java files I have already written, that won't change based on the DSL program). What is the best way to include such a library ?

I know it's possible to simply copy-paste the two Java files into an Xtend template and generate the files from there, but I would rather programatically copy the files.

Thanks in advance.

[Updated on: Thu, 28 March 2019 15:05] by Moderator

Re: Xtend code generation: include library [message #1804567 is a reply to message #1804551] Thu, 28 March 2019 14:55 Go to previous messageGo to next message
Eclipse UserFriend
hi maybe you are looking for something like http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/
Re: Xtend code generation: include library [message #1804568 is a reply to message #1804567] Thu, 28 March 2019 15:04 Go to previous messageGo to next message
Eclipse UserFriend
I can't seem to get that working in Xtend. It doesn't recognize Bundle or Platform.

Re: Xtend code generation: include library [message #1804569 is a reply to message #1804568] Thu, 28 March 2019 15:07 Go to previous messageGo to next message
Eclipse UserFriend
well the problem is that is not available outside of eclipse.
the runtime module is meant to work from standalone mode as well where no plugins exist

=> you could create a Service IDoSomething
=> implement it in runtime with a impl that throws an illegalstate (or does read the file from classpath)
=> implement it in ui by using the code from above
=> add bindings to both runtime and ui
=> inject service to generator and call it from there
Re: Xtend code generation: include library [message #1804573 is a reply to message #1804569] Thu, 28 March 2019 16:08 Go to previous messageGo to next message
Eclipse UserFriend
I'll rephrase my question: is it possible to access files in the project where my xtext grammar and xtend generator are, from the project in a new Eclipse runtime, where I write programs in my DSL?
Re: Xtend code generation: include library [message #1804574 is a reply to message #1804573] Thu, 28 March 2019 16:09 Go to previous messageGo to next message
Eclipse UserFriend
what do you mean by "access files"
and what do you mean by "access from the project"

if e.g. you want to create a java library and your model project can be a java project
you can make the model project a plugin project,
create a library plugin and add it to the dependencies of the model project.

or you create a custom classpath container as XtendContainerInitializerdoes it for xtend
(you can see how that works if you
- create a java project
- create a xtend file
- it will complain about missing library
- there is a quickfx to add it

[Updated on: Thu, 28 March 2019 16:27] by Moderator

Re: Xtend code generation: include library [message #1804578 is a reply to message #1804551] Thu, 28 March 2019 17:53 Go to previous message
Eclipse UserFriend
Quote:
I'll rephrase my question: is it possible to access files in the project where my xtext grammar and xtend generator are, from the project in a new Eclipse runtime, where I write programs in my DSL?


Nothing is impossible, but this approach does not make sense. Put your library into a library project and reference the library like you would do for any other Java library. If your target project is a plugin project, the library should also be a plugin project and use plugin dependencies. If the library is plain Java, build a Jar and use it as a referenced library.

The target project where the code is generated to is "just" a Java project, so think that you need a library in a Java project. That's it.
Previous Topic:[Language]ProposalProvider for generic IDE (VS-Code)
Next Topic:Update label of search page
Goto Forum:
  


Current Time: Sun Jun 22 02:25:09 EDT 2025

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

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

Back to the top