Class TypeDescriptor<T>

    • Method Detail

      • isInitialized

        protected boolean isInitialized()
        Returns whether this descriptor was initialized.
        Returns:
        true if it was initialized, false else
      • setName

        protected void setName​(java.lang.String name)
        Defines the name of this descriptor explicitly.
        Parameters:
        name - the name of this descriptor (may be qualified by :: and is split internally)
      • isNameSet

        protected boolean isNameSet()
        Returns whether the name of this type descriptor (single or qualified) has yet been set.
        Returns:
        true if the name has been set, false else
      • setOperations

        protected void setOperations​(java.util.Collection<OperationDescriptor> operations)
        Defines the operations for this type.
        Parameters:
        operations - the operations (may be null)
      • setFields

        protected void setFields​(java.util.Collection<FieldDescriptor> fields)
        Defines the fields for this type.
        Parameters:
        fields - the fields (may be null)
      • setFields

        protected void setFields​(FieldDescriptor[] fields)
        Changes the fields.
        Parameters:
        fields - the new fields
      • isFieldsNull

        protected boolean isFieldsNull()
        Returns whether so far no fields have been defined at all.
        Returns:
        true for no fields, false else
      • addOperation

        protected void addOperation​(OperationDescriptor operation)
        Adds an operation.
        Parameters:
        operation - the operation to be added
      • setConversions

        protected void setConversions​(java.util.Collection<OperationDescriptor> conversions)
        Defines the conversions for this type.
        Parameters:
        conversions - the conversions (may be null)
      • getName

        public java.lang.String getName()
        Description copied from interface: IMetaType
        Returns the (simple) name of this type.
        Specified by:
        getName in interface IMetaType
        Returns:
        the simple name
      • getQualifiedName

        public java.lang.String getQualifiedName()
        Description copied from interface: IMetaType
        Returns the qualified name of this type.
        Specified by:
        getQualifiedName in interface IMetaType
        Returns:
        the qualified name
      • enableDynamicDispatch

        public boolean enableDynamicDispatch()
        Description copied from interface: IMetaType
        Returns whether this type enables dynamic dispatch of operations.
        Specified by:
        enableDynamicDispatch in interface IMetaType
        Returns:
        true if it enables dynamic dispatch, false else
      • getTypeClass

        public abstract java.lang.Class<T> getTypeClass()
        Returns the class of the described VIL type. Please use this method sparingly as the required functionality is provided by this class.
        Returns:
        the class
      • canBeInstantiated

        public abstract boolean canBeInstantiated()
        Returns whether create(Object...) will return an instance.
        Returns:
        true if this type can be instantiated from VIL/VTL, false else
      • create

        public abstract T create​(java.lang.Object... params)
                          throws VilException
        Creates an instance of the type according to the given parameters.
        Parameters:
        params - the parameters
        Returns:
        the created instance
        Throws:
        VilException - in case that the creation does not work
      • getFields

        public java.lang.Iterable<FieldDescriptor> getFields()
        Returns the available fields.
        Returns:
        the available fields
      • getOperations

        public java.lang.Iterable<OperationDescriptor> getOperations()
        Returns the available operations.
        Returns:
        the available operations
      • getConversions

        public java.lang.Iterable<OperationDescriptor> getConversions()
        Returns the available conversions.
        Returns:
        the available conversion
      • getOperationsCount

        public int getOperationsCount()
        Description copied from interface: IMetaType
        Returns the number of operations provided by this type.
        Specified by:
        getOperationsCount in interface IMetaType
        Returns:
        the number of operations
      • getOperation

        public OperationDescriptor getOperation​(int index)
        Description copied from interface: IMetaType
        Returns the specified operation.
        Specified by:
        getOperation in interface IMetaType
        Parameters:
        index - the 0-based index of the operation to be returned
        Returns:
        the specified operation
      • getField

        public FieldDescriptor getField​(int index)
        Description copied from interface: IMetaType
        Returns the specified field.
        Specified by:
        getField in interface IMetaType
        Parameters:
        index - the 0-based index of the field to be returned
        Returns:
        the specified field
      • getField

        public FieldDescriptor getField​(java.lang.String name)
        Returns the field descriptor with the specified name.
        Parameters:
        name - the name of the field
        Returns:
        the field descriptor (may be null if not found)
      • getFieldCount

        public int getFieldCount()
        Description copied from interface: IMetaType
        Returns the number of fields provided by this type.
        Specified by:
        getFieldCount in interface IMetaType
        Returns:
        the number of fields
      • getConversionsCount

        public int getConversionsCount()
        Returns the number of conversions provided by this type descriptor.
        Returns:
        the number of conversions, i.e., from this type to other types
      • getConversion

        public OperationDescriptor getConversion​(int index)
        Returns the specified conversion.
        Parameters:
        index - the index of the conversion to be returned
        Returns:
        the specified conversion
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index>=getConversionsCount()
      • isAssignableFrom

        public abstract boolean isAssignableFrom​(TypeDescriptor<?> desc)
        Returns whether this descriptor is the same or a super class of desc.
        Parameters:
        desc - the descriptor to be tested
        Returns:
        true if both descriptors are assignment compatible, false else
      • findConversion

        public IMetaOperation findConversion​(IMetaType sourceType,
                                             IMetaType targetType)
        Returns the most specific conversion operation from this type to target type (if there is any).
        Specified by:
        findConversion in interface IMetaType
        Parameters:
        sourceType - the source type to convert from
        targetType - the target type to convert to
        Returns:
        the most specific conversion operation as defined in the underlying implementation class, null if no matching can be found
      • findConversionOnBoth

        public static final OperationDescriptor findConversionOnBoth​(TypeDescriptor<?> sourceType,
                                                                     TypeDescriptor<?> targetType)
        Returns the most specific conversion operation from this type to target type considering both types as declarators of the conversion operation (if there is any).
        Parameters:
        sourceType - the source type to convert from
        targetType - the target type to convert to
        Returns:
        the most specific conversion operation as defined in the underlying implementation class, null if no matching can be found
      • findConversion

        public OperationDescriptor findConversion​(TypeDescriptor<?> sourceType,
                                                  TypeDescriptor<?> targetType)
        Returns the most specific conversion operation from this type to target type (if there is any).
        Parameters:
        sourceType - the source type to convert from
        targetType - the target type to convert to
        Returns:
        the most specific conversion operation as defined in the underlying implementation class, null if no matching can be found
      • getConversionToSequence

        public OperationDescriptor getConversionToSequence()
        Returns the first registered conversion operation from this type to a sequence.
        Returns:
        the conversion operation or null if none was found
      • 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
      • getGenericParameter

        public TypeDescriptor<?>[] getGenericParameter()
        Returns the type parameters as array.
        Returns:
        the type parameters as array, may be null
      • getGenericParameterCount

        public int getGenericParameterCount()
        Description copied from interface: IMetaType
        Returns the number of generic type parameters.
        Specified by:
        getGenericParameterCount in interface IMetaType
        Returns:
        the number of generic type parameters
      • getGenericParameterType

        public TypeDescriptor<?> getGenericParameterType​(int index)
        Description copied from interface: IMetaType
        Returns the specified generic parameter type.
        Specified by:
        getGenericParameterType in interface IMetaType
        Parameters:
        index - the index of the parameter type to return
        Returns:
        the specified parameter type
      • createArray

        public static TypeDescriptor<?>[] createArray​(int length)
        Creates an empty array of type descriptors.
        Parameters:
        length - the length of the array to be created
        Returns:
        the array instance
      • appendParameter

        protected java.lang.String appendParameter​(java.lang.String name,
                                                   int exclude)
        Appends the type parameters to name.
        Parameters:
        name - the VIL name of this type
        exclude - the parameters from the end to exclude, 0 for none
        Returns:
        the VIL name including parameter types if applicable
      • getVilName

        public java.lang.String getVilName()
        Returns the name of this type in VIL notation.
        Returns:
        the name of this type
      • isMap

        public abstract boolean isMap()
        Returns whether this descriptor represents a VIL map.
        Returns:
        true if this is a VIL map, false else
      • isIterator

        public abstract boolean isIterator()
        Returns whether this descriptor represents an iterator.
        Returns:
        true if this is an iterator, false else
      • isCollection

        public abstract boolean isCollection()
        Returns whether this descriptor represents a VIL collection, i.e., set, sequence or collection.
        Returns:
        true if this is a VIL collection, false else
      • isSet

        public abstract boolean isSet()
        Returns whether this descriptor represents a VIL set.
        Returns:
        true if this is a VIL set, false else
      • isSequence

        public abstract boolean isSequence()
        Returns whether this descriptor represents a VIL sequence.
        Returns:
        true if this is a VIL sequence, false else
      • isInstance

        public abstract boolean isInstance​(java.lang.Object object)
        Returns whether the given object is an instance of this descriptor.
        Parameters:
        object - the object to be checked
        Returns:
        true if it is an instance, false else
      • isSameType

        public abstract boolean isSameType​(java.lang.Object object)
        Returns whether the given object of of the type of this descriptor.
        Parameters:
        object - the object to be checked
        Returns:
        true if object has the same type, false else
      • addPlaceholderOperation

        public abstract OperationDescriptor addPlaceholderOperation​(java.lang.String name,
                                                                    int parameterCount,
                                                                    boolean acceptsNamedParameters)
        Adds a placeholder operation, i.e., in case that the original operation cannot be resolved but the script shall remain executable.
        Specified by:
        addPlaceholderOperation in interface IMetaType
        Parameters:
        name - the name of the operation
        parameterCount - the number of parameters of the operation
        acceptsNamedParameters - whether the operation accepts named parameters
        Returns:
        the added operation, null if this type is not a placeholder
      • isInstantiator

        public abstract boolean isInstantiator()
        Returns whether this type is an instantiator.
        Returns:
        true if it is an instantiator, false else
      • isSame

        public boolean isSame​(TypeDescriptor<?> typeDescriptor)
        Returns whether a given object is the same.
        Parameters:
        typeDescriptor - the object to be checked
        Returns:
        true if the object is the same, false else
      • flatten

        public TypeDescriptor<?> flatten()
                                  throws VilException
        Returns a flattened collection type if this type is a collection. If not, return this.
        Returns:
        the flattened collection type or this
        Throws:
        VilException - in case that the derivation of the type fails
      • flattenParam

        public TypeDescriptor<?> flattenParam()
        Returns deepest nested non-collection parameter type of this type.
        Returns:
        the nested non-collection type
      • flattenParam

        private TypeDescriptor<?> flattenParam​(TypeDescriptor<?> type)
        Returns deepest nested non-collection parameter type.
        Parameters:
        type - the type to return the parameter type for
        Returns:
        the nested non-collection type
      • findCollectionIteratorOperation

        public OperationDescriptor findCollectionIteratorOperation​(java.lang.String name)
        Returns a collection iterator operation with given name.
        Parameters:
        name - the name of the operation to search for
        Returns:
        the collection iterator operation or null
      • allInstances

        public Set<?> allInstances()
        Provides access to all instances of this type.
        Returns:
        access to all instances (may be null if there are none)
      • getDefaultValue

        public java.lang.Object getDefaultValue()
        Returns the default value for this type, usually a neutral value or a constant value to compare against.
        Returns:
        the default value, null for none - may lead to an undefined operation execution
      • getCandidates

        public java.util.List<IMetaOperation> getCandidates​(java.lang.String name,
                                                            int unnamedArgsCount)
        Description copied from interface: IMetaType
        Returns operation candidates matching the given name and number of unnamed (required) arguments.
        Specified by:
        getCandidates in interface IMetaType
        Parameters:
        name - the name of the operation
        unnamedArgsCount - the number of unnamed arguments
        Returns:
        the operation candidates
      • getCandidates

        public static java.util.List<IMetaOperation> getCandidates​(IMetaType type,
                                                                   java.lang.String name,
                                                                   int argCount)
        Returns the potential operation candidates for a given name and parameter numbers on a specific type. This is the most basic implementation done by a linear search on the available operations. An optimized version may/shall be realized via getCandidates(String, int).
        Parameters:
        type - the type to be searched for
        name - the name of the operation call to be resolved
        argCount - the number of required arguments
        Returns:
        true if desc is a candidate, false else