use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class AnalysisResultProcessor method error.
@Override
public void error(Iterable<P> results, AnalysisException exception) {
for (P parseResult : results) {
final FileObject resource = parseResult.source();
if (parseResult.detached()) {
throw new MetaborgRuntimeException("Cannot process analysis errors for detached (no source) units");
}
final BehaviorSubject<AnalysisChange<A>> updates = getUpdates(resource.getName());
updates.onNext(AnalysisChange.<A>error(resource, exception));
}
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class AnalysisResultProcessor method update.
@Override
public void update(A result, Set<FileName> removedResources) {
if (result.detached()) {
throw new MetaborgRuntimeException("Cannot process updates for detached (no source) units");
}
final FileObject resource = result.source();
final FileName name = resource.getName();
if (removedResources.contains(name)) {
remove(resource);
} else {
logger.trace("Pushing analysis result for {}", name);
final BehaviorSubject<AnalysisChange<A>> updates = getUpdates(name);
updates.onNext(AnalysisChange.update(resource, result));
}
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class TaskEngineAnalyzer method updateResult.
private ISpoofaxAnalyzeUnitUpdate updateResult(IStrategoTerm result, IContext context) {
final String sourceString = Tools.asJavaString(result.getSubterm(0));
final FileObject source;
try {
source = resourceService.resolve(sourceString);
} catch (MetaborgRuntimeException e) {
logger.error("Cannot find original source for {}, skipping update result", e, sourceString);
return null;
}
final Collection<IMessage> errors = analysisCommon.messages(source, MessageSeverity.ERROR, result.getSubterm(1));
final Collection<IMessage> warnings = analysisCommon.messages(source, MessageSeverity.WARNING, result.getSubterm(2));
final Collection<IMessage> notes = analysisCommon.messages(source, MessageSeverity.NOTE, result.getSubterm(3));
final Collection<IMessage> messages = Lists.newArrayListWithCapacity(errors.size() + warnings.size() + notes.size());
messages.addAll(errors);
messages.addAll(warnings);
messages.addAll(notes);
return unitService.analyzeUnitUpdate(source, new AnalyzeUpdateData(messages), context);
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class ResourceService method localFile.
@Override
public File localFile(FileObject resource, FileObject dir) {
if (resource instanceof LocalFile) {
return FileUtils.toFile(resource);
}
final File localDir = localPath(dir);
if (localDir == null) {
throw new MetaborgRuntimeException("Replication directory " + dir + " is not on the local filesystem, cannot get local file for " + resource);
}
try {
dir.createFolder();
final FileObject copyLoc;
if (resource.getType() == FileType.FOLDER) {
copyLoc = dir;
} else {
copyLoc = dir.resolveFile(resource.getName().getBaseName());
}
copyLoc.copyFrom(resource, new AllFileSelector());
return localDir;
} catch (FileSystemException e) {
throw new MetaborgRuntimeException("Could not get local file for " + resource, e);
}
}
use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.
the class ResolverService method resolve.
@Override
public Resolution resolve(int offset, ISpoofaxParseUnit result) throws MetaborgException {
if (!result.valid()) {
return null;
}
final FileObject source = result.source();
final IProject project = projectService.get(source);
final ILanguageImpl langImpl = result.input().langImpl();
@Nullable IContext context;
if (project == null) {
context = null;
} else {
try {
context = contextService.get(source, project, langImpl);
} catch (ContextException | MetaborgRuntimeException e) {
// Failed to get a context, ignore and use the source file to get a stratego runtime later.
context = null;
}
}
final FacetContribution<ResolverFacet> facetContrib = facet(langImpl);
final ResolverFacet facet = facetContrib.facet;
final ILanguageComponent contributor = facetContrib.contributor;
final String strategy = facet.strategyName;
try {
final ITermFactory termFactory = termFactoryService.get(contributor, project, true);
final HybridInterpreter interpreter;
if (context == null) {
interpreter = strategoRuntimeService.runtime(contributor, source, true);
} else {
interpreter = strategoRuntimeService.runtime(contributor, context, true);
}
final Iterable<IStrategoTerm> inRegion = tracingService.fragments(result, new SourceRegion(offset));
final TermWithRegion tuple = common.outputs(termFactory, interpreter, source, source, result.ast(), inRegion, strategy);
return resolve(tuple);
} catch (MetaborgException e) {
throw new MetaborgException("Reference resolution failed", e);
}
}
Aggregations