Class Operation

java.lang.Object
net.ssehub.easy.varModel.model.datatypes.Operation
Direct Known Subclasses:
CustomOperation, SetReturningOperation

public class Operation extends Object
Describes an operation. Operations may be operators or function calls. Actually, this class does not describe how the implementation of the operation is done. It just describes the signature of the operation. The concrete implementation is part of the reasoning process. Operations are intended to be made available as constants in their declaring type in order to provide a simple operation-translation-mapping in the reasoning implementation.
Note that at least the Container datatype is generic, i.e. parameterized over the type of elements it is containing. Thus, operations need to be generic, too. We provide a Operation.ReturnTypeMode specifying how the actual return type is to be handled based on the actual type and its generic types. This is actually a simplification but should work as the type resolution relies on the return types. Generic return types may be specified using AnyType.
Author:
Tebbje, Holger Eichelberger
  • Field Details

    • allOperations

      private static List<Operation> allOperations
    • alias

      private static transient Map<Operation,Operation> alias
    • returns

      private IDatatype returns
    • name

      private String name
    • parameters

      private IDatatype[] parameters
    • operand

      private IDatatype operand
      Stores the data type this operation is defined for.
    • returnTypeMode

      private Operation.ReturnTypeMode returnTypeMode
      Stores the return type mode.
    • requiresAssignableParameter

      private boolean requiresAssignableParameter
    • acceptsNull

      private boolean acceptsNull
    • formattingHint

      private Operation.FormattingHint formattingHint
    • nestingMode

      private Operation.NestingMode nestingMode
    • fallback

      private boolean fallback
  • Constructor Details

    • Operation

      Operation()
      Constructor for serialization.
    • Operation

      Operation(IDatatype returns, String name, IDatatype operand, IDatatype... parameters)
      Creates a non-container operation (descriptor). The return type mode is Operation.ReturnTypeMode.UNCHANGED by default. Use markAsContainerOperation() to flag this operation as a container operation.
      Parameters:
      returns - result type of the operation
      name - name of the operation
      operand - the data type the operation is defined for
      parameters - list of parameters for operation
    • Operation

      Operation(IDatatype returns, Operation.ReturnTypeMode returnTypeMode, String name, IDatatype operand, IDatatype... parameters)
      Creates an operation (descriptor). Use markAsContainerOperation() to flag this operation as a container operation.
      Parameters:
      returns - result type of the operation
      returnTypeMode - the return type mode
      name - name of the operation
      operand - the data type the operation is defined for
      parameters - list of parameters for operation
  • Method Details

    • createInfixOperator

      public static Operation createInfixOperator(IDatatype returns, String name, IDatatype operand, IDatatype... parameters)
      Creates an infix operator (descriptor). The return type mode is Operation.ReturnTypeMode.UNCHANGED by default.
      Parameters:
      returns - result type of the operation
      name - name of the operation
      operand - the data type the operation is defined for
      parameters - list of parameters for operation
      Returns:
      the operation
    • createPrefixOperator

      public static Operation createPrefixOperator(IDatatype returns, String name, IDatatype operand, IDatatype... parameters)
      Creates a prefix operator (descriptor). The return type mode is Operation.ReturnTypeMode.UNCHANGED by default.
      Parameters:
      returns - result type of the operation
      name - name of the operation
      operand - the data type the operation is defined for
      parameters - list of parameters for operation
      Returns:
      the operation
    • createPostfixOperator

      public static Operation createPostfixOperator(IDatatype returns, String name, IDatatype operand, IDatatype... parameters)
      Creates a postfix operator (descriptor). The return type mode is Operation.ReturnTypeMode.UNCHANGED by default.
      Parameters:
      returns - result type of the operation
      name - name of the operation
      operand - the data type the operation is defined for
      parameters - list of parameters for operation
      Returns:
      the operation
    • getReturns

      public IDatatype getReturns()
      Getter for the return type of this operation.
      Returns:
      IDatatype
    • getName

      public String getName()
      Returns the name of the operation.
      Returns:
      the name of the operation
    • isStatic

      public boolean isStatic()
      Returns whether this operation is static.
      Returns:
      true for static, false else
    • isFallback

      public boolean isFallback()
      Returns whether this operation shall only be resolved as a fallback, i.e., as last resort if no other operation matches. Typically resolution starts at the most generic type. This flag reverses the resolution order for operations with the same name and number of parameters.
      Returns:
      true for fallback operations, false else
    • getParameterCount

      public int getParameterCount()
      Returns the number of parameters of this operation.
      Returns:
      the number of parameters
    • getRequiredParameterCount

      public int getRequiredParameterCount()
      Returns the number of required parameters.
      Returns:
      the number of required parameters
    • getParameterType

      public IDatatype getParameterType(int index)
      Returns the parameter type at position index.
      Parameters:
      index - a 0-based index denoting the parameter to be returned
      Returns:
      the specified parameter
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getParameterCount()
    • getParameterDeclaration

      public DecisionVariableDeclaration getParameterDeclaration(int index)
      Returns the parameter at position index.
      Parameters:
      index - a 0-based index denoting the parameter to be returned
      Returns:
      the specified parameter (may be null if there is no formal declaration
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getParameterCount()
    • getParameterDefaultValue

      public ConstraintSyntaxTree getParameterDefaultValue(int index)
      Returns the parameter default value at position index.
      Parameters:
      index - a 0-based index denoting the parameter to be returned
      Returns:
      the specified parameter default value (may be null if there is no default value)
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getParameterCount()
    • getParameter

      public DecisionVariableDeclaration getParameter(String name)
      Returns the specified named parameter.
      Parameters:
      name - the name of the parameter
      Returns:
      the named parameter declaration (may be null)
    • getOperand

      public IDatatype getOperand()
      The operand this operation is defined on.
      Returns:
      IDatatype the operand as datatype
    • getFunction

      public ConstraintSyntaxTree getFunction()
      Returns the function expression calculated by this operation.
      Returns:
      the function operation (always null)
    • getReturnTypeMode

      public Operation.ReturnTypeMode getReturnTypeMode()
      Returns the return type mode.
      Returns:
      the return type mode
    • getActualReturnType

      public final IDatatype getActualReturnType(IDatatype immediateOperand, IDatatype... parameter)
      Determines the actual return type.
      Parameters:
      immediateOperand - the actual operand type (complying to getOperand().
      parameter - the actual parameter
      Returns:
      the actual return type
    • immediateOperandCollection

      private IDatatype immediateOperandCollection(IDatatype immediateOperand)
      Returns a collection type using the immediate operand as generic based on the original return type of this operation.
      Parameters:
      immediateOperand - the immediate operand
      Returns:
      the datatype
    • createCollectionReturnType

      protected IDatatype createCollectionReturnType(IDatatype aim, IDatatype elementType, IModelElement parent)
      Creates a collection return type based on aim. Subclasses may override to limit the actual return type.
      Parameters:
      aim - the type aim (Sequence.TYPE or Set.TYPE)
      elementType - the element type
      parent - the parent model element
      Returns:
      the collection return type, null if aim is none of the types given above
    • immediateOperandCollection

      private IDatatype immediateOperandCollection(Operation.ReturnTypeMode mode, IDatatype immediateOperand, IDatatype[] parameter)
      Determines the immediate operand for a collection.
      Parameters:
      mode - the return type mode
      immediateOperand - the actual immediate operand
      parameter - the parameters
      Returns:
      the return type
    • isContainerOperation

      public boolean isContainerOperation()
      Returns whether this operation is a container iterating operation, e.g. a quantor, i.e., some form of nesting mode is activated.
      Returns:
      true if this is a container operation, false else
    • getNestingMode

      public Operation.NestingMode getNestingMode()
      Returns the nesting mode.
      Returns:
      the nesting mode
    • acceptsNull

      public boolean acceptsNull()
      Returns whether this operation accepts null as argument.
      Returns:
      whether it accepts null
    • markAsFlatteningContainerOperation

      Operation markAsFlatteningContainerOperation()
      Marks this operation as a flattening container iterating operation.
      Returns:
      this
    • markAsNestingContainerOperation

      Operation markAsNestingContainerOperation()
      Marks this operation as a flattening container iterating operation.
      Returns:
      this
    • markAsFallback

      Operation markAsFallback()
      Marks this operation as a fallback operation, see isFallback() for an explanation. Introduced as constructors grew to more than 5 parameter.
      Returns:
      this
    • markAsContainerOperation

      Operation markAsContainerOperation()
      Marks this operation as a container iterating operation. Introduced as constructors grew to more than 5 parameter.
      Returns:
      this
    • markAsAliasOf

      Operation markAsAliasOf(Operation op)
      Marks this operation as an alias of op, indicating that this operation is a potential a risk for breaking OCL compliance.
      Parameters:
      op - the aliased operation
      Returns:
      this
    • markAsAssignableParameterOperation

      Operation markAsAssignableParameterOperation()
      Marks that this operation requires assignable parameter types. Introduced as constructors grew to more than 5 parameter.
      Returns:
      this
    • markAsAcceptsNull

      Operation markAsAcceptsNull()
      Marks that this operation accepts null as argument.
      Returns:
      this
    • requiresAssignableParameter

      public boolean requiresAssignableParameter()
      Returns whether this operation requires equal parameter types.
      Returns:
      true if parameter types need to be
    • markByFormattingHint

      Operation markByFormattingHint(Operation.FormattingHint formattingHint)
      Marks this operation by a formatting hint.
      Parameters:
      formattingHint - the formatting hint
      Returns:
      this (builder pattern)
    • getFormattingHint

      public Operation.FormattingHint getFormattingHint()
      Returns the formatting hint.
      Returns:
      the formatting hint
    • getOperationsCount

      public static int getOperationsCount()
      Returns the number of all defined operations. As a prerequisite, the related datatype classes need to be loaded into the VM, e.g. by explicitly stating BooleanType.class.getClass(); for all relevant classes.
      Returns:
      the number of parameters
    • getOperation

      public static Operation getOperation(int index)
      Returns the specified defined operation. As a prerequisite, the related datatype classes need to be loaded into the VM, e.g. by explicitly stating BooleanType.class.getClass(); for all relevant classes.
      Parameters:
      index - a 0-based index denoting the operation
      Returns:
      the operation
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getOperationsCount()
    • registerAsOperation

      protected boolean registerAsOperation()
      Returns whether this operation shall be registered as a global operation.
      Returns:
      true if it should be registered, false else
    • getSignature

      public String getSignature()
      Returns the signature of the operation.
      Returns:
      the signature of the operation
    • getAlias

      public static Operation getAlias(Operation op)
      Returns the alias defined for the given operation has.
      Parameters:
      op - the operation to look for (ignored if null)
      Returns:
      the alias or null for none