Class Operation
- java.lang.Object
-
- net.ssehub.easy.varModel.model.datatypes.Operation
-
- Direct Known Subclasses:
CustomOperation,SetReturningOperation
public class Operation extends java.lang.ObjectDescribes 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 theContainerdatatype is generic, i.e. parameterized over the type of elements it is containing. Thus, operations need to be generic, too. We provide aOperation.ReturnTypeModespecifying 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 usingAnyType.- Author:
- Tebbje, Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOperation.FormattingHintDefines some formatting hints for emitting operations in a canonical form.static classOperation.NestingModeDefines the nesting mode of the results.static classOperation.ReturnTypeModeDefines how to handle the return type of an operation.
-
Field Summary
Fields Modifier and Type Field Description private booleanacceptsNullprivate static java.util.Map<Operation,Operation>aliasprivate static java.util.List<Operation>allOperationsprivate booleanfallbackprivate Operation.FormattingHintformattingHintprivate java.lang.Stringnameprivate Operation.NestingModenestingModeprivate IDatatypeoperandStores the data type this operation is defined for.private IDatatype[]parametersprivate booleanrequiresAssignableParameterprivate IDatatypereturnsprivate Operation.ReturnTypeModereturnTypeModeStores the return type mode.
-
Constructor Summary
Constructors Constructor Description Operation()Constructor for serialization.Operation(IDatatype returns, java.lang.String name, IDatatype operand, IDatatype... parameters)Creates a non-container operation (descriptor).Operation(IDatatype returns, Operation.ReturnTypeMode returnTypeMode, java.lang.String name, IDatatype operand, IDatatype... parameters)Creates an operation (descriptor).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptsNull()Returns 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, java.lang.String name, IDatatype operand, IDatatype... parameters)Creates an infix operator (descriptor).static OperationcreatePostfixOperator(IDatatype returns, java.lang.String name, IDatatype operand, IDatatype... parameters)Creates a postfix operator (descriptor).static OperationcreatePrefixOperator(IDatatype returns, java.lang.String name, IDatatype operand, IDatatype... parameters)Creates a prefix operator (descriptor).IDatatypegetActualReturnType(IDatatype immediateOperand, IDatatype... parameter)Determines the actual return type.static OperationgetAlias(Operation op)Returns the alias defined for the given operation has.Operation.FormattingHintgetFormattingHint()Returns the formatting hint.ConstraintSyntaxTreegetFunction()Returns the function expression calculated by this operation.java.lang.StringgetName()Returns the name of the operation.Operation.NestingModegetNestingMode()Returns the nesting mode.IDatatypegetOperand()The operand this operation is defined on.static OperationgetOperation(int index)Returns the specified defined operation.static intgetOperationsCount()Returns the number of all defined operations.DecisionVariableDeclarationgetParameter(java.lang.String name)Returns the specified named parameter.intgetParameterCount()Returns the number of parameters of this operation.DecisionVariableDeclarationgetParameterDeclaration(int index)Returns the parameter at positionindex.ConstraintSyntaxTreegetParameterDefaultValue(int index)Returns the parameter default value at positionindex.IDatatypegetParameterType(int index)Returns the parameter type at positionindex.intgetRequiredParameterCount()Returns the number of required parameters.IDatatypegetReturns()Getter for the return type of this operation.Operation.ReturnTypeModegetReturnTypeMode()Returns the return type mode.java.lang.StringgetSignature()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.booleanisContainerOperation()Returns whether this operation is a container iterating operation, e.g.booleanisFallback()Returns 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) OperationmarkAsAcceptsNull()Marks that this operation accepts null as argument.(package private) OperationmarkAsAliasOf(Operation op)Marks this operation as an alias ofop, indicating that this operation is a potential a risk for breaking OCL compliance.(package private) OperationmarkAsAssignableParameterOperation()Marks that this operation requires assignable parameter types.(package private) OperationmarkAsContainerOperation()Marks this operation as a container iterating operation.(package private) OperationmarkAsFallback()Marks this operation as a fallback operation, seeisFallback()for an explanation.(package private) OperationmarkAsFlatteningContainerOperation()Marks this operation as a flattening container iterating operation.(package private) OperationmarkAsNestingContainerOperation()Marks this operation as a flattening container iterating operation.(package private) OperationmarkByFormattingHint(Operation.FormattingHint formattingHint)Marks this operation by a formatting hint.protected booleanregisterAsOperation()Returns whether this operation shall be registered as a global operation.booleanrequiresAssignableParameter()Returns whether this operation requires equal parameter types.
-
-
-
Field Detail
-
allOperations
private static java.util.List<Operation> allOperations
-
returns
private IDatatype returns
-
name
private java.lang.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 Detail
-
Operation
Operation()
Constructor for serialization.
-
Operation
Operation(IDatatype returns, java.lang.String name, IDatatype operand, IDatatype... parameters)
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, java.lang.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 Detail
-
createInfixOperator
public static Operation createInfixOperator(IDatatype returns, java.lang.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, java.lang.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, java.lang.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
public IDatatype getReturns()
Getter for the return type of this operation.- Returns:
- IDatatype
-
getName
public java.lang.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:
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
public IDatatype getParameterType(int index)
Returns the parameter type at positionindex.- Parameters:
index- a 0-based index denoting the parameter to be returned- Returns:
- the specified parameter
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getParameterCount()
-
getParameterDeclaration
public DecisionVariableDeclaration getParameterDeclaration(int index)
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:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getParameterCount()
-
getParameterDefaultValue
public ConstraintSyntaxTree getParameterDefaultValue(int index)
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:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getParameterCount()
-
getParameter
public DecisionVariableDeclaration getParameter(java.lang.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 togetOperand().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 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
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, 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
Operation markAsAliasOf(Operation op)
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
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 statingBooleanType.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 statingBooleanType.class.getClass();for all relevant classes.- Parameters:
index- a 0-based index denoting the operation- Returns:
- the operation
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>={@link #getOperationsCount()()}
-
registerAsOperation
protected boolean registerAsOperation()
Returns whether this operation shall be registered as a global operation.- Returns:
trueif it should be registered,falseelse
-
getSignature
public java.lang.String getSignature()
Returns the signature of the operation.- Returns:
- the signature of the operation
-
-