Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using Formatter2
Using Formatter2 [message #1795997] Wed, 03 October 2018 17:54 Go to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Hello,

I am using Xtext 2.10 on Eclipse Neon 4.6.3 with JDK 8.

I wanted to start using the formatter and know from past experience that the old formatter had issues and the suggestion from you guys was to use Formatter2.

Now that I am using new Xtext version 2.10 instead of 2.8 which I was using back then, I started trying to use Formatter2 but I faced big issues.

I basically added fragment = formatting2.Formatter2Fragment {} to my MWE2 file which looks like this:

module com.mydsl.GenerateMYDSL

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/com/mydsl/mydsl/MYDSL.xtext"
var file.extensions = "mylang"
var projectName = "com.mydsl.mydsl"
var runtimeProject = "../${projectName}"

Workflow {
    bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
    }
    component = DirectoryCleaner {
        directory = "${runtimeProject}/src-gen"
    }
    component = DirectoryCleaner {
        directory = "${runtimeProject}.ui/src-gen"
    }
    component = Generator {
        pathRtProject = runtimeProject
        pathUiProject = "${runtimeProject}.ui"
        pathTestProject = "${runtimeProject}.tests"
        projectNameRt = projectName
        projectNameUi = "${projectName}.ui"
        language = {
            uri = grammarURI
            fileExtensions = file.extensions
            fragment = grammarAccess.GrammarAccessFragment {}
            fragment = MYDSLEMFGeneratorFragment auto-inject {}
            fragment = serializer.SerializerFragment {
            	generateStub = false
            }
            fragment = resourceFactory.ResourceFactoryFragment {
                fileExtensions = file.extensions
            }
             fragment = parser.antlr.ex.rt.AntlrGeneratorFragment 	 {
               options =  {
                  backtrack = false
                  classSplitting = true
                  fieldsPerClass = "500"
                  ignoreCase = true
                  memoize=true
              }
            }
            fragment = validation.JavaValidatorFragment {}
            fragment = scoping.ImportNamespacesScopingFragment {
            	ignoreCase = true
            }
            fragment = exporting.QualifiedNamesFragment {}
            fragment = builder.BuilderIntegrationFragment {}
 			fragment = parser.antlr.DebugAntlrGeneratorFragment {
            	options = auto-inject{}
            }
            fragment = formatting2.Formatter2Fragment {}
            fragment = labeling.LabelProviderFragment {}
            fragment = outline.OutlineTreeProviderFragment {}
            fragment = outline.QuickOutlineFragment {}
            fragment = quickfix.QuickfixProviderFragment {}
            fragment = contentAssist.JavaBasedContentAssistFragment {}
            fragment = org.eclipse.xtext.generator.parser.antlr.ex.ca.ContentAssistParserGeneratorFragment {
              options ={
                  backtrack = false 
                  classSplitting = true
                  fieldsPerClass = "500"
                  memoize=true
                  ignoreCase = true
              }
            }
            fragment = junit.Junit4Fragment {}
            fragment = refactoring.RefactorElementNameFragment {}
            fragment = templates.CodetemplatesGeneratorFragment {}
            fragment = compare.CompareFragment {
                 fileExtensions = file.extensions
            }
        }
    }
}


I then tried to generate xtext artifacts but I got the following error:
69217 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow com.mydsl.mydsl.GenerateMYDSL: 
[ERROR]: GeneratorException: (Element: -UNKNOWN-; Reported by: Generator)
	 java.lang.RuntimeException: No GenPackage for NsURI http://www.eclipse.org/emf/2002/Ecore.
	at org.eclipse.xtext.generator.GenModelAccess.getGenPackage(GenModelAccess.java:98)
	at org.eclipse.xtext.generator.GenModelAccess.getGenClassifier(GenModelAccess.java:42)
	at org.eclipse.xtext.generator.GenModelAccess.getGenClass(GenModelAccess.java:38)
	at org.eclipse.xtext.generator.serializer.JavaEMFFile.importedGenTypeName(JavaEMFFile.java:83)
	at org.eclipse.xtext.generator.formatting2.FormatterStubGenerator.generateFormatMethod(FormatterStubGenerator.java:248)
	at org.eclipse.xtext.generator.formatting2.FormatterStubGenerator.generateStubFileContents(FormatterStubGenerator.java:204)
	at org.eclipse.xtext.generator.formatting2.Formatter2Fragment.generate(Formatter2Fragment.java:86)
	at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:75)
	at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:68)
	at org.eclipse.xtext.generator.DefaultGeneratorFragment.generate(DefaultGeneratorFragment.java:167)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:163)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:600)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:178)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:78)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)

