Java Code Examples for org.eclipse.xtext.generator.IFileSystemAccess2#generateFile()
The following examples show how to use
org.eclipse.xtext.generator.IFileSystemAccess2#generateFile() .
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: ManifestAccess.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public void writeTo(final IFileSystemAccess2 fileSystemAccess) { try { if ((fileSystemAccess != null)) { CharSequence _content = this.getContent(); StringBuffer _stringBuffer = new StringBuffer(_content); final String contentToWrite = MergeableManifest2.make512Safe(_stringBuffer, this.lineDelimiter); byte[] _bytes = contentToWrite.getBytes("UTF-8"); ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_bytes); final MergeableManifest2 mergeableManifest = new MergeableManifest2(_byteArrayInputStream); mergeableManifest.setLineDelimiter(this.lineDelimiter); ByteArrayOutputStream bout = new ByteArrayOutputStream(); mergeableManifest.write(bout); String _path = this.getPath(); byte[] _byteArray = bout.toByteArray(); ByteArrayInputStream _byteArrayInputStream_1 = new ByteArrayInputStream(_byteArray); fileSystemAccess.generateFile(_path, _byteArrayInputStream_1); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 2
Source File: IndexTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public void doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { TreeIterator<EObject> iter = input.getAllContents(); while (iter.hasNext()) { EObject e = iter.next(); if (e instanceof Entity) { Entity entity = (Entity) e; StringConcatenation builder = new StringConcatenation(); builder.append("Hello "); builder.append(entity.getName()); builder.append("!"); builder.newLineIfNotEmpty(); fsa.generateFile(entity.getName() + ".txt", builder); } } }
Example 3
Source File: PyGenerator.java From sarl with Apache License 2.0 | 6 votes |
/** Generate the Python package files. * * <p>This function generates the "__init__.py" files for all the packages. * * @param name the name of the generated type. * @param lineSeparator the line separator. * @param context the generation context. */ protected void writePackageFiles(QualifiedName name, String lineSeparator, IExtraLanguageGeneratorContext context) { final IFileSystemAccess2 fsa = context.getFileSystemAccess(); final String outputConfiguration = getOutputConfigurationName(); QualifiedName libraryName = null; for (final String segment : name.skipLast(1).getSegments()) { if (libraryName == null) { libraryName = QualifiedName.create(segment, LIBRARY_FILENAME); } else { libraryName = libraryName.append(segment).append(LIBRARY_FILENAME); } final String fileName = toFilename(libraryName); if (!fsa.isFile(fileName)) { final String content = PYTHON_FILE_HEADER + lineSeparator + getGenerationComment(context) + lineSeparator + LIBRARY_CONTENT; if (Strings.isEmpty(outputConfiguration)) { fsa.generateFile(fileName, content); } else { fsa.generateFile(fileName, outputConfiguration, content); } } libraryName = libraryName.skipLast(1); } }
Example 4
Source File: StatemachineGenerator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) { String _className = this.className(resource); String _plus = (_className + ".java"); EObject _head = IterableExtensions.<EObject>head(resource.getContents()); fsa.generateFile(_plus, this.toJavaCode(((Statemachine) _head))); }
Example 5
Source File: NoJdtTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { @Override public String apply(Greeting greeting) { return greeting.getName(); } }); String fileName = resource.getURI().lastSegment(); if(fileName == null) fileName = "greetings"; fsa.generateFile(fileName+".txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example 6
Source File: TracingSugar.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * Use to generate a file based on generator node. */ public void generateTracedFile(IFileSystemAccess2 fsa, String path, CompositeGeneratorNode rootNode) { GeneratorNodeProcessor.Result result = processor.process(rootNode); fsa.generateFile(path, result); }
Example 7
Source File: TestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) { String _scheme = fsa.getURI("").scheme(); boolean _equals = Objects.equal(_scheme, "inmemory"); if (_equals) { return; } List<TypeDeclaration> _list = IteratorExtensions.<TypeDeclaration>toList(Iterators.<TypeDeclaration>filter(resource.getAllContents(), TypeDeclaration.class)); for (final TypeDeclaration type : _list) { String _name = type.getName(); String _plus = (_name + ".java"); StringConcatenation _builder = new StringConcatenation(); _builder.append("public class "); String _name_1 = type.getName(); _builder.append(_name_1); _builder.append(" {"); _builder.newLineIfNotEmpty(); { Iterable<Property> _filter = Iterables.<Property>filter(type.getMembers(), Property.class); for(final Property p : _filter) { _builder.append("\t"); _builder.append("private "); String _java = this.toJava(p.getType()); _builder.append(_java, "\t"); _builder.append(" "); String _name_2 = p.getName(); _builder.append(_name_2, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("public void set"); String _firstUpper = StringExtensions.toFirstUpper(p.getName()); _builder.append(_firstUpper, "\t"); _builder.append("("); String _java_1 = this.toJava(p.getType()); _builder.append(_java_1, "\t"); _builder.append(" "); String _name_3 = p.getName(); _builder.append(_name_3, "\t"); _builder.append(") {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("this."); String _name_4 = p.getName(); _builder.append(_name_4, "\t\t"); _builder.append(" = "); String _name_5 = p.getName(); _builder.append(_name_5, "\t\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("public "); String _java_2 = this.toJava(p.getType()); _builder.append(_java_2, "\t"); _builder.append(" get"); String _firstUpper_1 = StringExtensions.toFirstUpper(p.getName()); _builder.append(_firstUpper_1, "\t"); _builder.append("() {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("return this."); String _name_6 = p.getName(); _builder.append(_name_6, "\t\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); } } _builder.append("}"); _builder.newLine(); fsa.generateFile(_plus, _builder); } }
Example 8
Source File: TextFileAccess.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void writeTo(IFileSystemAccess2 fileSystemAccess) { if (fileSystemAccess != null) { fileSystemAccess.generateFile(path, getContent()); } }
Example 9
Source File: BinaryFileAccess.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void writeTo(IFileSystemAccess2 fileSystemAccess) { if (fileSystemAccess != null) { fileSystemAccess.generateFile(path, new ByteArrayInputStream(internalContents)); } }