use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class AbstractScopeGraphContext method readLock.
private IClosableLock readLock() {
final Lock readLock = lock.readLock();
final IClosableLock lock = new ClosableLock(readLock);
return lock;
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class AbstractScopeGraphContext method reset.
@Override
public void reset() throws IOException {
try (IClosableLock lock = writeLock()) {
if (state != null) {
state = null;
}
final FileObject contextFile = contextFile();
contextFile.delete();
}
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class Builder method analyze.
private Multimap<IContext, A> analyze(BuildInput input, ILanguageImpl langImpl, FileObject location, Multimap<IContext, P> sourceParseUnits, Iterable<P> includeParseUnits, boolean pardoned, Collection<AU> analyzeUpdates, Set<FileName> removedResources, Collection<IMessage> extraMessages, RefBool success, IProgress progress, ICancel cancel) throws InterruptedException {
final int size = sourceParseUnits.size() + Iterables.size(includeParseUnits);
final Multimap<IContext, A> allAnalyzeUnits = ArrayListMultimap.create();
if (size == 0) {
return allAnalyzeUnits;
}
final Set<Entry<IContext, Collection<P>>> toAnalyze = sourceParseUnits.asMap().entrySet();
final int toAnalyzeSize = toAnalyze.size();
progress.setWorkRemaining(toAnalyzeSize);
progress.setDescription("Analyzing " + size + " file(s) of " + langImpl.belongsTo().name());
logger.debug("Analyzing {} parse results in {} context(s)", size, toAnalyzeSize);
for (Entry<IContext, Collection<P>> entry : toAnalyze) {
cancel.throwIfCancelled();
final IContext context = entry.getKey();
final Iterable<P> parseResults = Iterables.concat(entry.getValue(), includeParseUnits);
try {
try (IClosableLock lock = context.write()) {
analysisResultUpdater.invalidate(parseResults);
final IAnalyzeResults<A, AU> results = analysisService.analyzeAll(parseResults, context, progress.subProgress(1), cancel);
for (A result : results.results()) {
cancel.throwIfCancelled();
final boolean noErrors = printMessages(result.messages(), "Analysis", input, pardoned);
success.and(noErrors);
analysisResultUpdater.update(result, removedResources);
allAnalyzeUnits.put(context, result);
}
analyzeUpdates.addAll(results.updates());
} finally {
context.persist();
}
} catch (AnalysisException e) {
final String message = "Analysis failed unexpectedly";
final boolean noErrors = printMessage(message, e, input, pardoned);
success.and(noErrors);
analysisResultUpdater.error(parseResults, e);
extraMessages.add(MessageFactory.newAnalysisErrorAtTop(location, message, e));
} catch (IOException e) {
final String message = "Persisting analysis data failed unexpectedly";
final boolean noErrors = printMessage(message, e, input, pardoned);
success.and(noErrors);
extraMessages.add(MessageFactory.newAnalysisErrorAtTop(location, message, e));
}
}
return allAnalyzeUnits;
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class HoverService method hover.
@Override
public Hover hover(int offset, ISpoofaxAnalyzeUnit result) throws MetaborgException {
if (!result.valid() || !result.hasAst()) {
return null;
}
final FileObject source = result.source();
final IContext context = result.context();
final ILanguageImpl language = context.language();
final FacetContribution<HoverFacet> facetContrib = facet(language);
final HoverFacet facet = facetContrib.facet;
final String strategy = facet.strategyName;
try {
final IProject project = context.project();
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, context.location(), source, result.ast(), inRegion, strategy);
}
return hover(tuple);
} catch (MetaborgException e) {
throw new MetaborgException("Getting hover tooltip information failed unexpectedly", e);
}
}
use of org.metaborg.util.concurrent.IClosableLock in project nabl by metaborg.
the class ScopeGraphContextPrimitive method call.
@Override
public final boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
final Object contextObj = env.contextObject();
if (contextObj == null) {
logger.warn("Context is null.");
return false;
}
if (!(contextObj instanceof IScopeGraphContext)) {
throw new InterpreterException("Context does not implement IScopeGraphContext");
}
final IScopeGraphContext<?> context = (IScopeGraphContext<?>) env.contextObject();
List<IStrategoTerm> termArgs = Arrays.asList(tvars);
Optional<? extends IStrategoTerm> result;
try (IClosableLock lock = context.guard()) {
result = call(context, env.current(), termArgs, env.getFactory());
}
return result.map(t -> {
env.setCurrent(t);
return true;
}).orElse(false);
}
Aggregations