java.lang.RuntimeException: Problems running workflow com.mydsl.mydsl.GenerateVHDL: 
[ERROR]: GeneratorException: (Element: -UNKNOWN-; Reported by: Generator)
	 java.lang.RuntimeException: No GenPackage for NsURI http://www.eclipse.org/emf/2002/Ecore.
	at org.eclipse.xtext.generator.GenModelAccess.getGenPackage(GenModelAccess.java:98)
	at org.eclipse.xtext.generator.GenModelAccess.getGenClassifier(GenModelAccess.java:42)
	at org.eclipse.xtext.generator.GenModelAccess.getGenClass(GenModelAccess.java:38)
	at org.eclipse.xtext.generator.serializer.JavaEMFFile.importedGenTypeName(JavaEMFFile.java:83)
	at org.eclipse.xtext.generator.formatting2.FormatterStubGenerator.generateFormatMethod(FormatterStubGenerator.java:248)
	at org.eclipse.xtext.generator.formatting2.FormatterStubGenerator.generateStubFileContents(FormatterStubGenerator.java:204)
	at org.eclipse.xtext.generator.formatting2.Formatter2Fragment.generate(Formatter2Fragment.java:86)
	at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:75)
	at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:68)
	at org.eclipse.xtext.generator.DefaultGeneratorFragment.generate(DefaultGeneratorFragment.java:167)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:163)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:600)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:178)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:78)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)

	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:104)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:78)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)
Caused by: java.lang.RuntimeException: 
[ERROR]: GeneratorException: (Element: -UNKNOWN-; Reported by: Generator)
	 java.lang.RuntimeException: No GenPackage for NsURI http://www.eclipse.org/emf/2002/Ecore.
	at org.eclipse.xtext.generator.GenModelAccess.getGenPackage(GenModelAccess.java:98)
	at org.eclipse.xtext.generator.GenModelAccess.getGenClassifier(GenModelAccess.java:42)
	at org.eclipse.xtext.generator.GenModelAccess.getGenClass(GenModelAccess.java:38)
	at org.eclipse.xtext.generator.serializer.JavaEMFFile.importedGenTypeName(JavaEMFFile.java:83)
	at org.eclipse.xtext.generator.formatting2.FormatterStubGenerator.generateFormatMethod(FormatterStubGenerator.java:248)
	at org.eclipse.xtext.generator.formatting2.FormatterStubGenerator.generateStubFileContents(FormatterStubGenerator.java:204)
	at org.eclipse.xtext.generator.formatting2.Formatter2Fragment.generate(Formatter2Fragment.java:86)
	at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:75)
	at org.eclipse.xtext.generator.Xtend2GeneratorFragment.generate(Xtend2GeneratorFragment.java:68)
	at org.eclipse.xtext.generator.DefaultGeneratorFragment.generate(DefaultGeneratorFragment.java:167)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:163)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:600)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:178)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:78)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)

	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.handleIssues(Mwe2Bridge.java:56)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:48)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	... 4 more


I though thought that this issue was fixed here .

What is the simplest way to overcome my issue?

I also know that there is a new format for MWE2 now. But I have tried to use it and keep all what I have defined currently in my old MWE2 file and failed miserably, the new MWE2 format is not as flexible or is a bit vague to me.
Re: Using Formatter2 [message #1795998 is a reply to message #1795997] Wed, 03 October 2018 17:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
This may be a bug in your Stone Age xtext version.
Please try the same with a hello world grammar
And or have a look at the fragment code to see which bindings to manually create.
Thus you can skip the fragment


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: Using Formatter2 [message #1796000 is a reply to message #1795997] Wed, 03 October 2018 20:00 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 748
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Also your MWE workflow is old-style. Use the project wizard to create a similar project and adopt the changes.
Re: Using Formatter2 [message #1796236 is a reply to message #1795998] Mon, 08 October 2018 15:53 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
My stone age Xtext, you mean version 2.10?

"which bindings to manually create" I tired doing so and failed. The bindIFormatter2() method gets executed with no issues. But the Ctrl+Shift+F does nothing. I have added it in MyDslRuntimeModule.java
Am I missing something?

As for migrating my MWE2 to the new Generator format. How can I do so for the following parts?

fragment = parser.antlr.ex.rt.AntlrGeneratorFragment 	 {
               options =  {
                  backtrack = false
                  classSplitting = true
                  fieldsPerClass = "500"
                  ignoreCase = true
                  memoize=true
              }


fragment = org.eclipse.xtext.generator.parser.antlr.ex.ca.ContentAssistParserGeneratorFragment {
              options ={
                  backtrack = false 
                  classSplitting = true
                  fieldsPerClass = "500"
                  memoize=true
                  ignoreCase = true
              }
            }
Re: Using Formatter2 [message #1796239 is a reply to message #1796236] Mon, 08 October 2018 16:24 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 748
Registered: July 2009
Location: Dortmund, Germany
Senior Member

		language = StandardLanguage {
...
			parserGenerator = {
				options = {
					backtrack = true
					classSplitting = true
					fieldsPerClass = "500"
					ignoreCase = true
					memoize=true
				}
			}

Previous Topic:Transient attributes in Xtext grammar
Next Topic:Serialization of Xtext model
Goto Forum:
  


Current Time: Sun Oct 17 23:17:16 GMT 2021

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

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

Back to the top