|
|
|
Re: How to decide which generator to use [message #757585 is a reply to message #757583] |
Sat, 19 November 2011 21:48 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.04484 seconds