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 DecimalFormatstatic final Objectprivate IType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate IType_verifyTypesComparable(IType lhsType, IType rhsType, boolean bBiDirectional) private booleanareJavaClassesAndAreNotAssignable(IType typeToCoerceTo, IType typeToCoerceFrom) static booleanarePrimitiveTypesAssignable(IType toType, IType fromType) final booleanprivate ObjectconvertNullAsPrimitive(IType intrType, boolean isForBoxing) Converts a null value to a value compatible with the specified primitive type.final ObjectconvertValue(Object value, IType intrType) Given a value and a target Class, return a compatible value via the target Class.private ObjectextractObjectArray(IType intrType, Object value) final ICoercerfindCoercer(IType lhsType, IType rhsType, boolean runtime) private ICoercerfindCoercerImpl(IType lhsType, IType rhsType, boolean runtime) formatDate(Date value, String strFormat) formatNumber(Double value, String strFormat) formatTime(Date value, String strFormat) private ITypegetBoundingTypeOfTypeVariable(IType intrType) protected ICoercergetCoercerInternal(IType lhsType, IType rhsType, boolean runtime) Returns a coercer from values of rhsType to values of lhsType if one exists.protected ICoercerprotected ICoercerprivate booleanhasPotentialLossOfPrecisionOrScale(IType lhsType, IType rhsType) private ICoerceridentityOrRuntime(IType typeToCoerceTo, IType typeToCoerceFrom) static booleanbooleanisDateTime(String str) static booleanbooleanisPrimitiveOrBoxed(IType lhsType) Determine whether the specified type is either a primitive or a boxed primitive.private static booleanisStrictGenerics(IType type) static booleanisStructurallyAssignable(IType toType, IType fromType) static booleanisStructurallyAssignable_Laxed(IType toType, IType fromType) static booleanisStructurallyAssignable_Laxed(IType toType, IType fromType, TypeVarToTypeMap inferenceMap) static booleanisStructurallyAssignable_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) booleandoublefloatintlongmakeRationalFrom(Object obj) makeStringFrom(Object obj) booleannotCoercibleOrRequiresExplicitCoercion(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, waitMethods 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:
canCoercein 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:
findCoercerin 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:ICoercionManagerDetermine whether the specified type is either a primitive or a boxed primitive.- Specified by:
isPrimitiveOrBoxedin 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:ICoercionManagerVerifies 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:
verifyTypesComparablein interfaceICoercionManager- Throws:
ParseException
-
verifyTypesComparable
public IType verifyTypesComparable(IType lhsType, IType rhsType, boolean bBiDirectional, IFullParserState parserState) throws ParseException Description copied from interface:ICoercionManagerVerifies 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:
verifyTypesComparablein 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:
notCoercibleOrRequiresExplicitCoercionin interfaceICoercionManager
-
convertValue
Given a value and a target Class, return a compatible value via the target Class.- Specified by:
convertValuein 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:ICoercionManagerConverts a null value to a value compatible with the specified primitive type.- Specified by:
convertNullAsPrimitivein interfaceICoercionManager- Parameters:
intrType- The primitive type to convert to.- Returns:
- A wrapped primitive value corresponding to null.
-
resolveCoercerStatically
Description copied from interface:ICoercionManagerDetermine and return a statically valid coercer from the rhsType to the lhsType. Returns null if no coercion is necessary.- Specified by:
resolveCoercerStaticallyin interfaceICoercionManager- Parameters:
typeToCoerceTo- the type to coerce totypeToCoerceFrom- the type to coerce from
-
areJavaClassesAndAreNotAssignable
-
identityOrRuntime
-
makeDoubleFrom
Description copied from interface:ICoercionManagerReturns 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:
makeDoubleFromin interfaceICoercionManager- Returns:
- A Double for an arbitrary object (may return a pooled instance).
-
makePrimitiveIntegerFrom
- Specified by:
makePrimitiveIntegerFromin interfaceICoercionManager
-
makeIntegerFrom
- Specified by:
makeIntegerFromin interfaceICoercionManager
-
makePrimitiveLongFrom
- Specified by:
makePrimitiveLongFromin interfaceICoercionManager
-
makeLongFrom
- Specified by:
makeLongFromin interfaceICoercionManager
-
makeBigDecimalFrom
- Specified by:
makeBigDecimalFromin interfaceICoercionManager
-
makeRationalFrom
- Specified by:
makeRationalFromin interfaceICoercionManager
-
makeBigIntegerFrom
- Specified by:
makeBigIntegerFromin interfaceICoercionManager
-
makePrimitiveDoubleFrom
- Specified by:
makePrimitiveDoubleFromin interfaceICoercionManager
-
makeFloatFrom
- Specified by:
makeFloatFromin interfaceICoercionManager
-
makePrimitiveFloatFrom
- Specified by:
makePrimitiveFloatFromin interfaceICoercionManager
-
makeStringFrom
- Specified by:
makeStringFromin interfaceICoercionManager
-
makePrimitiveBooleanFrom
- Specified by:
makePrimitiveBooleanFromin interfaceICoercionManager- Returns:
- A Boolean for an arbitrary object.
-
makeBooleanFrom
- Specified by:
makeBooleanFromin interfaceICoercionManager
-
makeDateFrom
Returns a new Date instance representing the object.- Specified by:
makeDateFromin interfaceICoercionManager
-
isDateTime
- Specified by:
isDateTimein interfaceICoercionManager- Throws:
ParseException
-
parseDateTime
Produce a date from a string using standard DateFormat parsing.- Specified by:
parseDateTimein interfaceICoercionManager- Throws:
ParseException
-
formatDate
- Specified by:
formatDatein interfaceICoercionManager
-
formatTime
- Specified by:
formatTimein interfaceICoercionManager
-
formatNumber
- Specified by:
formatNumberin interfaceICoercionManager
-
parseNumber
- Specified by:
parseNumberin interfaceICoercionManager
-