我需要在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.resources和org.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) 我使用Xtext插件为eclipse定义我的语言并从中生成一些文件.该项目很大,我想使用多个生成器来生成我的文件,以及插件生成的默认生成器.
我试过这个解决方案http://www.eclipse.org/forums/index.php/t/263021/,但它不起作用,看起来它与旧版本的Xtext相关.
例如我默认拥有
class com.company.mylang.generator.MylangGenerator implements IGenerator {...}
Run Code Online (Sandbox Code Playgroud)
我需要添加其他一个
class com.company.mylang.generator.MylangGenerator2 implements IGenerator {...}
Run Code Online (Sandbox Code Playgroud)
作为eclipse构建的一部分运行.