Search in sources :

Example 6 with ConfigException

use of org.metaborg.core.config.ConfigException in project spoofax by metaborg.

the class LanguageSpecPpNamePrimitive 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.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 name for " + location, e);
    }
    if (languageSpec == null) {
        return null;
    }
    return factory.makeString(languageSpec.config().prettyPrintLanguage());
}
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)

Example 7 with ConfigException

use of org.metaborg.core.config.ConfigException in project spoofax by metaborg.

the class SpoofaxLanguageSpecService method get.

@Override
@Nullable
public ISpoofaxLanguageSpec get(IProject project) throws ConfigException {
    if (project instanceof ISpoofaxLanguageSpec) {
        return (ISpoofaxLanguageSpec) project;
    }
    final FileObject location = project.location();
    if (!configService.available(location)) {
        return null;
    }
    final ConfigRequest<ISpoofaxLanguageSpecConfig> configRequest = configService.get(location);
    if (!configRequest.valid()) {
        logger.error("Errors occurred when retrieving language specification configuration from project {}", project);
        configRequest.reportErrors(new StreamMessagePrinter(sourceTextService, false, false, logger));
        throw new ConfigException("Configuration for language specification at " + project + " is invalid");
    }
    final ISpoofaxLanguageSpecConfig config = configRequest.config();
    if (config == null) {
        // Configuration should never be null if it is available, but sanity check anyway.
        return null;
    }
    return new SpoofaxLanguageSpecWrapper(config, project);
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) ISpoofaxLanguageSpecConfig(org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig) ConfigException(org.metaborg.core.config.ConfigException) FileObject(org.apache.commons.vfs2.FileObject) Nullable(javax.annotation.Nullable)

Aggregations

ConfigException (org.metaborg.core.config.ConfigException)7 FileObject (org.apache.commons.vfs2.FileObject)5 IProject (org.metaborg.core.project.IProject)5 ISpoofaxLanguageSpec (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec)5 ISpoofaxLanguageSpecService (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService)5 MetaborgException (org.metaborg.core.MetaborgException)3 IContext (org.spoofax.interpreter.core.IContext)2 InterpreterException (org.spoofax.interpreter.core.InterpreterException)2 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)2 Nullable (javax.annotation.Nullable)1 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)1 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)1 StreamMessagePrinter (org.metaborg.core.messages.StreamMessagePrinter)1 ISpoofaxLanguageSpecConfig (org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig)1 PlaceholderCharacters (org.metaborg.spoofax.meta.core.config.PlaceholderCharacters)1