Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xtext get project root directory from validator

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
    }
}
like image 941
Hersh Avatar asked Mar 13 '14 11:03

Hersh


1 Answers

You can get the full path from the Resource:

@Check
def checkEventFileNameEqualsEventName(Mytype my){
    val myTypeFullPath=my.eResource.URI.toPlatformString(true)
}
like image 145
Arnon Rotem-Gal-Oz Avatar answered Sep 28 '22 07:09

Arnon Rotem-Gal-Oz