use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class OutlineService method outline.
@Override
public IOutline outline(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<OutlineFacet> facetContrib = facet(language);
final OutlineFacet facet = facetContrib.facet;
final ILanguageComponent contributor = facetContrib.contributor;
final String strategy = facet.strategyName;
try {
final HybridInterpreter interpreter = strategoRuntimeService.runtime(contributor, context, true);
final IStrategoTerm input = common.builderInputTerm(result.ast(), source, context.location());
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.language.ILanguageImpl 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.language.ILanguageImpl in project spoofax by metaborg.
the class LanguageChangeProcessor method reloadedImpl.
/**
* Implementation was reloaded
*
* @param impl
* Reloaded implementation
*/
protected void reloadedImpl(ILanguageImpl impl) {
for (ILanguageCache languageCache : languageCaches) {
languageCache.invalidateCache(impl);
}
parseResultProcessor.invalidate(impl);
analysisResultProcessor.invalidate(impl);
final Iterable<IEditor> editors = editorRegistry.openEditors();
for (IEditor editor : editors) {
final ILanguageImpl editorLanguage = editor.language();
if (editorLanguage == null || impl.equals(editorLanguage)) {
editor.reconfigure();
editor.forceUpdate();
}
}
}
use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class ParseFile method build.
@Override
protected Out<IStrategoTerm> build(Input input) throws Throwable {
requireBuild(input.requiredUnits);
require(input.file);
if (!FileCommands.exists(input.file)) {
return null;
}
final FileObject resource = context.resourceService().resolve(input.file);
final ILanguageImpl language = context.languageIdentifierService().identify(resource);
if (language == null) {
return null;
}
final String text = context.sourceTextService().text(resource);
final ISpoofaxInputUnit inputUnit = context.unitService().inputUnit(resource, text, language, null);
final ISpoofaxParseUnit result = context.syntaxService().parse(inputUnit);
if (!result.valid()) {
return null;
}
return input.persistResult ? OutputPersisted.of(result.ast()) : OutputTransient.of(result.ast());
}
use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.
the class Builder method build.
@Override
public IBuildOutput<P, A, AU, T> build(BuildInput input, IProgress progress, ICancel cancel) throws InterruptedException {
cancel.throwIfCancelled();
final Multimap<ILanguageImpl, IdentifiedResourceChange> changes = ArrayListMultimap.create();
identifyResources(input.sourceChanges, input, changes, cancel);
if (changes.size() == 0) {
// When there are no source changes, keep the old state and skip building.
final IBuildOutputInternal<P, A, AU, T> buildOutput = buildOutputProvider.get();
buildOutput.setState(input.state);
return buildOutput;
}
cancel.throwIfCancelled();
logger.info("Building " + input.project.location());
final BuildState newState = new BuildState();
final IBuildOutputInternal<P, A, AU, T> buildOutput = buildOutputProvider.get();
buildOutput.setState(newState);
final Iterable<ILanguageImpl> buildOrder = input.buildOrder.buildOrder();
progress.setWorkRemaining(Iterables.size(buildOrder));
for (ILanguageImpl language : buildOrder) {
cancel.throwIfCancelled();
final LanguageBuildState languageState = input.state.get(resourceService, languageIdentifier, language);
final Collection<IdentifiedResourceChange> sourceChanges = changes.get(language);
if (sourceChanges.size() == 0) {
// When there are no source changes for this language, keep the old state and don't build.
newState.add(language, languageState);
continue;
}
final Iterable<FileObject> includePaths = input.includePaths.get(language);
final Iterable<IdentifiedResource> includeFiles = languagePathService.toFiles(includePaths, language);
final LanguageBuildDiff diff = languageState.diff(changes.get(language), includeFiles);
final boolean pardoned = input.pardonedLanguages.contains(language);
final Collection<FileObject> newResources = updateLanguageResources(input, language, diff, buildOutput, pardoned, progress.subProgress(1), cancel);
final Iterable<ResourceChange> newResourceChanges = ResourceUtils.toChanges(newResources, ResourceChangeKind.Create);
identifyResources(newResourceChanges, input, changes, cancel);
newState.add(language, diff.newState);
}
final IMessagePrinter printer = input.messagePrinter;
if (printer != null) {
printer.printSummary();
}
return buildOutput;
}
Aggregations