Class AbstractCallExpression

    • Field Detail

      • 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 VilException
        Creates an instance from the given call name.
        Parameters:
        name - the name of the call
        unqualify - 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 of getPrefix() (if present) and getName().
        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 operation
        index - the parameter index
        arguments - the arguments
        unnamedArgsCount - 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 from operand, 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 resolved
        name - the name of the operation call to be resolved
        arguments - the arguments of the call
        allowAny - allow AnyType as assignable parameter type (dynamic dispatch)
        unnamedArgsCount - the number of unnamed arguments in arguments
        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 given operations into 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 type IModel, may be null then the model from initExpression is taken if it is a VarModelIdentifierExpression)
        pType - the parameter type
        aType - the argument type
        initExpression - the initialization expression (shall be of aType)
        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 of type into an array.
        Parameters:
        type - the type to take the generic parameters from
        exclude - 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)
        Adds toAdd to candidates if it is considered as the best candidate with respect to the given argTypes. May prune existing candidates with lower ranking.
        Parameters:
        candidates - the candidates to modify
        toAdd - the candidate to add if it is the best candidate
        argTypes - the argument types
        arguments - the actual arguments
        unnamedArgsCount - the number of unnamed arguments in arguments
      • calcTypeDiff

        private static int calcTypeDiff​(IMetaOperation operation,
                                        IMetaType[] argTypes,
                                        CallArgument[] arguments,
                                        int unnamedArgsCount)
        Calculates the differences in types between the given operation and the given argument types.
        Parameters:
        operation - the operation to compare
        argTypes - the argument types to take into account
        arguments - the actual arguments
        unnamedArgsCount - the number of unnamed arguments in arguments
        Returns:
        the (pseudo) difference in number of types
      • calcSuperDiffRec

        private static int calcSuperDiffRec​(IMetaType iter,
                                            IMetaType reference)
        Calculates the difference of super types from reference to iter over the types and their generic parameter.
        Parameters:
        iter - the node to follow the super type hierarchy
        reference - the node to search for
        Returns:
        the difference if found, 0 if equal, a value of at least 100 if not found (shall not occur)
      • calcSuperDiff

        private static int calcSuperDiff​(IMetaType iter,
                                         IMetaType reference)
        Calculates the difference of super types from reference to iter.
        Parameters:
        iter - the node to follow the super type hierarchy
        reference - the node to search for
        Returns:
        the difference if found, 0 if equal, 100 if 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 from operand, i.e., operations which can be applied including parameter conversion.
        Parameters:
        operand - the operand of the call to be resolved
        name - the name of the operation call to be resolved
        arguments - the arguments of the call
        unnamedArgsCount - the number of unnamed arguments in arguments
        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
      • resolveOperation

        public static IMetaOperation resolveOperation​(IMetaType operand,
                                                      java.lang.String name,
                                                      CallArgument... arguments)
                                               throws VilException
        Resolves the given operation on operand.
        Parameters:
        operand - the operand, i.e., the type to be searched for operations
        name - the name of the operation to be resolved
        arguments - 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 type
        name - the operation name
        arguments - 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 on operand, 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 operations
        checkMetaForFirstArgField - 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 resolved
        arguments - 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 on operand, considering operand as a model with imports.
        Parameters:
        operand - the operand, i.e., the model to be searched for operations
        name - the name of the operation to be resolved
        arguments - the (named) arguments of the call
        done - 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 type
        name - the name of the operation
        arguments - 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 operations
        name - the name of the operation to be resolved
        arguments - the (named) arguments of the call
        allowConversion - whether conversion shall be allowed
        allowAny - 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 operation
        arguments - 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 of object. Considers IMetaType.isActualTypeOf(IMetaType).
        Parameters:
        type - the type of object
        object - the object to determine the type for
        registry - the responsible type registry
        Returns:
        type or the actual type of object
      • getEnumType

        private static IMetaType getEnumType​(TypeRegistry registry,
                                             EnumValue val)
        Returns the VIL type for an enum value.
        Parameters:
        registry - the type registry
        val - 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 of args. Argument-less operations are not dispatched dynamically.
        Type Parameters:
        O - the actual type of operation
        Parameters:
        operation - the operation to be considered
        args - the arguments
        cls - the type of operation
        registry - the (local) type registry
        arguments - access to the declared arguments
        operandOverride - type to replace the operand if in same type hierarchy, may be null
        Returns:
        operation or the one determined dynamically
      • 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:
        true if operation is a placeholder, false else
      • getVilSignature

        protected java.lang.String getVilSignature​(IMetaOperation operation)
        Returns the VIL signature of the specified operation.
        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 a placeholder, its signature or its return type does contain a placeholder type.
        Returns:
        true if this operation is a placeholder and cannot be executed, false else
      • 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:
        true for compliant, false else
      • isIteratingCollectionOperation

        public boolean isIteratingCollectionOperation()
        Returns whether this operation is a collection-iterator operation.
        Returns:
        true for collection-iterator, false else
      • getArgumentsCount

        public abstract int getArgumentsCount()
        Returns the number of arguments.
        Specified by:
        getArgumentsCount in interface IArgumentProvider
        Returns:
        the number of arguments
      • getArgument

        public abstract CallArgument getArgument​(int index)
        Returns the specified argument.
        Specified by:
        getArgument in interface IArgumentProvider
        Parameters:
        index - the 0-based index of the argument to return
        Returns:
        the argument
        Throws:
        java.lang.IndexOutOfBoundsException - in case that index < 0 || index >=getArgumentsCount()