Class ReflectionTypeDescriptor<T>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.TypeDescriptor<T>
-
- net.ssehub.easy.instantiation.core.model.vilTypes.ReflectionTypeDescriptor<T>
-
- Type Parameters:
T- the specific VilType or Artifact
- All Implemented Interfaces:
IMetaType
- Direct Known Subclasses:
ActualValueReflectionTypeDescriptor
public class ReflectionTypeDescriptor<T> extends TypeDescriptor<T>
Represents an actual type based on reflection analysis of the underlying class. Instances of this class are created upon registration. This class works on the default type registry (only). Thereby, the available operations are determined and cached for fast access. ConsidersIActualTypeProvider.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description static TypeDescriptor<PseudoAny>ANYprivate booleancanBeInstantiatedprivate java.lang.Class<T>clsprivate java.lang.ObjectdefltValueprivate static EASyLoggerFactory.EASyLoggerLOGGERstatic java.lang.StringNAME_ANYstatic java.lang.StringNAME_TYPEstatic java.lang.StringNAME_VERSIONstatic java.lang.StringNAME_VOIDprivate java.lang.Class<?>[]nAssignStores non-assignable classes.static TypeDescriptor<?>[]PSEUDO_TYPESprivate IMetaTypesuperTypestatic TypeDescriptor<PseudoType>TYPEstatic TypeDescriptor<PseudoVersion>VERSIONstatic TypeDescriptor<PseudoVoid>VOID-
Fields inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.TypeDescriptor
EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedReflectionTypeDescriptor(java.lang.Class<T> cls)Creates a new type descriptor.(package private)ReflectionTypeDescriptor(java.lang.Class<T> cls, TypeDescriptor<?>... parameter)Creates a new type descriptor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddConversions(java.lang.Class<?> cls, java.util.List<OperationDescriptor> convs)Adds the the conversions inclstoconvs.private voidaddMethod(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.reflect.Method method, java.lang.String instantiatorName)Adds the given method to the operations map.private voidaddMethods(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.Class<?> cls, java.lang.Class<?> start, java.lang.String instantiatorName)Adds all (relevant and not invisible) methods provided bycls.private voidaddOperation(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.String sig, OperationDescriptor desc)Adds a specific operation descriptor via its signature to the temporary operation map.OperationDescriptoraddPlaceholderOperation(java.lang.String name, int parameterCount, boolean acceptsNamedParameters)Adds a placeholder operation, i.e., in case that the original operation cannot be resolved but the script shall remain executable.booleancanBeInstantiated()Returns whetherTypeDescriptor.create(Object...)will return an instance.booleancheckConversion(IMetaType param, IMetaOperation conversion)Checks a conversion from this type toparamvia the givenconversion.protected booleanconsiderAsConstructor(java.lang.reflect.Method method)Returns whether the givenmethodshall be considered as constructor.Tcreate(java.lang.Object... params)Creates an instance of the type according to the given parameters.protected ReflectionOperationDescriptorcreateDescriptor(java.lang.reflect.Method method, java.lang.String name, boolean constructor)Creates a reflection operation descriptor for an usual method call.protected booleanenableMethod(java.lang.reflect.Method method)Returns whether a method shall be added.private static booleanfilterMethodByName(java.lang.reflect.Method method, java.lang.String instantiatorName)Returns whether the method shall be considered based on its name.static java.lang.StringgetAlias(java.lang.Class<?> cls)Returns a possible alias forclsbased onClassMeta.private static java.lang.StringgetAlias(ClassMeta meta)Returns a possible alias forClassMeta.IMetaTypegetBaseType()Returns the base type (in case of IVML derived types).java.lang.ObjectgetDefaultValue()Returns the default value for this type, usually a neutral value or a constant value to compare against.java.lang.StringgetName()Returns the (simple) name of this type.java.lang.StringgetQualifiedName()Returns the qualified name of this type.static java.lang.StringgetRegName(java.lang.Class<?> cls)Returns the name how a class shall be registered based onClassMeta.IMetaTypegetSuperType()Returns the type this type is refined from.java.lang.Class<T>getTypeClass()Returns the class of the described VIL type.TypeRegistrygetTypeRegistry()Returns the type registry this type was registered by.java.lang.StringgetVilName()Returns the name of this type in VIL notation.booleanisActualTypeOf(IMetaType type)Returns whether this type can act as an actual type oftype.booleanisAssignableFrom(IMetaType type)Returns whether this type is the same or a super class oftype.booleanisAssignableFrom(TypeDescriptor<?> desc)Returns whether this descriptor is the same or a super class ofdesc.booleanisBasicType()Returns whether this instance represents a basic type.booleanisCollection()Returns whether this descriptor represents a VIL collection, i.e., set, sequence or collection.(package private) static booleanisCollection(java.lang.Class<?> cls)Returns whether the given class represents a VIL collection.booleanisInstance(java.lang.Object object)Returns whether the givenobjectis an instance of this descriptor.booleanisInstantiator()Returns whether this type is an instantiator.booleanisInternal()Returns whether this type is internal and shall not be visible to the user.booleanisIterator()Returns whether this descriptor represents an iterator.(package private) static booleanisIterator(java.lang.Class<?> cls)Returns whether the given class represents an iterator.booleanisMap()Returns whether this descriptor represents a VIL map.(package private) static booleanisMap(java.lang.Class<?> cls)Returns whether the given class represents a VIL map.private booleanisNAssign(java.lang.Class<?> cls)Checks whether the given classclsis considered as a non-assignable class for this type descriptor.booleanisPlaceholder()Returns whether this type is valid or whether it is a placeholder type in case that the original type cannot be resolved but the script shall remain executable.booleanisSameType(java.lang.Object object)Returns whether the givenobjectof of the type of this descriptor.booleanisSequence()Returns whether this descriptor represents a VIL sequence.(package private) static booleanisSequence(java.lang.Class<?> cls)Returns whether the given class represents a VIL sequence.booleanisSet()Returns whether this descriptor represents a VIL set.(package private) static booleanisSet(java.lang.Class<?> cls)Returns whether the given class represents a VIL set.protected voidprocessInner(java.lang.Class<?> cls)Processes the inner classes ofcls.private booleanregisterAliasOperation(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.reflect.Method method)Register the givenmethodas an alias operation, i.e., getters withoutConstants.GETTER_PREFIX.protected ReflectionTypeDescriptor<T>resolve()Resolves the details of the type.protected voidresolveFields()Resolves the fields.static java.lang.StringstripGetterPrefix(java.lang.String name)Strips the getter prefixConstants.GETTER_PREFIXfromname.java.lang.StringtoString()Returns a textual representation of this descriptor (the Java signature).-
Methods inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.TypeDescriptor
addOperation, allInstances, appendParameter, createArray, enableDynamicDispatch, findCollectionIteratorOperation, findConversion, findConversion, findConversionOnBoth, flatten, flattenParam, getCandidates, getCandidates, getConversion, getConversions, getConversionsCount, getConversionToSequence, getField, getField, getFieldCount, getFields, getGenericParameter, getGenericParameterCount, getGenericParameterType, getOperation, getOperations, getOperationsCount, isFieldsNull, isInitialized, isNameSet, isSame, setConversions, setFields, setFields, setName, setOperations
-
-
-
-
Field Detail
-
VOID
public static final TypeDescriptor<PseudoVoid> VOID
-
NAME_VOID
public static final java.lang.String NAME_VOID
- See Also:
- Constant Field Values
-
TYPE
public static final TypeDescriptor<PseudoType> TYPE
-
NAME_TYPE
public static final java.lang.String NAME_TYPE
- See Also:
- Constant Field Values
-
ANY
public static final TypeDescriptor<PseudoAny> ANY
-
NAME_ANY
public static final java.lang.String NAME_ANY
- See Also:
- Constant Field Values
-
VERSION
public static final TypeDescriptor<PseudoVersion> VERSION
-
NAME_VERSION
public static final java.lang.String NAME_VERSION
- See Also:
- Constant Field Values
-
LOGGER
private static final EASyLoggerFactory.EASyLogger LOGGER
-
PSEUDO_TYPES
public static final TypeDescriptor<?>[] PSEUDO_TYPES
-
cls
private java.lang.Class<T> cls
-
canBeInstantiated
private boolean canBeInstantiated
-
superType
private IMetaType superType
-
defltValue
private java.lang.Object defltValue
-
nAssign
private java.lang.Class<?>[] nAssign
Stores non-assignable classes.- See Also:
ClassMeta.nAssign()
-
-
Constructor Detail
-
ReflectionTypeDescriptor
protected ReflectionTypeDescriptor(java.lang.Class<T> cls) throws VilException
Creates a new type descriptor.- Parameters:
cls- the class to create the type descriptor for- Throws:
VilException- if analyzing the class fails for some reason
-
ReflectionTypeDescriptor
ReflectionTypeDescriptor(java.lang.Class<T> cls, TypeDescriptor<?>... parameter) throws VilException
Creates a new type descriptor.- Parameters:
cls- the class to create the type descriptor forparameter- type parameter (may be null)- Throws:
VilException- if analyzing the class fails for some reason
-
-
Method Detail
-
resolve
protected ReflectionTypeDescriptor<T> resolve() throws VilException
Resolves the details of the type. Required to register the type first in order to allow resolution of the own type in operations and fields.- Returns:
- this (builder pattern)
- Throws:
VilException- in case of resolution problems
-
resolveFields
protected void resolveFields()
Resolves the fields.
-
processInner
protected void processInner(java.lang.Class<?> cls) throws VilExceptionProcesses the inner classes ofcls.- Parameters:
cls- the class- Throws:
VilException- in case of failures
-
addConversions
private void addConversions(java.lang.Class<?> cls, java.util.List<OperationDescriptor> convs)Adds the the conversions inclstoconvs.- Parameters:
cls- the class to analyzeconvs- the conversions (to be modified as a side effect)
-
addOperation
private void addOperation(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.String sig, OperationDescriptor desc)
Adds a specific operation descriptor via its signature to the temporary operation map. AdjustscanBeInstantiated.- Parameters:
operations- the map of operations (signature-descriptor) to be modified as a side effectsig- the signaturedesc- the operation descriptor to be added
-
addMethods
private void addMethods(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.Class<?> cls, java.lang.Class<?> start, java.lang.String instantiatorName)
Adds all (relevant and not invisible) methods provided bycls. This method works recursively on superclasses ofcls.- Parameters:
operations- the map of operations (signature-descriptor) to be modified as a side effectcls- the class to be analyzedstart- the class for which this call was initiatedinstantiatorName- the name of the instantiator (may be null)
-
enableMethod
protected boolean enableMethod(java.lang.reflect.Method method)
Returns whether a method shall be added.- Parameters:
method- the method to be added- Returns:
trueif the method shall be added,falseelse
-
considerAsConstructor
protected boolean considerAsConstructor(java.lang.reflect.Method method)
Returns whether the givenmethodshall be considered as constructor.- Parameters:
method- the method to be checked- Returns:
trueif the method shall be considered as constructor,falseelse
-
addMethod
private void addMethod(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.reflect.Method method, java.lang.String instantiatorName)
Adds the given method to the operations map.- Parameters:
operations- the map of operations (signature-descriptor) to be modified as a side effectmethod- the method to be addedinstantiatorName- the name of the instantiator (may be null)- See Also:
OperationDescriptor.isOperationOrConstructor(Method)
-
createDescriptor
protected ReflectionOperationDescriptor createDescriptor(java.lang.reflect.Method method, java.lang.String name, boolean constructor)
Creates a reflection operation descriptor for an usual method call.- Parameters:
method- the method to be wrapped into the descriptorname- the name of the operation (null use the one ofmethod)constructor- whether the method is considered to be a constructor- Returns:
- the descriptor
-
filterMethodByName
private static boolean filterMethodByName(java.lang.reflect.Method method, java.lang.String instantiatorName)Returns whether the method shall be considered based on its name. In instantiators, only methods with the instantiator name or constructors are considered.- Parameters:
method- the method to be checkedinstantiatorName- the instantiator name signalling that we check for an instantiator (may be null in case of an ordinaryIVilTypeor an artifact)- Returns:
trueif it shall be considered,falseelse
-
registerAliasOperation
private boolean registerAliasOperation(java.util.Map<java.lang.String,OperationDescriptor> operations, java.lang.reflect.Method method)
Register the givenmethodas an alias operation, i.e., getters withoutConstants.GETTER_PREFIX. This method considersOperationMeta.- Parameters:
operations- the map of operations (signature-descriptor) to be modified as a side effectmethod- the method to be considered- Returns:
trueregister also the original operation,falsedo not register the original operation
-
stripGetterPrefix
public static java.lang.String stripGetterPrefix(java.lang.String name)
Strips the getter prefixConstants.GETTER_PREFIXfromname.- Parameters:
name- the name to strip- Returns:
- the name without the getter prefix, null if there was nothing to strip off
-
getRegName
public static java.lang.String getRegName(java.lang.Class<?> cls)
Returns the name how a class shall be registered based onClassMeta.- Parameters:
cls- the class to be considered- Returns:
- the name
-
getAlias
public static java.lang.String getAlias(java.lang.Class<?> cls)
Returns a possible alias forclsbased onClassMeta.- Parameters:
cls- the class to be considered- Returns:
- the alias or null if there is none
-
getAlias
private static java.lang.String getAlias(ClassMeta meta)
Returns a possible alias forClassMeta.- Parameters:
meta- the annotation to query- Returns:
- the alias or null if there is none
-
getName
public java.lang.String getName()
Description copied from interface:IMetaTypeReturns the (simple) name of this type.- Specified by:
getNamein interfaceIMetaType- Overrides:
getNamein classTypeDescriptor<T>- Returns:
- the simple name
-
getQualifiedName
public java.lang.String getQualifiedName()
Description copied from interface:IMetaTypeReturns the qualified name of this type.- Specified by:
getQualifiedNamein interfaceIMetaType- Overrides:
getQualifiedNamein classTypeDescriptor<T>- Returns:
- the qualified name
-
canBeInstantiated
public boolean canBeInstantiated()
Description copied from class:TypeDescriptorReturns whetherTypeDescriptor.create(Object...)will return an instance.- Specified by:
canBeInstantiatedin classTypeDescriptor<T>- Returns:
trueif this type can be instantiated from VIL/VTL,falseelse
-
create
public T create(java.lang.Object... params) throws VilException
Creates an instance of the type according to the given parameters.- Specified by:
createin classTypeDescriptor<T>- Parameters:
params- the parameters- Returns:
- the created instance
- Throws:
VilException- in case that the creation does not work
-
getTypeClass
public java.lang.Class<T> getTypeClass()
Description copied from class:TypeDescriptorReturns the class of the described VIL type. Please use this method sparingly as the required functionality is provided by this class.- Specified by:
getTypeClassin classTypeDescriptor<T>- Returns:
- the class
-
isNAssign
private boolean isNAssign(java.lang.Class<?> cls)
Checks whether the given classclsis considered as a non-assignable class for this type descriptor.- Parameters:
cls- the class to be tested- Returns:
trueif it is non-assignable,falseelse- See Also:
ClassMeta.nAssign()
-
isAssignableFrom
public boolean isAssignableFrom(IMetaType type)
Description copied from interface:IMetaTypeReturns whether this type is the same or a super class oftype.- Parameters:
type- the descriptor to be tested- Returns:
trueif both types are assignment compatible,falseelse
-
isAssignableFrom
public boolean isAssignableFrom(TypeDescriptor<?> desc)
Description copied from class:TypeDescriptorReturns whether this descriptor is the same or a super class ofdesc.- Specified by:
isAssignableFromin classTypeDescriptor<T>- Parameters:
desc- the descriptor to be tested- Returns:
trueif both descriptors are assignment compatible,falseelse
-
toString
public java.lang.String toString()
Returns a textual representation of this descriptor (the Java signature).- Overrides:
toStringin classTypeDescriptor<T>- Returns:
- the textual representation
-
getVilName
public java.lang.String getVilName()
Description copied from class:TypeDescriptorReturns the name of this type in VIL notation.- Overrides:
getVilNamein classTypeDescriptor<T>- Returns:
- the name of this type
-
isCollection
static boolean isCollection(java.lang.Class<?> cls)
Returns whether the given class represents a VIL collection.- Parameters:
cls- the class to be checked- Returns:
trueif it is a VIL collection,falseelse
-
isSet
static boolean isSet(java.lang.Class<?> cls)
Returns whether the given class represents a VIL set.- Parameters:
cls- the class to be checked- Returns:
trueif it is a VIL set,falseelse
-
isIterator
static boolean isIterator(java.lang.Class<?> cls)
Returns whether the given class represents an iterator.- Parameters:
cls- the class to be checked- Returns:
trueif it is an iterator,falseelse
-
isSequence
static boolean isSequence(java.lang.Class<?> cls)
Returns whether the given class represents a VIL sequence.- Parameters:
cls- the class to be checked- Returns:
trueif it is a VIL sequence,falseelse
-
isMap
static boolean isMap(java.lang.Class<?> cls)
Returns whether the given class represents a VIL map.- Parameters:
cls- the class to be checked- Returns:
trueif it is a VIL map,falseelse
-
isCollection
public boolean isCollection()
Description copied from class:TypeDescriptorReturns whether this descriptor represents a VIL collection, i.e., set, sequence or collection.- Specified by:
isCollectionin classTypeDescriptor<T>- Returns:
trueif this is a VIL collection,falseelse
-
isIterator
public boolean isIterator()
Description copied from class:TypeDescriptorReturns whether this descriptor represents an iterator.- Specified by:
isIteratorin classTypeDescriptor<T>- Returns:
trueif this is an iterator,falseelse
-
isMap
public boolean isMap()
Description copied from class:TypeDescriptorReturns whether this descriptor represents a VIL map.- Specified by:
isMapin classTypeDescriptor<T>- Returns:
trueif this is a VIL map,falseelse
-
isSet
public boolean isSet()
Description copied from class:TypeDescriptorReturns whether this descriptor represents a VIL set.- Specified by:
isSetin classTypeDescriptor<T>- Returns:
trueif this is a VIL set,falseelse
-
isSequence
public boolean isSequence()
Description copied from class:TypeDescriptorReturns whether this descriptor represents a VIL sequence.- Specified by:
isSequencein classTypeDescriptor<T>- Returns:
trueif this is a VIL sequence,falseelse
-
isInstance
public boolean isInstance(java.lang.Object object)
Description copied from class:TypeDescriptorReturns whether the givenobjectis an instance of this descriptor.- Specified by:
isInstancein classTypeDescriptor<T>- Parameters:
object- the object to be checked- Returns:
trueif it is an instance,falseelse
-
isSameType
public boolean isSameType(java.lang.Object object)
Description copied from class:TypeDescriptorReturns whether the givenobjectof of the type of this descriptor.- Specified by:
isSameTypein classTypeDescriptor<T>- Parameters:
object- the object to be checked- Returns:
trueifobjecthas the same type,falseelse
-
isBasicType
public boolean isBasicType()
Description copied from interface:IMetaTypeReturns whether this instance represents a basic type.- Returns:
trueif this instance represents a basic type,falseelse
-
getTypeRegistry
public TypeRegistry getTypeRegistry()
Description copied from interface:IMetaTypeReturns the type registry this type was registered by.- Returns:
- the type registry
-
isPlaceholder
public boolean isPlaceholder()
Description copied from interface:IMetaTypeReturns whether this type is valid or whether it is a placeholder type in case that the original type cannot be resolved but the script shall remain executable.- Returns:
trueif this type is a placeholder,falseelse
-
addPlaceholderOperation
public OperationDescriptor addPlaceholderOperation(java.lang.String name, int parameterCount, boolean acceptsNamedParameters)
Description copied from class:TypeDescriptorAdds a placeholder operation, i.e., in case that the original operation cannot be resolved but the script shall remain executable.- Specified by:
addPlaceholderOperationin interfaceIMetaType- Specified by:
addPlaceholderOperationin classTypeDescriptor<T>- Parameters:
name- the name of the operationparameterCount- the number of parameters of the operationacceptsNamedParameters- whether the operation accepts named parameters- Returns:
- the added operation, null if this type is not a
placeholder
-
isActualTypeOf
public boolean isActualTypeOf(IMetaType type)
Description copied from interface:IMetaTypeReturns whether this type can act as an actual type oftype.- Parameters:
type- the type to be checked- Returns:
trueif this type can act as an actual type oftype,falseelse- See Also:
IActualTypeProvider
-
getBaseType
public IMetaType getBaseType()
Description copied from interface:IMetaTypeReturns the base type (in case of IVML derived types).- Returns:
- the base type or null
-
isInternal
public boolean isInternal()
Description copied from interface:IMetaTypeReturns whether this type is internal and shall not be visible to the user.- Returns:
trueif this type is internal,falseelse
-
isInstantiator
public boolean isInstantiator()
Description copied from class:TypeDescriptorReturns whether this type is an instantiator.- Specified by:
isInstantiatorin classTypeDescriptor<T>- Returns:
trueif it is an instantiator,falseelse
-
getSuperType
public IMetaType getSuperType()
Description copied from interface:IMetaTypeReturns the type this type is refined from.- Returns:
- the super type or null if there is none
-
checkConversion
public boolean checkConversion(IMetaType param, IMetaOperation conversion)
Description copied from interface:IMetaTypeChecks a conversion from this type toparamvia the givenconversion.- Parameters:
param- the original parameter valueconversion- the conversion function- Returns:
trueif ok,falseelse
-
getDefaultValue
public java.lang.Object getDefaultValue()
Description copied from class:TypeDescriptorReturns the default value for this type, usually a neutral value or a constant value to compare against.- Overrides:
getDefaultValuein classTypeDescriptor<T>- Returns:
- the default value, null for none - may lead to an undefined operation execution
-
-