Class Operation
java.lang.Object
net.ssehub.easy.varModel.model.datatypes.Operation
- Direct Known Subclasses:
CustomOperation,SetReturningOperation
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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines some formatting hints for emitting operations in a canonical form.static enumDefines the nesting mode of the results.static enumDefines how to handle the return type of an operation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate Operation.FormattingHintprivate Stringprivate Operation.NestingModeprivate IDatatypeStores the data type this operation is defined for.private IDatatype[]private booleanprivate IDatatypeprivate Operation.ReturnTypeModeStores the return type mode. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this operation accepts null as argument.protected IDatatypecreateCollectionReturnType(IDatatype aim, IDatatype elementType, IModelElement parent) Creates a collection return type based onaim.static OperationcreateInfixOperator(IDatatype returns, String name, IDatatype operand, IDatatype... parameters) Creates an infix operator (descriptor).static OperationcreatePostfixOperator(IDatatype returns, String name, IDatatype operand, IDatatype... parameters) Creates a postfix operator (descriptor).static OperationcreatePrefixOperator(IDatatype returns, String name, IDatatype operand, IDatatype... parameters) Creates a prefix operator (descriptor).final IDatatypegetActualReturnType(IDatatype immediateOperand, IDatatype... parameter) Determines the actual return type.static OperationReturns the alias defined for the given operation has.Returns the formatting hint.Returns the function expression calculated by this operation.getName()Returns the name of the operation.Returns the nesting mode.The operand this operation is defined on.static OperationgetOperation(int index) Returns the specified defined operation.static intReturns the number of all defined operations.getParameter(String name) Returns the specified named parameter.intReturns the number of parameters of this operation.getParameterDeclaration(int index) Returns the parameter at positionindex.getParameterDefaultValue(int index) Returns the parameter default value at positionindex.getParameterType(int index) Returns the parameter type at positionindex.intReturns the number of required parameters.Getter for the return type of this operation.Returns the return type mode.Returns the signature of the operation.private IDatatypeimmediateOperandCollection(IDatatype immediateOperand) Returns a collection type using the immediate operand as generic based on the original return type of this operation.private IDatatypeimmediateOperandCollection(Operation.ReturnTypeMode mode, IDatatype immediateOperand, IDatatype[] parameter) Determines the immediate operand for a collection.booleanReturns whether this operation is a container iterating operation, e.g.booleanReturns whether this operation shall only be resolved as a fallback, i.e., as last resort if no other operation matches.booleanisStatic()Returns whether this operation is static.(package private) OperationMarks that this operation accepts null as argument.(package private) OperationMarks this operation as an alias ofop, indicating that this operation is a potential a risk for breaking OCL compliance.(package private) OperationMarks that this operation requires assignable parameter types.(package private) OperationMarks this operation as a container iterating operation.(package private) OperationMarks this operation as a fallback operation, seeisFallback()for an explanation.(package private) OperationMarks this operation as a flattening container iterating operation.(package private) OperationMarks this operation as a flattening container iterating operation.(package private) OperationmarkByFormattingHint(Operation.FormattingHint formattingHint) Marks this operation by a formatting hint.protected booleanReturns whether this operation shall be registered as a global operation.booleanReturns whether this operation requires equal parameter types.
-
Field Details
-
allOperations
-
alias
-
returns
-
name
-
parameters
-
operand
Stores the data type this operation is defined for. -
returnTypeMode
Stores the return type mode. -
requiresAssignableParameter
private boolean requiresAssignableParameter -
acceptsNull
private boolean acceptsNull -
formattingHint
-
nestingMode
-
fallback
private boolean fallback
-
-
Constructor Details
-
Operation
Operation()Constructor for serialization. -
Operation
Creates a non-container operation (descriptor). The return type mode isOperation.ReturnTypeMode.UNCHANGEDby default. UsemarkAsContainerOperation()to flag this operation as a container operation.- Parameters:
returns- result type of the operationname- name of the operationoperand- the data type the operation is defined forparameters- list of parameters for operation
-
Operation
Operation(IDatatype returns, Operation.ReturnTypeMode returnTypeMode, String name, IDatatype operand, IDatatype... parameters) Creates an operation (descriptor). UsemarkAsContainerOperation()to flag this operation as a container operation.- Parameters:
returns- result type of the operationreturnTypeMode- the return type modename- name of the operationoperand- the data type the operation is defined forparameters- 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 isOperation.ReturnTypeMode.UNCHANGEDby default.- Parameters:
returns- result type of the operationname- name of the operationoperand- the data type the operation is defined forparameters- 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 isOperation.ReturnTypeMode.UNCHANGEDby default.- Parameters:
returns- result type of the operationname- name of the operationoperand- the data type the operation is defined forparameters- 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 isOperation.ReturnTypeMode.UNCHANGEDby default.- Parameters:
returns- result type of the operationname- name of the operationoperand- the data type the operation is defined forparameters- list of parameters for operation- Returns:
- the operation
-
getReturns
Getter for the return type of this operation.- Returns:
- IDatatype
-
getName
Returns the name of the operation.- Returns:
- the name of the operation
-
isStatic
public boolean isStatic()Returns whether this operation is static.- Returns:
truefor static,falseelse
-
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:
truefor fallback operations,falseelse
-
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
Returns the parameter type at positionindex.- Parameters:
index- a 0-based index denoting the parameter to be returned- Returns:
- the specified parameter
- Throws:
IndexOutOfBoundsException- ifindex<0 || index>=getParameterCount()
-
getParameterDeclaration
Returns the parameter at positionindex.- 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- ifindex<0 || index>=getParameterCount()
-
getParameterDefaultValue
Returns the parameter default value at positionindex.- 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- ifindex<0 || index>=getParameterCount()
-
getParameter
Returns the specified named parameter.- Parameters:
name- the name of the parameter- Returns:
- the named parameter declaration (may be null)
-
getOperand
The operand this operation is defined on.- Returns:
- IDatatype the operand as datatype
-
getFunction
Returns the function expression calculated by this operation.- Returns:
- the function operation (always null)
-
getReturnTypeMode
Returns the return type mode.- Returns:
- the return type mode
-
getActualReturnType
Determines the actual return type.- Parameters:
immediateOperand- the actual operand type (complying togetOperand().parameter- the actual parameter- Returns:
- the actual return type
-
immediateOperandCollection
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 onaim. Subclasses may override to limit the actual return type.- Parameters:
aim- the type aim (Sequence.TYPEorSet.TYPE)elementType- the element typeparent- the parent model element- Returns:
- the collection return type, null if
aimis 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 modeimmediateOperand- the actual immediate operandparameter- 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:
trueif this is a container operation,falseelse
-
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, seeisFallback()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
Marks this operation as an alias ofop, 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:
trueif parameter types need to be
-
markByFormattingHint
Marks this operation by a formatting hint.- Parameters:
formattingHint- the formatting hint- Returns:
- this (builder pattern)
-
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 statingBooleanType.class.getClass();for all relevant classes.- Returns:
- the number of parameters
-
getOperation
Returns the specified defined operation. As a prerequisite, the related datatype classes need to be loaded into the VM, e.g. by explicitly statingBooleanType.class.getClass();for all relevant classes.- Parameters:
index- a 0-based index denoting the operation- Returns:
- the operation
- Throws:
IndexOutOfBoundsException- ifindex<0 || index>=getOperationsCount()
-
registerAsOperation
protected boolean registerAsOperation()Returns whether this operation shall be registered as a global operation.- Returns:
trueif it should be registered,falseelse
-
getSignature
Returns the signature of the operation.- Returns:
- the signature of the operation
-
getAlias
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
-