Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Help with Generate Infrastructure MWE - create generator package
Help with Generate Infrastructure MWE - create generator package [message #842305] Thu, 12 April 2012 07:07 Go to next message
John Bito is currently offline John BitoFriend
Messages: 54
Registered: July 2009
Member
Using Xtext 2.2.1, the MWE created my language infrastructure and I was able to launch the Eclipse runtime with the resulting editor. Very smooth and much more clear than when I worked with version 1 (and earlier).

The issue I encounter is that there is no '...generator' package in the src folder of the project that has my grammar. When I create a new Xtext project, running the MWE produced the generator package. I'd appreciate if you can help me understand what would prevent the creation of the generator package in my project.

I suppose I could move my grammar into the new project that has the generator package, but I suspect I'm missing some understanding with this.

Thanks!
John
Re: Help with Generate Infrastructure MWE - create generator package [message #842316 is a reply to message #842305] Thu, 12 April 2012 07:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi I guess the GeneratorFragment is missing in your workflow

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with Generate Infrastructure MWE - create generator package [message #842333 is a reply to message #842316] Thu, 12 April 2012 07:42 Go to previous messageGo to next message
John Bito is currently offline John BitoFriend
Messages: 54
Registered: July 2009
Member
Well, I was comparing MWE files between the project where the generator package is produced and the one in which it is not produced and the Workflows are the same - only the header module and var lines differ. I tried setting the generateMwe and generateJavaMain properties true in the GeneratorFragment, but didn't see a difference.

Here's the console line that indicates the GeneratorFragment was processed.
2447 [main] INFO  ipse.xtext.generator.LanguageConfig  - generating infrastructure for com.bobberinteractive.expeng.flow.Module with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, SerializerFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, Junit4Fragment, RefactorElementNameFragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment, CompareFragment


I wonder if it's not compatable with the Xbase grammar mix-in - that's one thing that I added to my project that wasn't there by default.
Re: Help with Generate Infrastructure MWE - create generator package [message #842355 is a reply to message #842333] Thu, 12 April 2012 08:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
hi if you use xbase the is no generator generated cause
jvmmodelgenerator is used by default - it uses the jvmmodel inferred
by the jvmmodelinferrer


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with Generate Infrastructure MWE - create generator package [message #842360 is a reply to message #842333] Thu, 12 April 2012 08:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
hi if you use xbase the is no generator generated cause
jvmmodelgenerator is used by default - it uses the jvmmodel inferred
by the jvmmodelinferrer


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with Generate Infrastructure MWE - create generator package [message #842810 is a reply to message #842360] Thu, 12 April 2012 16:19 Go to previous messageGo to next message
John Bito is currently offline John BitoFriend
Messages: 54
Registered: July 2009
Member
Thanks very much, Christian! I wasn't expecting that. Would it be worth submitting an enhancement request to suggest that logging note that the Generator fragment isn't doing anything due to the conflict with Xbase processing?
Re: Help with Generate Infrastructure MWE - create generator package [message #1746030 is a reply to message #842810] Thu, 20 October 2016 16:23 Go to previous messageGo to next message
Ajit Dingankar is currently offline Ajit DingankarFriend
Messages: 12
Registered: July 2011
Junior Member
I'm just starting out with Xtext and in a particular situation where I need to generate a standalone command-line compiler and generator.
I need to be able run tests on machines that I don't administer and don't have Eclipse installed. I started with a "traditional" Xtext grammar,
inheriting only the terminals and the generator flow worked fine. Since I need to support complex expressions and statements in my DSL,
I created another project where the grammar inherits from Xbase. I've done a bit of development in the latter, but I can't figure out how to
create a generator project. I don't need to process XExpressions (yet Wink but just run the same parsing and generation flow without Eclipse.
Re: Help with Generate Infrastructure MWE - create generator package [message #1746032 is a reply to message #1746030] Thu, 20 October 2016 16:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi, i am not sure if i can follow you and this is the right topic to discuss this.

- the recent versions of xtext do no longer use a separate generator project. the generator class goes into the runtime project.
as mentioned obove for xtext there is no generator class stub generated since jvmmodelgenerator is used. you can create a subclass of it or implement IGenerator yourself and overide bindIGenerated in the runtime module.
- the flow you are talking of: is this maven or gradle based or do you want to create a java main?





Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with Generate Infrastructure MWE - create generator package [message #1746034 is a reply to message #1746032] Thu, 20 October 2016 16:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
ps maybe you are just looking for something like

/*******************************************************************************
* Copyright (c) 2016 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.example.domainmodel;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.generator.GeneratorContext;
import org.eclipse.xtext.generator.GeneratorDelegate;
import org.eclipse.xtext.generator.IGeneratorContext;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;

import com.google.common.collect.Lists;
import com.google.inject.Injector;

/**
* @author dietrich - Initial contribution and API
*/
public class Main {

public static void main(String[] args) {
// TODO traverse directory
List<String> files = Lists.newArrayList("model/a.dmodel","model/b.dmodel");
Injector injector = new DomainmodelStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = injector.getInstance(ResourceSet.class);
ArrayList<Resource> resources = Lists.newArrayList();
for (String file : files) {
Resource r = rs.getResource(URI.createFileURI(file), true);
resources.add(r);
}

IResourceValidator validator = injector.getInstance(IResourceValidator.class);
for (Resource r : resources) {
List<Issue> issues = validator.validate(r, CheckMode.ALL, CancelIndicator.NullImpl);
for(Issue i : issues) {
System.out.println(i);
}
}

GeneratorDelegate generator = injector.getInstance(GeneratorDelegate.class);
JavaIoFileSystemAccess fsa = injector.getInstance(JavaIoFileSystemAccess.class);
fsa.setOutputPath("src-gen-code/");
GeneratorContext context = new GeneratorContext();
context.setCancelIndicator(CancelIndicator.NullImpl);

for (Resource r : resources) {
generator.generate(r, fsa, context);
}
}

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with Generate Infrastructure MWE - create generator package [message #1746037 is a reply to message #1746034] Thu, 20 October 2016 18:11 Go to previous messageGo to next message
Ajit Dingankar is currently offline Ajit DingankarFriend
Messages: 12
Registered: July 2011
Junior Member
Hi Christian!
Thanks a lot for the quick response, and sorry about posting in this thread (after 7 years! Smile
I was going through the section on standalone compiler in the code generator chapter of
Lorenzo Bettini's book, and tried to generate a Main Xtend class as the first step, so I think
your example above may work for me since it look similar to the Main.xtend generated for
my first implementation.

I apologize for bothering you again with a stupid question, but how do I use your example?
I suspect I need to put this in a generator package. If so, I'd appreciate any pointers to creating
a generator package from the MWE2 file, since it seems to ignore the generator paragraph that
I added there.

I was thinking of copying/modifying the generator package from the first implementation, but
I'm not sure if that may interfere with the jvmmodel package when I create new models in the
DSL.

Thanks,
Ajit
====
Re: Help with Generate Infrastructure MWE - create generator package [message #1746038 is a reply to message #1746037] Thu, 20 October 2016 18:13 Go to previous messageGo to next message
Ajit Dingankar is currently offline Ajit DingankarFriend
Messages: 12
Registered: July 2011
Junior Member
Please let me know if I should create another thread and point to my first post in this thread there.
Re: Help with Generate Infrastructure MWE - create generator package [message #1746039 is a reply to message #1746038] Thu, 20 October 2016 18:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi we can keep it here but I still don't understand your problem

As I said : if you use xbase the generator paragraph will be ignored and you have to create it manually if you want it


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with Generate Infrastructure MWE - create generator package [message #1746057 is a reply to message #1746039] Thu, 20 October 2016 22:08 Go to previous message
Ajit Dingankar is currently offline Ajit DingankarFriend
Messages: 12
Registered: July 2011
Junior Member
Thanks, Christian! I understand the current limitations, but was trying to find workarounds.
I created the generator package myself and it seems to work!
Previous Topic:customise plugin.xml
Next Topic:Code Completion In A Standalone Project?
Goto Forum:
  


Current Time: Sun Apr 18 07:22:32 GMT 2021

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

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

Back to the top