use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class ActionService method actionContributions.
@Override
public Collection<TransformActionContrib> actionContributions(ILanguageImpl language, ITransformGoal goal) {
final Iterable<FacetContribution<ActionFacet>> facetsContributions = language.facetContributions(ActionFacet.class);
final Collection<TransformActionContrib> actionContributions = Lists.newLinkedList();
for (FacetContribution<ActionFacet> facetContribution : facetsContributions) {
final ActionFacet facet = facetContribution.facet;
final ILanguageComponent component = facetContribution.contributor;
for (ITransformAction action : facet.actions(goal)) {
actionContributions.add(new TransformActionContrib(action, component));
}
}
return actionContributions;
}
use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class LanguageDiscoveryService method create.
private ILanguageComponent create(IComponentCreationConfigRequest request) throws MetaborgException {
final ComponentCreationConfig config = componentFactory.createConfig(request);
final ILanguageComponent component = languageService.add(config);
return component;
}
use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class DialectService method createDialect.
private ILanguageImpl createDialect(String name, FileObject location, ILanguageImpl base, IFacet syntaxFacet, boolean replaceIdentification, boolean appendDialectName) {
final LanguageIdentifier baseId = base.id();
final String dialectId;
if (appendDialectName) {
dialectId = baseId.id + "-Dialect-" + name;
} else {
dialectId = baseId.id;
}
final LanguageIdentifier id = new LanguageIdentifier(baseId.groupId, dialectId, baseId.version);
// HACK: use config of first component.
final ILanguageComponentConfig config = Iterables.get(base.components(), 0).config();
final ComponentCreationConfig creationConfig = languageService.create(id, location, Iterables2.singleton(new LanguageContributionIdentifier(id, name)), config);
for (IFacet facet : base.facets()) {
if (facet instanceof IdentificationFacet && replaceIdentification) {
creationConfig.addFacet(new IdentificationFacet(new MetaFileIdentifier((IdentificationFacet) facet)));
} else if (facet instanceof SyntaxFacet || facet instanceof ResourceExtensionFacet) {
// Ignore
} else {
creationConfig.addFacet(facet);
}
}
creationConfig.addFacet(syntaxFacet);
final ILanguageComponent dialectComponent = languageService.add(creationConfig);
final ILanguageImpl dialect = Iterables.get(dialectComponent.contributesTo(), 0);
return dialect;
}
use of org.metaborg.core.language.ILanguageComponent 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.ILanguageComponent 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);
}
}
Aggregations