- All Superinterfaces:
Serializable
- All Known Subinterfaces:
FactoryBase
- All Known Implementing Classes:
AbstractCacheFactory,ClassValueCacheFactory,ClassValueCacheFactory.Concurrent,ClassValueCacheFactory.WeakReference,LegacyCacheFactory,LegacyCacheFactory.Concurrent,LegacyCacheFactory.WeakReference
TypeInfo
For getting TypeInfo representing a Type, use create(Type) and its overloads
For mutating an existed TypeInfo, use toArray(TypeInfo), attachParam(TypeInfo, TypeInfo...). These methods will not modify the original TypeInfo
This class is serializable, but cached TypeInfo (if implementation has a cache) will not be de/serialized
- Author:
- ZZZank
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TypeInfo[]static final TypeInfoFactoryTypeInfoFactory used by scope independent actions. -
Method Summary
Modifier and TypeMethodDescriptiondefault TypeInfoFactoryAssociate this TypeInfoFactory object with the given top-level scope.attachParam(TypeInfo base, List<TypeInfo> params) In general, implementations are recommended, but not required, to return aParameterizedTypeInfo.default TypeInfoattachParam(TypeInfo base, TypeInfo... params) consolidateAll(List<TypeInfo> types, Map<VariableTypeInfo, TypeInfo> mapping) Transform providedtypesby applyingTypeInfo.consolidate(Map)on its elementsdefault TypeInfoconsolidateType(TypeInfo type, TypeInfo consolidateHint) consolidate a type using the mapping extracted fromconsolidateHintcreate(GenericArrayType genericArrayType) create(ParameterizedType parameterizedType) default TypeInfocreate(TypeVariable<?> typeVariable) create(WildcardType wildcardType) createArray(T[] types) createList(T[] types) static TypeInfoFactorySearch for TypeInfoFactory in the given scope.default Map<VariableTypeInfo,TypeInfo> getConsolidationMapping(Class<?> from) Get consolidation mapping from the input class.static TypeInfoFactorygetOrElse(VarScope scope, TypeInfoFactory fallback) Search for TypeInfoFactory in the given scope.static TypeInfomatchPredefined(Class<?> clazz) static Map<VariableTypeInfo,TypeInfo> transformMapping(Map<VariableTypeInfo, TypeInfo> mapping, Map<VariableTypeInfo, TypeInfo> transformer) Transform a mapping by applyingTypeInfo.consolidate(Map)on its values.
-
Field Details
-
GLOBAL
TypeInfoFactory used by scope independent actions.This factory will cache
TypeInfo. TypeInfo created from simple types likeTypeInfoFactory.class will be kept in a cache, so that when the same type is passed to this factory, no new TypeInfo is created.This factory is weakly referencing cached types. It holds a
WeakReferenceto the type for each cached type, and will not prevent cached types from being unloadedFor actions with scope available, the TypeInfoFactory can be obtained via
get(VarScope). -
EMPTY_ARRAY
-
-
Method Details
-
create
-
create
-
create
-
create
-
create
-
toArray
- Returns:
- a TypeInfo representing an array type whose component type is the provided
componentparam - See Also:
-
attachParam
In general, implementations are recommended, but not required, to return aParameterizedTypeInfo.Default implementations in Rhino will return a TypeInfo representing a parameterized type with raw type being
baseparam, and parameters beingparamsparam. If thebaseparam itself is already aParameterizedTypeInfo, the raw type will then beParameterizedTypeInfo.rawType()ofbase- See Also:
-
attachParam
-
getConsolidationMapping
Get consolidation mapping from the input class.Example (for factory implemented by Rhino):
class
and input class isA<Ta>{} classB<Tb>extendsA<Tb>{} interfaceC<Tc>{} interfaceD<Td>extendsC<Td>{} classE<Te>extendsB<Te>implementsD<String>{}E.class. The result mapping will then be:Ta -> Te,Tb -> Te,Tc -> String,Td -> String- See Also:
-
consolidateType
consolidate a type using the mapping extracted fromconsolidateHintExample:
typeisE in List<E>,consolidateHintisArrayList<SomeRandomType>, result (for factories that support Java Generic) should then beSomeRandomType -
consolidateAll
Transform providedtypesby applyingTypeInfo.consolidate(Map)on its elementsExample: types is
[int, E], mapping isE -> String, return value will then be[int, String] -
transformMapping
static Map<VariableTypeInfo,TypeInfo> transformMapping(Map<VariableTypeInfo, TypeInfo> mapping, Map<VariableTypeInfo, TypeInfo> transformer) Transform a mapping by applyingTypeInfo.consolidate(Map)on its values.Example: mapping is
K -> V, transformer isV -> String, return value will then beK -> String -
create
create aTypeInfofromType.Implementations are recommended, but not required, to maintain the uniqueness of simple types like
Class, to reduce allocationThere's no guarantee that created
TypeInfowill keep all their original information. For example,WildcardTypemight be mapped to one of its bounds, instead of aWildcardTypeInfoImplementations should return
TypeInfo.NONEif it's unable to parse theTypeit received -
createArray
-
createList
-
matchPredefined
-
associate
Associate this TypeInfoFactory object with the given top-level scope.NOTE: If you're about associate a custom TypeInfoFactory to a scope, call this method before
initStandardObjects(...)orinitSafeStandardObjects(...)- Parameters:
topScope- scope to associate this TypeInfoFactory object with.- Returns:
thisif no previous TypeInfoFactory object was associated with the scope and this TypeInfoFactory is successfully associated, or the old associated factory otherwise.- Throws:
IllegalArgumentException- if provided scope is not top scope- See Also:
-
get
Search for TypeInfoFactory in the given scope.- Parameters:
scope- scope to search for TypeInfoFactory object.- Returns:
- previously associated TypeInfoFactory object.
- Throws:
IllegalArgumentException- if the top scope of provided scope have no associated TypeInfoFactory.- See Also:
-
getOrElse
Search for TypeInfoFactory in the given scope. When none was found,fallbackis returned instead- Parameters:
scope- scope to search for TypeInfoFactory object.- Returns:
- previously associated TypeInfoFactory object, or
fallbackif none was found - See Also:
-