Java Code Examples for org.eclipse.xtext.generator.JavaIoFileSystemAccess

The following examples show how to use org.eclipse.xtext.generator.JavaIoFileSystemAccess. These examples are extracted from open source projects. 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 Project: xtext-extras   Source File: StandaloneBuilder.java    License: 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 Project: xtext-xtend   Source File: XtendBatchCompiler.java    License: 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 Project: xtext-extras   Source File: StandaloneBuilder.java    License: 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 Project: xtext-xtend   Source File: XtendBatchCompiler.java    License: 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 Project: joynr   Source File: AbstractJoynrTSGeneratorTest.java    License: 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 Project: joynr   Source File: AbstractJoynrJavaGeneratorTest.java    License: 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 Project: joynr   Source File: Executor.java    License: 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
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example 9
protected Class<JavaIoFileSystemAccess> bindJavaIoFileSystemAccess() {
	return JavaIoFileSystemAccess.class;
}
 
Example 10
Source Project: xtext-extras   Source File: LanguageAccess.java    License: 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 Project: xtext-extras   Source File: StandaloneBuilder.java    License: Eclipse Public License 2.0 4 votes vote down vote up
protected JavaIoFileSystemAccess configureFileSystemAccess(JavaIoFileSystemAccess fsa, LanguageAccess language) {
	return fsa;
}
 
Example 12
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example 13
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example 14
public Class<? extends AbstractFileSystemAccess2> bindAbstractFileSystemAccess2() {
	return JavaIoFileSystemAccess.class;
}
 
Example 15
Source Project: joynr   Source File: AbstractJoynrCppGeneratorTest.java    License: 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());
}