use of org.metaborg.core.context.ContextException in project spoofax by metaborg.
the class HoverService method hover.
@Override
public Hover hover(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<HoverFacet> facetContrib = facet(langImpl);
final HoverFacet 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, 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.ContextException in project spoofax by metaborg.
the class Builder method updateLanguageResources.
private Collection<FileObject> updateLanguageResources(BuildInput input, ILanguageImpl language, LanguageBuildDiff diff, IBuildOutputInternal<P, A, AU, T> output, boolean pardoned, IProgress progress, ICancel cancel) throws InterruptedException {
cancel.throwIfCancelled();
final boolean analyze = input.analyze && analysisService.available(language);
final boolean transform = input.transform;
progress.setWorkRemaining(10 + (analyze ? 45 : 0) + (transform ? 45 : 0));
final Iterable<IdentifiedResourceChange> sourceChanges = diff.sourceChanges;
final Iterable<IdentifiedResourceChange> includeChanges = diff.includeChanges;
final Set<FileName> includes = Sets.newHashSet();
for (IdentifiedResourceChange includeChange : includeChanges) {
includes.add(includeChange.change.resource.getName());
}
final FileObject location = input.project.location();
final Collection<FileObject> changedSources = Sets.newHashSet();
final Set<FileName> removedResources = Sets.newHashSet();
final Collection<IMessage> extraMessages = Lists.newLinkedList();
final RefBool success = new RefBool(true);
logger.info("Building {} sources, {} includes of {}", Iterables.size(sourceChanges), Iterables.size(includeChanges), language);
// Parse
cancel.throwIfCancelled();
final Collection<P> sourceParseUnits = parse(input, language, sourceChanges, pardoned, changedSources, removedResources, extraMessages, success, progress.subProgress(5), cancel);
// GTODO: when a new context is created, all include files need to be parsed and analyzed in that context, this
// approach does not do that!
final Collection<P> includeParseUnits = parse(input, language, includeChanges, pardoned, changedSources, removedResources, extraMessages, success, progress.subProgress(5), cancel);
final Iterable<P> allParseResults = Iterables.concat(sourceParseUnits, includeParseUnits);
// Analyze
cancel.throwIfCancelled();
final Multimap<IContext, A> allAnalyzeUnits;
final Collection<AU> allAnalyzeUpdates = Lists.newArrayList();
if (analyze) {
// Segregate by context
final Multimap<IContext, P> parseUnitsPerContext = ArrayListMultimap.create();
for (P parseResult : sourceParseUnits) {
cancel.throwIfCancelled();
final FileObject resource = parseResult.source();
final ILanguageImpl langImpl = parseResult.input().langImpl();
try {
if (contextService.available(langImpl)) {
final IContext context = contextService.get(resource, input.project, langImpl);
parseUnitsPerContext.put(context, parseResult);
}
} catch (ContextException e) {
final String message = String.format("Failed to retrieve context for parse result of %s", resource);
printMessage(resource, message, e, input, pardoned);
extraMessages.add(MessageFactory.newAnalysisErrorAtTop(resource, "Failed to retrieve context", e));
}
}
// Run analysis
cancel.throwIfCancelled();
allAnalyzeUnits = analyze(input, language, location, parseUnitsPerContext, includeParseUnits, pardoned, allAnalyzeUpdates, removedResources, extraMessages, success, progress.subProgress(45), cancel);
} else {
allAnalyzeUnits = ArrayListMultimap.create();
}
// Transform
cancel.throwIfCancelled();
final Collection<T> allTransformUnits;
if (transform) {
allTransformUnits = transform(input, language, location, allAnalyzeUnits, includes, pardoned, removedResources, extraMessages, success, progress.subProgress(45), cancel);
} else {
allTransformUnits = Lists.newLinkedList();
}
printMessages(extraMessages, "Something", input, pardoned);
output.add(success.get(), removedResources, includes, changedSources, allParseResults, allAnalyzeUnits.values(), allAnalyzeUpdates, allTransformUnits, extraMessages);
final Collection<FileObject> newResources = Lists.newArrayList();
for (T transformUnit : allTransformUnits) {
for (ITransformOutput transformOutput : transformUnit.outputs()) {
final FileObject outputFile = transformOutput.output();
if (outputFile != null) {
newResources.add(outputFile);
}
}
}
return newResources;
}
use of org.metaborg.core.context.ContextException in project spoofax by metaborg.
the class OutlineService method outline.
@Override
public IOutline outline(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<OutlineFacet> facetContrib = facet(langImpl);
final OutlineFacet facet = facetContrib.facet;
final ILanguageComponent contributor = facetContrib.contributor;
final String strategy = facet.strategyName;
try {
final HybridInterpreter interpreter;
if (context == null) {
interpreter = strategoRuntimeService.runtime(contributor, source, true);
} else {
interpreter = strategoRuntimeService.runtime(contributor, context, true);
}
final IStrategoTerm input = common.builderInputTerm(result.ast(), source, source);
final IStrategoTerm outlineTerm = common.invoke(interpreter, input, strategy);
if (outlineTerm == null) {
return null;
}
final IOutline outline = toOutline(outlineTerm, facet.expandTo, contributor.location());
return outline;
} catch (MetaborgException e) {
throw new MetaborgException("Creating outline failed", e);
}
}
use of org.metaborg.core.context.ContextException 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