use of org.metaborg.core.context.IContext in project spoofax by metaborg.
the class Builder method clean.
@Override
public void clean(CleanInput input, IProgress progress, ICancel cancel) throws InterruptedException {
final FileObject location = input.project.location();
logger.debug("Cleaning {}", location);
FileSelector selector = new LanguagesFileSelector(languageIdentifier, input.languages);
if (input.selector != null) {
selector = FileSelectorUtils.and(selector, input.selector);
}
try {
final FileObject[] resources = location.findFiles(selector);
if (resources == null) {
return;
}
final Set<IContext> contexts = ContextUtils.getAll(Iterables2.from(resources), input.project, languageIdentifier, contextService);
for (IContext context : contexts) {
cancel.throwIfCancelled();
try {
context.reset();
} catch (IOException e) {
logger.error("Could not clean {}", e, context);
}
}
} catch (FileSystemException e) {
logger.error("Could not clean contexts at {}", e, location);
}
}
use of org.metaborg.core.context.IContext 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.core.context.IContext 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