package jetbrains.mps.checkers;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.errors.item.ReportItem;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import org.jetbrains.mps.openapi.module.SRepository;
import org.jetbrains.mps.openapi.util.Consumer;
import org.jetbrains.mps.openapi.util.ProgressMonitor;
import jetbrains.mps.progress.ProgressTask;

/**
 * Conditionally applies the checker passed as {@code origin} parameter to the constructor, based on 
 * boolean value returned from the function {@code accept} passed as the second parameter.
 */
@GeneratedClass(node = "r:ba41e9c6-15ca-4a47-95f2-6a81c2318547(jetbrains.mps.checkers)/8195773907766032343", model = "r:ba41e9c6-15ca-4a47-95f2-6a81c2318547(jetbrains.mps.checkers)")
public class SkippingChecker<O, I extends ReportItem> implements IAbstractChecker<O, I> {
  private IAbstractChecker<O, ? extends I> myOrigin;
  private _FunctionTypes._return_P2_E0<? extends Boolean, ? super O, ? super SRepository> myAccept;
  public SkippingChecker(IAbstractChecker<O, ? extends I> origin, _FunctionTypes._return_P2_E0<? extends Boolean, ? super O, ? super SRepository> accept) {
    myOrigin = origin;
    myAccept = accept;
  }
  @Override
  public void check(O toCheck, SRepository repository, Consumer<? super I> errorCollector, ProgressMonitor monitor) {
    throw new UnsupportedOperationException();
  }
  @Override
  public ProgressTask checkTask(final O toCheck, final SRepository repository, final Consumer<? super I> errorCollector) {
    if (myAccept.invoke(toCheck, repository)) {
      return myOrigin.checkTask(toCheck, repository, errorCollector);
    } else {
      return ProgressTask.nop();
    }
  }
}
