package org.metaborg.spoofax.core.style;

import java.util.Collection;

import org.metaborg.core.source.ISourceRegion;
import org.metaborg.core.style.IRegionCategory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;

public class CategorizerValidator {
    private static final Logger logger = LoggerFactory.getLogger(CategorizerValidator.class);

    public static <T> Iterable<IRegionCategory<T>> validate(Iterable<IRegionCategory<T>> categorization) {
        int offset = -1;
        final Collection<IRegionCategory<T>> validated = Lists.newLinkedList();
        for(IRegionCategory<T> regionCategory : categorization) {
            final ISourceRegion region = regionCategory.region();
            if(offset > region.startOffset()) {
                logger.warn("Invalid {}, starting offset is greater than offset in previous regions, "
                    + "region category will be skipped", regionCategory);
            } else if(offset > region.endOffset()) {
                logger.warn("Invalid {}, ending offset is greater than offset in previous regions, "
                    + "region category will be skipped", regionCategory);
            } else if(region.startOffset() > region.endOffset()) {
                logger.warn("Invalid {}, starting offset is greater than ending offset, "
                    + "region category will be skipped", regionCategory);
            } else {
                validated.add(regionCategory);
                offset = regionCategory.region().endOffset();
            }
        }
        return validated;
    }
}

@@ -749,32 +749,33 @@
      if(offset %3E
+=
  region.startOff
@@ -990,16 +990,17 @@
 offset %3E
+=
  region.

Fix categorization validator