Package gw.lang.parser
Class StandardCoercionManager
java.lang.Object
gw.config.BaseService
gw.lang.parser.StandardCoercionManager
- All Implemented Interfaces:
IService
,ICoercionManager
,IPluginHost
- Direct Known Subclasses:
GWCoercionManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
(package private) class
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal TypeSystemAwareCache<Pair<IType,
IType>, ICoercer> private final TypeSystemAwareCache<StandardCoercionManager.TypesComp,
IType> private static final DecimalFormat
static final Object
private IType
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate IType
_verifyTypesComparable
(IType lhsType, IType rhsType, boolean bBiDirectional) private boolean
areJavaClassesAndAreNotAssignable
(IType typeToCoerceTo, IType typeToCoerceFrom) static boolean
arePrimitiveTypesAssignable
(IType toType, IType fromType) final boolean
private Object
convertNullAsPrimitive
(IType intrType, boolean isForBoxing) Converts a null value to a value compatible with the specified primitive type.final Object
convertValue
(Object value, IType intrType) Given a value and a target Class, return a compatible value via the target Class.private Object
extractObjectArray
(IType intrType, Object value) final ICoercer
findCoercer
(IType lhsType, IType rhsType, boolean runtime) private ICoercer
findCoercerImpl
(IType lhsType, IType rhsType, boolean runtime) formatDate
(Date value, String strFormat) formatNumber
(Double value, String strFormat) formatTime
(Date value, String strFormat) private IType
getBoundingTypeOfTypeVariable
(IType intrType) protected ICoercer
getCoercerInternal
(IType lhsType, IType rhsType, boolean runtime) Returns a coercer from values of rhsType to values of lhsType if one exists.protected ICoercer
protected ICoercer
private boolean
hasPotentialLossOfPrecisionOrScale
(IType lhsType, IType rhsType) private ICoercer
identityOrRuntime
(IType typeToCoerceTo, IType typeToCoerceFrom) static boolean
boolean
isDateTime
(String str) static boolean
boolean
isPrimitiveOrBoxed
(IType lhsType) Determine whether the specified type is either a primitive or a boxed primitive.private static boolean
isStrictGenerics
(IType type) static boolean
isStructurallyAssignable
(IType toType, IType fromType) static boolean
isStructurallyAssignable_Laxed
(IType toType, IType fromType) static boolean
isStructurallyAssignable_Laxed
(IType toType, IType fromType, TypeVarToTypeMap inferenceMap) static boolean
isStructurallyAssignable_Laxed
(IType toType, IType fromType, IMethodInfo specificMethod, TypeVarToTypeMap inferenceMap) makeBigDecimalFrom
(Object obj) makeBigIntegerFrom
(Object obj) makeBooleanFrom
(Object obj) makeDateFrom
(Object obj) Returns a new Date instance representing the object.makeDoubleFrom
(Object obj) Returns a Double for an arbitrary object.makeFloatFrom
(Object obj) makeIntegerFrom
(Object obj) makeLongFrom
(Object obj) boolean
double
float
int
long
makeRationalFrom
(Object obj) makeStringFrom
(Object obj) boolean
notCoercibleOrRequiresExplicitCoercion
(IType lhsType, IType rhsType) parseDateTime
(String str) Produce a date from a string using standard DateFormat parsing.parseNumber
(String strValue) resolveCoercerStatically
(IType typeToCoerceTo, IType typeToCoerceFrom) Determine and return a statically valid coercer from the rhsType to the lhsType.verifyTypesComparable
(IType lhsType, IType rhsType, boolean bBiDirectional) Verifies that the right hand type can be converted or coerced to the left hand type.verifyTypesComparable
(IType lhsType, IType rhsType, boolean bBiDirectional, IFullParserState parserState) Verifies that the right hand type can be converted or coerced to the left hand type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface gw.plugin.IPluginHost
getInterface
-
Field Details
-
BIG_DECIMAL_FORMAT
-
NO_DICE
-
_coercerCache
-
NULL_COMP
-
_compCache
-
-
Constructor Details
-
StandardCoercionManager
public StandardCoercionManager()
-
-
Method Details
-
canCoerce
- Specified by:
canCoerce
in interfaceICoercionManager
- Parameters:
lhsType
- type to be coerced torhsType
- type to be coerced from- Returns:
- true if a coercion exists from rhsType to lhsType, false otherwise
-
coerce
-
hasPotentialLossOfPrecisionOrScale
-
findCoercer
- Specified by:
findCoercer
in interfaceICoercionManager
-
findCoercerImpl
-
getCoercerInternal
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 torhsType
- the type to coerce fromruntime
- 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
Description copied from interface:ICoercionManager
Determine whether the specified type is either a primitive or a boxed primitive.- Specified by:
isPrimitiveOrBoxed
in interfaceICoercionManager
- Parameters:
lhsType
- the type to examine- Returns:
- true if the specified type is a primitive or a boxed primitive
-
isBoxed
-
getPrimitiveOrBoxedConverter
-
getHighPriorityPrimitiveOrBoxedConverter
-
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 interfaceICoercionManager
- 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 interfaceICoercionManager
- Throws:
ParseException
-
_verifyTypesComparable
-
isStrictGenerics
-
isStructurallyAssignable
-
isStructurallyAssignable_Laxed
-
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
-
isObjectMethod
-
notCoercibleOrRequiresExplicitCoercion
- Specified by:
notCoercibleOrRequiresExplicitCoercion
in interfaceICoercionManager
-
convertValue
Given a value and a target Class, return a compatible value via the target Class.- Specified by:
convertValue
in interfaceICoercionManager
- Parameters:
value
- the value to coerce (may not be null)intrType
- type to coerce to- Returns:
- the converted value
-
getBoundingTypeOfTypeVariable
-
extractObjectArray
-
convertNullAsPrimitive
Description copied from interface:ICoercionManager
Converts a null value to a value compatible with the specified primitive type.- Specified by:
convertNullAsPrimitive
in interfaceICoercionManager
- Parameters:
intrType
- The primitive type to convert to.- Returns:
- A wrapped primitive value corresponding to null.
-
resolveCoercerStatically
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 interfaceICoercionManager
- Parameters:
typeToCoerceTo
- the type to coerce totypeToCoerceFrom
- the type to coerce from
-
areJavaClassesAndAreNotAssignable
-
identityOrRuntime
-
makeDoubleFrom
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 interfaceICoercionManager
- Returns:
- A Double for an arbitrary object (may return a pooled instance).
-
makePrimitiveIntegerFrom
- Specified by:
makePrimitiveIntegerFrom
in interfaceICoercionManager
-
makeIntegerFrom
- Specified by:
makeIntegerFrom
in interfaceICoercionManager
-
makePrimitiveLongFrom
- Specified by:
makePrimitiveLongFrom
in interfaceICoercionManager
-
makeLongFrom
- Specified by:
makeLongFrom
in interfaceICoercionManager
-
makeBigDecimalFrom
- Specified by:
makeBigDecimalFrom
in interfaceICoercionManager
-
makeRationalFrom
- Specified by:
makeRationalFrom
in interfaceICoercionManager
-
makeBigIntegerFrom
- Specified by:
makeBigIntegerFrom
in interfaceICoercionManager
-
makePrimitiveDoubleFrom
- Specified by:
makePrimitiveDoubleFrom
in interfaceICoercionManager
-
makeFloatFrom
- Specified by:
makeFloatFrom
in interfaceICoercionManager
-
makePrimitiveFloatFrom
- Specified by:
makePrimitiveFloatFrom
in interfaceICoercionManager
-
makeStringFrom
- Specified by:
makeStringFrom
in interfaceICoercionManager
-
makePrimitiveBooleanFrom
- Specified by:
makePrimitiveBooleanFrom
in interfaceICoercionManager
- Returns:
- A Boolean for an arbitrary object.
-
makeBooleanFrom
- Specified by:
makeBooleanFrom
in interfaceICoercionManager
-
makeDateFrom
Returns a new Date instance representing the object.- Specified by:
makeDateFrom
in interfaceICoercionManager
-
isDateTime
- Specified by:
isDateTime
in interfaceICoercionManager
- Throws:
ParseException
-
parseDateTime
Produce a date from a string using standard DateFormat parsing.- Specified by:
parseDateTime
in interfaceICoercionManager
- Throws:
ParseException
-
formatDate
- Specified by:
formatDate
in interfaceICoercionManager
-
formatTime
- Specified by:
formatTime
in interfaceICoercionManager
-
formatNumber
- Specified by:
formatNumber
in interfaceICoercionManager
-
parseNumber
- Specified by:
parseNumber
in interfaceICoercionManager
-