Search in sources :

Example 1 with CommonPaths

use of org.metaborg.core.build.CommonPaths in project spoofax by metaborg.

the class LanguageSpecSrcGenDirectory method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
    final IProject project = context.project();
    if (project == null) {
        return null;
    }
    final CommonPaths paths = new CommonPaths(project.location());
    if (languageSpecServiceProvider == null) {
        // Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
        // should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
        logger.error("Language specification service is not available; static injection failed");
        return null;
    }
    if (!Tools.isTermString(current)) {
        throw new MetaborgException("Expect a string as argument term, got " + current);
    }
    String name = Tools.asJavaString(current);
    final String srcGenDir;
    try {
        srcGenDir = ResourceUtils.relativeName(paths.srcGenDir().resolveFile(name).getName(), project.location().getName(), true);
    } catch (FileSystemException e) {
        return null;
    }
    return factory.makeString(srcGenDir);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) CommonPaths(org.metaborg.core.build.CommonPaths) MetaborgException(org.metaborg.core.MetaborgException) IProject(org.metaborg.core.project.IProject)

Aggregations

FileSystemException (org.apache.commons.vfs2.FileSystemException)1 MetaborgException (org.metaborg.core.MetaborgException)1 CommonPaths (org.metaborg.core.build.CommonPaths)1 IProject (org.metaborg.core.project.IProject)1