All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.codemodder.CodemodRegulator Maven / Gradle / Ivy

There is a newer version: 0.98.6
Show newest version
package io.codemodder;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

/** A type that is relied on to inform our in-flight analysis on whether codemods are allowed. */
public interface CodemodRegulator {

  /**
   * Taking into account the configuration, understand if this codemod is currently allowed.
   *
   * @param codemodId the string id of the codemod
   * @return true, if the codemod is allowed -- false otherwise
   */
  boolean isAllowed(String codemodId);

  Optional> desiredCodemodIdOrder();

  class DefaultCodemodRegulator implements CodemodRegulator {

    private final DefaultRuleSetting setting;
    private final List exceptions;
    private final List desiredOrder;

    DefaultCodemodRegulator(
        final DefaultRuleSetting defaultCodemodSetting, final List codemodExceptions) {
      this.setting = Objects.requireNonNull(defaultCodemodSetting);
      this.exceptions = Objects.requireNonNull(codemodExceptions);
      if (DefaultRuleSetting.ENABLED.equals(defaultCodemodSetting)) {
        this.desiredOrder = null;
      } else {
        this.desiredOrder = codemodExceptions;
      }
    }

    @Override
    public boolean isAllowed(final String codemodId) {
      if (DefaultRuleSetting.ENABLED.equals(setting)) {
        return !exceptions.contains(codemodId);
      }
      return exceptions.contains(codemodId);
    }

    @Override
    public Optional> desiredCodemodIdOrder() {
      return Optional.ofNullable(desiredOrder);
    }
  }

  static CodemodRegulator of(
      final DefaultRuleSetting defaultCodemodSetting, final List codemodExceptions) {
    return new DefaultCodemodRegulator(defaultCodemodSetting, codemodExceptions);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy