protected IFileSystemAccess2 getFileSystemAccess(final IProject project, final IProgressMonitor monitor) { EclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get(); access.setContext(project); access.setMonitor(monitor); OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); defaultOutput.setDescription("Output Folder"); defaultOutput.setOutputDirectory("./"); defaultOutput.setOverrideExistingResources(true); defaultOutput.setCreateOutputDirectory(true); defaultOutput.setCleanUpDerivedResources(false); defaultOutput.setSetDerivedProperty(false); defaultOutput.setKeepLocalHistory(false); HashMap<String, OutputConfiguration> outputConfigurations = new HashMap<String, OutputConfiguration>(); outputConfigurations.put(IFileSystemAccess.DEFAULT_OUTPUT, defaultOutput); access.setOutputConfigurations(outputConfigurations); return access; }
public String generate(final Resource res, final JvmDeclaredType type) { String _xblockexpression = null; { res.eSetDeliver(false); EList<EObject> _contents = res.getContents(); this.builder.<JvmDeclaredType>operator_add(_contents, type); res.eSetDeliver(true); final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess(); this.generator.doGenerate(res, fsa); Map<String, CharSequence> _files = fsa.getFiles(); String _replace = type.getIdentifier().replace(".", "/"); String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace); String _plus_1 = (_plus + ".java"); _xblockexpression = _files.get(_plus_1).toString(); } return _xblockexpression; }
@Before public void before() { try { final Path tmpPath = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value()); StringConcatenation _builder = new StringConcatenation(); _builder.append("tempFolder_"); UUID _randomUUID = UUID.randomUUID(); _builder.append(_randomUUID); final Path output = Files.createTempDirectory(tmpPath, _builder.toString()); final Path resource = Files.createFile(output.resolve(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME)); resource.toFile().deleteOnExit(); output.toFile().deleteOnExit(); final OutputConfiguration config = IterableExtensions.<OutputConfiguration>head(this.configProvider.getOutputConfigurations()); config.setOutputDirectory(output.toString()); Pair<String, OutputConfiguration> _mappedTo = Pair.<String, OutputConfiguration>of(IFileSystemAccess.DEFAULT_OUTPUT, config); this.fsa.setOutputConfigurations(Collections.<String, OutputConfiguration>unmodifiableMap(CollectionLiterals.<String, OutputConfiguration>newHashMap(_mappedTo))); this.fsa.setConverter(this.uriConverter); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
private void generateClassesForApp(IFileSystemAccess filesystem, List<Application> applications, Application application) { String projectName = getProjectName(applications, application); ApplicationElementList elements = getFieldData(application.getAttributes(), ApplicationElementList.class); for (ApplicationElement element : elements.getElements()) { if (isAllowedElement(element)) { String classPath = application.getName().replace(".", "/"); filesystem.generateFile(String.format("%s/src/main/java/%s/%s/%s.java", projectName, classPath, getSubClassPath(), element.getName()), retrieveElementTemplate(application, element)); } } }
public void doGenerate(final Resource input, final IFileSystemAccess fsa) { EList<EObject> _contents = input.getContents(); EObject _head = IterableExtensions.<EObject>head(_contents); final Model m = ((Model) _head); Assembly _assembly = m.getAssembly(); boolean _notEquals = (!Objects.equal(_assembly, null)); if (_notEquals) { final LinkedHashSet<Action> actions = new LinkedHashSet<Action>(); Assembly _assembly_1 = m.getAssembly(); this.collectActions(_assembly_1, actions); boolean _isEmpty = actions.isEmpty(); boolean _not = (!_isEmpty); if (_not) { final LinkedHashSet<MountedAssemblyItem> items = new LinkedHashSet<MountedAssemblyItem>(); Assembly _assembly_2 = m.getAssembly(); this.collectItems(_assembly_2, items); Assembly _assembly_3 = m.getAssembly(); String _name = _assembly_3.getName(); String _plus = ("3d/" + _name); String _plus_1 = (_plus + ".js"); CharSequence _generateJS = this.generateJS(actions, items); fsa.generateFile(_plus_1, _generateJS); } } }
public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { try { ResourceSetImpl _resourceSetImpl = new ResourceSetImpl(); final ResourceSetImpl rset = _resourceSetImpl; URI _uRI = resource.getURI(); URI _appendFileExtension = _uRI.appendFileExtension("xml"); final Resource xmlResource = rset.createResource(_appendFileExtension); EList<EObject> _contents = xmlResource.getContents(); EList<EObject> _contents_1 = resource.getContents(); EObject _head = IterableExtensions.<EObject>head(_contents_1); _contents.add(_head); xmlResource.save(Collections.EMPTY_MAP); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Before public void setup() throws Exception { temporaryOutputDirectory = Files.createTempDir(); temporaryOutputDirectory.deleteOnExit(); InvocationArguments arguments = new InvocationArguments(); arguments.setGenerationLanguage("java"); arguments.setModelPath("src/test/resources"); arguments.setOutputPath(temporaryOutputDirectory.getAbsolutePath()); Injector francaInjector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration() .createChildInjector(new AbstractModule() { @Override protected void configure() { 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()); }
@Override public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { TreeIterator<EObject> _allContents = resource.getAllContents(); Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents); Iterable<ExpressionsModel> _filter = Iterables.<ExpressionsModel>filter(_iterable, ExpressionsModel.class); final Procedure1<ExpressionsModel> _function = new Procedure1<ExpressionsModel>() { @Override public void apply(final ExpressionsModel it) { StringConcatenation _builder = new StringConcatenation(); URI _uRI = resource.getURI(); String _lastSegment = _uRI.lastSegment(); _builder.append(_lastSegment, ""); _builder.append(".evaluated"); String _interpretExpressions = ExpressionsGenerator.this.interpretExpressions(it); fsa.generateFile(_builder.toString(), _interpretExpressions); } }; IterableExtensions.<ExpressionsModel>forEach(_filter, _function); }
@Override public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { TreeIterator<EObject> _allContents = resource.getAllContents(); Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents); Iterable<Entity> _filter = Iterables.<Entity>filter(_iterable, Entity.class); final Procedure1<Entity> _function = new Procedure1<Entity>() { @Override public void apply(final Entity it) { StringConcatenation _builder = new StringConcatenation(); _builder.append("entities/"); String _name = it.getName(); _builder.append(_name, ""); _builder.append(".java"); CharSequence _compile = EntitiesGenerator.this.compile(it); fsa.generateFile(_builder.toString(), _compile); } }; IterableExtensions.<Entity>forEach(_filter, _function); }
@Override public void doGenerate(Resource input, IFileSystemAccess fsa) { if (isApplicableTo(input)) { String fileExtension = xpectAwareFileExtensionCalculator.getXpectAwareFileExtension(input.getURI()); for (ISubGenerator subgenerator : getSubGenerators(fileExtension)) { subgenerator.doGenerate(input, fsa); } } }
@Override protected List<String> getAllFolders() { Set<OutputConfiguration> outputConfigurations = outputConfigurationProvider.getOutputConfigurations(); String outputFolder = "src-gen"; for (OutputConfiguration outputConfiguration : outputConfigurations) { if (IFileSystemAccess.DEFAULT_OUTPUT.equals(outputConfiguration.getName())) { outputFolder = outputConfiguration.getOutputDirectory(); break; } } return ImmutableList.of(getModelFolderName(), outputFolder); }
@Override public void doGenerate(final Resource input, final IFileSystemAccess fsa) { EList<EObject> _contents = input.getContents(); for (final EObject obj : _contents) { this.internalDoGenerate(obj, fsa); } }
protected void _internalDoGenerate(final JvmDeclaredType type, final IFileSystemAccess fsa) { boolean _isDisabled = DisableCodeGenerationAdapter.isDisabled(type); if (_isDisabled) { return; } String _qualifiedName = type.getQualifiedName(); boolean _tripleNotEquals = (_qualifiedName != null); if (_tripleNotEquals) { String _replace = type.getQualifiedName().replace(".", "/"); String _plus = (_replace + ".java"); fsa.generateFile(_plus, this.generateType(type, this.generatorConfigProvider.get(type))); } }
public void internalDoGenerate(final EObject type, final IFileSystemAccess fsa) { if (type instanceof JvmDeclaredType) { _internalDoGenerate((JvmDeclaredType)type, fsa); return; } else if (type != null) { _internalDoGenerate(type, fsa); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(type, fsa).toString()); } }
@Override public void doGenerate(Resource input, IFileSystemAccess fsa) { if (input.getContents().isEmpty()) return; EObject root = input.getContents().get(0); if (!(root instanceof Model)) return; GenerateDirective generateDirective = ((Model) root).getGenerateDirective(); if (generateDirective != null) { fsa.generateFile(generateFileName(generateDirective), generateFileContents(generateDirective)); } }
@Override public Set<OutputConfiguration> getOutputConfigurations() { OutputConfiguration config = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); config.setOutputDirectory("src-gen"); if (useOutputPerSource) { SourceMapping sourceMapping = new OutputConfiguration.SourceMapping("src2"); sourceMapping.setOutputDirectory("src2-gen"); config.getSourceMappings().add(sourceMapping); config.setUseOutputPerSourceFolder(true); } return ImmutableSet.of(config); }
@Override public void doGenerate(final Resource input, final IFileSystemAccess fsa) { Iterable<Element> _filter = Iterables.<Element>filter(IteratorExtensions.<EObject>toIterable(input.getAllContents()), Element.class); for (final Element ele : _filter) { { if ((fsa instanceof IFileSystemAccess2)) { StringConcatenation _builder = new StringConcatenation(); String _name = ele.getName(); _builder.append(_name); _builder.append(".txt"); boolean _isFile = ((IFileSystemAccess2)fsa).isFile(_builder.toString()); if (_isFile) { StringConcatenation _builder_1 = new StringConcatenation(); String _name_1 = ele.getName(); _builder_1.append(_name_1); _builder_1.append(".txt"); ((IFileSystemAccess2)fsa).readTextFile(_builder_1.toString()); } } StringConcatenation _builder_2 = new StringConcatenation(); String _name_2 = ele.getName(); _builder_2.append(_name_2); _builder_2.append(".txt"); StringConcatenation _builder_3 = new StringConcatenation(); _builder_3.append("object "); String _name_3 = ele.getName(); _builder_3.append(_name_3); fsa.generateFile(_builder_2.toString(), _builder_3); } } }
@Override public void doGenerateStubs(IFileSystemAccess access, IResourceDescription description) { for (IEObjectDescription objectDesc : description.getExportedObjects()) { String javaStubSource = getJavaStubSource(objectDesc, description); if(javaStubSource != null) { String javaFileName = getJavaFileName(objectDesc); access.generateFile(javaFileName, javaStubSource); } } }
/** * Creates output configuration for regular generated files. * * @return output configuration */ private OutputConfiguration getDefaultConfig() { OutputConfiguration config = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); config.setDescription("Output configuration for generated classes"); config.setOverrideExistingResources(true); config.setOutputDirectory("src-gen"); return config; }
/** * @return a set of {@link OutputConfiguration} available for the generator */ public Set<OutputConfiguration> getOutputConfigurations() { OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); defaultOutput.setDescription("Output Folder"); defaultOutput.setOutputDirectory("./src-gen"); defaultOutput.setOverrideExistingResources(true); defaultOutput.setCreateOutputDirectory(true); defaultOutput.setCleanUpDerivedResources(true); defaultOutput.setSetDerivedProperty(true); return newHashSet(defaultOutput); }
private void testOutputFileNames(InMemoryFileSystemAccess fsa, String path) { assertEquals(6, fsa.getFiles().size()); assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.PADS_EXT)); assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.BOM_EXT)); assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.INFO_EXT)); assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.REFDES_EXT)); assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.EAGLE_EXT)); assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.NET_EXT)); }
private void testOutputFiles(InMemoryFileSystemAccess fsa, String expected, String actual) { assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.PADS_EXT), fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.PADS_EXT).toString()); assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.BOM_EXT), fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.BOM_EXT).toString()); assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.INFO_EXT), fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.INFO_EXT).toString()); assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.REFDES_EXT), fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.REFDES_EXT).toString()); assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.EAGLE_EXT), fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.EAGLE_EXT).toString()); assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.NET_EXT), fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.NET_EXT).toString()); }
@Override public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { EList<EObject> _contents = resource.getContents(); EObject _head = IterableExtensions.<EObject>head(_contents); this.createFiles(((Model) _head), fsa); this.mapMachine.clear(); }
public void createFiles(final Model model, final IFileSystemAccess fsa) { EList<MachineDecl> _machines = model.getMachines(); for (final MachineDecl machine : _machines) { String _name = machine.getName(); String _plus = (_name + ".dot"); CharSequence _dotCode = this.toDotCode(machine); fsa.generateFile(_plus, _dotCode); } }
/** * Method doGenerate() * * @see org.eclipse.xtext.generator.IGenerator#doGenerate(org.eclipse.emf.ecore.resource.Resource, * org.eclipse.xtext.generator.IFileSystemAccess) */ @Override public void doGenerate(final Resource input, final IFileSystemAccess fsa) { // TODO: Deactivated for the moment [DEACTIVATION OF // META_INFORMATION] // final GamlResource resource = (GamlResource) input; // final String fileName = getFilenameFor(resource); // final String contents = getContentsFor(resource); // fsa.generateFile(fileName, GamlOutputConfigurationProvider.META, // contents); }
public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { String _className = this.className(resource); String _plus = (_className + "_output.all"); EList<EObject> _contents = resource.getContents(); EObject _head = IterableExtensions.<EObject>head(_contents); CharSequence _aLLcode = this.toALLcode(((Root) _head)); fsa.generateFile(_plus, _aLLcode); }
public Set<OutputConfiguration> getOutputConfigurations() { OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); defaultOutput.setDescription("Output Folder"); defaultOutput.setOutputDirectory("./application-gen"); defaultOutput.setOverrideExistingResources(true); defaultOutput.setCreateOutputDirectory(true); defaultOutput.setCleanUpDerivedResources(true); defaultOutput.setSetDerivedProperty(true); defaultOutput.setKeepLocalHistory(true); return newHashSet(defaultOutput); }
@Test public void doGenerate() throws CoreException { Resource resource = createMock(Resource.class); IFileSystemAccess fsa = createMock(IFileSystemAccess.class); GrammarResource grammarResource = createMock(GrammarResource.class); URI resourceURI = createMock(URI.class); IFile file = createMock(IFile.class); ToolOptionsProvider optionsProvider = createMock(ToolOptionsProvider.class); ToolOptions options = createMock(ToolOptions.class); ILaunchManager launchManager = createMock(ILaunchManager.class); IPath fileFullPath = createMock(IPath.class); ILaunchConfigurationType configType = createMock(ILaunchConfigurationType.class); CodeGeneratorListener listener = createMock(CodeGeneratorListener.class); Set<CodeGeneratorListener> listeners = newHashSet(listener); ToolRunner toolRunner = createMock(ToolRunner.class); Console console = createMock(Console.class); expect(grammarResource.fileFrom(resource)).andReturn(file); expect(optionsProvider.options(file)).andReturn(options); listener.beforeProcess(file, options); toolRunner.run(file, options, console); listener.afterProcess(file, options); Object[] mocks = {resource, fsa, grammarResource, resourceURI, file, optionsProvider, options, fileFullPath, configType, listener, toolRunner, console }; replay(mocks); Antlr4Generator generator = newAntlr4Generator(console, launchManager, listeners, optionsProvider, toolRunner, grammarResource); generator.doGenerate(resource, fsa); verify(mocks); }
/** * The constructor calls the needed data filtered by a * concrete element-filter. * @param filter - represents a base filter which can be substituted by a specific * subclass that filters a particular set of elements. */ public ProjectGenerationStep(final ElementFilter filter, final IFileSystemAccess newFsa) { Object _filterData = filter.<Object>filterData(); String _name = ((SensorInterface) _filterData).getName(); this.projectName = _name; this.fsa = newFsa; }
public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { System.out.println("Starting XMI generation..."); final Registry registery = Registry.INSTANCE; final Map<String,Object> map = registery.getExtensionToFactoryMap(); XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); final XMIResourceFactoryImpl xmiRes = _xMIResourceFactoryImpl; map.put(LanguageGenerator.LANGUAGE_EXTENSION, xmiRes); ResourceSetImpl _resourceSetImpl = new ResourceSetImpl(); final ResourceSetImpl resSet = _resourceSetImpl; String _plus = (LanguageGenerator.GEN_PATH + File.separator); String _plus_1 = (_plus + LanguageGenerator.FILE_NAME); final URI uri = URI.createURI(_plus_1); final Resource res = resSet.createResource(uri); String _plus_2 = ("Resource created at \"" + LanguageGenerator.GEN_PATH); String _plus_3 = (_plus_2 + File.separator); String _plus_4 = (_plus_3 + LanguageGenerator.FILE_NAME); String _plus_5 = (_plus_4 + "\""); System.out.println(_plus_5); EList<EObject> _contents = res.getContents(); EList<EObject> _contents_1 = resource.getContents(); _contents.addAll(_contents_1); try { res.save(Collections.EMPTY_MAP); } catch (final Throwable _t) { if (_t instanceof IOException) { final IOException e = (IOException)_t; e.printStackTrace(); } else { throw Exceptions.sneakyThrow(_t); } } System.out.println("Generation completed"); }
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(""); } 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()); } }); this.outputFileSystem = injector.getInstance(IFileSystemAccess.class); this.generator = createGenerator(injector); }
public static void createFileSystemAccess(IFileSystemAccess fileSystemAccess, String outputDirectory) { if (!(fileSystemAccess instanceof AbstractFileSystemAccess)) { throw new IllegalStateException("Guice Module configuration wrong: IFileSystemAccess.class shall be binded to a sub type of org.eclipse.xtext.generator.AbstractFileSystemAccess"); } ((AbstractFileSystemAccess) fileSystemAccess).setOutputPath(outputDirectory); ((AbstractFileSystemAccess) fileSystemAccess).getOutputConfigurations() .get(IFileSystemAccess.DEFAULT_OUTPUT) .setCreateOutputDirectory(true); }
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(Sets.newHashSet("fidl"), file); } else { uriProvider = new IUriProvider() { @Override public Iterable<URI> allUris() { return Lists.newArrayList(uris); } }; } ModelStore modelStore = ModelStore.modelsIn(uriProvider); for (URI foundUri : uriProvider.allUris()) { final Resource r = modelStore.getResource(foundUri); generator.doGenerate(r, fileSystemAccess); } }
protected IFileSystemAccess createFileSystemAccess(String outputDirectory) { assertTrue(fileSystemAccess instanceof AbstractFileSystemAccess); ((AbstractFileSystemAccess) fileSystemAccess).setOutputPath(outputDirectory); ((AbstractFileSystemAccess) fileSystemAccess).getOutputConfigurations() .get(IFileSystemAccess.DEFAULT_OUTPUT) .setCreateOutputDirectory(true); return fileSystemAccess; }
@Override protected void internalDoGenerate(Resource resource, GeneratorOption[] options, IFileSystemAccess fsa) { if (!(resource instanceof N4JSResource)) { if (IN4JSProject.N4MF_MANIFEST.equals(resource.getURI().lastSegment())) { return; } throw new IllegalArgumentException("Given resource is not an N4JSResource. " + resource); } final N4JSResource resourceCasted = (N4JSResource) resource; if (resourceCasted.getModule().isStaticPolyfillModule()) { return; // do not transpile static polyfill modules (i.e. the fillers) } Measurement measurement = this.collector.getMeasurement(resource.getURI().toString()); /* * In addition to here, check for cancellation is done also on file-emit boundaries, see fsa.generateFile(). */ CancelIndicator monitor = ciExtractor.extractCancelIndicator(fsa); // if the transpile-conditions are all met, then transpile: if (shouldBeCompiled(resource, monitor)) { final String compiledFileExtension = getCompiledFileExtension(resource); final String filename = getTargetFileName(resource, compiledFileExtension); final String sourceMapFileExtension = getCompiledFileSourceMapExtension(resource); final String sourceMapFileName = getTargetFileName(resource, sourceMapFileExtension); // used within the file-content to refer to sibling-file: final String simpleSourceMapFileName = new File(sourceMapFileName).toPath().getFileName().toString(); final String simpleCompiledFileName = new File(filename).toPath().getFileName().toString(); // the next two variables store the navigation-prefix to get to the sources final Path relativeNavigationToSrc = calculateNavigationFromOutputToSourcePath(fsa, getCompilerID(), resourceCasted); final Path explicitNavigationToSrc = Paths.get("/sources"); boolean useExplicitSourceRef = true; // true use explicitNavigationToSrc | false use relativeNavigationToSrc boolean createSourceMap = true; if (filename != null) { final EObject root = rootElement(resource); if (root != null) { final Writer buffCode = new StringWriter(); Optional<SourceMapInfo> optSourceMapData = Optional.absent(); if (createSourceMap) { SourceMapInfo sourceMapDataInstance = ecmaScriptTranspiler.new SourceMapInfo(); sourceMapDataInstance.sourceMapBuff = new StringWriter(); sourceMapDataInstance.simpleSourceMapFileName = simpleSourceMapFileName; sourceMapDataInstance.simpleCompiledFileName = simpleCompiledFileName; sourceMapDataInstance.isExplicitSourceRef = useExplicitSourceRef; sourceMapDataInstance.explicitNavigationToSrc = explicitNavigationToSrc; sourceMapDataInstance.n4jsFilePath = relativeNavigationToSrc .resolve(resourceCasted.getURI().lastSegment()).toString(); sourceMapDataInstance.sourceMapFileExtension = sourceMapFileExtension; optSourceMapData = Optional.of(sourceMapDataInstance); } ecmaScriptTranspiler.transpile(resourceCasted, options, buffCode, optSourceMapData); fsa.generateFile(filename, COMPILER_ID, buffCode.toString()); if (createSourceMap) { fsa.generateFile(sourceMapFileName, COMPILER_ID, optSourceMapData.get().sourceMapBuff.toString()); } } } } measurement.end(); }
public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { }
public GeneradorWeb(final Resource resource, final IFileSystemAccess fsa) { this.resource = resource; this.fsa = fsa; }
public GeneradorTexto(final Resource resource, final IFileSystemAccess fsa) { this.resource = resource; this.fsa = fsa; }