Class RuleDescriptor


  • public class RuleDescriptor
    extends java.lang.Object
    Defines the complex parts of a rule. Instances of this class are just for creating rules. More or less direct access to the attributes is ok for this class.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • RuleDescriptor

        public RuleDescriptor()
        Creates an empty descriptor.
    • Method Detail

      • setRuleExpressions

        public void setRuleExpressions​(Rule.Side side,
                                       java.util.List<Expression> conditions)
                                throws RuleDescriptorException
        Defines the rule conditions on the given side. Rule calls and rule condition expressions are separated in here.
        Parameters:
        side - the side to return the calls for (LHS, RHS)
        conditions - the conditions (may be null if there are none)
        Throws:
        RuleDescriptorException - in case that the given expressions cannot be applied (in the given sequence)
      • getRuleMatches

        public AbstractRuleMatchExpression[] getRuleMatches​(Rule.Side side)
        Returns the rule match conditions on the specified side.
        Parameters:
        side - the side to return the calls for (LHS, RHS)
        Returns:
        the rule match conditions (may be null)
      • getRuleMatchCount

        public int getRuleMatchCount​(Rule.Side side)
        Returns the number of match expressions on the specified side.
        Parameters:
        side - the side to return the calls for (LHS, RHS)
        Returns:
        the number of match expressions
      • getRuleCalls

        public RuleCallExpression[] getRuleCalls​(Rule.Side side)
        Returns the rule calls on the specified side.
        Parameters:
        side - the side to return the calls for (LHS, RHS)
        Returns:
        the rule calls (may be null)
      • getRuleCallCount

        public int getRuleCallCount​(Rule.Side side)
        Returns the number of rule calls on the specified side.
        Parameters:
        side - the side to return the calls for (LHS, RHS)
        Returns:
        the number of rule calls
      • registerVariables

        public void registerVariables​(Resolver resolver)
                               throws VilException
        Registers the LHS/RHS variables in resolver if applicable.
        Parameters:
        resolver - the resolver instance
        Throws:
        VilException - in case that resolving one of the expressions fails
      • registerVariables

        private void registerVariables​(Rule.Side side,
                                       Resolver res,
                                       java.util.Map<java.lang.String,​java.lang.Integer> names)
                                throws VilException
        Registers the variables in resolver if applicable.
        Parameters:
        side - the side to register variables for (LHS, RHS)
        res - the resolver instance
        names - a mapping of names and a related counter how often the variable name (without number) has been used so far in this rule head
        Throws:
        VilException - in case that resolving one of the expressions fails
      • toArray

        private static VariableDeclaration[] toArray​(java.util.List<VariableDeclaration> vars)
        Turns a list of variable declarations into an array and considers null as input.
        Parameters:
        vars - the list of variables to be turned into an array
        Returns:
        the array, null if the input is empty or null
      • getVariables

        public VariableDeclaration[] getVariables​(Rule.Side side)
        Returns the variables on the given side.
        Parameters:
        side - the side to return the variables for (LHS, RHS)
        Returns:
        the LHS variables or null if there is none
      • getMatchVariables

        public VariableDeclaration[] getMatchVariables​(Rule.Side side)
        Returns the match variables on the given side.
        Parameters:
        side - the side to return the match variables for (LHS, RHS)
        Returns:
        the LHS variables or null if there is none
      • setReturnType

        public void setReturnType​(TypeDescriptor<?> returnType)
        Defines the return type of this rule descriptor.
        Parameters:
        returnType - the return type (may be null if undefined, use default instead)
      • getReturnType

        public TypeDescriptor<?> getReturnType()
        Returns the return type of this rule descriptor.
        Returns:
        the return type (may be null if undefined, use default instead)