use of org.metaborg.core.style.IRegionStyle in project spoofax by metaborg.
the class StylerService method style.
@Nullable
private IRegionStyle<IStrategoTerm> style(StylerFacet facet, IRegionCategory<IStrategoTerm> regionCategory) {
if (regionCategory.region().length() == 0) {
// Skip empty regions for styling.
return null;
}
final ICategory category = regionCategory.category();
// HACK: instanceof checks are nasty, but required since we do not have separate specifications for categories
// and styles, they are intertwined.
final IStyle style;
if (category instanceof SortConsCategory) {
final SortConsCategory cat = (SortConsCategory) category;
style = facet.sortConsStyle(cat.sort, cat.cons);
} else if (category instanceof ConsCategory) {
final ConsCategory cat = (ConsCategory) category;
style = facet.consStyle(cat.cons);
} else if (category instanceof SortCategory) {
final SortCategory cat = (SortCategory) category;
style = facet.sortStyle(cat.sort);
} else if (category instanceof TokenCategory) {
final TokenCategory cat = (TokenCategory) category;
style = facet.tokenStyle(cat.token);
} else {
style = null;
}
if (style == null) {
logger.warn("Cannot determine style for category " + category.name());
return null;
}
return new RegionStyle<>(regionCategory.region(), style, regionCategory.fragment());
}
Aggregations