Class ReflectionOperationDescriptor
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.OperationDescriptor
-
- net.ssehub.easy.instantiation.core.model.vilTypes.ReflectionOperationDescriptor
-
- All Implemented Interfaces:
ILazyDescriptor,IMetaOperation
public class ReflectionOperationDescriptor extends OperationDescriptor implements ILazyDescriptor
Represents an individual operation available to the VIL languages based on reflection analysis of the underlying class. This class works on the default type registry. Please note that named arguments are passed in terms of a map as the last parameter of the respective method. If the underlying Java method takes such a parameter, the descriptor will count one parameter less!- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.OperationDescriptor
OperationDescriptor.AliasType
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IMetaOperation
IMetaOperation.CompatibilityResult
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Methodmethodprivate java.util.Map<java.lang.String,ReflectionOperationParameter>namedParamsprivate ReflectionOperationParameter[]namedParamsSeqprivate static java.util.Map<java.lang.Class<?>,java.lang.Class<?>>REFLECTION_EQUALITIESStores implicit type equalities handled by boxing/unboxing in Java reflection.private intreturnGenericParameterIndexprivate intreturnParameterIndexprivate booleanstoreArtifactsBeforeExecutionprivate booleantrace-
Fields inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.OperationDescriptor
CONSTRUCTOR_NAME, EMPTY_PARAMETER
-
-
Constructor Summary
Constructors Constructor Description ReflectionOperationDescriptor(TypeDescriptor<?> declaringType, java.lang.reflect.Method method, boolean isConstructor)Creates a new operation descriptor.ReflectionOperationDescriptor(TypeDescriptor<?> declaringType, java.lang.reflect.Method method, java.lang.String name, boolean isConstructor)Creates a new operation descriptor as an alias.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddReflectionEquality(java.lang.Class<?> cls1, java.lang.Class<?> cls2)Adds a new bi-directional reflection equality.booleanallowsAggregation()Returns whether this operation allows iterator aggregation.private java.util.Map<java.lang.String,java.lang.Object>checkForNamedParameter(TypeDescriptor<?> type, int index, java.lang.annotation.Annotation[][] annotations, java.util.Map<java.lang.String,java.lang.Object> defltValues, int paramCount)Checks the current parameter for a named parameter.protected booleanconsiderNamedParameters()Returns whether named parameters shall be considered for this descriptor.booleanflatten()When resolving expression types, flatten the final return type.voidforceInitialization()Forces the initialization of the typically lazily deferred parameters and return types.protected java.lang.StringgetDeclaringTypeNameFallback()Returns the name of the declaring type in case thatOperationDescriptor.getDeclaringType()is null.private java.util.Map<java.lang.String,java.lang.Object>getDefaultValues()Returns the default values for this method.java.lang.StringgetJavaSignature()Returns the Java signature of the method (public for testing).protected java.lang.reflect.MethodgetMethod()Returns the wrapped method.java.lang.StringgetName()Returns the name of the method.IMetaParameterDeclarationgetParameter(int index)Returns the parameter declaration of named parameters.IMetaParameterDeclarationgetParameter(java.lang.String name)Returns a named parameter declaration.protected java.lang.Class<?>[]getParameterGenerics(int index)Determines the type of a parameter.intgetRequiredParameterCount()Returns the number of required parameters, i.e., non-default and non-named parameters.protected java.lang.Class<?>[]getReturnGenerics()Determines the return type generics.java.lang.StringgetSignature()Returns the signature of the method.protected voidinitializeParameters()Initializes the parameters (lazy init).protected voidinitializeReturnType()Initializes the return type (lazy init).java.lang.Objectinvoke(java.lang.Object... args)Invokes the specified operation.IMetaOperation.CompatibilityResultisCompatible(java.lang.Class<?> retType, java.lang.Object... params)Returns whether the operation represented by this instance is compatible to the given return type and parameters.booleanisFirstParameterOperand()Returns whether the first parameter is the operand.booleanisOclCompliant()Returns whether this operation is OCL compliant or flagged as not compliant.booleanisPlaceholder()Returns whether this operation is valid or whether it is a placeholder operation in case that the original operation cannot be resolved but the script shall remain executable.booleanisStatic()Returns whether this operation is static.private static java.lang.Objectnullify(java.lang.Object value)Nullifiesvalue, i.e., checks whether it is an IVML null value and turns it into null.booleanrequiresDynamicExpressionProcessing()Indicates whether this function requires dynamic expression processing and may cause problems with serialized models in standalone settings without xText.OperationDescriptorspecializeFor(TypeDescriptor<?> declaringType)Tries to specialize this operation descriptor for the given type, e.g., to consider the specific generic parameters of that type.booleanstoreArtifactsBeforeExecution()Returns whether artifacts shall be stored before execution of this operation.booleantrace()Returns whether an execution of this descriptor shall be traced.private java.lang.ObjecttryEvaluateEquality(java.lang.Object[] args, java.lang.Object[] callArgs)Tries to evaluate equality/unequality if the actual parameters are incompatible for a regular call.booleanuseAny()When resolving expression types, use any as return type if object is given and do not try to override this.intuseGenericParameterAsReturn()Returns whether a generc parameter of the operand shall be used as return type.booleanuseOperandTypeAsParameter()When resolving the return type, use the actual operand type as return generics.intuseParameterAsReturn()Returns whether a parameter shall be used as return type.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.OperationDescriptor
acceptsImplicitParameters, acceptsNamedParameters, composeExceptionMessage, convertVariables, getAliasType, getDeclaringType, getDeclaringTypeName, getOperationType, getParameterCount, getParameterType, getReturnType, getStoredName, isAlias, isConstructor, isConstructor, isConversion, isGenericCollectionOperation, isIteratingCollectionOperation, isOperation, isOperationOrConstructor, isSameSignature, isTypeSelect, setCharacteristics, setParameters, setReturnType, throwIncompatibleParameter, toString
-
-
-
-
Field Detail
-
REFLECTION_EQUALITIES
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> REFLECTION_EQUALITIES
Stores implicit type equalities handled by boxing/unboxing in Java reflection.
-
method
private java.lang.reflect.Method method
-
returnGenericParameterIndex
private int returnGenericParameterIndex
-
returnParameterIndex
private int returnParameterIndex
-
storeArtifactsBeforeExecution
private boolean storeArtifactsBeforeExecution
-
trace
private boolean trace
-
namedParams
private java.util.Map<java.lang.String,ReflectionOperationParameter> namedParams
-
namedParamsSeq
private ReflectionOperationParameter[] namedParamsSeq
-
-
Constructor Detail
-
ReflectionOperationDescriptor
public ReflectionOperationDescriptor(TypeDescriptor<?> declaringType, java.lang.reflect.Method method, boolean isConstructor)
Creates a new operation descriptor.- Parameters:
declaringType- the declaring typemethod- the reflection method to be calledisConstructor- whether this descriptor shall act as constructor
-
ReflectionOperationDescriptor
public ReflectionOperationDescriptor(TypeDescriptor<?> declaringType, java.lang.reflect.Method method, java.lang.String name, boolean isConstructor)
Creates a new operation descriptor as an alias.- Parameters:
declaringType- the declaring typemethod- the reflection method to be calledname- the alias name (may be null if the original name ofmethodshall be used)isConstructor- whether this descriptor shall act as a constructor
-
-
Method Detail
-
addReflectionEquality
private static final void addReflectionEquality(java.lang.Class<?> cls1, java.lang.Class<?> cls2)Adds a new bi-directional reflection equality.- Parameters:
cls1- a class to be considered equivalent / assignment compatible tocls2cls2- a class to be considered equivalent / assignment compatible tocls1
-
forceInitialization
public void forceInitialization()
Description copied from interface:ILazyDescriptorForces the initialization of the typically lazily deferred parameters and return types.- Specified by:
forceInitializationin interfaceILazyDescriptor
-
considerNamedParameters
protected boolean considerNamedParameters()
Returns whether named parameters shall be considered for this descriptor.- Returns:
trueif named parameters shall be considered,falseelse
-
initializeParameters
protected void initializeParameters()
Description copied from class:OperationDescriptorInitializes the parameters (lazy init). Is called byOperationDescriptor.initialize(). Shall callOperationDescriptor.setParameters(List, boolean, boolean).- Specified by:
initializeParametersin classOperationDescriptor
-
getDefaultValues
private java.util.Map<java.lang.String,java.lang.Object> getDefaultValues()
Returns the default values for this method.- Returns:
- the default values
-
checkForNamedParameter
private java.util.Map<java.lang.String,java.lang.Object> checkForNamedParameter(TypeDescriptor<?> type, int index, java.lang.annotation.Annotation[][] annotations, java.util.Map<java.lang.String,java.lang.Object> defltValues, int paramCount)
Checks the current parameter for a named parameter.- Parameters:
type- the VIL type of the parameterindex- the 0-based index of the parameterannotations- the parameter annotations for the method (may be null)defltValues- the default values (global or local, may be null)paramCount- the total number of parameters- Returns:
defltValues, a new instance ifdefltValuesis null or null
-
getRequiredParameterCount
public int getRequiredParameterCount()
Description copied from interface:IMetaOperationReturns the number of required parameters, i.e., non-default and non-named parameters.- Specified by:
getRequiredParameterCountin interfaceIMetaOperation- Overrides:
getRequiredParameterCountin classOperationDescriptor- Returns:
- the number of required parameters
-
getParameter
public IMetaParameterDeclaration getParameter(java.lang.String name)
Description copied from interface:IMetaOperationReturns a named parameter declaration.- Specified by:
getParameterin interfaceIMetaOperation- Overrides:
getParameterin classOperationDescriptor- Parameters:
name- the name of the parameter- Returns:
- the declaration or null if there is none
-
getParameter
public IMetaParameterDeclaration getParameter(int index)
Description copied from class:OperationDescriptorReturns the parameter declaration of named parameters.- Overrides:
getParameterin classOperationDescriptor- Parameters:
index- the index of the parameter to return- Returns:
- the named parameter or null for an usual parameter
-
specializeFor
public OperationDescriptor specializeFor(TypeDescriptor<?> declaringType)
Description copied from class:OperationDescriptorTries to specialize this operation descriptor for the given type, e.g., to consider the specific generic parameters of that type.- Overrides:
specializeForin classOperationDescriptor- Parameters:
declaringType- the declaring type to specialize for- Returns:
- either this if no specialization is needed or a specializing instance
-
initializeReturnType
protected void initializeReturnType()
Description copied from class:OperationDescriptorInitializes the return type (lazy init). Is called byOperationDescriptor.initialize(). Shall callOperationDescriptor.setReturnType(TypeDescriptor).- Specified by:
initializeReturnTypein classOperationDescriptor
-
invoke
public java.lang.Object invoke(java.lang.Object... args) throws VilExceptionDescription copied from interface:IMetaOperationInvokes the specified operation. This method does not consider possible unnamed parameter rather than the underlying Java parameter. In case ofIMetaOperation.acceptsNamedParameters()the caller must ensure that the last parameter is amap<String, Object>containing the named parameters.- Specified by:
invokein interfaceIMetaOperation- Parameters:
args- the arguments, in case of non-static operations the first argument must be the object to execute on- Returns:
- the result of the execution
- Throws:
VilException- if the invocation fails- See Also:
IMetaOperation.isCompatible(java.lang.Class<?>, java.lang.Object...)
-
nullify
private static java.lang.Object nullify(java.lang.Object value)
Nullifiesvalue, i.e., checks whether it is an IVML null value and turns it into null.- Parameters:
value- the value to check- Returns:
valueor null
-
tryEvaluateEquality
private java.lang.Object tryEvaluateEquality(java.lang.Object[] args, java.lang.Object[] callArgs) throws VilExceptionTries to evaluate equality/unequality if the actual parameters are incompatible for a regular call. This allows evaluating null comparisons against primitive types (decision variables declare a specific operation for that).- Parameters:
args- the original call argumentscallArgs- the actual call arguments prepared for a reflective call- Returns:
- the evaluation result
- Throws:
VilException- in case that the arguments are still considered incompatible
-
isCompatible
public IMetaOperation.CompatibilityResult isCompatible(java.lang.Class<?> retType, java.lang.Object... params)
Returns whether the operation represented by this instance is compatible to the given return type and parameters. This method does not consider possible unnamed parameter rather than the underlying Java parameter.- Specified by:
isCompatiblein interfaceIMetaOperation- Parameters:
retType- the return type (may be null in order to ignore this parameter)params- the parameters (may be null if there are none, may be classes)- Returns:
- an instance of
IMetaOperation.CompatibilityResultdenoting the actual compatibility level
-
isStatic
public boolean isStatic()
Description copied from interface:IMetaOperationReturns whether this operation is static.- Specified by:
isStaticin interfaceIMetaOperation- Returns:
trueif it is static,falseelse
-
isFirstParameterOperand
public boolean isFirstParameterOperand()
Description copied from interface:IMetaOperationReturns whether the first parameter is the operand.- Specified by:
isFirstParameterOperandin interfaceIMetaOperation- Returns:
trueif the first parameter is the operand,falseelse
-
getJavaSignature
public java.lang.String getJavaSignature()
Description copied from class:OperationDescriptorReturns the Java signature of the method (public for testing).- Specified by:
getJavaSignaturein interfaceIMetaOperation- Specified by:
getJavaSignaturein classOperationDescriptor- Returns:
- the Java signature of the method
-
getSignature
public java.lang.String getSignature()
Description copied from class:OperationDescriptorReturns the signature of the method.- Specified by:
getSignaturein interfaceIMetaOperation- Overrides:
getSignaturein classOperationDescriptor- Returns:
- the signature of the method
-
getDeclaringTypeNameFallback
protected java.lang.String getDeclaringTypeNameFallback()
Description copied from class:OperationDescriptorReturns the name of the declaring type in case thatOperationDescriptor.getDeclaringType()is null.- Specified by:
getDeclaringTypeNameFallbackin classOperationDescriptor- Returns:
- the name of the declaring type
-
getMethod
protected java.lang.reflect.Method getMethod()
Returns the wrapped method.- Returns:
- the method
-
getName
public java.lang.String getName()
Description copied from class:OperationDescriptorReturns the name of the method.- Specified by:
getNamein interfaceIMetaOperation- Overrides:
getNamein classOperationDescriptor- Returns:
- the name of the method
-
getParameterGenerics
protected java.lang.Class<?>[] getParameterGenerics(int index)
Determines the type of a parameter.- Parameters:
index- the index of the parameter- Returns:
- the parameter generics (null if none are specified)
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=OperationDescriptor.getParameterCount()
-
getReturnGenerics
protected java.lang.Class<?>[] getReturnGenerics()
Determines the return type generics.- Returns:
- the return type generics (null if none are specified)
-
isPlaceholder
public boolean isPlaceholder()
Description copied from interface:IMetaOperationReturns whether this operation is valid or whether it is a placeholder operation in case that the original operation cannot be resolved but the script shall remain executable.- Specified by:
isPlaceholderin interfaceIMetaOperation- Returns:
trueif this operation is a placeholder,falseelse
-
useGenericParameterAsReturn
public int useGenericParameterAsReturn()
Description copied from class:OperationDescriptorReturns whether a generc parameter of the operand shall be used as return type.- Specified by:
useGenericParameterAsReturnin classOperationDescriptor- Returns:
- the parameter to be used as index number, negative if none
-
useParameterAsReturn
public int useParameterAsReturn()
Description copied from class:OperationDescriptorReturns whether a parameter shall be used as return type.- Specified by:
useParameterAsReturnin classOperationDescriptor- Returns:
- the parameter to be used as index number, negative if none
-
storeArtifactsBeforeExecution
public boolean storeArtifactsBeforeExecution()
Description copied from class:OperationDescriptorReturns whether artifacts shall be stored before execution of this operation.- Specified by:
storeArtifactsBeforeExecutionin classOperationDescriptor- Returns:
trueif artifacts shall be stored,falseelse
-
requiresDynamicExpressionProcessing
public boolean requiresDynamicExpressionProcessing()
Description copied from class:OperationDescriptorIndicates whether this function requires dynamic expression processing and may cause problems with serialized models in standalone settings without xText.- Overrides:
requiresDynamicExpressionProcessingin classOperationDescriptor- Returns:
trueif this function requires dynamic exception processing,falseelse
-
trace
public boolean trace()
Description copied from class:OperationDescriptorReturns whether an execution of this descriptor shall be traced. Conversions shall not be traced by default as well as some operation types.- Overrides:
tracein classOperationDescriptor- Returns:
trueif it shall be traced,false
-
allowsAggregation
public boolean allowsAggregation()
Description copied from class:OperationDescriptorReturns whether this operation allows iterator aggregation.- Overrides:
allowsAggregationin classOperationDescriptor- Returns:
trueif allowed,false
-
isOclCompliant
public boolean isOclCompliant()
Description copied from class:OperationDescriptorReturns whether this operation is OCL compliant or flagged as not compliant.- Overrides:
isOclCompliantin classOperationDescriptor- Returns:
truefor compliant,falseelse
-
useAny
public boolean useAny()
Description copied from class:OperationDescriptorWhen resolving expression types, use any as return type if object is given and do not try to override this.- Overrides:
useAnyin classOperationDescriptor- Returns:
truefor use any,falseelse (default)
-
flatten
public boolean flatten()
Description copied from class:OperationDescriptorWhen resolving expression types, flatten the final return type.- Overrides:
flattenin classOperationDescriptor- Returns:
truefor use any,falseelse (default)
-
useOperandTypeAsParameter
public boolean useOperandTypeAsParameter()
Description copied from class:OperationDescriptorWhen resolving the return type, use the actual operand type as return generics.- Overrides:
useOperandTypeAsParameterin classOperationDescriptor- Returns:
truefor use return type,falseelse (default)
-
-