Search in sources :

Example 1 with IRegionStyle

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());
}
Also used : IStyle(org.metaborg.core.style.IStyle) IRegionStyle(org.metaborg.core.style.IRegionStyle) RegionStyle(org.metaborg.core.style.RegionStyle) ICategory(org.metaborg.core.style.ICategory) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 ICategory (org.metaborg.core.style.ICategory)1 IRegionStyle (org.metaborg.core.style.IRegionStyle)1 IStyle (org.metaborg.core.style.IStyle)1 RegionStyle (org.metaborg.core.style.RegionStyle)1