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());
}
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);
}
Aggregations