use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class LanguageDiscoveryService method scanComponentsInDirectory.
@Override
public Set<ILanguageComponent> scanComponentsInDirectory(FileObject directory) throws MetaborgException {
final Collection<IComponentCreationConfigRequest> requests = componentFactory.requestAllInDirectory(directory);
final Collection<ComponentCreationConfig> configs = componentFactory.createConfigs(requests);
final Set<ILanguageComponent> components = Sets.newHashSet();
for (ComponentCreationConfig config : configs) {
final ILanguageComponent component = languageService.add(config);
components.add(component);
}
return components;
}
use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class DialectService method remove.
@Override
public Iterable<ILanguageImpl> remove(ILanguageImpl base) {
final Collection<ILanguageImpl> dialects = baseLanguageToDialects.get(base);
if (dialects.isEmpty()) {
return dialects;
}
logger.debug("Removing {} dialects for base language {}", dialects.size(), base);
final Collection<ILanguageImpl> removedDialects = Lists.newArrayListWithCapacity(dialects.size());
for (ILanguageImpl dialect : dialects) {
final String name = dialect.belongsTo().name();
nameToDialect.remove(name);
dialectToBase.remove(dialect);
baseLanguageToDialects.remove(base, dialect);
try {
// Remove dialect after updating maps, exception indicates that dialect has already been removed.
final ILanguageComponent dialectComponent = Iterables.get(dialect.components(), 0);
languageService.remove(dialectComponent);
} catch (IllegalStateException e) {
final String message = String.format("Error removing dialect %s", name);
logger.error(message, e);
continue;
}
removedDialects.add(dialect);
}
return removedDialects;
}
use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class DialectService method remove.
@Override
public ILanguageImpl remove(String name) {
final ILanguageImpl dialect = nameToDialect.remove(name);
if (dialect == null) {
final String message = String.format("Dialect with name %s does not exist", name);
logger.error(message);
throw new MetaborgRuntimeException(message);
}
logger.debug("Removing dialect {}", name);
final ILanguageImpl base = dialectToBase.remove(dialect);
baseLanguageToDialects.remove(base, dialect);
try {
// Remove dialect after updating maps, exception indicates that dialect has already been removed.
final ILanguageComponent dialectComponent = Iterables.get(dialect.components(), 0);
languageService.remove(dialectComponent);
} catch (IllegalStateException e) {
final String message = String.format("Error removing dialect %s", name);
logger.error(message, e);
}
return dialect;
}
use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class CallStrategyPrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext currentContext) throws MetaborgException {
final String languageName = Tools.asJavaString(tvars[0]);
final String strategyName = Tools.asJavaString(tvars[1]);
final Iterable<ILanguageComponent> compileDeps = dependencyService.compileDeps(currentContext.project());
final Iterable<ILanguageImpl> impls = LanguageUtils.toImpls(compileDeps);
final List<ILanguageImpl> selectedImpls = Lists.newArrayList();
for (ILanguageImpl impl : impls) {
if (impl.belongsTo().name().equals(languageName)) {
selectedImpls.add(impl);
}
}
if (selectedImpls.isEmpty()) {
final String message = logger.format("Stratego strategy call of '{}' into language '{}' failed, no language implementation found", strategyName, languageName);
throw new MetaborgException(message);
} else if (selectedImpls.size() > 1) {
final String message = logger.format("Stratego strategy call of '{}' into language '{}' failed, multiple language implementations found: {}", strategyName, languageName, Joiner.on(", ").join(selectedImpls));
throw new MetaborgException(message);
}
final ILanguageImpl impl = selectedImpls.get(0);
final IContext context = contextService.get(currentContext.location(), currentContext.project(), impl);
return common.invoke(impl, context, current, strategyName);
}
use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.
the class LanguageComponentsPrimitive method call.
@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException, IOException {
IStrategoList list = factory.makeList();
for (ILanguageComponent component : context.language().components()) {
final LanguageIdentifier id = component.id();
final IStrategoString groupIdTerm = factory.makeString(id.groupId);
final IStrategoString idTerm = factory.makeString(id.id);
final IStrategoString versionTerm = factory.makeString(id.version.toString());
final IStrategoString locationTerm = factory.makeString(component.location().getName().getURI());
final IStrategoTuple tuple = factory.makeTuple(groupIdTerm, idTerm, versionTerm, locationTerm);
list = factory.makeListCons(tuple, list);
}
return list;
}
Aggregations