org.eclipse.xtext.generator.JavaIoFileSystemAccess Java Examples

The following examples show how to use org.eclipse.xtext.generator.JavaIoFileSystemAccess. 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: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void generate(List<Resource> sourceResources) {
	GeneratorContext context = new GeneratorContext();
	context.setCancelIndicator(CancelIndicator.NullImpl);
	for (Resource it : sourceResources) {
		LOG.info("Starting generator for input: '" + it.getURI().lastSegment() + "'");
		registerCurrentSource(it.getURI());
		LanguageAccess access = languageAccess(it.getURI());
		JavaIoFileSystemAccess fileSystemAccess = getFileSystemAccess(access);
		if (isWriteStorageResources()) {
			if (it instanceof StorageAwareResource) {
				IResourceStorageFacade resourceStorageFacade = ((StorageAwareResource) it)
						.getResourceStorageFacade();
				if (resourceStorageFacade != null) {
					resourceStorageFacade.saveResource((StorageAwareResource) it, fileSystemAccess);
				}
			}
		}
		access.getGenerator().generate(it, fileSystemAccess, context);
	}
}
 
Example #2
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void generateJavaFiles(ResourceSet resourceSet) {
	JavaIoFileSystemAccess javaIoFileSystemAccess = javaIoFileSystemAccessProvider.get();
	javaIoFileSystemAccess.setOutputPath(outputPath);
	javaIoFileSystemAccess.setWriteTrace(writeTraceFiles);

	GeneratorContext context = new GeneratorContext();
	context.setCancelIndicator(CancelIndicator.NullImpl);
	for (Resource resource : newArrayList(resourceSet.getResources())) {
		if (isSourceFile(resource)) {
			if (isWriteStorageFiles()) {
				StorageAwareResource storageAwareResource = (StorageAwareResource)resource;
				storageAwareResource.getResourceStorageFacade().saveResource(storageAwareResource, javaIoFileSystemAccess);
			}
			generator.generate(resource, javaIoFileSystemAccess, context);
		}
	}
}
 
Example #3
Source File: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private JavaIoFileSystemAccess getFileSystemAccess(LanguageAccess language) {
	JavaIoFileSystemAccess fsa = configuredFsas.get(language);
	if (fsa == null) {
		fsa = language.createFileSystemAccess(new File(baseDir));
		fsa = this.configureFileSystemAccess(fsa, language);
		configuredFsas.put(language, fsa);
	}
	return fsa;
}
 
Example #4
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected File createStubs(ResourceSet resourceSet) {
	File outputDirectory = createTempDir("stubs");
	JavaIoFileSystemAccess fileSystemAccess = javaIoFileSystemAccessProvider.get();
	fileSystemAccess.setOutputPath(outputDirectory.toString());
	List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
	for (Resource resource : resources) {
		IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
		stubGenerator.doGenerateStubs(fileSystemAccess, description);
	}
	return outputDirectory;
}
 
Example #5
Source File: AbstractJoynrTSGeneratorTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
public void setup(boolean generateProxy, boolean generateProvider) throws Exception {
    temporaryOutputDirectory = Files.createTempDirectory(null).toFile();
    temporaryOutputDirectory.deleteOnExit();
    InvocationArguments arguments = new InvocationArguments();
    arguments.setGenerationLanguage("javascript");
    arguments.setModelPath("src/test/resources");
    arguments.setOutputPath(temporaryOutputDirectory.getAbsolutePath());
    if (generateProxy && !generateProvider) {
        arguments.setTarget("proxy");
    } else if (!generateProxy && generateProvider) {
        arguments.setTarget("provider");
    }

    Injector francaInjector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration()
                                                            .createChildInjector(new AbstractModule() {

                                                                @Override
                                                                protected void configure() {
                                                                    bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE))
                                                                                  .to(true);
                                                                    bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_PACKAGEWITHVERSION))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_NAMEWITHVERSION))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named("generateProxyCode"))
                                                                                  .to(arguments.getGenerateProxyCode());
                                                                    bindConstant().annotatedWith(Names.named("generateProviderCode"))
                                                                                  .to(arguments.getGenerateProviderCode());
                                                                    bind(IFileSystemAccess.class).to(JavaIoFileSystemAccess.class);
                                                                }
                                                            });
    francaInjector.injectMembers(this);
    generator = new JoynrJSGenerator();
    Injector injector = francaInjector.createChildInjector(generator.getGeneratorModule());
    injector.injectMembers(this);
    injector.injectMembers(generator);
    FileSystemAccessUtil.createFileSystemAccess(outputFileSystem, arguments.getOutputPath());
}
 
