I need to get to validate existence of specific file in Xtext project. The file has similar path as validated object but other root directory, for example:
$projPath/src/dir1/dir2/ValidatedFile.src
$projPath/resources/dir1/dir2/SchoudBeExistFile.src
In validate function I get resource only with relative path (/src/dir1/dir2/ValidatedFile.src
). But I don't know the project path, so I can't check existence of the /resources/dir1/dir2/SchoudBeExistFile.src
.
Can you help me to find the absolute project path in validation function?
@Check
def checkExternalFileExistance(MyType my) {
val myTypeFullPath = ??
val projectPath = ??
}
Thanks
UPDATE:
Solved by adding org.eclipse.core.resources
and org.eclipse.core.runtime
plugin dependencies to xtext project via plugin.xml
and using this solution in grammar style. No absolute path required for this.
@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
}
}
You can get the full path from the Resource:
@Check
def checkEventFileNameEqualsEventName(Mytype my){
val myTypeFullPath=my.eResource.URI.toPlatformString(true)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With