org.eclipse.xtext.generator.IGenerator Java Examples

The following examples show how to use org.eclipse.xtext.generator.IGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaSourceLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
	bind(Resource.Factory.class).to(JavaResource.Factory.class);
	bind(IResourceValidator.class).toInstance(IResourceValidator.NULL);
	bind(IGenerator.class).to(IGenerator.NullGenerator.class);
	bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
	bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class);
	bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class);
	bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class);
	bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class);
	bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java");
	bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME))
			.toInstance("org.eclipse.xtext.java.Java");
	bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class);
	bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader());
	bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class);
	bind(IResourceDescriptionsProvider.class)
			.toInstance((ResourceSet rs) -> ChunkedResourceDescriptions.findInEmfObject(rs));
}
 
Example #2
Source File: GeneratorTask.java    From joynr with Apache License 2.0 6 votes vote down vote up
public void printHelp(Log log) {
    IGenerator generator = executor.getGenerator();
    if (generator instanceof IJoynrGenerator) {
        IJoynrGenerator joynrGenerator = (IJoynrGenerator) generator;
        Set<String> parameters = joynrGenerator.supportedParameters();
        StringBuffer sb = new StringBuffer();
        sb.append("Supported configuration parameters by the generator: ");
        if (parameters != null && parameters.size() > 0) {
            for (String parameter : parameters) {
                sb.append(parameter + ",");
            }
            sb.deleteCharAt(sb.length() - 1);
        } else {
            sb.append("none");
        }
        log.info(sb.toString());
    } else {
        log.info("no additional information available for the provider generator");
    }
}
 
Example #3
Source File: Executor.java    From joynr with Apache License 2.0 5 votes vote down vote up
private IGenerator createGenerator(Injector injector) throws ClassNotFoundException, InstantiationException,
                                                      IllegalAccessException {
    String rootGenerator = arguments.getRootGenerator();
    Class<?> rootGeneratorClass = Class.forName(rootGenerator,
                                                true,
                                                Thread.currentThread().getContextClassLoader());
    Object templateRootInstance = rootGeneratorClass.newInstance();

    if (templateRootInstance instanceof IGenerator) {
        // This is a standard generator
        IGenerator generator = (IGenerator) templateRootInstance;
        if (generator instanceof IJoynrGenerator) {
            IJoynrGenerator joynrGenerator = (IJoynrGenerator) generator;
            if (joynrGenerator.getGeneratorModule() != null) {
                injector = injector.createChildInjector(joynrGenerator.getGeneratorModule());
            }
            injector.injectMembers(generator);
            joynrGenerator.setParameters(arguments.getParameter());
        } else {
            injector.injectMembers(generator);
        }
        return generator;
    } else {
        throw new IllegalStateException("Root generator \"" + "\" is not implementing interface \""
                + IGenerator.class.getName() + "\"");
    }

}
 
Example #4
Source File: AbstractGeneratorTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
protected void invokeGenerator(IGenerator generator,
                               String fileName,
                               String outputDirectory,
                               String... referencedResources) {
    final IFileSystemAccess fileSystemAccess = createFileSystemAccess(outputDirectory);

    final URI uri = URI.createFileURI(new File(fileName).getAbsolutePath());
    final Set<URI> uris = new HashSet<URI>();
    uris.add(uri);
    for (String refRes : referencedResources) {
        uris.add(URI.createFileURI(new File(refRes).getAbsolutePath()));
    }
    File file = new File(fileName);
    IUriProvider uriProvider = null;
    if (file.isDirectory()) {
        uriProvider = new FolderUriProvider(new HashSet<String>(Arrays.asList("fidl")), file);
    } else {
        uriProvider = new IUriProvider() {

            @Override
            public Iterable<URI> allUris() {
                return Arrays.asList(uris);
            }
        };
    }

    ModelStore modelStore = ModelStore.modelsIn(uriProvider);

    for (URI foundUri : uriProvider.allUris()) {
        final Resource r = modelStore.getResource(foundUri);
        generator.doGenerate(r, fileSystemAccess);
    }

}
 
Example #5
Source File: N4JSIdeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return N4JSCompositeGenerator.class;
}
 
Example #6
Source File: DefaultXbaseRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return JvmModelGenerator.class;
}
 
Example #7
Source File: ContentAssistTestLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return ContentAssistTestLanguageGenerator.class;
}
 
Example #8
Source File: BuilderTestLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return MyGenerator.class;
}
 
Example #9
Source File: GeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Set<Binding> getGuiceBindingsRt(Grammar grammar) {
	if (isGenerateStub(grammar))
		return new BindFactory().addTypeToType(IGenerator.class.getName(), getGeneratorName(grammar, getNaming())).getBindings();
	return Collections.emptySet();
}
 
Example #10
Source File: ContentAssistTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return ContentAssistTestLanguageGenerator.class;
}
 
Example #11
Source File: BuilderTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return MyGenerator.class;
}
 
Example #12
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.2
 * @deprecated use {@link #getGenerator2()} instead. 
 */
@Deprecated
public IGenerator getGenerator() {
	return generatorDelegate;
}
 
Example #13
Source File: CheckCfgRuntimeModule.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/** Creates a properties file in the .settings folder. {@inheritDoc} */
@Override
public Class<? extends IGenerator> bindIGenerator() {
  return CheckCfgGenerator.class;
}
 
Example #14
Source File: XtxtUMLRuntimeModule.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return XtxtUMLGenerator.class;
}
 
Example #15
Source File: AbstractSARLRuntimeModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends IGenerator> bindIGenerator() {
	return ExtraLanguageGeneratorSupport.class;
}
 
Example #16
Source File: Executor.java    From joynr with Apache License 2.0 4 votes vote down vote up
public IGenerator getGenerator() {
    return generator;
}