'How do I save a file using Xtend? (from Xtext project)
Where does Xtend saves the file generated by
fsa.generateFile('hi.txt', 'Write something in the file');" ?
Thank you.
My application: I run my xtext project as an Eclipse application. Then save it in the runtime-EclipseXtext folder.
I want know to automatically create a new file, let's say "hi.txt" from Xtend.
Inside se.gu.xtext.mydsl.generator folder, I have the MyDslGenerator.xtend file:
class MyDslGenerator extends AbstractGenerator {
@Inject extension IQualifiedNameProvider //we need the name to create a file, so this helps provide a qualified name
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
fsa.generateFile('hi.txt', 'Write something in the file');
}
}
My xtext file looks like:
grammar se.gu.xtext.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate mydsl "www.xtext.gu.se/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
ProblemSpecifications returns ProblemSpecifications:
'problem' 'specifications'
...
and my file explorer:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

