Class OCLFeatureCall

    • Constructor Detail

      • OCLFeatureCall

        OCLFeatureCall()
        Constructor for serialization.
      • OCLFeatureCall

        public OCLFeatureCall​(ConstraintSyntaxTree operand,
                              java.lang.String operation,
                              ConstraintSyntaxTree... parameters)
        Constructs an OCL feature call as a node of a constraint syntax tree. Please note that this node receives the name of an operation/feature call while resolution whether the name is valid will be done in inferDatatype().
        Parameters:
        operand - the constraint syntax tree to execute the feature call / operation on (may be null in case of a custom operation)
        operation - the name of the operation / feature call
        parameters - the parameters for the operation (may be null in case of no parameter)
      • OCLFeatureCall

        public OCLFeatureCall​(ConstraintSyntaxTree operand,
                              java.lang.String operation,
                              ICustomOperationAccessor opAccessor,
                              ConstraintSyntaxTree... parameters)
        Constructs an OCL feature call as a node of a constraint syntax tree. Please note that this node receives the name of an operation/feature call while resolution whether the name is valid will be done in inferDatatype(). The opHolder is required to resolve custom operations.
        Parameters:
        operand - the constraint syntax tree to execute the feature call / operation on (may be null in case of a custom operation)
        operation - the name of the operation / feature call
        opAccessor - an optional instance which stores additional operation definitions, typically the containing project, may be null
        parameters - the parameters for the operation (may be null in case of no parameter)
    • Method Detail

      • checkTypeCompliance

        public static void checkTypeCompliance​(Operation op,
                                               IDatatype operandType,
                                               IDatatype[] parameterTypes)
                                        throws CSTSemanticException
        Performs specific type compliance checks for found operations, e.g., in case of equality or assignments.
        Parameters:
        op - the operation to be checked
        operandType - the actual operand type
        parameterTypes - the actual parameter types
        Throws:
        CSTSemanticException - in case that operand type and parameter types shall match somehow but do not match
      • dfltInferDatatype

        private void dfltInferDatatype()
                                throws CSTSemanticException
        Performs the default infer operation, i.e. resolve operation on operand or search for a custom operation.
        Throws:
        CSTSemanticException - in case of type resolution problems
      • checkOperand

        private Operation checkOperand​(Operation op,
                                       IDatatype operandType,
                                       IDatatype[] paramTypes)
        If required, checks the operand against the operation result type.
        Parameters:
        op - the operation
        operandType - the operand type
        paramTypes - the parameter types
        Returns:
        op or null if op is not valid with respect to its operand
      • resolveFully

        private static void resolveFully​(ConstraintSyntaxTree[] parameter,
                                         IDatatype[] types)
        Dereferences types if parameter does not indicate a refBy.
        Parameters:
        parameter - the parameter
        types - the types (modified as a side effect)
      • replaceEmptyInitializer

        private void replaceEmptyInitializer​(Operation op)
        Replaces (temporary) empty initializers.
        Parameters:
        op - the operation to be considered
      • getActualReturnType

        private IDatatype getActualReturnType​(Operation op,
                                              IDatatype immediateOperand,
                                              IDatatype... parameter)
        Determines the actual return type and considers the actual type of meta type parameters.
        Parameters:
        op - the operation to consider
        immediateOperand - the actual operand type (complying to getOperand().
        parameter - the actual parameter
        Returns:
        the actual return type
      • checkRequiredAssignableParameter

        private void checkRequiredAssignableParameter​(Operation op,
                                                      IDatatype operandType,
                                                      IDatatype[] paramTypes)
                                               throws CSTSemanticException
        Checks the operation for required assignable parameter if required. Mismatch leads to exception.
        Parameters:
        op - the resolved operation
        operandType - the resolved operand type
        paramTypes - the resolved parameter types
        Throws:
        CSTSemanticException - in case of any type conflict or mismatching parameter
      • customInferDatatype

        private Operation customInferDatatype​(boolean fallback)
                                       throws CSTSemanticException
        Performs the infer operation for custom operations only, i.e. operand and parameter need to be mapped appropriately.
        Parameters:
        fallback - if this is a fallback resolution
        Returns:
        the resolved operation or null
        Throws:
        CSTSemanticException - in case of type resolution problems
      • getCustomOperation

        private Operation getCustomOperation​(ICustomOperationAccessor accessor,
                                             IDatatype[] paramTypes,
                                             java.util.HashSet<ICustomOperationAccessor> done,
                                             int opInc)
        Searches for a custom operation on accessor and, if not found, on the imports of accessor.
        Parameters:
        accessor - the custom operation accessor
        paramTypes - the parameter types
        done - the already processed custom operation accessors to avoid cycles
        opInc - number of left parameters to ignore
        Returns:
        the operation or null if not found
      • getCustomOperation

        private Operation getCustomOperation​(ICustomOperationAccessor accessor,
                                             IDatatype[] paramTypes,
                                             int opInc)
        Searches for a custom operation on accessor.
        Parameters:
        accessor - the custom operation accessor
        paramTypes - the parameter types
        opInc - number of left parameters to ignore
        Returns:
        the operation or null if not found
      • isParameterAssignable

        private static boolean isParameterAssignable​(IDatatype declared,
                                                     IDatatype argument)
        Returns whether the argument type is assignable to the declared type.
        Parameters:
        declared - the declared type
        argument - the argument type
        Returns:
        true for assignable, false else
      • getParameterType

        private IDatatype getParameterType​(Operation tmp,
                                           int index,
                                           int requiredParamCount,
                                           int opInc)
        Returns the parameter type of tmp at position index considering named and positional parameters.
        Parameters:
        tmp - the operation
        index - the index to return the type for
        requiredParamCount - the required parameter count distinguishing positional and named parameters
        opInc - number of left parameters to ignore
        Returns:
        the type or null if the parameter does not exist
      • getOperand

        public ConstraintSyntaxTree getOperand()
        Returns the operand.
        Returns:
        the operand, may be null in case of custom operations with no parameter
      • getOperation

        public java.lang.String getOperation()
        Returns the operation name.
        Returns:
        the operation name
      • getParameterCount

        public int getParameterCount()
        Returns the number of parameters.
        Returns:
        the number of parameters
      • getParameter

        public ConstraintSyntaxTree getParameter​(int index)
        Returns a specific parameter.
        Parameters:
        index - the index of the parameter
        Returns:
        the parameter
        Throws:
        java.lang.IndexOutOfBoundsException - if index<0 || index>=getParameterCount()
      • getResolvedOperation

        public Operation getResolvedOperation()
        Returns the resolved operation. The result is only valid if inferDatatype() was called before this operation.
        Returns:
        the resolved operation, null if the operation cannot be resolved or inferDatatype() was not called before
      • getAccessor

        public ICustomOperationAccessor getAccessor()
        Returns the custom operation accessor.
        Returns:
        the accessor (may be null)
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object