Class AbstractCallExpression
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.Expression
-
- net.ssehub.easy.instantiation.core.model.expressions.AbstractCallExpression
-
- All Implemented Interfaces:
IArgumentProvider
- Direct Known Subclasses:
CallExpression,ModelCallExpression,ResolvableOperationCallExpression
public abstract class AbstractCallExpression extends Expression implements IArgumentProvider
Implements the type checking and automated type conversion mechanism in an abstracted form based onIMetaTypeandIMetaOperation. The search for matching operations is based on unnamed arguments. Named arguments are ignored here as they are handled differently. However, results may have to be casted.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractCallExpression.ConvertibleOperationStores an operation as well as the required type conversion operations.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringnameprivate java.lang.Stringprefixprivate static ResolutionListenerRESLIST
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCallExpression()Constructor for serialization.protectedAbstractCallExpression(java.lang.String name, boolean unqualify)Creates an instance from the given call name.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static voidaddAndPruneByType(java.util.List<IMetaOperation> candidates, IMetaOperation toAdd, IMetaType[] argTypes, CallArgument[] arguments, int unnamedArgsCount)AddstoAddtocandidatesif it is considered as the best candidate with respect to the givenargTypes.private static java.util.List<IMetaOperation>assignableCandidates(IMetaType operand, java.lang.String name, CallArgument[] arguments, int unnamedArgsCount, boolean allowAny)Derives the assignable candidates fromoperand, i.e., operations which can be directly applied with identical parameters or (second step) with assignable parameters but without parameter conversion.private static intcalcSuperDiff(IMetaType iter, IMetaType reference)Calculates the difference of super types fromreferencetoiter.private static intcalcSuperDiffRec(IMetaType iter, IMetaType reference)Calculates the difference of super types fromreferencetoiterover the types and their generic parameter.private static intcalcTypeDiff(IMetaOperation operation, IMetaType[] argTypes, CallArgument[] arguments, int unnamedArgsCount)Calculates the differences in types between the givenoperationand the given argument types.private static java.util.List<AbstractCallExpression.ConvertibleOperation>convertibleCandidates(IMetaType operand, java.lang.String name, CallArgument[] arguments, int unnamedArgsCount)Derives the convertible candidates fromoperand, i.e., operations which can be applied including parameter conversion.private static IMetaTypedetermineActualType(IMetaType type, java.lang.Object object, TypeRegistry registry)Determines the actual type ofobject.static <O extends IMetaOperation>
OdynamicDispatch(O operation, java.lang.Object[] args, java.lang.Class<O> cls, TypeRegistry registry, IArgumentProvider arguments, IMetaType operandOverride)Aims at re-resolving the given operation according to the dynamic types ofargs.abstract CallArgumentgetArgument(int index)Returns the specified argument.abstract intgetArgumentsCount()Returns the number of arguments.private static IMetaTypegetEnumType(TypeRegistry registry, EnumValue val)Returns the VIL type for an enum value.java.lang.StringgetName()Returns the name of the call.private static <O extends IMetaOperation>
IMetaTypegetOperand(O operation, IMetaType operandOverride)protected static IMetaTypegetParameterType(IMetaOperation operation, int index, CallArgument[] arguments, int unnamedArgsCount)Returns the parameter type considering named parameters.java.lang.StringgetPrefix()Returns the name prefix.java.lang.StringgetQualifiedName()Returns the qualified name consisting ofgetPrefix()(if present) andgetName().static java.lang.StringgetSignature(java.lang.String name, CallArgument[] arguments)Returns a java-like signature for the specified operation.abstract java.lang.StringgetVilSignature()Returns the VIL signature of the resolved operation.protected java.lang.StringgetVilSignature(IMetaOperation operation)Returns the VIL signature of the specifiedoperation.booleanisIteratingCollectionOperation()Returns whether this operation is a collection-iterator operation.booleanisOclCompliant()Returns whether this operation is OCL compliant or flagged as not compliant.abstract booleanisPlaceholder()Returns whether this operation is a placeholder, i.e., either the resolved operation is aplaceholder, its signature or its return type does contain aplaceholder type.protected static booleanisPlaceholder(IMetaOperation operation)Returns whether the specified operation is a placeholder and cannot be executed, i.e., the operation itself is a placeholder or a placeholder type is used in its signature.private static IMetaOperationresolveFallbacks(IMetaType opType, java.lang.String name, CallArgument[] arguments)Last resort resolution, try with String or in case of a decision variable with the primitive types it can represent.static IMetaOperationresolveOperation(IMetaType operand, boolean checkMetaForFirstArgField, java.lang.String name, CallArgument[] arguments)Resolves the given operation onoperand, but allows checking the first field for a meta type (e.g., DecisionVariable instead of the actual field type).static IMetaOperationresolveOperation(IMetaType operand, java.lang.String name, CallArgument... arguments)Resolves the given operation onoperand.private static IMetaOperationresolveOperation(IMetaType operand, java.lang.String name, CallArgument[] arguments, boolean allowConversion, boolean allowAny)Actually aims at resolving the operation.private static IMetaOperationresolveOperationOnModel(java.lang.Object operand, java.lang.String name, CallArgument[] arguments, java.util.Set<java.lang.Object> done)Resolves the given operation onoperand, consideringoperandas a model with imports.static IMetaOperationresolveResolvableOperation(IMetaType operand, IMetaType pType, IMetaType aType, Expression initExpression, ResolutionListener listener)Resolves a resolvable operation ("function pointer").private static java.util.List<AbstractCallExpression.ConvertibleOperation>selectAmongMultipleCandidates(java.util.List<AbstractCallExpression.ConvertibleOperation> candidates, CallArgument[] arguments, int unnamedArgsCount)Selects among multiple convertible candidates.private static java.lang.StringtoSignatures(java.lang.Iterable<IMetaOperation> operations)Turns the signatures of the givenoperationsinto a string.private static IMetaType[]toTypeDescriptors(CallArgument[] args)Turns the given call arguments to type descriptors.private static CallArgument[]toTypeDescriptors(IMetaType type, int exclude)Turns the generic parameter types oftypeinto an array.private static IMetaOperationtryOpConversionToSecond(IMetaType opType, java.lang.String name, CallArgument[] arguments)Tries to convert the operand to the second argument type and resolves it.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.expressions.Expression
accept, inferType, replaceEmptyLine
-
-
-
-
Field Detail
-
RESLIST
private static final ResolutionListener RESLIST
-
name
private java.lang.String name
-
prefix
private java.lang.String prefix
-
-
Constructor Detail
-
AbstractCallExpression
protected AbstractCallExpression()
Constructor for serialization.
-
AbstractCallExpression
protected AbstractCallExpression(java.lang.String name, boolean unqualify) throws VilExceptionCreates an instance from the given call name.- Parameters:
name- the name of the callunqualify- reduce the name into name and prefix if possible, else leave name untouched- Throws:
VilException- in case of an illegal qualified name
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name of the call.- Returns:
- the name
-
getPrefix
public java.lang.String getPrefix()
Returns the name prefix.- Returns:
- the prefix (or null if there is none)
-
getQualifiedName
public java.lang.String getQualifiedName()
Returns the qualified name consisting ofgetPrefix()(if present) andgetName().- Returns:
- the qualified name
-
getParameterType
protected static IMetaType getParameterType(IMetaOperation operation, int index, CallArgument[] arguments, int unnamedArgsCount)
Returns the parameter type considering named parameters. After unnamed arguments, this method may switch to parameter names.- Parameters:
operation- the operationindex- the parameter indexarguments- the argumentsunnamedArgsCount- the number of unnamed arguments- Returns:
- the parameter type (may be null if there is none / legacy optional named parameter)
-
assignableCandidates
private static java.util.List<IMetaOperation> assignableCandidates(IMetaType operand, java.lang.String name, CallArgument[] arguments, int unnamedArgsCount, boolean allowAny) throws VilException
Derives the assignable candidates fromoperand, i.e., operations which can be directly applied with identical parameters or (second step) with assignable parameters but without parameter conversion.- Parameters:
operand- the operand of the call to be resolvedname- the name of the operation call to be resolvedarguments- the arguments of the callallowAny- allow AnyType as assignable parameter type (dynamic dispatch)unnamedArgsCount- the number of unnamed arguments inarguments- Returns:
- the list of candidate operations
- Throws:
VilException- in case of type resolution problems or in case of an ambiguous call specification
-
toSignatures
private static java.lang.String toSignatures(java.lang.Iterable<IMetaOperation> operations)
Turns the signatures of the givenoperationsinto a string.- Parameters:
operations- the operations- Returns:
- the string containing all signatures
-
resolveResolvableOperation
public static IMetaOperation resolveResolvableOperation(IMetaType operand, IMetaType pType, IMetaType aType, Expression initExpression, ResolutionListener listener) throws VilException
Resolves a resolvable operation ("function pointer").- Parameters:
operand- the operand (must also be of typeIModel, may be null then the model frominitExpressionis taken if it is aVarModelIdentifierExpression)pType- the parameter typeaType- the argument typeinitExpression- the initialization expression (shall be ofaType)listener- the listener to be informed about the variability model identifier resolution done- Returns:
- the resolved operation if there is one, else null
- Throws:
VilException- in case of type resolution problems
-
toTypeDescriptors
private static CallArgument[] toTypeDescriptors(IMetaType type, int exclude)
Turns the generic parameter types oftypeinto an array.- Parameters:
type- the type to take the generic parameters fromexclude- the amount of parameters at the end of the generics to be excluded (operation return)- Returns:
- the related type descriptors according sequence of generic types
-
toTypeDescriptors
private static IMetaType[] toTypeDescriptors(CallArgument[] args) throws VilException
Turns the given call arguments to type descriptors.- Parameters:
args- the arguments to be turned into type descriptors- Returns:
- the related type descriptors according to the input sequence
- Throws:
VilException- in case that obtaining a type fails
-
addAndPruneByType
private static void addAndPruneByType(java.util.List<IMetaOperation> candidates, IMetaOperation toAdd, IMetaType[] argTypes, CallArgument[] arguments, int unnamedArgsCount)
AddstoAddtocandidatesif it is considered as the best candidate with respect to the givenargTypes. May prune existing candidates with lower ranking.- Parameters:
candidates- the candidates to modifytoAdd- the candidate to add if it is the best candidateargTypes- the argument typesarguments- the actual argumentsunnamedArgsCount- the number of unnamed arguments inarguments
-
calcTypeDiff
private static int calcTypeDiff(IMetaOperation operation, IMetaType[] argTypes, CallArgument[] arguments, int unnamedArgsCount)
Calculates the differences in types between the givenoperationand the given argument types.- Parameters:
operation- the operation to compareargTypes- the argument types to take into accountarguments- the actual argumentsunnamedArgsCount- the number of unnamed arguments inarguments- Returns:
- the (pseudo) difference in number of types
-
calcSuperDiffRec
private static int calcSuperDiffRec(IMetaType iter, IMetaType reference)
Calculates the difference of super types fromreferencetoiterover the types and their generic parameter.- Parameters:
iter- the node to follow the super type hierarchyreference- the node to search for- Returns:
- the difference if found,
0if equal, a value of at least100if not found (shall not occur)
-
calcSuperDiff
private static int calcSuperDiff(IMetaType iter, IMetaType reference)
Calculates the difference of super types fromreferencetoiter.- Parameters:
iter- the node to follow the super type hierarchyreference- the node to search for- Returns:
- the difference if found,
0if equal,100if not found (shall not occur)
-
convertibleCandidates
private static java.util.List<AbstractCallExpression.ConvertibleOperation> convertibleCandidates(IMetaType operand, java.lang.String name, CallArgument[] arguments, int unnamedArgsCount) throws VilException
Derives the convertible candidates fromoperand, i.e., operations which can be applied including parameter conversion.- Parameters:
operand- the operand of the call to be resolvedname- the name of the operation call to be resolvedarguments- the arguments of the callunnamedArgsCount- the number of unnamed arguments inarguments- Returns:
- the list of candidate operations including their required conversions
- Throws:
VilException- in case of type resolution problems or in case of an ambiguous call specification
-
selectAmongMultipleCandidates
private static java.util.List<AbstractCallExpression.ConvertibleOperation> selectAmongMultipleCandidates(java.util.List<AbstractCallExpression.ConvertibleOperation> candidates, CallArgument[] arguments, int unnamedArgsCount) throws VilException
Selects among multiple convertible candidates.- Parameters:
candidates- the candidatesarguments- the actual argumentsunnamedArgsCount- the number of unnamed arguments inarguments- Returns:
candidatesor a list with exactly one candidate- Throws:
VilException- in case that types cannot be inferred
-
resolveOperation
public static IMetaOperation resolveOperation(IMetaType operand, java.lang.String name, CallArgument... arguments) throws VilException
Resolves the given operation onoperand.- Parameters:
operand- the operand, i.e., the type to be searched for operationsname- the name of the operation to be resolvedarguments- the (named) arguments of the call- Returns:
- the resolved operation
- Throws:
VilException- in case that no resolution can be found for various (typically type compliance) reasons
-
resolveFallbacks
private static IMetaOperation resolveFallbacks(IMetaType opType, java.lang.String name, CallArgument[] arguments)
Last resort resolution, try with String or in case of a decision variable with the primitive types it can represent.- Parameters:
opType- the operand typename- the operation namearguments- the arguments- Returns:
- the operation or null if there is none
-
resolveOperation
public static IMetaOperation resolveOperation(IMetaType operand, boolean checkMetaForFirstArgField, java.lang.String name, CallArgument[] arguments) throws VilException
Resolves the given operation onoperand, but allows checking the first field for a meta type (e.g., DecisionVariable instead of the actual field type).- Parameters:
operand- the operand, i.e., the type to be searched for operationscheckMetaForFirstArgField- whether the check for the meta type shall be enabled on the first field (replacing operand) or not. In case that this is enabled and there is a compliant operation for meta type, the found operation is returned.name- the name of the operation to be resolvedarguments- the (named) arguments of the call- Returns:
- the resolved operation
- Throws:
VilException- in case that no resolution can be found for various (typically type compliance) reasons
-
resolveOperationOnModel
private static IMetaOperation resolveOperationOnModel(java.lang.Object operand, java.lang.String name, CallArgument[] arguments, java.util.Set<java.lang.Object> done) throws VilException
Resolves the given operation onoperand, consideringoperandas a model with imports.- Parameters:
operand- the operand, i.e., the model to be searched for operationsname- the name of the operation to be resolvedarguments- the (named) arguments of the calldone- already searched models- Returns:
- the resolved operation
- Throws:
VilException- in case that no resolution can be found for various (typically type compliance) reasons
-
tryOpConversionToSecond
private static IMetaOperation tryOpConversionToSecond(IMetaType opType, java.lang.String name, CallArgument[] arguments) throws VilException
Tries to convert the operand to the second argument type and resolves it.- Parameters:
opType- the operand typename- the name of the operationarguments- the actual call arguments- Returns:
- the operation if resolved, null else
- Throws:
VilException- in case of type resolution problems
-
resolveOperation
private static IMetaOperation resolveOperation(IMetaType operand, java.lang.String name, CallArgument[] arguments, boolean allowConversion, boolean allowAny) throws VilException
Actually aims at resolving the operation.- Parameters:
operand- the operand, i.e., the type to be searched for operationsname- the name of the operation to be resolvedarguments- the (named) arguments of the callallowConversion- whether conversion shall be allowedallowAny- allow AnyType as assignable parameter type (dynamic dispatch)- Returns:
- the resolved operation
- Throws:
VilException- in case that no resolution can be found for various (typically type compliance) reasons
-
getSignature
public static final java.lang.String getSignature(java.lang.String name, CallArgument[] arguments)Returns a java-like signature for the specified operation.- Parameters:
name- the name of the operationarguments- the (named) arguments of the call- Returns:
- the signature
-
determineActualType
private static IMetaType determineActualType(IMetaType type, java.lang.Object object, TypeRegistry registry)
Determines the actual type ofobject. ConsidersIMetaType.isActualTypeOf(IMetaType).- Parameters:
type- the type ofobjectobject- the object to determine the type forregistry- the responsible type registry- Returns:
typeor the actual type ofobject
-
getEnumType
private static IMetaType getEnumType(TypeRegistry registry, EnumValue val)
Returns the VIL type for an enum value.- Parameters:
registry- the type registryval- the enum value- Returns:
- the enum type or null
-
dynamicDispatch
public static <O extends IMetaOperation> O dynamicDispatch(O operation, java.lang.Object[] args, java.lang.Class<O> cls, TypeRegistry registry, IArgumentProvider arguments, IMetaType operandOverride)
Aims at re-resolving the given operation according to the dynamic types ofargs. Argument-less operations are not dispatched dynamically.- Type Parameters:
O- the actual type of operation- Parameters:
operation- the operation to be consideredargs- the argumentscls- the type of operationregistry- the (local) type registryarguments- access to the declared argumentsoperandOverride- type to replace the operand if in same type hierarchy, may be null- Returns:
operationor the one determined dynamically
-
getOperand
private static <O extends IMetaOperation> IMetaType getOperand(O operation, IMetaType operandOverride)
-
isPlaceholder
protected static boolean isPlaceholder(IMetaOperation operation)
Returns whether the specified operation is a placeholder and cannot be executed, i.e., the operation itself is a placeholder or a placeholder type is used in its signature.- Parameters:
operation- the operation to be tested- Returns:
trueifoperationis a placeholder,falseelse
-
getVilSignature
protected java.lang.String getVilSignature(IMetaOperation operation)
Returns the VIL signature of the specifiedoperation.- Parameters:
operation- the operation to return the VIL signature for- Returns:
- the VIL signature (for messages, warnings, errors, etc.)
-
isPlaceholder
public abstract boolean isPlaceholder()
Returns whether this operation is a placeholder, i.e., either the resolved operation is aplaceholder, its signature or its return type does contain aplaceholder type.- Returns:
trueif this operation is a placeholder and cannot be executed,falseelse
-
getVilSignature
public abstract java.lang.String getVilSignature()
Returns the VIL signature of the resolved operation.- Returns:
- the VIL signature
-
isOclCompliant
public boolean isOclCompliant()
Returns whether this operation is OCL compliant or flagged as not compliant.- Returns:
truefor compliant,falseelse
-
isIteratingCollectionOperation
public boolean isIteratingCollectionOperation()
Returns whether this operation is a collection-iterator operation.- Returns:
truefor collection-iterator,falseelse
-
getArgumentsCount
public abstract int getArgumentsCount()
Returns the number of arguments.- Specified by:
getArgumentsCountin interfaceIArgumentProvider- Returns:
- the number of arguments
-
getArgument
public abstract CallArgument getArgument(int index)
Returns the specified argument.- Specified by:
getArgumentin interfaceIArgumentProvider- Parameters:
index- the 0-based index of the argument to return- Returns:
- the argument
- Throws:
java.lang.IndexOutOfBoundsException- in case thatindex < 0 || index >=getArgumentsCount()
-
-