Example #6
Source File: AbstractJoynrJavaGeneratorTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
public void setup(boolean generateProxy, boolean generateProvider) throws Exception {
    temporaryOutputDirectory = Files.createTempDirectory(null).toFile();
    temporaryOutputDirectory.deleteOnExit();
    InvocationArguments arguments = new InvocationArguments();
    arguments.setGenerationLanguage("java");
    arguments.setModelPath("src/test/resources");
    arguments.setOutputPath(temporaryOutputDirectory.getAbsolutePath());
    if (generateProxy && !generateProvider) {
        arguments.setTarget("proxy");
    } else if (!generateProxy && generateProvider) {
        arguments.setTarget("provider");
    }

    Injector francaInjector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration()
                                                            .createChildInjector(new AbstractModule() {

                                                                @Override
                                                                protected void configure() {
                                                                    bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE))
                                                                                  .to(true);
                                                                    bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_PACKAGEWITHVERSION))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_NAMEWITHVERSION))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named("generateProxyCode"))
                                                                                  .to(arguments.getGenerateProxyCode());
                                                                    bindConstant().annotatedWith(Names.named("generateProviderCode"))
                                                                                  .to(arguments.getGenerateProviderCode());
                                                                    bind(IFileSystemAccess.class).to(JavaIoFileSystemAccess.class);
                                                                }
                                                            });
    francaInjector.injectMembers(this);
    generator = new JoynrJavaGenerator();
    Injector injector = francaInjector.createChildInjector(generator.getGeneratorModule());
    injector.injectMembers(this);
    injector.injectMembers(generator);
    FileSystemAccessUtil.createFileSystemAccess(outputFileSystem, arguments.getOutputPath());
}
 
Example #7
Source File: Executor.java    From joynr with Apache License 2.0 5 votes vote down vote up
public Executor(final InvocationArguments arguments) throws ClassNotFoundException,
                                                     InstantiationException,
                                                     IllegalAccessException {
    arguments.checkArguments();
    this.arguments = arguments;

    // Get an injector and inject into the current instance
    Injector francaInjector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration();

    // Use a child injector that contains configuration parameters passed to this Executor
    Injector injector = francaInjector.createChildInjector(new AbstractModule() {
        @Override
        protected void configure() {
            bind(IFileSystemAccess.class).to(JavaIoFileSystemAccess.class);
            String generationId = arguments.getGenerationId();
            if (generationId != null) {
                bindConstant().annotatedWith(Names.named("generationId")).to(generationId);
            } else {
                // Guice does not allow null binding - use an empty string to show there is no generationId
                bindConstant().annotatedWith(Names.named("generationId")).to("");
            }
            bindConstant().annotatedWith(Names.named("generateProxyCode")).to(arguments.getGenerateProxyCode());
            bindConstant().annotatedWith(Names.named("generateProviderCode"))
                          .to(arguments.getGenerateProviderCode());

            bind(Boolean.class).annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE))
                               .toInstance(arguments.generate());
            bind(Boolean.class).annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN))
                               .toInstance(arguments.clean());
            bind(Boolean.class).annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_PACKAGEWITHVERSION))
                               .toInstance(arguments.addVersionToPackage());
            bind(Boolean.class).annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_NAMEWITHVERSION))
                               .toInstance(arguments.addVersionToName());
        }
    });
    this.outputFileSystem = injector.getInstance(IFileSystemAccess.class);
    this.generator = createGenerator(injector);
}
 
Example #8
Source File: DefaultXbaseRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example #9
Source File: StandaloneBuilderModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Class<JavaIoFileSystemAccess> bindJavaIoFileSystemAccess() {
	return JavaIoFileSystemAccess.class;
}
 
Example #10
Source File: LanguageAccess.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public JavaIoFileSystemAccess createFileSystemAccess(final File baseDir) {
	JavaIoFileSystemAccess fsa = resourceServiceProvider.get(JavaIoFileSystemAccess.class);
	configureFileSystemAccess(baseDir, fsa);
	return fsa;
}
 
Example #11
Source File: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected JavaIoFileSystemAccess configureFileSystemAccess(JavaIoFileSystemAccess fsa, LanguageAccess language) {
	return fsa;
}
 
Example #12
Source File: BuilderTestLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example #13
Source File: BuilderTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example #14
Source File: LangATestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example #15
Source File: AbstractJoynrCppGeneratorTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
public void setup(boolean generateProxy, boolean generateProvider) throws Exception {
    temporaryOutputDirectory = Files.createTempDirectory(null).toFile();
    temporaryOutputDirectory.deleteOnExit();
    InvocationArguments arguments = new InvocationArguments();
    arguments.setGenerationLanguage("cpp");
    arguments.setModelPath("src/test/resources");
    arguments.setOutputPath(temporaryOutputDirectory.getAbsolutePath());
    if (generateProxy && !generateProvider) {
        arguments.setTarget("proxy");
    } else if (!generateProxy && generateProvider) {
        arguments.setTarget("provider");
    }

    Injector francaInjector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration()
                                                            .createChildInjector(new AbstractModule() {

                                                                @Override
                                                                protected void configure() {
                                                                    bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE))
                                                                                  .to(true);
                                                                    bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_PACKAGEWITHVERSION))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_NAMEWITHVERSION))
                                                                                  .to(false);
                                                                    bindConstant().annotatedWith(Names.named("generationId"))
                                                                                  .to("5");
                                                                    bindConstant().annotatedWith(Names.named("generateProxyCode"))
                                                                                  .to(arguments.getGenerateProxyCode());
                                                                    bindConstant().annotatedWith(Names.named("generateProviderCode"))
                                                                                  .to(arguments.getGenerateProviderCode());
                                                                    bind(IFileSystemAccess.class).to(JavaIoFileSystemAccess.class);
                                                                }
                                                            });
    francaInjector.injectMembers(this);
    generator = new JoynrCppGenerator();
    Injector injector = francaInjector.createChildInjector(generator.getGeneratorModule());
    injector.injectMembers(this);
    injector.injectMembers(generator);
    FileSystemAccessUtil.createFileSystemAccess(outputFileSystem, arguments.getOutputPath());
}