use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class SpoofaxContext method init.
public void init() {
this.base = this.resourceService().resolve(baseURI);
this.project = projectService.get(base);
if (this.project == null) {
this.languageSpec = null;
return;
}
try {
this.languageSpec = languageSpecService.get(project);
} catch (ConfigException e) {
throw new MetaborgRuntimeException("Cannot convert project " + project + " into a language specification project", e);
}
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class Builder method printMessages.
private boolean printMessages(Iterable<IMessage> messages, String phase, BuildInput input, boolean pardoned) {
final IMessagePrinter printer = input.messagePrinter;
if (printer != null) {
for (IMessage message : messages) {
printer.print(message, pardoned);
}
}
final boolean failed = !pardoned && MessageUtils.containsSeverity(messages, MessageSeverity.ERROR);
if (input.throwOnErrors && failed) {
throw new MetaborgRuntimeException(phase + " produced errors");
}
return !failed;
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class LanguageIdentifierService method identifyToResource.
@Override
@Nullable
public IdentifiedResource identifyToResource(FileObject resource, Iterable<? extends ILanguageImpl> impls) {
// Ignore directories.
try {
if (resource.getType() == FileType.FOLDER) {
return null;
}
} catch (FileSystemException e) {
logger.error("Cannot identify {}, cannot determine its file type", e, resource);
return null;
}
// Try to identify using the dialect identifier first.
try {
final IdentifiedDialect dialect = dialectIdentifier.identify(resource);
if (dialect != null) {
return new IdentifiedResource(resource, dialect);
}
} catch (MetaborgException e) {
logger.error("Cannot identify dialect of {}", e, resource);
return null;
} catch (MetaborgRuntimeException e) {
// Ignore
}
// Identify using identification facet.
final Set<ILanguage> identifiedLanguages = Sets.newLinkedHashSet();
ILanguageImpl identifiedImpl = null;
for (ILanguageImpl impl : impls) {
if (identify(resource, impl)) {
identifiedLanguages.add(impl.belongsTo());
identifiedImpl = impl;
}
}
if (identifiedLanguages.size() > 1) {
throw new IllegalStateException("Resource " + resource + " identifies to multiple languages: " + Joiner.on(", ").join(identifiedLanguages));
}
if (identifiedImpl == null) {
return null;
}
return new IdentifiedResource(resource, null, identifiedImpl);
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class ResourceService method resolve.
@Override
public FileObject resolve(FileObject parent, String path) {
try {
final String pathEncoded = URIEncode.encode(path);
final URI uri = new URI(pathEncoded);
if (uri.isAbsolute()) {
return resolve(uri);
}
} catch (URISyntaxException e) {
// Ignore
}
final File file = new File(path);
if (file.isAbsolute()) {
return resolve("file://" + path);
}
try {
return parent.resolveFile(path);
} catch (FileSystemException e) {
throw new MetaborgRuntimeException(e);
}
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class AnalysisResultProcessor method getUpdates.
private BehaviorSubject<AnalysisChange<A>> getUpdates(I input, IContext context) {
if (input.detached()) {
throw new MetaborgRuntimeException("Cannot get updates for detached (no source) units");
}
final FileObject source = input.source();
final FileName name = source.getName();
// THREADING: it is possible that two different threads asking for a subject may do the parsing twice here, as
// this is not an atomic operation. However, the chance is very low and it does not break anything (only
// duplicates some work), so it is acceptable.
BehaviorSubject<AnalysisChange<A>> updates = updatesPerResource.get(name);
if (updates == null) {
updates = BehaviorSubject.create();
updatesPerResource.put(name, updates);
try {
logger.trace("Requesting parse result for {}", source);
final P parseResult = parseResultRequester.request(input).toBlocking().single();
if (!parseResult.valid()) {
updates.onNext(AnalysisChange.<A>error(source, new AnalysisException(context, "Parsing failed")));
return updates;
}
logger.trace("Analysing for {}", source);
final IAnalyzeResult<A, AU> result;
try (IClosableLock lock = context.write()) {
result = analysisService.analyze(parseResult, context);
}
updates.onNext(AnalysisChange.<A>update(source, result.result()));
// HACK: ignore analyze unit updates from result.updates(), may cause incrementality problems.
} catch (AnalysisException e) {
final String message = logger.format("Analysis for {} failed", name);
logger.error(message, e);
updates.onNext(AnalysisChange.<A>error(source, e));
} catch (Exception e) {
final String message = logger.format("Analysis for {} failed", name);
logger.error(message, e);
updates.onNext(AnalysisChange.<A>error(source, new AnalysisException(context, message, e)));
}
}
return updates;
}
Aggregations