如何为生成的代码复制源代码文件夹结构

问题描述 投票:-1回答:1

我用Xtext创建了一个简单的DSL。我所有的源文件(“ 。src”)都在“ src”下的一组文件夹中。我希望在“ src-gen”内部创建生成的文件(“。obj”),但保留源文件的文件夹结构。

下面的(默认)代码输出同一文件夹(“ src-gen”)中的所有文件。

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {

  // Root node of parsing tree

  val Program prg = resource.allContents.filter(Program).next()

  // Compiled code

  var String code = prg.compile().toString()

  // change file extension

  val outName = ....

  // Generate output

  fsa.generateFile(outName, code)

  ...

如果文件A.src在src / one文件夹中,而B.src在src / two文件夹中,我希望在src-gen / one中创建A.obj,在src-gen / two中创建B.obj。

xtext
1个回答
0
投票

您可以使用resourcegetURI()来获取资源的uri。那么您可以使用该uri查找带有src的细分,然后采用以下细分来获取路径

© www.soinside.com 2019 - 2024. All rights reserved.