Class Rule

    • Constructor Detail

      • Rule

        Rule()
        Constructor for serialization.
      • Rule

        public Rule​(java.lang.String name,
                    boolean isProtected,
                    TypeDescriptor<?> returnType,
                    VariableDeclaration[] parameters,
                    Script parent)
        Create a new rule with the given name. As no descriptor is given, call setDescriptorInformation(RuleDescriptor) somewhen before using this rule.
        Parameters:
        name - The name of the rule.
        isProtected - if the visibility of the rule is actually restricted
        returnType - the return type (may be null to use the default)
        parameters - the parameters of this rule (may be null)
        parent - the parent rule
      • Rule

        public Rule​(java.lang.String name,
                    boolean isProtected,
                    VariableDeclaration[] parameters,
                    RuleDescriptor descriptor,
                    Script parent)
        Create a new rule with the given name.
        Parameters:
        name - The name of the rule.
        isProtected - if the visibility of the rule is actually restricted
        parameters - the parameters of this rule (may be null)
        descriptor - the descriptor
        parent - the parent rule
        See Also:
        setDescriptorInformation(RuleDescriptor)
    • Method Detail

      • setDescriptorInformation

        public void setDescriptorInformation​(RuleDescriptor descriptor)
        Sets the information from the given rule descriptor.
        Parameters:
        descriptor - the descriptor to be used
      • getParameterCount

        public int getParameterCount()
        Description copied from interface: IParameterizable
        Get the number of parameters of this rule.
        Returns:
        The number of parameters of this rule.
      • getParameter

        public VariableDeclaration getParameter​(int index)
        Description copied from interface: IParameterizable
        Get the parameter of this rule at the specified index.
        Parameters:
        index - The 0-based index of the rule parameter to be returned.
        Returns:
        The rule parameter at the given index.
      • getRequiredParameterCount

        public int getRequiredParameterCount()
        Description copied from interface: IParameterizable
        Returns the number of required parameters, i.e., non-default and non-named parameters.
        Returns:
        the number of required parameters
      • getParameter

        public VariableDeclaration getParameter​(java.lang.String name)
        Description copied from interface: IParameterizable
        Returns a named parameter declaration.
        Parameters:
        name - the name of the parameter
        Returns:
        the declaration or null if there is none
      • getVariable

        public VariableDeclaration getVariable​(Rule.Side side,
                                               int index)
        Returns the specified variable.
        Parameters:
        side - the side (LHS, RHS)
        index - The 0-based index of the rule element to be returned.
        Returns:
        the variable or null if there is none
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >=getVariablesCount(Side)
      • getMatchVariable

        public VariableDeclaration getMatchVariable​(Rule.Side side,
                                                    int index)
        Returns the specified match variable.
        Parameters:
        side - the side (LHS, RHS)
        index - The 0-based index of the rule element to be returned.
        Returns:
        the match variable or null if there is none
      • getVariablesCount

        public int getVariablesCount​(Rule.Side side)
        Get the number of variables of this rule on the specified side.
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        the number of variables .
      • selectVars

        private VariableDeclaration[] selectVars​(Rule.Side side)
        Returns the LHS/RHS variables on the specified side of this rule.
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        the rule calls
      • selectMatchVars

        private VariableDeclaration[] selectMatchVars​(Rule.Side side)
        Returns the LHS/RHS match variables on the specified side of this rule.
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        the rule calls
      • selectConditions

        private AbstractRuleMatchExpression[] selectConditions​(Rule.Side side)
        Returns the match conditions on the specified side of this rule.
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        the select conditions
      • selectCalls

        private RuleCallExpression[] selectCalls​(Rule.Side side)
        Returns the rule calls on the specified side of this rule.
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        the rule calls
      • hasCondition

        public boolean hasCondition​(Rule.Side side)
        Description copied from class: AbstractRule
        Returns whether the specified side has either rule calls or a matching condition.
        Specified by:
        hasCondition in class AbstractRule
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        whether the specified side has cinditions at all
      • getRuleConditionCount

        public int getRuleConditionCount​(Rule.Side side)
        Description copied from class: AbstractRule
        Get the number of match conditions on the given side of this rule.
        Specified by:
        getRuleConditionCount in class AbstractRule
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        The number of preconditions (match conditions) of this rule.
      • getRuleCondition

        public AbstractRuleMatchExpression getRuleCondition​(Rule.Side side,
                                                            int index)
        Description copied from class: AbstractRule
        Get the match conditions of this rule on the given side at the specified index.
        Specified by:
        getRuleCondition in class AbstractRule
        Parameters:
        side - the side (LHS, RHS)
        index - The 0-based index of the match condition to be returned.
        Returns:
        The match condition at the given index.
      • getRuleCallCount

        public int getRuleCallCount​(Rule.Side side)
        Description copied from class: AbstractRule
        Get the number of rule calls on the given side of this rule.
        Specified by:
        getRuleCallCount in class AbstractRule
        Parameters:
        side - the side (LHS, RHS)
        Returns:
        The number of postconditions of this rule.
      • getRuleCall

        public RuleCallExpression getRuleCall​(Rule.Side side,
                                              int index)
        Description copied from class: AbstractRule
        Get the rule call on the given side of this rule at the specified index.
        Specified by:
        getRuleCall in class AbstractRule
        Parameters:
        side - the side (LHS, RHS)
        index - The 0-based index of the rule element to be returned.
        Returns:
        The rule element at the given index.
      • isProtected

        public boolean isProtected()
        Description copied from class: AbstractRule
        Returns whether a rule is declared as protected regarding its visibility.
        Specified by:
        isProtected in class AbstractRule
        Returns:
        true if it is protected, false else
      • accept

        public java.lang.Object accept​(IVisitor visitor)
                                throws VilException
        Description copied from interface: IBuildlangElement
        Accepts the visitor for visiting.
        Parameters:
        visitor - the visitor to be used
        Returns:
        the result of visiting this instance (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • getParameterType

        public IMetaType getParameterType​(int index)
        Description copied from interface: IMetaOperation
        Returns the specified parameter type.
        Parameters:
        index - the index of the parameter to return
        Returns:
        the specified parameter type
      • getJavaSignature

        public java.lang.String getJavaSignature()
        Description copied from interface: IMetaOperation
        Returns the java-like signature of this operation.
        Returns:
        the java-like Java signature of this operation
      • getSignature

        public java.lang.String getSignature()
        Description copied from interface: IMetaOperation
        Returns the signature of the method (in terms of VIL types where possible).
        Returns:
        the signature of the method
      • getDefaultReturnType

        public TypeDescriptor<?> getDefaultReturnType()
        Returns the default return type that shall not be emitted / does not require return expressions.
        Returns:
        the default return type
      • returnActualValue

        public boolean returnActualValue()
        Returns whether this rule shall return an actual value (function) or a rule execution result.
        Returns:
        true in case of an actual value, false else
      • getReturnType

        public TypeDescriptor<?> getReturnType()
        Description copied from interface: IResolvableOperation
        Returns the return type of this operation.
        Returns:
        the return type
      • acceptsNamedParameters

        public boolean acceptsNamedParameters()
        Description copied from interface: IMetaOperation
        Returns whether the operation accepts named parameters.
        Returns:
        true if it accepts named parameters, false else
      • isStatic

        public boolean isStatic()
        Description copied from interface: IMetaOperation
        Returns whether this operation is static.
        Returns:
        true if it is static, false else
      • isFirstParameterOperand

        public boolean isFirstParameterOperand()
        Description copied from interface: IMetaOperation
        Returns whether the first parameter is the operand.
        Returns:
        true if the first parameter is the operand, false else
      • getDeclaringType

        public IMetaType getDeclaringType()
        Description copied from interface: IMetaOperation
        Returns the declaring type.
        Returns:
        the declaring type (may be null in case of a wrapped external Java method)
      • appendCallTo

        public void appendCallTo​(AbstractRule target,
                                 boolean qualifiedCall)
                          throws VilException
        Description copied from class: AbstractRule
        Appends a call to target to the rule body. Currently, this method considers parameters only in the sequence of the parameters of this rule.
        Specified by:
        appendCallTo in class AbstractRule
        Parameters:
        target - the rule to append the call to
        qualifiedCall - insert a qualified call if true, an unqualified call if false
        Throws:
        VilException - in case that creating / resolving the rule call fails
      • isPlaceholder

        public boolean isPlaceholder()
        Description copied from interface: IMetaOperation
        Returns whether this operation is valid or whether it is a placeholder operation in case that the original operation cannot be resolved but the script shall remain executable.
        Returns:
        true if this operation is a placeholder, false else
      • isVirtual

        public boolean isVirtual()
        Description copied from interface: IRuleBlock
        Returns whether this block is a real block or consists just of a block element without brackets.
        Returns:
        true if this block is virtual, false else
      • getStringValue

        public java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
        Description copied from interface: IStringValueProvider
        Returns the string value of this object.
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • setParent

        protected void setParent​(ILanguageElement parent)
        Description copied from class: ProjectElement
        Changes the parent. Please override if children must be adjusted according. Shall be called only once per instance, but there is no limitation.
        Overrides:
        setParent in class RuleBlock
        Parameters:
        parent - the parent
      • setParentFor

        protected void setParentFor​(VariableDeclaration[] vars)
        Changes the parents for vars to this. [convenience]
        Parameters:
        vars - the variables
      • setParentFor

        protected void setParentFor​(VariableDeclaration var)
        Changes the parent of the given variable to this. [access modifiers]
        Parameters:
        var - the variable
      • isCompatible

        public IMetaOperation.CompatibilityResult isCompatible​(java.lang.Class<?> retType,
                                                               java.lang.Object... params)
        Description copied from interface: IMetaOperation
        Returns whether the operation represented by this instance is compatible to the given return type and parameters. This method does not consider possible unnamed parameter rather than the underlying Java parameter.
        Parameters:
        retType - the return type (may be null in order to ignore this parameter)
        params - the parameters (may be null if there are none, may be classes)
        Returns:
        an instance of IMetaOperation.CompatibilityResult denoting the actual compatibility level