Class OperationDescriptor

    • Field Detail

      • CONSTRUCTOR_NAME

        public static final java.lang.String CONSTRUCTOR_NAME
        The name of constructor methods (static, same return type as declaring class, this name). We do not rely on constructors, as constructor methods simplify reflection analysis.
        See Also:
        Constant Field Values
      • EMPTY_PARAMETER

        public static final java.util.List<TypeDescriptor<?>> EMPTY_PARAMETER
        Defines a constant unmodifiable list for empty parameters.
      • name

        private java.lang.String name
      • isConstructor

        private boolean isConstructor
      • acceptsNamedParameters

        private boolean acceptsNamedParameters
      • acceptsImplicitParameters

        private boolean acceptsImplicitParameters
      • isConversion

        private boolean isConversion
    • Constructor Detail

      • OperationDescriptor

        protected OperationDescriptor​(TypeDescriptor<?> declaringType,
                                      java.lang.String name,
                                      boolean isConstructor)
        Creates a new operation descriptor. Overriding constructors shall call #setCharacteristics(OperationType, AliasType, boolean) in order to redefined the default values.
        Parameters:
        declaringType - the declaring type
        name - the alias name (may be null if the original name of method shall be used)
        isConstructor - whether the operation is a constructor
    • Method Detail

      • setCharacteristics

        protected void setCharacteristics​(OperationType opType,
                                          OperationDescriptor.AliasType aliasType,
                                          boolean isConversion,
                                          java.lang.String name)
        Sets the characteristics of this operation descriptor. To be called by overridden constructors.
        Parameters:
        opType - the operation type
        aliasType - the alias type
        isConversion - whether the operation is a conversion
        name - the actual name of the operation
      • initialize

        private void initialize()
        Initializes the parameter and the return type if necessary (lazy, due to linked descriptor structures which may not have been completely initialized during the constructor execution).
        See Also:
        #initializeParameter(), initializeReturnType()
      • setParameters

        protected void setParameters​(java.util.List<TypeDescriptor<?>> parameters,
                                     boolean acceptsNamedParameters,
                                     boolean acceptsImplicitParameters)
        Sets the parameters. Shall only be called in initializeParameters().
        Parameters:
        parameters - the parameters
        acceptsNamedParameters - whether this operation accepts named parameters
        acceptsImplicitParameters - whether this operation accepts implicit parameters
      • setReturnType

        protected void setReturnType​(TypeDescriptor<?> returnType)
        Sets the return type. Shall only be called in initializeReturnType().
        Parameters:
        returnType - the return type of this operation
      • acceptsNamedParameters

        public boolean acceptsNamedParameters()
        Returns whether the operation accepts named parameters.
        Specified by:
        acceptsNamedParameters in interface IMetaOperation
        Returns:
        true if it accepts named parameters, false else
      • acceptsImplicitParameters

        public boolean acceptsImplicitParameters()
        Returns whether the operation accepts implicit named parameters.
        Returns:
        true if it accepts implicit named parameters, false else
      • getName

        public java.lang.String getName()
        Returns the name of the method.
        Specified by:
        getName in interface IMetaOperation
        Returns:
        the name of the method
      • getStoredName

        protected final java.lang.String getStoredName()
        Returns the name stored in this instance.
        Returns:
        the name stored in this instance
      • getOperationType

        public OperationType getOperationType()
        Returns the operation / operator type.
        Returns:
        the operation / operator type
      • getDeclaringTypeName

        public java.lang.String getDeclaringTypeName()
        Returns the name of the declaring type. In case that getDeclaringType() is null, the result of getDeclaringTypeNameFallback() is returned.
        Returns:
        the name of the declaring type
      • getDeclaringTypeNameFallback

        protected abstract java.lang.String getDeclaringTypeNameFallback()
        Returns the name of the declaring type in case that getDeclaringType() is null.
        Returns:
        the name of the declaring type
      • getSignature

        public java.lang.String getSignature()
        Returns the signature of the method.
        Specified by:
        getSignature in interface IMetaOperation
        Returns:
        the signature of the method
      • getJavaSignature

        public abstract java.lang.String getJavaSignature()
        Returns the Java signature of the method (public for testing).
        Specified by:
        getJavaSignature in interface IMetaOperation
        Returns:
        the Java signature of the method
      • isConstructor

        public boolean isConstructor()
        Description copied from interface: IMetaOperation
        Returns whether this operation represents a constructor. Basically, for VIL a constructor is a public static method named "create" which returns an instance of the underlying type. Declared constructors are used for internal purposes.
        Specified by:
        isConstructor in interface IMetaOperation
        Returns:
        true if this operation is a "constructor", false else
      • getDeclaringType

        public TypeDescriptor<?> getDeclaringType()
        Returns the declaring type.
        Specified by:
        getDeclaringType in interface IMetaOperation
        Returns:
        the declaring type (may be null in case of a wrapped external Java method)
      • throwIncompatibleParameter

        protected void throwIncompatibleParameter​(java.lang.Object[] args)
                                           throws VilException
        Throws an exception for the case that parameter are incompatible.
        Parameters:
        args - the actual arguments
        Throws:
        VilException - the created exception (happens in any case)
      • isSameSignature

        public static boolean isSameSignature​(java.lang.reflect.Method method1,
                                              java.lang.reflect.Method method2)
        Returns whether two Java methods have the same Java signature (public for testing). This method does not consider possible unnamed parameter rather than the underlying Java parameter.
        Parameters:
        method1 - the first method to compare
        method2 - the second method to compare
        Returns:
        true if both have the same signature, false else
      • isConstructor

        public static boolean isConstructor​(java.lang.reflect.Method method)
        Returns whether the given method is considered to be a VIL "constructor". A VIL constructor must comply to the VIL rules, it must be static, the name must be equal to CONSTRUCTOR_NAME and the return type must be equal to the one of the declaring class (public for testing).
        Parameters:
        method - the method to be analyzed
        Returns:
        true if it is considered as a constructor, false else
      • isOperation

        public static boolean isOperation​(java.lang.reflect.Method method)
        Returns whether the given method is considered to be a VIL operation. A VIL operation must comply to the VIL rules and not be static (public for testing).
        Parameters:
        method - the method to be analyzed
        Returns:
        true if it is considered as an operation, false else
      • isOperationOrConstructor

        static boolean isOperationOrConstructor​(java.lang.reflect.Method method)
        Returns whether the given method is a VIL operation or a VIL constructor.
        Parameters:
        method - the method to be analyzed
        Returns:
        true in case of a VIL operation or VIL constructor
        See Also:
        isConstructor(Method), isOperation(Method)
      • getParameterCount

        public int getParameterCount()
        Description copied from interface: IMetaOperation
        Returns the number of parameters.
        Specified by:
        getParameterCount in interface IMetaOperation
        Returns:
        the number of parameter
      • getRequiredParameterCount

        public int getRequiredParameterCount()
        Description copied from interface: IMetaOperation
        Returns the number of required parameters, i.e., non-default and non-named parameters.
        Specified by:
        getRequiredParameterCount in interface IMetaOperation
        Returns:
        the number of required parameters
      • getParameterType

        public TypeDescriptor<?> getParameterType​(int index)
        Returns the specified parameter type.
        Specified by:
        getParameterType in interface IMetaOperation
        Parameters:
        index - the index of the parameter to return
        Returns:
        the specified parameter type
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= getParameterCount()
      • getParameter

        public IMetaParameterDeclaration getParameter​(java.lang.String name)
        Description copied from interface: IMetaOperation
        Returns a named parameter declaration.
        Specified by:
        getParameter in interface IMetaOperation
        Parameters:
        name - the name of the parameter
        Returns:
        the declaration or null if there is none
      • getParameter

        public IMetaParameterDeclaration getParameter​(int index)
        Returns the parameter declaration of named parameters.
        Parameters:
        index - the index of the parameter to return
        Returns:
        the named parameter or null for an usual parameter
      • toString

        public java.lang.String toString()
        Returns a textual representation of this descriptor (the Java signature).
        Overrides:
        toString in class java.lang.Object
        Returns:
        the textual representation
      • isTypeSelect

        public boolean isTypeSelect()
        Returns whether this operation is a type select operation (non-static, collection return, parameter is type).
        Returns:
        true if it is a type select operation, false else
      • isGenericCollectionOperation

        public boolean isGenericCollectionOperation()
        Returns whether this operation is a generic collection operation, i.e., whether the collection itself determines the return type (non-static, collection return, implicit parameter is generic collection).
        Returns:
        true if it is a generic collection operation, false else
      • isIteratingCollectionOperation

        public boolean isIteratingCollectionOperation()
        Return whether this operation returns the result of iterating over a collection. Such an operation may be a quantor, a collector or a selector. Therefore, the operation must not be static, belong to a collection (first parameter type) and accept exactly one ExpressionEvaluator (typically the only additional parameter).
        Returns:
        true of this operation is an iterating operation, false else
      • isConversion

        public boolean isConversion()
        Returns whether this operation descriptor is a conversion.
        Returns:
        true if it is a conversion, false else
      • useGenericParameterAsReturn

        public abstract int useGenericParameterAsReturn()
        Returns whether a generc parameter of the operand shall be used as return type.
        Returns:
        the parameter to be used as index number, negative if none
      • useParameterAsReturn

        public abstract int useParameterAsReturn()
        Returns whether a parameter shall be used as return type.
        Returns:
        the parameter to be used as index number, negative if none
      • storeArtifactsBeforeExecution

        public abstract boolean storeArtifactsBeforeExecution()
        Returns whether artifacts shall be stored before execution of this operation.
        Returns:
        true if artifacts shall be stored, false else
      • requiresDynamicExpressionProcessing

        public boolean requiresDynamicExpressionProcessing()
        Indicates whether this function requires dynamic expression processing and may cause problems with serialized models in standalone settings without xText.
        Returns:
        true if this function requires dynamic exception processing, false else
      • trace

        public boolean trace()
        Returns whether an execution of this descriptor shall be traced. Conversions shall not be traced by default as well as some operation types.
        Returns:
        true if it shall be traced, false
      • specializeFor

        public OperationDescriptor specializeFor​(TypeDescriptor<?> declaringType)
        Tries to specialize this operation descriptor for the given type, e.g., to consider the specific generic parameters of that type.
        Parameters:
        declaringType - the declaring type to specialize for
        Returns:
        either this if no specialization is needed or a specializing instance
      • allowsAggregation

        public boolean allowsAggregation()
        Returns whether this operation allows iterator aggregation.
        Returns:
        true if allowed, false
      • composeExceptionMessage

        protected java.lang.String composeExceptionMessage​(java.lang.Throwable ex,
                                                           java.lang.Object[] args)
        Composes an execution exception message from a given (Java) exception.
        Parameters:
        ex - the original exception
        args - the call arguments
        Returns:
        the execution message
      • convertVariables

        protected void convertVariables​(java.lang.Object[] params)
        Converts variables to objects, e.g., for reflection calls.
        Parameters:
        params - the parameters (may be changed as a side effect)
      • isOclCompliant

        public boolean isOclCompliant()
        Returns whether this operation is OCL compliant or flagged as not compliant.
        Returns:
        true for compliant, false else
      • useAny

        public boolean useAny()
        When resolving expression types, use any as return type if object is given and do not try to override this.
        Returns:
        true for use any, false else (default)
      • flatten

        public boolean flatten()
        When resolving expression types, flatten the final return type.
        Returns:
        true for use any, false else (default)
      • useOperandTypeAsParameter

        public boolean useOperandTypeAsParameter()
        When resolving the return type, use the actual operand type as return generics.
        Returns:
        true for use return type, false else (default)