Xtext从验证器获取项目根目录

Her*_*rsh 6 grammar xtext xtend

我需要在Xtext项目中验证特定文件的存在.该文件具有与验证对象类似的路径,但具有与其他根目录类似的路径,例如:

$ projPath/src目录/ DIR1/DIR2/ValidatedFile.src

$ projPath /资源/ DIR1/DIR2/SchoudBeExistFile.src

在validate函数中,我只使用相对路径(/src/dir1/dir2/ValidatedFile.src)获取资源.但我不知道项目路径,所以我无法检查存在的/resources/dir1/dir2/SchoudBeExistFile.src.

你能帮我找一下验证函数中的绝对项目路径吗? @Check def checkExternalFileExistance(MyType my) { val myTypeFullPath = ?? val projectPath = ?? }

谢谢

更新: 解决方法是通过在xtext项目中添加org.eclipse.core.resourcesorg.eclipse.core.runtime插件依赖项,plugin.xml并使用语法风格的解决方案.没有必要的绝对路径.

@Check
def checkExternalFlowDirExistance(MyType my) {
    val platformString = my.eResource.URI.toPlatformString(true);
    val myFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString));
    val proj = myFile.getProject();
    val shouldExistsFile = proj.geFile("/resources/dir1/dir2/SchoudBeExistFile.src")
    if (!shouldExistsFile.exists) {
    // error
    }
}
Run Code Online (Sandbox Code Playgroud)

Arn*_*-Oz 2

您可以从资源中获取完整路径:

@Check
def checkEventFileNameEqualsEventName(Mytype my){
    val myTypeFullPath=my.eResource.URI.toPlatformString(true)
}
Run Code Online (Sandbox Code Playgroud)