Class StandardCoercionManager

java.lang.Object
gw.config.BaseService
gw.lang.parser.StandardCoercionManager
All Implemented Interfaces:
IService, ICoercionManager, IPluginHost
Direct Known Subclasses:
GWCoercionManager

public class StandardCoercionManager extends BaseService implements ICoercionManager
  • Field Details

  • Constructor Details

    • StandardCoercionManager

      public StandardCoercionManager()
  • Method Details

    • 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 Object coerce(IType intrType, IType runtimeType, Object value)
    • hasPotentialLossOfPrecisionOrScale

      private boolean hasPotentialLossOfPrecisionOrScale(IType lhsType, IType rhsType)
    • findCoercer

      public final ICoercer findCoercer(IType lhsType, IType rhsType, boolean runtime)
      Specified by:
      findCoercer in interface ICoercionManager
    • 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

      public IType verifyTypesComparable(IType lhsType, IType rhsType, boolean bBiDirectional) throws ParseException
      Description copied from interface: ICoercionManager
      Verifies that the right hand type can be converted or coerced to the left hand type. If bBiDirectional is true, it will verify that either converts to another
      Specified by:
      verifyTypesComparable in interface ICoercionManager
      Throws:
      ParseException
    • verifyTypesComparable

      public IType verifyTypesComparable(IType lhsType, IType rhsType, boolean bBiDirectional, IFullParserState parserState) throws ParseException
      Description copied from interface: ICoercionManager
      Verifies that the right hand type can be converted or coerced to the left hand type. If bBiDirectional is true, it will verify that either converts to another. The parser state will be used to report parse errors with.
      Specified by:
      verifyTypesComparable in interface ICoercionManager
      Throws:
      ParseException
    • _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)
    • isStructurallyAssignable_Laxed

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

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

      public static boolean isObjectMethod(IMethodInfo mi)
    • notCoercibleOrRequiresExplicitCoercion

      public boolean notCoercibleOrRequiresExplicitCoercion(IType lhsType, IType rhsType)
      Specified by:
      notCoercibleOrRequiresExplicitCoercion in interface ICoercionManager
    • convertValue

      public final Object convertValue(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 Object extractObjectArray(IType intrType, Object value)
    • convertNullAsPrimitive

      public 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 Double makeDoubleFrom(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).
    • makePrimitiveIntegerFrom

      public int makePrimitiveIntegerFrom(Object obj)
      Specified by:
      makePrimitiveIntegerFrom in interface ICoercionManager
    • makeIntegerFrom

      public Integer makeIntegerFrom(Object obj)
      Specified by:
      makeIntegerFrom in interface ICoercionManager
    • makePrimitiveLongFrom

      public long makePrimitiveLongFrom(Object obj)
      Specified by:
      makePrimitiveLongFrom in interface ICoercionManager
    • makeLongFrom

      public Long makeLongFrom(Object obj)
      Specified by:
      makeLongFrom in interface ICoercionManager
    • makeBigDecimalFrom

      public BigDecimal makeBigDecimalFrom(Object obj)
      Specified by:
      makeBigDecimalFrom in interface ICoercionManager
    • makeRationalFrom

      public Rational makeRationalFrom(Object obj)
      Specified by:
      makeRationalFrom in interface ICoercionManager
    • makeBigIntegerFrom

      public BigInteger makeBigIntegerFrom(Object obj)
      Specified by:
      makeBigIntegerFrom in interface ICoercionManager
    • makePrimitiveDoubleFrom

      public double makePrimitiveDoubleFrom(Object obj)
      Specified by:
      makePrimitiveDoubleFrom in interface ICoercionManager
    • makeFloatFrom

      public Float makeFloatFrom(Object obj)
      Specified by:
      makeFloatFrom in interface ICoercionManager
    • makePrimitiveFloatFrom

      public float makePrimitiveFloatFrom(Object obj)
      Specified by:
      makePrimitiveFloatFrom in interface ICoercionManager
    • makeStringFrom

      public String makeStringFrom(Object obj)
      Specified by:
      makeStringFrom in interface ICoercionManager
    • makePrimitiveBooleanFrom

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

      public Boolean makeBooleanFrom(Object obj)
      Specified by:
      makeBooleanFrom in interface ICoercionManager
    • makeDateFrom

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

      public boolean isDateTime(String str) throws ParseException
      Specified by:
      isDateTime in interface ICoercionManager
      Throws:
      ParseException
    • parseDateTime

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

      public String formatDate(Date value, String strFormat)
      Specified by:
      formatDate in interface ICoercionManager
    • formatTime

      public String formatTime(Date value, String strFormat)
      Specified by:
      formatTime in interface ICoercionManager
    • formatNumber

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

      public Number parseNumber(String strValue)
      Specified by:
      parseNumber in interface ICoercionManager