How to get "Generator output path" in the generator
Hello, community!
I have the following line in the generated concept class:
class $[name]{
.......
String content = new String(Files.readAllBytes(Paths.get("$[Myfile.txt]")));
.........
}
How can I get "Generator output path" for the module in the property macro $[Myfile.txt]?
Please sign in to leave a comment.
Hi,
I haven't tried it, but there exists an API that suggests to get the output path: SolutionDescriptor.getOutputPath()
So, if you have the solution that contains the model that is generated, you can ask for its ModuleDescriptor and cast it to a SolutionDescriptor.
Something like:
It is important that you get the original module. In the context of generation, something like "node.model.module" will likely yield "null", since the generator operates on a transient model. In other words, I am not 100% certain where you would use this API in the context of a transformation to reliably receive the output path of your original model.
Thanks for answer,
Yes, node.model.module - transient module.
Maybe I can create facet and calculate gen paths for every model. How can I pass that paths in the generator and use them?
I'm also looking for the generator output path (or any path for the model or solution module). I think I can use the code in sampleFacet project to find out the model paths and save it as a property in the facet, but don't know how to retrieve this in the generator code. I need the path in the CopyOutcome annotation.
This document has a clear explanation of how to pass parameters to the generator.
https://mps-support.jetbrains.com/hc/en-us/community/posts/206611835/comments/205727955