Search in sources :

Example 6 with IProject

use of org.metaborg.core.project.IProject in project spoofax by metaborg.

the class ResolverService method resolve.

@Override
public Resolution resolve(int offset, ISpoofaxAnalyzeUnit result) throws MetaborgException {
    if (!result.valid() || !result.hasAst()) {
        return null;
    }
    final FileObject source = result.source();
    final IContext context = result.context();
    final IProject project = context.project();
    final ILanguageImpl language = context.language();
    final FacetContribution<ResolverFacet> facetContrib = facet(language);
    final ResolverFacet facet = facetContrib.facet;
    final String strategy = facet.strategyName;
    try {
        final ITermFactory termFactory = termFactoryService.get(facetContrib.contributor, project, true);
        final HybridInterpreter interpreter = strategoRuntimeService.runtime(facetContrib.contributor, context, true);
        final Iterable<IStrategoTerm> inRegion = tracingService.fragments(result, new SourceRegion(offset));
        final TermWithRegion tuple;
        try (IClosableLock lock = context.read()) {
            tuple = common.outputs(termFactory, interpreter, source, source, result.ast(), inRegion, strategy);
        }
        return resolve(tuple);
    } catch (MetaborgException e) {
        throw new MetaborgException("Reference resolution failed", e);
    }
}
Also used : IContext(org.metaborg.core.context.IContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) MetaborgException(org.metaborg.core.MetaborgException) HybridInterpreter(org.strategoxt.HybridInterpreter) ISourceRegion(org.metaborg.core.source.ISourceRegion) SourceRegion(org.metaborg.core.source.SourceRegion) IProject(org.metaborg.core.project.IProject) TermWithRegion(org.metaborg.spoofax.core.tracing.TracingCommon.TermWithRegion) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) FileObject(org.apache.commons.vfs2.FileObject) IClosableLock(org.metaborg.util.concurrent.IClosableLock) ITermFactory(org.spoofax.interpreter.terms.ITermFactory)

Example 7 with IProject

use of org.metaborg.core.project.IProject in project spoofax by metaborg.

the class CheckSdf2TablePrimitive method call.

@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
    org.metaborg.core.context.IContext context = (org.metaborg.core.context.IContext) env.contextObject();
    final FileObject location = context.location();
    final IProject project = projectService.get(location);
    if (project == null) {
        return false;
    }
    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 false;
    }
    final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
    if (!languageSpecService.available(project)) {
        return false;
    }
    final ISpoofaxLanguageSpec languageSpec;
    try {
        languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new InterpreterException("Unable to get language specification name for " + location, e);
    }
    if (languageSpec == null) {
        return false;
    }
    if (!languageSpec.config().sdfEnabled()) {
        env.setCurrent(env.getFactory().makeString("disabled"));
        return true;
    }
    env.setCurrent(env.getFactory().makeString(languageSpec.config().sdf2tableVersion().toString()));
    return true;
}
Also used : IContext(org.spoofax.interpreter.core.IContext) ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) InterpreterException(org.spoofax.interpreter.core.InterpreterException) ConfigException(org.metaborg.core.config.ConfigException) FileObject(org.apache.commons.vfs2.FileObject) IProject(org.metaborg.core.project.IProject)

Example 8 with IProject

use of org.metaborg.core.project.IProject 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)

Example 9 with IProject

use of org.metaborg.core.project.IProject in project spoofax by metaborg.

the class LanguageSpecificationPrimitive 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;
    }
    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;
    }
    final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
    if (!languageSpecService.available(project)) {
        return null;
    }
    final ISpoofaxLanguageSpec languageSpec;
    try {
        languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new MetaborgException("Unable to get language specification configuration for " + project, e);
    }
    if (languageSpec == null) {
        return null;
    }
    final IStrategoString nameTerm = factory.makeString(languageSpec.config().name());
    final LanguageIdentifier id = languageSpec.config().identifier();
    final IStrategoString groupIdTerm = factory.makeString(id.groupId);
    final IStrategoString idTerm = factory.makeString(id.id);
    final IStrategoString versionTerm = factory.makeString(id.version.toString());
    final IStrategoString locationTerm = factory.makeString(languageSpec.location().getName().getURI());
    return factory.makeTuple(nameTerm, groupIdTerm, idTerm, versionTerm, locationTerm);
}
Also used : ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) MetaborgException(org.metaborg.core.MetaborgException) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ConfigException(org.metaborg.core.config.ConfigException) IProject(org.metaborg.core.project.IProject)

Example 10 with IProject

use of org.metaborg.core.project.IProject in project spoofax by metaborg.

the class LegacyLanguageSpecNamePrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
    final FileObject location = context.location();
    final IProject project = projectService.get(location);
    if (project == null) {
        return null;
    }
    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.debug("Language specification service is not available; static injection failed");
        return null;
    }
    final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
    if (!languageSpecService.available(project)) {
        return null;
    }
    final ISpoofaxLanguageSpec languageSpec;
    try {
        languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new MetaborgException("Unable to get language specification name for " + location, e);
    }
    if (languageSpec == null) {
        return null;
    }
    return factory.makeString(languageSpec.config().name());
}
Also used : ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) MetaborgException(org.metaborg.core.MetaborgException) ConfigException(org.metaborg.core.config.ConfigException) FileObject(org.apache.commons.vfs2.FileObject) IProject(org.metaborg.core.project.IProject)

Aggregations

IProject (org.metaborg.core.project.IProject)21 FileObject (org.apache.commons.vfs2.FileObject)13 MetaborgException (org.metaborg.core.MetaborgException)12 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)9 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)8 IContext (org.metaborg.core.context.IContext)6 HybridInterpreter (org.strategoxt.HybridInterpreter)6 ConfigException (org.metaborg.core.config.ConfigException)5 ISpoofaxLanguageSpec (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec)5 ISpoofaxLanguageSpecService (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService)5 ISourceRegion (org.metaborg.core.source.ISourceRegion)4 SourceRegion (org.metaborg.core.source.SourceRegion)4 TermWithRegion (org.metaborg.spoofax.core.tracing.TracingCommon.TermWithRegion)4 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)4 Nullable (javax.annotation.Nullable)3 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)3 ContextException (org.metaborg.core.context.ContextException)3 ILanguage (org.metaborg.core.language.ILanguage)3 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)3 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)3