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
public class OCLFeatureCall extends ConstraintSyntaxTree
Class for OCLFeatureCall. This class may resolve custom operations if aICustomOperationAccessoris provided to the constructor.- Author:
- jaehne, tebbje, El-Sharkawy, Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private ICustomOperationAccessoropAccessorprivate ConstraintSyntaxTreeoperandprivate java.lang.Stringoperationprivate ConstraintSyntaxTree[]parametersprivate OperationresolvedOperationprivate IDatatyperesult
-
Constructor Summary
Constructors Constructor Description OCLFeatureCall()Constructor for serialization.OCLFeatureCall(ConstraintSyntaxTree operand, java.lang.String operation, ConstraintSyntaxTree... parameters)Constructs an OCL feature call as a node of a constraint syntax tree.OCLFeatureCall(ConstraintSyntaxTree operand, java.lang.String operation, ICustomOperationAccessor opAccessor, ConstraintSyntaxTree... parameters)Constructs an OCL feature call as a node of a constraint syntax tree.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(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 OperationcustomInferDatatype(boolean fallback)Performs the infer operation for custom operations only, i.e.private voiddfltInferDatatype()Performs the default infer operation, i.e.booleanequals(java.lang.Object obj)ICustomOperationAccessorgetAccessor()Returns 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, java.util.HashSet<ICustomOperationAccessor> done, int opInc)Searches for a custom operation onaccessorand, if not found, on the imports ofaccessor.ConstraintSyntaxTreegetOperand()Returns the operand.java.lang.StringgetOperation()Returns the operation name.ConstraintSyntaxTreegetParameter(int index)Returns a specific parameter.intgetParameterCount()Returns the number of parameters.private IDatatypegetParameterType(Operation tmp, int index, int requiredParamCount, int opInc)Returns the parameter type oftmpat positionindexconsidering named and positional parameters.OperationgetResolvedOperation()Returns the resolved operation.inthashCode()IDatatypeinferDatatype()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 voidreplaceEmptyInitializer(Operation op)Replaces (temporary) empty initializers.private static voidresolveFully(ConstraintSyntaxTree[] parameter, IDatatype[] types)Dereferencestypesifparameterdoes not indicate a refBy.java.lang.StringtoString()-
Methods inherited from class net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
getAttribute, getAttribute, getAttributesCount, getContainedType, getName, getParent
-
-
-
-
Field Detail
-
operand
private ConstraintSyntaxTree operand
-
operation
private java.lang.String operation
-
parameters
private ConstraintSyntaxTree[] parameters
-
resolvedOperation
private Operation resolvedOperation
-
result
private IDatatype result
-
opAccessor
private ICustomOperationAccessor opAccessor
-
-
Constructor Detail
-
OCLFeatureCall
OCLFeatureCall()
Constructor for serialization.
-
OCLFeatureCall
public OCLFeatureCall(ConstraintSyntaxTree operand, java.lang.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, java.lang.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 Detail
-
inferDatatype
public IDatatype inferDatatype() throws CSTSemanticException
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
private void dfltInferDatatype() throws CSTSemanticExceptionPerforms 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 operationoperandType- the operand typeparamTypes- the parameter types- Returns:
opor null ifopis not valid with respect to its operand
-
resolveFully
private static void resolveFully(ConstraintSyntaxTree[] parameter, IDatatype[] types)
Dereferencestypesifparameterdoes not indicate a refBy.- Parameters:
parameter- the parametertypes- 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 considerimmediateOperand- the actual operand type (complying togetOperand().parameter- the actual parameter- Returns:
- the actual return type
-
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
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, java.util.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
-
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
private static boolean isParameterAssignable(IDatatype declared, IDatatype argument)
Returns whether theargumenttype is assignable to thedeclaredtype.- Parameters:
declared- the declared typeargument- the argument type- Returns:
truefor assignable,falseelse
-
getParameterType
private IDatatype getParameterType(Operation tmp, int index, int requiredParamCount, int opInc)
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
public void accept(IConstraintTreeVisitor visitor)
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
public ConstraintSyntaxTree getOperand()
Returns the operand.- Returns:
- the operand, may be null in case of custom operations with no parameter
-
getOperation
public java.lang.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:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getParameterCount()
-
getResolvedOperation
public Operation 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
-
getAccessor
public ICustomOperationAccessor getAccessor()
Returns the custom operation accessor.- Returns:
- the accessor (may be null)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isSemanticallyEqual
public boolean isSemanticallyEqual(ConstraintSyntaxTree otherTree)
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:
- true if both trees are semantically equal, false otherwise.
-
-