Class StandardCoercionManager

    • Constructor Detail

      • StandardCoercionManager

        public StandardCoercionManager()
    • Method Detail

      • canCoerce

        public final boolean canCoerce​(IType lhsType,
                                       IType rhsType)
        Specified by:
        canCoerce in interface ICoercionManager
        Parameters:
        lhsType - type to be coerced to
        rhsType - type to be coerced from
        Returns:
        true if a coercion exists from rhsType to lhsType, false otherwise
      • coerce

        private java.lang.Object coerce​(IType intrType,
                                        IType runtimeType,
                                        java.lang.Object value)
      • hasPotentialLossOfPrecisionOrScale

        private boolean hasPotentialLossOfPrecisionOrScale​(IType lhsType,
                                                           IType rhsType)
      • findCoercerImpl

        private ICoercer findCoercerImpl​(IType lhsType,
                                         IType rhsType,
                                         boolean runtime)
      • getCoercerInternal

        protected ICoercer getCoercerInternal​(IType lhsType,
                                              IType rhsType,
                                              boolean runtime)
        Returns a coercer from values of rhsType to values of lhsType if one exists. I tried to write a reasonable spec in the comments below that indicate exactly what should coerce to what.
        Parameters:
        lhsType - the type to coerce to
        rhsType - the type to coerce from
        runtime - true if the coercion is happening at runtime rather than compile time (note: This param should go away as we store the coercions on the parsed elements, rather than calling into the coercion manager)
        Returns:
        a coercer from the lhsType to the rhsType, or null if no such coercer exists or is needed
      • isPrimitiveOrBoxed

        public boolean isPrimitiveOrBoxed​(IType lhsType)
        Description copied from interface: ICoercionManager
        Determine whether the specified type is either a primitive or a boxed primitive.
        Specified by:
        isPrimitiveOrBoxed in interface ICoercionManager
        Parameters:
        lhsType - the type to examine
        Returns:
        true if the specified type is a primitive or a boxed primitive
      • isBoxed

        public static boolean isBoxed​(IType lhsType)
      • getPrimitiveOrBoxedConverter

        protected ICoercer getPrimitiveOrBoxedConverter​(IType type)
      • getHighPriorityPrimitiveOrBoxedConverter

        protected ICoercer getHighPriorityPrimitiveOrBoxedConverter​(IType type)
      • _verifyTypesComparable

        private IType _verifyTypesComparable​(IType lhsType,
                                             IType rhsType,
                                             boolean bBiDirectional)
      • isStrictGenerics

        private static boolean isStrictGenerics​(IType type)
      • isStructurallyAssignable

        public static boolean isStructurallyAssignable​(IType toType,
                                                       IType fromType)
      • isStructurallyAssignable_Laxed

        public static boolean isStructurallyAssignable_Laxed​(IType toType,
                                                             IType fromType)
      • isStructurallyAssignable_Laxed

        public static boolean isStructurallyAssignable_Laxed​(IType toType,
                                                             IType fromType,
                                                             TypeVarToTypeMap inferenceMap)
      • arePrimitiveTypesAssignable

        public static boolean arePrimitiveTypesAssignable​(IType toType,
                                                          IType fromType)
      • isObjectMethod

        public static boolean isObjectMethod​(IMethodInfo mi)
      • convertValue

        public final java.lang.Object convertValue​(java.lang.Object value,
                                                   IType intrType)
        Given a value and a target Class, return a compatible value via the target Class.
        Specified by:
        convertValue in interface ICoercionManager
        Parameters:
        value - the value to coerce (may not be null)
        intrType - type to coerce to
        Returns:
        the converted value
      • getBoundingTypeOfTypeVariable

        private IType getBoundingTypeOfTypeVariable​(IType intrType)
      • extractObjectArray

        private java.lang.Object extractObjectArray​(IType intrType,
                                                    java.lang.Object value)
      • convertNullAsPrimitive

        public java.lang.Object convertNullAsPrimitive​(IType intrType,
                                                       boolean isForBoxing)
        Description copied from interface: ICoercionManager
        Converts a null value to a value compatible with the specified primitive type.
        Specified by:
        convertNullAsPrimitive in interface ICoercionManager
        Parameters:
        intrType - The primitive type to convert to.
        Returns:
        A wrapped primitive value corresponding to null.
      • resolveCoercerStatically

        public ICoercer resolveCoercerStatically​(IType typeToCoerceTo,
                                                 IType typeToCoerceFrom)
        Description copied from interface: ICoercionManager
        Determine and return a statically valid coercer from the rhsType to the lhsType. Returns null if no coercion is necessary.
        Specified by:
        resolveCoercerStatically in interface ICoercionManager
        Parameters:
        typeToCoerceTo - the type to coerce to
        typeToCoerceFrom - the type to coerce from
      • areJavaClassesAndAreNotAssignable

        private boolean areJavaClassesAndAreNotAssignable​(IType typeToCoerceTo,
                                                          IType typeToCoerceFrom)
      • identityOrRuntime

        private ICoercer identityOrRuntime​(IType typeToCoerceTo,
                                           IType typeToCoerceFrom)
      • makeDoubleFrom

        public java.lang.Double makeDoubleFrom​(java.lang.Object obj)
        Description copied from interface: ICoercionManager
        Returns a Double for an arbitrary object. Uses a semi-intelligent algorithm to create an appropriate Double instance. If the Object argument is a:
         null value - an appropriate value respecting this parsed element's nullAsZero
           setting e.g., either null or an 'empty' value.
         Double - returns the argument as is.
         Number - the Number's doubleValue().
         String - Double.parseDouble( String )
         Boolean - a pooled instance of either Double( 0 ) or Double( 1 )
         Date - A Double for Date.getTime().
         default - A parsed Double for the Object argument's toString() method.
         
        Specified by:
        makeDoubleFrom in interface ICoercionManager
        Returns:
        A Double for an arbitrary object (may return a pooled instance).
      • makePrimitiveBooleanFrom

        public boolean makePrimitiveBooleanFrom​(java.lang.Object obj)
        Specified by:
        makePrimitiveBooleanFrom in interface ICoercionManager
        Returns:
        A Boolean for an arbitrary object.
      • makeDateFrom

        public java.util.Date makeDateFrom​(java.lang.Object obj)
        Returns a new Date instance representing the object.
        Specified by:
        makeDateFrom in interface ICoercionManager
      • isDateTime

        public boolean isDateTime​(java.lang.String str)
                           throws java.text.ParseException
        Specified by:
        isDateTime in interface ICoercionManager
        Throws:
        java.text.ParseException
      • parseDateTime

        public java.util.Date parseDateTime​(java.lang.String str)
                                     throws java.text.ParseException
        Produce a date from a string using standard DateFormat parsing.
        Specified by:
        parseDateTime in interface ICoercionManager
        Throws:
        java.text.ParseException
      • formatDate

        public java.lang.String formatDate​(java.util.Date value,
                                           java.lang.String strFormat)
        Specified by:
        formatDate in interface ICoercionManager
      • formatTime

        public java.lang.String formatTime​(java.util.Date value,
                                           java.lang.String strFormat)
        Specified by:
        formatTime in interface ICoercionManager
      • formatNumber

        public java.lang.String formatNumber​(java.lang.Double value,
                                             java.lang.String strFormat)
        Specified by:
        formatNumber in interface ICoercionManager
      • parseNumber

        public java.lang.Number parseNumber​(java.lang.String strValue)
        Specified by:
        parseNumber in interface ICoercionManager