Package net.ssehub.easy.varModel.cst
Class OCLFeatureCall
java.lang.Object
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
net.ssehub.easy.varModel.cst.OCLFeatureCall
- All Implemented Interfaces:
IAttributeAccess
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 Summary
FieldsModifier and TypeFieldDescriptionprivate ICustomOperationAccessorprivate ConstraintSyntaxTreeprivate Stringprivate ConstraintSyntaxTree[]private Operationprivate IDatatype -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for serialization.OCLFeatureCall(ConstraintSyntaxTree operand, String operation, ConstraintSyntaxTree... parameters) Constructs an OCL feature call as a node of a constraint syntax tree.OCLFeatureCall(ConstraintSyntaxTree operand, String operation, ICustomOperationAccessor opAccessor, ConstraintSyntaxTree... parameters) Constructs an OCL feature call as a node of a constraint syntax tree. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(IConstraintTreeVisitor visitor) Visiting method for the visitor.private OperationcheckOperand(Operation op, IDatatype operandType, IDatatype[] paramTypes) If required, checks the operand against the operation result type.private voidcheckRequiredAssignableParameter(Operation op, IDatatype operandType, IDatatype[] paramTypes) Checks the operation for required assignable parameter if required.static voidcheckTypeCompliance(Operation op, IDatatype operandType, IDatatype[] parameterTypes) Performs specific type compliance checks for found operations, e.g., in case of equality or assignments.private IDatatypecreateCollectionType(IDatatype immediateOperand, IDatatype containedType) Creates a collection type.private OperationcustomInferDatatype(boolean fallback) Performs the infer operation for custom operations only, i.e.private voidPerforms the default infer operation, i.e.booleanReturns the custom operation accessor.private IDatatypegetActualReturnType(Operation op, IDatatype immediateOperand, IDatatype... parameter) Determines the actual return type and considers the actual type of meta type parameters.private OperationgetCustomOperation(ICustomOperationAccessor accessor, IDatatype[] paramTypes, int opInc) Searches for a custom operation onaccessor.private OperationgetCustomOperation(ICustomOperationAccessor accessor, IDatatype[] paramTypes, HashSet<ICustomOperationAccessor> done, int opInc) Searches for a custom operation onaccessorand, if not found, on the imports ofaccessor.private OperationgetCustomOperationOnImports(ICustomOperationAccessor accessor, IDatatype[] paramTypes, HashSet<ICustomOperationAccessor> done, int opInc) Finds an operation viaaccessorimports.Returns the operand.Returns the operation name.getParameter(int index) Returns a specific parameter.intReturns the number of parameters.private IDatatypegetParameterType(Operation tmp, int index, int requiredParamCount, int opInc) Returns the parameter type oftmpat positionindexconsidering named and positional parameters.Returns the resolved operation.inthashCode()Infers the datatype of the subtree represented by this object.private static booleanisParameterAssignable(IDatatype declared, IDatatype argument) Returns whether theargumenttype is assignable to thedeclaredtype.booleanisSemanticallyEqual(ConstraintSyntaxTree otherTree) Checks whether thisConstraintSyntaxTreeis semantically equal to anotherConstraintSyntaxTree.private voidReplaces (temporary) empty initializers.private static voidresolveFully(ConstraintSyntaxTree[] parameter, IDatatype[] types) Dereferencestypesifparameterdoes not indicate a refBy.voidExplicitly setting the resolved operation.toString()Methods inherited from class net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
getAttribute, getAttribute, getAttributesCount, getContainedType, getName, getParent
-
Field Details
-
operand
-
operation
-
parameters
-
resolvedOperation
-
result
-
opAccessor
-
-
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 ininferDatatype().- 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 callparameters- 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 ininferDatatype(). TheopHolderis 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 callopAccessor- an optional instance which stores additional operation definitions, typically the containing project, may be nullparameters- the parameters for the operation (may be null in case of no parameter)
-
-
Method Details
-
inferDatatype
Description copied from class:ConstraintSyntaxTreeInfers the datatype of the subtree represented by this object.- Specified by:
inferDatatypein classConstraintSyntaxTree- 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 checkedoperandType- the actual operand typeparameterTypes- the actual parameter types- Throws:
CSTSemanticException- in case that operand type and parameter types shall match somehow but do not match
-
dfltInferDatatype
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
If required, checks the operand against the operation result type.- Parameters:
op- the operationoperandType- the operand typeparamTypes- the parameter types- Returns:
opor null ifopis not valid with respect to its operand
-
resolveFully
Dereferencestypesifparameterdoes not indicate a refBy.- Parameters:
parameter- the parametertypes- the types (modified as a side effect)
-
replaceEmptyInitializer
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 considerimmediateOperand- the actual operand type (complying togetOperand().parameter- the actual parameter- Returns:
- the actual return type
-
createCollectionType
Creates a collection type.- Parameters:
immediateOperand- the operand determining the collection typecontainedType- the type to be used as contained type of the result collection- Returns:
- the collection type,
containedTypeifimmediateOperandis 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 operationoperandType- the resolved operand typeparamTypes- the resolved parameter types- Throws:
CSTSemanticException- in case of any type conflict or mismatching parameter
-
customInferDatatype
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 onaccessorand, if not found, on the imports ofaccessor.- Parameters:
accessor- the custom operation accessorparamTypes- the parameter typesdone- the already processed custom operation accessors to avoid cyclesopInc- 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 viaaccessorimports.- Parameters:
accessor- the accessor to look intoparamTypes- the parameter typesdone- the already processed custom operation accessors to avoid cyclesopInc- 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 onaccessor.- Parameters:
accessor- the custom operation accessorparamTypes- the parameter typesopInc- number of left parameters to ignore- Returns:
- the operation or null if not found
-
isParameterAssignable
Returns whether theargumenttype is assignable to thedeclaredtype.- Parameters:
declared- the declared typeargument- the argument type- Returns:
truefor assignable,falseelse
-
getParameterType
Returns the parameter type oftmpat positionindexconsidering named and positional parameters.- Parameters:
tmp- the operationindex- the index to return the type forrequiredParamCount- the required parameter count distinguishing positional and named parametersopInc- number of left parameters to ignore- Returns:
- the type or null if the parameter does not exist
-
accept
Description copied from class:ConstraintSyntaxTreeVisiting method for the visitor.
This method is used for saving this model element.- Specified by:
acceptin classConstraintSyntaxTree- Parameters:
visitor- The visitor, which should save this model element.
-
getOperand
Returns the operand.- Returns:
- the operand, may be null in case of custom operations with no parameter
-
getOperation
Returns the operation name.- Returns:
- the operation name
-
getParameterCount
public int getParameterCount()Returns the number of parameters.- Returns:
- the number of parameters
-
getParameter
Returns a specific parameter.- Parameters:
index- the index of the parameter- Returns:
- the parameter
- Throws:
IndexOutOfBoundsException- ifindex<0 || index>=getParameterCount()
-
getResolvedOperation
Returns the resolved operation. The result is only valid ifinferDatatype()was called before this operation.- Returns:
- the resolved operation, null if the operation cannot
be resolved or
inferDatatype()was not called before
-
setResolvedOperation
Explicitly setting the resolved operation. Usually, this shall be accomplished viainferDatatype(), but if, e.g., this happens out of context, such a fallback may be needed. Use with care!- Parameters:
op- the resolved operation
-
getAccessor
Returns the custom operation accessor.- Returns:
- the accessor (may be null)
-
equals
-
hashCode
public int hashCode() -
toString
-
isSemanticallyEqual
Description copied from class:ConstraintSyntaxTreeChecks whether thisConstraintSyntaxTreeis semantically equal to anotherConstraintSyntaxTree. Attention:This method is not fully supported by all operations and sub classes.- Overrides:
isSemanticallyEqualin classConstraintSyntaxTree- Parameters:
otherTree- Another cst to check whether it is semantically equal to this cst.- Returns:
trueif both trees are semantically equal,falseotherwise.
-