Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Where ist the formatting package in Xtext 2.10(How can I define an xtext formatter for my DSL ?)
Where ist the formatting package in Xtext 2.10 [message #1740430] Fri, 12 August 2016 18:33 Go to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
How can I define an xtext formatter for my DSL in Xtext 2.10 ?
The formatting/formatter package is not generated any more
Re: Where ist the formatting package in Xtext 2.10 [message #1740431 is a reply to message #1740430] Fri, 12 August 2016 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
simply add

formatter = {
    generateStub = true
}


to the 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: Where ist the formatting package in Xtext 2.10 [message #1740433 is a reply to message #1740430] Fri, 12 August 2016 18:45 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Sorry, I fount it in the docu.
Re: Where ist the formatting package in Xtext 2.10 [message #1740435 is a reply to message #1740431] Fri, 12 August 2016 19:00 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Christian Dietrich wrote on Fri, 12 August 2016 14:38
simply add

formatter = {
    generateStub = true
}


to the workflow


Thank you for this hint. Now I get the following error if runing the Generator workflow:
[ERROR]: GeneratorException: (Element: -UNKNOWN-; Reported by: XtextGenerator)
	 java.lang.RuntimeException: No GenPackage for NsURI http://www.mdsd.de/xtext/support/formatter/model/FormatterModel found in platform:/resource/de.mdsd.xtext.support.formatter.model/model/generated/FormatterModel.genmodel
	at org.eclipse.xtext.xtext.generator.util.GenModelUtil2.getGenPackage(GenModelUtil2.java:138)
	at org.eclipse.xtext.xtext.generator.util.GenModelUtil2.getGenClassifier(GenModelUtil2.java:45)
	at org.eclipse.xtext.xtext.generator.util.GenModelUtil2.getJavaTypeName(GenModelUtil2.java:262)
	at org.eclipse.xtext.xtext.generator.junit.Junit4Fragment2.generateExampleRuntimeTest(Junit4Fragment2.java:167)
	at org.eclipse.xtext.xtext.generator.junit.Junit4Fragment2.generate(Junit4Fragment2.java:133)
	at org.eclipse.xtext.xtext.generator.CompositeGeneratorFragment2.generate(CompositeGeneratorFragment2.java:48)
	at org.eclipse.xtext.xtext.generator.XtextGenerator.invokeInternal(XtextGenerator.java:202)
	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

The file /model/generated/FormatterModel.genmodel definitly exists in my project hence it is generated by an earlier step in the workflow,

My workflow looks like this:
module de.mdsd.xtext.support.formatter.model.GenerateFormatterModel

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

Workflow {
	
	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "de.mdsd.xtext.support.formatter.model"
				rootPath = rootPath
				runtimeTest = {
					enabled = true
				}
				eclipsePlugin = {
					enabled = true
				}
				eclipsePluginTest = {
					enabled = true
				}
				createEclipseMetaData = true
			}
			code = {
				encoding = "UTF-8"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "de.mdsd.xtext.support.formatter.model.FormatterModel"
			referencedResource = "platform:/resource/org.eclipse.xtext/org/eclipse/xtext/Xtext.genmodel"
			referencedResource = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"
			fileExtensions = "fm"

			formatter = {
			    generateStub = true
			}
			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
		}
	}
}
Re: Where ist the formatting package in Xtext 2.10 [message #1740436 is a reply to message #1740435] Fri, 12 August 2016 19:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
this looks like a bug to me. can you file a ticket with a minimal reproducing example?

as a workaround.

(1) generate a class manually

package org.xtext.example.mydsl2.formatting2

import com.google.inject.Inject
import org.eclipse.xtext.formatting2.AbstractFormatter2
import org.eclipse.xtext.formatting2.IFormattableDocument
import org.xtext.example.mydsl2.myDsl.Greeting
import org.xtext.example.mydsl2.myDsl.Model
import org.xtext.example.mydsl2.services.MyDslGrammarAccess

class MyDslFormatter extends AbstractFormatter2 {
	
	@Inject extension MyDslGrammarAccess

	def dispatch void format(Model model, extension IFormattableDocument document) {
		// TODO: format HiddenRegions around keywords, attributes, cross references, etc. 
		for (Greeting greetings : model.getGreetings()) {
			greetings.format;
		}
	}
	
	// TODO: implement for 
}


(2) bind it

public Class<? extends IFormatter2> bindIFormatter2() {
		return MyDslFormatter.class;
	}


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: Where ist the formatting package in Xtext 2.10 [message #1740438 is a reply to message #1740436] Fri, 12 August 2016 19:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
btw

referencedResource = "platform:/resource/org.eclipse.xtext/org/eclipse/xtext/Xtext.genmodel"
referencedResource = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel"


sounds very unusual


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: Where ist the formatting package in Xtext 2.10 [message #1740443 is a reply to message #1740436] Fri, 12 August 2016 20:28 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Christian Dietrich wrote on Fri, 12 August 2016 15:05
this looks like a bug to me. can you file a ticket with a minimal reproducing example?


Here is an minimal example. I striped my grammar by commenting to make it minimal. I figured out it has to do with the registration of other genmodels in the workflow file. The example grammar does not use other genmodels but if you declare an other genmodel in the work flow it does not run anymore.
  • Attachment: example.zip
    (Size: 35.93KB, Downloaded 41 times)
Re: Where ist the formatting package in Xtext 2.10 [message #1740444 is a reply to message #1740443] Fri, 12 August 2016 20:29 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I thing it may concern with the fact that the referenced genmodel is inside an eclipse plugin.
Re: Where ist the formatting package in Xtext 2.10 [message #1740446 is a reply to message #1740444] Fri, 12 August 2016 21:37 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
It turned out that this problem seems to exist only with the GenModel.genmodel.
Re: Where ist the formatting package in Xtext 2.10 [message #1740453 is a reply to message #1740446] Sat, 13 August 2016 07:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
well yes but referencedResource = "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel" is not neccessary.
so you seem to make strange things in your ecore


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: Where ist the formatting package in Xtext 2.10 [message #1740503 is a reply to message #1740453] Mon, 15 August 2016 09:07 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I need the generator infos from the GenClasses to generate class files. Wy only GenModel.genmodel does not work in the workflow ? Is there analternative ?
Re: Where ist the formatting package in Xtext 2.10 [message #1740504 is a reply to message #1740503] Mon, 15 August 2016 09:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
having a old 2.8.x style workflow. the new generator is buggy reegarding such usecases. this is why we need tickets with reprodung example (and time to fix 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
Previous Topic:Extending the grammar language
Next Topic:Evaluate the XBlockExpression to value?
Goto Forum:
  


Current Time: Tue Apr 20 11:52:48 GMT 2021

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

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

Back to the top