[Resolved] XText Generator fails, how to debug? [message #1069590] |
Tue, 16 July 2013 07:45 |
Sven Kasten 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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03168 seconds