How to decide which generator to use [message #757455] |
Fri, 18 November 2011 08:48  |
Eclipse User |
|
|
|
hi,
I have 2 generators and everything works fine.
But how can I decicde which generator should be taken,
when I start the new Eclipse instance?
first generator: My first generator produces a swing gui.
second generator: My second generator produces a GWT gui.
(The problem is, that gwt needs its own project file..)
So when I try the run as - .- always the first generator is executed in the
new eclipse instance.
Thanks in advance.
regards,
jens
|
|
|
|
|
Re: How to decide which generator to use [message #757585 is a reply to message #757583] |
Sat, 19 November 2011 16:48  |
Eclipse User |
|
|
|
Hi,
what about sublassing org.eclipse.xtext.builder.BuilderParticipant
(which has an igenerator injected)
and inject 2 igenerators there
public class JensBuilderParticipant extends BuilderParticipant {
@Inject @Named("A") IGenerator genA;
@Inject @Named("B") IGenerator genB;
@Inject
private IResourceServiceProvider resourceServiceProvider;
@Override
protected void handleChangedContents(Delta delta, IBuildContext context, EclipseResourceFileSystemAccess2 fileSystemAccess) throws CoreException {
if (!resourceServiceProvider.canHandle(delta.getUri()))
return;
// TODO: we will run out of memory here if the number of deltas is large enough
Resource resource = context.getResourceSet().getResource(delta.getUri(), true);
if (shouldGenerate(resource, context)) {
try {
boolean a = true; //read from prefs or whatever
boolean b = true; //read from prefs or whatever
if (a) {
genA.doGenerate(resource, fileSystemAccess);
}
if (b) {
genB.doGenerate(resource, fileSystemAccess);
}
} catch (RuntimeException e) {
if (e.getCause() instanceof CoreException) {
throw (CoreException) e.getCause();
}
throw e;
}
}
}
}
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
public void configureIGenerator(Binder binder) {
binder.bind(IGenerator.class).annotatedWith(Names.named("A")).to(MyDslGenerator.class);
binder.bind(IGenerator.class).annotatedWith(Names.named("B")).to(AnotherGenerator.class);
}
}
public class MyDslUiModule extends org.xtext.example.mydsl.ui.AbstractMyDslUiModule {
public MyDslUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
@Override
public Class<? extends IXtextBuilderParticipant> bindIXtextBuilderParticipant() {
return JensBuilderParticipant.class;
}
}
or (1)
public class StupidGenerator implements IGenerator {
@Inject MyDslGenerator genA;
@Inject AnotherGenerator genB;
@Override
public void doGenerate(Resource input, IFileSystemAccess fsa) {
boolean a = true; //read from prefs or whatever
boolean b = true; //read from prefs or whatever
if (a) {
genA.doGenerate(input, fsa);
}
if (b) {
genB.doGenerate(input, fsa);
}
}
}
~Christian
|
|
|
Powered by
FUDForum. Page generated in 0.08836 seconds