Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Resolved] XText Generator fails, how to debug?
[Resolved] XText Generator fails, how to debug? [message #1069590] Tue, 16 July 2013 07:45 Go to next message
Sven Kasten is currently offline Sven KastenFriend
Messages: 8
Registered: May 2011
Junior Member
Hi @all,

I have a general problem generating code from my model. I setup a new XText project, setup a very simple grammar. The grammar and the editor works. Here the simplyfied grammar:
grammar a.b.c.Lang with org.eclipse.xtext.common.Terminals

generate lang "http://a.b.c/l/Lang"

Model:
	'project' project=ID ';'
	(services+=Service)*
;

	
Service:
	'service' name=ID '{'
	'}'
;


After this I in the .ui project a GenerationGapBuilderParticipant which I already successfully used in another XText projet. It looks like this:
public class GenerationGapBuilderParticipant extends BuilderParticipant {
	
	public static final String DEFAULT_OUTPUT = "DEFAULT_OUTPUT";
	public static final String ONCE_OUTPUT = "ONCE_OUTPUT";
	
	protected Map<String, OutputConfiguration> getOutputConfigurations(IBuildContext context) {
		Map<String, OutputConfiguration> configurations = super.getOutputConfigurations(context);
		Map<String, OutputConfiguration> newConfigurations = new HashMap<String, OutputConfiguration>();
		OutputConfiguration newConfiguration = new OutputConfiguration(ONCE_OUTPUT);
		newConfiguration.setCanClearOutputDirectory(false);
		newConfiguration.setCleanUpDerivedResources(false);
		newConfiguration.setCreateOutputDirectory(true);
		newConfiguration.setDescription("Generates sources only once (setOverrrideExistingResource=false)");
		newConfiguration.setOutputDirectory("./src/main/java-once");
		newConfiguration.setOverrideExistingResources(false);
		newConfiguration.setSetDerivedProperty(false);
		OutputConfiguration oldConfiguration = configurations.get(DEFAULT_OUTPUT);
		oldConfiguration.setOutputDirectory("src/main/java-gen");
		
		/* Change config to enable SVN possibility */
		oldConfiguration.setCanClearOutputDirectory(false);
		oldConfiguration.setCleanUpDerivedResources(false);
		oldConfiguration.setOverrideExistingResources(true);
		oldConfiguration.setSetDerivedProperty(false);
		
		newConfigurations.put(DEFAULT_OUTPUT, oldConfiguration);
		newConfigurations.put(ONCE_OUTPUT, newConfiguration);
		return newConfigurations;
	}
}


And here the Codegenerator which should use the participant.
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		generateModel(resource.contents.head as Model, fsa);
	}
	
	def generateModel(Model model, IFileSystemAccess fsa) '''
	«var ifaceGenerator = new IFaceGenerator()»
	«FOR service : model.services»
		/* Iface */
		«fsa.generateFile("a/b/" + model.project + "/c/Access" + service.name.toFirstUpper + "Gen.java", ifaceGenerator.generate(service, model.project))»
		«fsa.generateFile("a/b/" + model.project + "/c/Access" + service.name.toFirstUpper + ".java", "ONCE_OUTPUT", ifaceGenerator.generateOnce(service, model.project))»
	«ENDFOR»
	'''


The IFaceGenerator:
	def generateOnce(Service service, String project) '''
	package a.b.«project».c;

	public class Access«service.name.toFirstUpper» {
	}
	'''
	
	def generate(Service service, String project) '''
	package a.b.«project».c;
	
	///////////////////////////////////////////////////////////////////////////////////////
	// 								!!!! WARNING !!!!									 //
	// THIS IS GENERATED SOURCE. ALL CHANGES WILL BE LOST AT THE NEXT GENERATION CYCLE!  //
	///////////////////////////////////////////////////////////////////////////////////////
	public abstract class Access«service.name.toFirstUpper»Gen implements Component {
	}
	'''


The problem is, that the generator is never triggered. I also didn't get any useful error message. I tried different things:

- deleted all other plugins from my eclipse which also uses xtext
- simplyfied the grammar so it was near the greeting example
- reinstalled xtext completely
- started a complete simple new xtext project. The greeting example worked with standard generator and with the GenerationGapBuilderParticipant
- started the dmodel example, which didn't work

The only exception I get is this one, which I also get with successful code-generation in other projects:
11648 [Worker-4] ERROR org.eclipse.xtext.builder.impl.XtextBuilder  - 
java.lang.NullPointerException
	at org.eclipse.xtext.builder.BuilderParticipant.isEnabled(BuilderParticipant.java:251)
	at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:148)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:186)
	at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:162)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:95)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)


Any ideas what I can do to find the problem? Eclipse Version is Kepler complete up-to-date with latest XText from Marketplace. How can I debug the Eclipse execution which can be started from the XText project? Any chance to debug the model validation oder code generation steps?

I hope someone can help.
Regards,
Sven

PS: In the sources I removed some words for the public showcase

[Updated on: Tue, 16 July 2013 08:39]

Report message to a moderator

Re: XText Generator fails, how to debug? [message #1069593 is a reply to message #1069590] Tue, 16 July 2013 07:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

sure you guiceyfied the entry in the plugin.xml?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Generator fails, how to debug? [message #1069602 is a reply to message #1069593] Tue, 16 July 2013 08:23 Go to previous messageGo to next message
Sven Kasten is currently offline Sven KastenFriend
Messages: 8
Registered: May 2011
Junior Member
In the .ui project I added this to the plugin.xml

  <extension point="org.eclipse.xtext.builder.participant">
        <participant class="a.b.c.ui.GenerationGapBuilderParticipant">
        </participant>
  </extension>

[Updated on: Tue, 16 July 2013 08:23]

Report message to a moderator

Re: XText Generator fails, how to debug? [message #1069608 is a reply to message #1069602] Tue, 16 July 2013 08:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Ähmmm

you should use x.y.z.YourDslExecutableExtensionFactory:a.b.c.ui.GenerationGapBuilderParticipant



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Generator fails, how to debug? [message #1069615 is a reply to message #1069608] Tue, 16 July 2013 08:38 Go to previous message
Sven Kasten is currently offline Sven KastenFriend
Messages: 8
Registered: May 2011
Junior Member
Hrmpf. Yes you are right.
(I have to mention, that in my old project it also worked without the ExecutableExtensionFactory)

Thank you! Smile
Previous Topic:ComposedChecks are triggered twice
Next Topic:How to add Xtext DSL into the Spring project.
Goto Forum:
  


Current Time: Fri Apr 26 07:29:47 GMT 2024

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

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

Back to the top