Class OCLFeatureCall

java.lang.Object
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
net.ssehub.easy.varModel.cst.OCLFeatureCall
All Implemented Interfaces:
IAttributeAccess

public class OCLFeatureCall extends ConstraintSyntaxTree
Class for OCLFeatureCall. This class may resolve custom operations if a ICustomOperationAccessor is provided to the constructor.
Author:
jaehne, tebbje, El-Sharkawy, Holger Eichelberger
  • Field Details

  • Constructor Details

    • OCLFeatureCall

      OCLFeatureCall()
      Constructor for serialization.
    • OCLFeatureCall

      public OCLFeatureCall(ConstraintSyntaxTree operand, 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, 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 Details

    • inferDatatype

      public IDatatype inferDatatype() throws CSTSemanticException
      Description copied from class: ConstraintSyntaxTree
      Infers the datatype of the subtree represented by this object.
      Specified by:
      inferDatatype in class ConstraintSyntaxTree
      Returns:
      the data type
      Throws:
      CSTSemanticException - Will be thrown if parameters of (sub-) trees do not fit together.
    • 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
    • createCollectionType

      private IDatatype createCollectionType(IDatatype immediateOperand, IDatatype containedType)
      Creates a collection type.
      Parameters:
      immediateOperand - the operand determining the collection type
      containedType - the type to be used as contained type of the result collection
      Returns:
      the collection type, containedType if immediateOperand is not a collection
    • 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, 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
    • getCustomOperationOnImports

      private Operation getCustomOperationOnImports(ICustomOperationAccessor accessor, IDatatype[] paramTypes, HashSet<ICustomOperationAccessor> done, int opInc)
      Finds an operation via accessor imports.
      Parameters:
      accessor - the accessor to look into
      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
    • accept

      public void accept(IConstraintTreeVisitor visitor)
      Description copied from class: ConstraintSyntaxTree
      Visiting method for the visitor.
      This method is used for saving this model element.
      Specified by:
      accept in class ConstraintSyntaxTree
      Parameters:
      visitor - The visitor, which should save this model element.
    • getOperand

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

      public 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:
      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
    • setResolvedOperation

      public void setResolvedOperation(Operation op)
      Explicitly setting the resolved operation. Usually, this shall be accomplished via inferDatatype(), but if, e.g., this happens out of context, such a fallback may be needed. Use with care!
      Parameters:
      op - the resolved operation
    • getAccessor

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
    • isSemanticallyEqual

      public boolean isSemanticallyEqual(ConstraintSyntaxTree otherTree)
      Description copied from class: ConstraintSyntaxTree
      Checks whether this ConstraintSyntaxTree is semantically equal to another ConstraintSyntaxTree. Attention:This method is not fully supported by all operations and sub classes.
      Overrides:
      isSemanticallyEqual in class ConstraintSyntaxTree
      Parameters:
      otherTree - Another cst to check whether it is semantically equal to this cst.
      Returns:
      true if both trees are semantically equal, false otherwise.