Skip to content

abstract rules should be supported through inherited annotation(s) #66

Description

@cogito-clarus

The support of inheriting the boilerplate decorations from a abstract class should be added to reduce said boilerplate in child classes.

  • @inherited should be added to all EasyRules annotations source
  • RuleDefinitionValidator.java/Utils.java in EasyRules lib should check to see if superclass has the valid definition if current class doesn't.

*** EasyRules user's abstract class looks something like ***

@Rule
public abstract class AbstractRule  {

   private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

   private String name;
   private boolean enabled;
   private int priority;

   public AbstractRule() { }

   public AbstractRule(String name, boolean enabled, int priority) {
      this.name = name;
      this.enabled = enabled;
      this.priority = priority;
   }

   @Condition
   public abstract boolean when();

   @Action
   public abstract void then();

   @Priority
   public int getPriority() {
      return this.priority;
  }
}

*** concrete class would look something like ***

 // the rule annotation is from the parent decoration, so not required here
public class oneRule extends AbstractRule {

   private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

   private int input;

   public oneRule(String name, boolean enabled, int priority) {
      super(name, enabled, priority);
      //whatever else
   }
   // the condition annotation is from the parent decoration, so not required here
   public boolean when() {
      return input % 1 == 0;
   }
   // the action annotation is from the parent decoration, so not required here
   public void then() {
      // do something important here
      LOG.debug("isOne => true for {}", input);
   }

   public void setInput(int input) {
      this.input = input;
   }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions