Reputation: 2453
I want to use the script-name in the generator to create the corresponding java file. For example if my script file would be "WordCount.script" I want to create a "WordCount.java" file. I found out the previous versions exposed this via "resource.className" but it did not work for 2.3.1.
override void doGenerate(...
fsa.generateFile(magic_here + ".java", compile...)
Upvotes: 2
Views: 934
Reputation: 999
You can access the normalized URI for your Resource using ECoreUtil2. For example;
import static extension org.eclipse.xtext.EcoreUtil2.*
....
override void doGenerate(Resource input...
fsa.generateFile(input.normalizedURI.lastSegment + ".java", compile...)
Or, if you want an absolute path, you can leave off the lastSegment
. You may want to strip the filename off the end (".mydsl" for example) before generation, such as in:
fsa.generateFile(input.normalizedURI.replace(".mydsl", ".java), compile...
Whatever suits your use case!
Upvotes: 4
Reputation: 373
Here is an example:
fsa.generateFile(
"src"+"/"+"com"+"/"+"stackoverflow"+"/"+"magic"+"/"+ //package
"more_magic"+".java", //class name
compile...)
The package will be in the src folder and will be 'com.stackoverflow.magic' You will only see it as a package once you import the files into a project.
Upvotes: 0
Reputation: 6729
The resource has a property URI that encapsulates the name of the file. You may want to access the #lastSegment of it to compute the name of the Java file.
Upvotes: 0