Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using Java instead of XTend
Using Java instead of XTend [message #1035320] Sat, 06 April 2013 17:55 Go to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
XText generates MyDSLValidator.xtend which in turn will generate MyDSLValidator.java

I know I'm in the minority here, but for the time being at least, I'd prefer to not use XTend. Nothing against XTend, it's just that I don't know it and that takes my process from "just figuring it out" to "figuring it out, then figuring it out in xtend".

With my scope provider, I simply named it MyDSLCustomScopeProvider and bound my scope provider in MyDSLRuntimeModule.

But that leaves the .xtend file and it's generated java file in place. My custom code is growing enough that I'd prefer for those extra files not to be there.

I'm using XText 2.4 if that makes a difference.

When I look at earlier projects (xtext 2.3 I believe), the MyDSLValidator.xtend file doesn't exist. I'm unsure if I created the project a little differently, or if it's just one of the differences between 2.3 and 2.4
Re: Using Java instead of XTend [message #1035323 is a reply to message #1035320] Sat, 06 April 2013 17:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
Hi,

have a look at the workflow

var generateXtendStub = true
Re: Using Java instead of XTend [message #1035324 is a reply to message #1035323] Sat, 06 April 2013 18:00 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
That's too much. Laughing

I completely ignored all lines above "Workflow {"

D'oh!

[Updated on: Wed, 01 May 2013 21:28]

Report message to a moderator

Re: Using Java instead of XTend [message #1052706 is a reply to message #1035324] Tue, 30 April 2013 12:40 Go to previous messageGo to next message
Mårten Carlzon is currently offline Mårten CarlzonFriend
Messages: 60
Registered: March 2013
Location: Sweden
Member

Hi Steve,

Did changing the variable work for you? I tried it and it only changed the formatter to java and the scopeprovider so I seem to be stuck with xtend files for the generator and validator. Anyone know what I might have setup wrong?
(Adding my mwe2 file incase it helps, what I have done is removed auto-inject at many places since at first I thought that would give me java files)

GenerateIiDsl.mwe2 file
Re: Using Java instead of XTend [message #1052713 is a reply to message #1052706] Tue, 30 April 2013 12:49 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio HeegFriend
Messages: 75
Registered: April 2013
Member
The Generator has been Xtend-based since (at least) Xtext 2.3.1.
As for the Validator being Xtend whether that option is active or not, that seems to be something new in Xtext 2.4 (and I can't say I like it).
So you got two easy options - fiddling with the Validator in the xtend-gen-Folder instead or going back to 2.3.1.
Simply creating the Validator (and Generator) class there/moving it there should work, too. But I could be mistaken.
Re: Using Java instead of XTend [message #1052738 is a reply to message #1052713] Tue, 30 April 2013 13:20 Go to previous messageGo to next message
Mårten Carlzon is currently offline Mårten CarlzonFriend
Messages: 60
Registered: March 2013
Location: Sweden
Member

Ok, well, sitting on 2.4 so I will try to learn xtend.
Besides the only thing I really need is to get the filename of my dsl file and make it to a xml, I get as far as "filename.mydsl.xml". I tried to use split and iterator but so far I get nothing Smile

But thanks for the information, I tried to create a class file and it works, it just gets overwritten if I rerun the mwe2 file so it is doable, but since its an annoyingly small thing I am stuck on I think it can be worth to try and learn a little bit of XTend instead of trying to make it into java.

Thanks for the quick reply

Write you later / Mårten
Re: Using Java instead of XTend [message #1052986 is a reply to message #1052738] Wed, 01 May 2013 17:31 Go to previous messageGo to next message
Alexei Adamovich is currently offline Alexei AdamovichFriend
Messages: 2
Registered: May 2013
Junior Member
In the situation like this I found the following solution:
since Xtext generates only a stub (written in Xtend), I had got an instance of my Java class there and then had called its method.

So the real work was being done by code written in Java.
Re: Using Java instead of XTend [message #1053003 is a reply to message #1052986] Wed, 01 May 2013 20:43 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
Sorry - I haven't been watching these forums much the last few days.

I submitted a bug because with my installation of 2.4, regardless of the setting it generates XTend files for ... I think it was the scope provider and the validator.

The easy workaround for me is simply deleting the xtend file, which deletes the auto-generated .java file under src-gen.

I have my own java classes defined with the same names for the validator and scope provider. When I re-run the mwe2 workflow, I simply go and delete those 2 xtend files and everything is fine. I *might* have some hooks declared in the runtime modules, but I don't think I even had to do that.

Re: Using Java instead of XTend [message #1053007 is a reply to message #1053003] Wed, 01 May 2013 20:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
For the validator it actually helps to use

validation.JavaValidatorFragment
Re: Using Java instead of XTend [message #1053026 is a reply to message #1053007] Thu, 02 May 2013 06:09 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
So... add this to the mwe2 file?

fragment = validation.JavaValidatorFragment auto-inject {
}

while commenting out:
    		fragment = validation.ValidatorFragment auto-inject {
    		//    composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
    		//    composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
    		}


How do we know what fragments are available?

I'm wondering if I missed something in the documentation (wouldn't be the first time).

The only thing I can think is to choose "Open Type", search for anything with a fragment in it's name. I'm sure there's a better way of hunting these things down than that.
Re: Using Java instead of XTend [message #1053032 is a reply to message #1053026] Thu, 02 May 2013 06:50 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1159
Registered: July 2009
Senior Member
Hi,

try code completion and note that fragments have to implement a certain interface so type hierarchy will help as well.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Using Java instead of XTend [message #1053040 is a reply to message #1053032] Thu, 02 May 2013 07:40 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
Ahh... interesting. If you type in "validation." and code complete you get no results. But if you just type a portion it works.

I had tried that, but since I got no results initially I never tried again until just now.
Re: Using Java instead of XTend [message #1092122 is a reply to message #1053003] Thu, 22 August 2013 11:01 Go to previous messageGo to next message
Shelby Moore III is currently offline Shelby Moore IIIFriend
Messages: 42
Registered: August 2013
Member
Steve Kallestad wrote on Wed, 01 May 2013 16:43
The easy workaround for me is simply deleting the xtend file, which deletes the auto-generated .java file under src-gen.

I have my own java classes defined with the same names for the validator and scope provider. When I re-run the mwe2 workflow, I simply go and delete those 2 xtend files and everything is fine. I *might* have some hooks declared in the runtime modules, but I don't think I even had to do that.


I appear to be using 2.4.2.v201306120542. Set the
var generateXtendStub = false
. That change caused the mwe2 workflow to only continue generating .xtend stub for the {ProjectName}Generator.xtend file in the org.xtext.{ProjectFileext}.generator. I can then delete that file as you explained after each re-run of the mwe2 workflow, for a manual work around if I wanted Java source for my code generation.

But I want to use Scala for code generation. Can anyone point me in the direction for learning how to do this?

I realize I might be in the minority, but consider this question applicable to using any JVM language with Xtext for code generation.

Alexei Adamovich wrote on Wed, 01 May 2013 13:31
In the situation like this I found the following solution:
since Xtext generates only a stub (written in Xtend), I had got an instance of my Java class there and then had called its method.

So the real work was being done by code written in Java.


Could I call a method in .jar? What do I do to integrate such into the work flow?

[Updated on: Thu, 22 August 2013 14:21]

Report message to a moderator

Re: Using Java instead of XTend [message #1092174 is a reply to message #1092122] Thu, 22 August 2013 12:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6489
Registered: July 2009
Senior Member
Scala as Generator language or Target Language?
Re: Using Java instead of XTend [message #1092191 is a reply to message #1092174] Thu, 22 August 2013 12:40 Go to previous messageGo to next message
Shelby Moore III is currently offline Shelby Moore IIIFriend
Messages: 42
Registered: August 2013
Member
Christian Dietrich wrote on Thu, 22 August 2013 08:19
Scala as Generator language or Target Language?


Both, yet it seems the former (generator language) is the aspect I need help with.

Perhaps it is best to answer in the thread I started for this issue:

http://www.eclipse.org/forums/index.php/m/1092181/

[Updated on: Thu, 22 August 2013 12:42]

Report message to a moderator

Re: Using Java instead of XTend [message #1092254 is a reply to message #1092191] Thu, 22 August 2013 14:16 Go to previous messageGo to next message
Shelby Moore III is currently offline Shelby Moore IIIFriend
Messages: 42
Registered: August 2013
Member
Another potential solution that may not require manually deleting the .xtend file.
Re: Using Java instead of XTend [message #1092331 is a reply to message #1092254] Thu, 22 August 2013 16:28 Go to previous message
Shelby Moore III is currently offline Shelby Moore IIIFriend
Messages: 42
Registered: August 2013
Member
I found an easy solution to eliminate the manual deletion of the .xtend file.

// generator API
    		fragment = generator.GeneratorFragment auto-inject {
            generateStub = false
         }
Previous Topic:running Headless Xtext DSL
Next Topic:Re: No EObjectDescription could be found in Scope
Goto Forum:
  


Current Time: Mon Nov 24 13:56:41 GMT 2014

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

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