I need to get confirmation of the existence of a specific file in an Xtext project. The file has a similar path as a verified object, but a different root directory, for example:
$ projPath / SRC / dir1 / dir2 / ValidatedFile.src
$ projPath / resources / dir1 / dir2 / SchoudBeExistFile.src
In the validate function, I only get the resource with a relative path ( /src/dir1/dir2/ValidatedFile.src). But I do not know the path to the project, so I can not verify the existence /resources/dir1/dir2/SchoudBeExistFile.src.
Can you help me find the absolute path of the project in the validation function?
@Check
def checkExternalFileExistance(MyType my) {
val myTypeFullPath = ??
val projectPath = ??
}
thank
UPDATE:
It is decided by adding the plugin dependencies org.eclipse.core.resourcesand org.eclipse.core.runtimethe project xtext through plugin.xmland using this solution in the style of grammar. This does not require an absolute path.
@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
}
}