Skip to main content



      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 14:33 Go to next message
Eclipse UserFriend
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 14:38 Go to previous messageGo to next message
Eclipse UserFriend
simply add

formatter = {
    generateStub = true
}


to the workflow
Re: Where ist the formatting package in Xtext 2.10 [message #1740433 is a reply to message #1740430] Fri, 12 August 2016 14:45 Go to previous messageGo to next message
Eclipse UserFriend
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 15:00 Go to previous messageGo to next message
Eclipse UserFriend
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 15:05 Go to previous messageGo to next message
Eclipse UserFriend
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;
	}
Re: Where ist the formatting package in Xtext 2.10 [message #1740438 is a reply to message #1740436] Fri, 12 August 2016 15:07 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Where ist the formatting package in Xtext 2.10 [message #1740443 is a reply to message #1740436] Fri, 12 August 2016 16:28 Go to previous messageGo to next message
Eclipse UserFriend
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 181 times)
Re: Where ist the formatting package in Xtext 2.10 [message #1740444 is a reply to message #1740443] Fri, 12 August 2016 16:29 Go to previous messageGo to next message
Eclipse UserFriend
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 17:37 Go to previous messageGo to next message
Eclipse UserFriend
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 03:26 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Where ist the formatting package in Xtext 2.10 [message #1740503 is a reply to message #1740453] Mon, 15 August 2016 05:07 Go to previous messageGo to next message
Eclipse UserFriend
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 05:10 Go to previous message
Eclipse UserFriend
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)
Previous Topic:Extending the grammar language
Next Topic:Evaluate the XBlockExpression to value?
Goto Forum:
  


Current Time: Mon Jul 28 17:21:06 EDT 2025

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

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

Back to the top