Class OperationDescriptor
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.OperationDescriptor
-
- All Implemented Interfaces:
IMetaOperation
- Direct Known Subclasses:
CompoundTypeDescriptor.ConstructorOperationDescriptor,CompoundTypeDescriptor.TypeOperationDescriptor,FakeOperationDescriptor,IvmlOperationDescriptor,ReflectionConstructorDescriptor,ReflectionOperationDescriptor
public abstract class OperationDescriptor extends java.lang.Object implements IMetaOperation
Represents an individual operation available to the VIL languages. 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 Modifier and Type Class Description static classOperationDescriptor.AliasTypeDeclares different types of alias.-
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 booleanacceptsImplicitParametersprivate booleanacceptsNamedParametersprivate OperationDescriptor.AliasTypealiasTypestatic java.lang.StringCONSTRUCTOR_NAMEThe name of constructor methods (static, same return type as declaring class, this name).private TypeDescriptor<?>declaringTypestatic java.util.List<TypeDescriptor<?>>EMPTY_PARAMETERDefines a constant unmodifiable list for empty parameters.private booleanisConstructorprivate booleanisConversionprivate java.lang.Stringnameprivate OperationTypeopTypeprivate java.util.List<TypeDescriptor<?>>parameterprivate TypeDescriptor<?>returnType
-
Constructor Summary
Constructors Modifier Constructor Description protectedOperationDescriptor(TypeDescriptor<?> declaringType, java.lang.String name, boolean isConstructor)Creates a new operation descriptor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanacceptsImplicitParameters()Returns whether the operation accepts implicit named parameters.booleanacceptsNamedParameters()Returns whether the operation accepts named parameters.booleanallowsAggregation()Returns whether this operation allows iterator aggregation.protected java.lang.StringcomposeExceptionMessage(java.lang.Throwable ex, java.lang.Object[] args)Composes an execution exception message from a given (Java) exception.protected voidconvertVariables(java.lang.Object[] params)Converts variables to objects, e.g., for reflection calls.booleanflatten()When resolving expression types, flatten the final return type.protected OperationDescriptor.AliasTypegetAliasType()Returns the alias type.TypeDescriptor<?>getDeclaringType()Returns the declaring type.java.lang.StringgetDeclaringTypeName()Returns the name of the declaring type.protected abstract java.lang.StringgetDeclaringTypeNameFallback()Returns the name of the declaring type in case thatgetDeclaringType()is null.abstract java.lang.StringgetJavaSignature()Returns the Java signature of the method (public for testing).java.lang.StringgetName()Returns the name of the method.OperationTypegetOperationType()Returns the operation / operator type.IMetaParameterDeclarationgetParameter(int index)Returns the parameter declaration of named parameters.IMetaParameterDeclarationgetParameter(java.lang.String name)Returns a named parameter declaration.intgetParameterCount()Returns the number of parameters.TypeDescriptor<?>getParameterType(int index)Returns the specified parameter type.intgetRequiredParameterCount()Returns the number of required parameters, i.e., non-default and non-named parameters.TypeDescriptor<?>getReturnType()Returns the return type of this operation.java.lang.StringgetSignature()Returns the signature of the method.protected java.lang.StringgetStoredName()Returns the name stored in this instance.private voidinitialize()Initializes the parameter and the return type if necessary (lazy, due to linked descriptor structures which may not have been completely initialized during the constructor execution).protected abstract voidinitializeParameters()Initializes the parameters (lazy init).protected abstract voidinitializeReturnType()Initializes the return type (lazy init).OperationDescriptor.AliasTypeisAlias()Returns the alias type.booleanisConstructor()Returns whether this operation represents a constructor.static booleanisConstructor(java.lang.reflect.Method method)Returns whether the given method is considered to be a VIL "constructor".booleanisConversion()Returns whether this operation descriptor is a conversion.booleanisGenericCollectionOperation()Returns whether this operation is a generic collection operation, i.e., whether the collection itself determines the return type (non-static, collection return, implicit parameter is generic collection).booleanisIteratingCollectionOperation()Return whether this operation returns the result of iterating over a collection.booleanisOclCompliant()Returns whether this operation is OCL compliant or flagged as not compliant.static booleanisOperation(java.lang.reflect.Method method)Returns whether the given method is considered to be a VIL operation.(package private) static booleanisOperationOrConstructor(java.lang.reflect.Method method)Returns whether the given method is a VIL operation or a VIL constructor.static booleanisSameSignature(java.lang.reflect.Method method1, java.lang.reflect.Method method2)Returns whether two Java methods have the same Java signature (public for testing).booleanisTypeSelect()Returns whether this operation is a type select operation (non-static, collection return, parameter is type).booleanrequiresDynamicExpressionProcessing()Indicates whether this function requires dynamic expression processing and may cause problems with serialized models in standalone settings without xText.protected voidsetCharacteristics(OperationType opType, OperationDescriptor.AliasType aliasType, boolean isConversion, java.lang.String name)Sets the characteristics of this operation descriptor.protected voidsetParameters(java.util.List<TypeDescriptor<?>> parameters, boolean acceptsNamedParameters, boolean acceptsImplicitParameters)Sets the parameters.protected voidsetReturnType(TypeDescriptor<?> returnType)Sets the return type.OperationDescriptorspecializeFor(TypeDescriptor<?> declaringType)Tries to specialize this operation descriptor for the given type, e.g., to consider the specific generic parameters of that type.abstract booleanstoreArtifactsBeforeExecution()Returns whether artifacts shall be stored before execution of this operation.protected voidthrowIncompatibleParameter(java.lang.Object[] args)Throws an exception for the case that parameter are incompatible.java.lang.StringtoString()Returns a textual representation of this descriptor (the Java signature).booleantrace()Returns whether an execution of this descriptor shall be traced.booleanuseAny()When resolving expression types, use any as return type if object is given and do not try to override this.abstract 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.abstract intuseParameterAsReturn()Returns whether a parameter shall be used as return type.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IMetaOperation
invoke, isCompatible, isFirstParameterOperand, isPlaceholder, isStatic
-
-
-
-
Field Detail
-
CONSTRUCTOR_NAME
public static final java.lang.String CONSTRUCTOR_NAME
The name of constructor methods (static, same return type as declaring class, this name). We do not rely on constructors, as constructor methods simplify reflection analysis.- See Also:
- Constant Field Values
-
EMPTY_PARAMETER
public static final java.util.List<TypeDescriptor<?>> EMPTY_PARAMETER
Defines a constant unmodifiable list for empty parameters.
-
name
private java.lang.String name
-
isConstructor
private boolean isConstructor
-
opType
private OperationType opType
-
declaringType
private TypeDescriptor<?> declaringType
-
returnType
private TypeDescriptor<?> returnType
-
aliasType
private OperationDescriptor.AliasType aliasType
-
parameter
private java.util.List<TypeDescriptor<?>> parameter
-
acceptsNamedParameters
private boolean acceptsNamedParameters
-
acceptsImplicitParameters
private boolean acceptsImplicitParameters
-
isConversion
private boolean isConversion
-
-
Constructor Detail
-
OperationDescriptor
protected OperationDescriptor(TypeDescriptor<?> declaringType, java.lang.String name, boolean isConstructor)
Creates a new operation descriptor. Overriding constructors shall call#setCharacteristics(OperationType, AliasType, boolean)in order to redefined the default values.- Parameters:
declaringType- the declaring typename- the alias name (may be null if the original name ofmethodshall be used)isConstructor- whether the operation is a constructor
-
-
Method Detail
-
setCharacteristics
protected void setCharacteristics(OperationType opType, OperationDescriptor.AliasType aliasType, boolean isConversion, java.lang.String name)
Sets the characteristics of this operation descriptor. To be called by overridden constructors.- Parameters:
opType- the operation typealiasType- the alias typeisConversion- whether the operation is a conversionname- the actual name of the operation
-
initialize
private void initialize()
Initializes the parameter and the return type if necessary (lazy, due to linked descriptor structures which may not have been completely initialized during the constructor execution).- See Also:
#initializeParameter(),initializeReturnType()
-
initializeParameters
protected abstract void initializeParameters()
Initializes the parameters (lazy init). Is called byinitialize(). Shall callsetParameters(List, boolean, boolean).
-
initializeReturnType
protected abstract void initializeReturnType()
Initializes the return type (lazy init). Is called byinitialize(). Shall callsetReturnType(TypeDescriptor).
-
setParameters
protected void setParameters(java.util.List<TypeDescriptor<?>> parameters, boolean acceptsNamedParameters, boolean acceptsImplicitParameters)
Sets the parameters. Shall only be called ininitializeParameters().- Parameters:
parameters- the parametersacceptsNamedParameters- whether this operation accepts named parametersacceptsImplicitParameters- whether this operation accepts implicit parameters
-
setReturnType
protected void setReturnType(TypeDescriptor<?> returnType)
Sets the return type. Shall only be called ininitializeReturnType().- Parameters:
returnType- the return type of this operation
-
acceptsNamedParameters
public boolean acceptsNamedParameters()
Returns whether the operation accepts named parameters.- Specified by:
acceptsNamedParametersin interfaceIMetaOperation- Returns:
trueif it accepts named parameters,falseelse
-
acceptsImplicitParameters
public boolean acceptsImplicitParameters()
Returns whether the operation accepts implicit named parameters.- Returns:
trueif it accepts implicit named parameters,falseelse
-
getName
public java.lang.String getName()
Returns the name of the method.- Specified by:
getNamein interfaceIMetaOperation- Returns:
- the name of the method
-
getStoredName
protected final java.lang.String getStoredName()
Returns the name stored in this instance.- Returns:
- the name stored in this instance
-
getOperationType
public OperationType getOperationType()
Returns the operation / operator type.- Returns:
- the operation / operator type
-
getAliasType
protected OperationDescriptor.AliasType getAliasType()
Returns the alias type.- Returns:
- the alias type
-
getDeclaringTypeName
public java.lang.String getDeclaringTypeName()
Returns the name of the declaring type. In case thatgetDeclaringType()is null, the result ofgetDeclaringTypeNameFallback()is returned.- Returns:
- the name of the declaring type
-
getDeclaringTypeNameFallback
protected abstract java.lang.String getDeclaringTypeNameFallback()
Returns the name of the declaring type in case thatgetDeclaringType()is null.- Returns:
- the name of the declaring type
-
getSignature
public java.lang.String getSignature()
Returns the signature of the method.- Specified by:
getSignaturein interfaceIMetaOperation- Returns:
- the signature of the method
-
getJavaSignature
public abstract java.lang.String getJavaSignature()
Returns the Java signature of the method (public for testing).- Specified by:
getJavaSignaturein interfaceIMetaOperation- Returns:
- the Java signature of the method
-
isConstructor
public boolean isConstructor()
Description copied from interface:IMetaOperationReturns whether this operation represents a constructor. Basically, for VIL a constructor is a public static method named "create" which returns an instance of the underlying type. Declared constructors are used for internal purposes.- Specified by:
isConstructorin interfaceIMetaOperation- Returns:
trueif this operation is a "constructor",falseelse
-
getDeclaringType
public TypeDescriptor<?> getDeclaringType()
Returns the declaring type.- Specified by:
getDeclaringTypein interfaceIMetaOperation- Returns:
- the declaring type (may be null in case of a wrapped external Java method)
-
isAlias
public OperationDescriptor.AliasType isAlias()
Returns the alias type.- Returns:
- the alias type
-
throwIncompatibleParameter
protected void throwIncompatibleParameter(java.lang.Object[] args) throws VilExceptionThrows an exception for the case that parameter are incompatible.- Parameters:
args- the actual arguments- Throws:
VilException- the created exception (happens in any case)
-
isSameSignature
public static boolean isSameSignature(java.lang.reflect.Method method1, java.lang.reflect.Method method2)Returns whether two Java methods have the same Java signature (public for testing). This method does not consider possible unnamed parameter rather than the underlying Java parameter.- Parameters:
method1- the first method to comparemethod2- the second method to compare- Returns:
trueif both have the same signature,falseelse
-
isConstructor
public static boolean isConstructor(java.lang.reflect.Method method)
Returns whether the given method is considered to be a VIL "constructor". A VIL constructor must comply to the VIL rules, it must be static, the name must be equal toCONSTRUCTOR_NAMEand the return type must be equal to the one of the declaring class (public for testing).- Parameters:
method- the method to be analyzed- Returns:
trueif it is considered as a constructor,falseelse
-
isOperation
public static boolean isOperation(java.lang.reflect.Method method)
Returns whether the given method is considered to be a VIL operation. A VIL operation must comply to the VIL rules and not be static (public for testing).- Parameters:
method- the method to be analyzed- Returns:
trueif it is considered as an operation,falseelse
-
isOperationOrConstructor
static boolean isOperationOrConstructor(java.lang.reflect.Method method)
Returns whether the given method is a VIL operation or a VIL constructor.- Parameters:
method- the method to be analyzed- Returns:
truein case of a VIL operation or VIL constructor- See Also:
isConstructor(Method),isOperation(Method)
-
getReturnType
public TypeDescriptor<?> getReturnType()
Returns the return type of this operation.- Specified by:
getReturnTypein interfaceIMetaOperation- Returns:
- the return type
-
getParameterCount
public int getParameterCount()
Description copied from interface:IMetaOperationReturns the number of parameters.- Specified by:
getParameterCountin interfaceIMetaOperation- Returns:
- the number of parameter
-
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- Returns:
- the number of required parameters
-
getParameterType
public TypeDescriptor<?> getParameterType(int index)
Returns the specified parameter type.- Specified by:
getParameterTypein interfaceIMetaOperation- Parameters:
index- the index of the parameter to return- Returns:
- the specified parameter type
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getParameterCount()
-
getParameter
public IMetaParameterDeclaration getParameter(java.lang.String name)
Description copied from interface:IMetaOperationReturns a named parameter declaration.- Specified by:
getParameterin interfaceIMetaOperation- Parameters:
name- the name of the parameter- Returns:
- the declaration or null if there is none
-
getParameter
public IMetaParameterDeclaration getParameter(int index)
Returns the parameter declaration of named parameters.- Parameters:
index- the index of the parameter to return- Returns:
- the named parameter or null for an usual parameter
-
toString
public java.lang.String toString()
Returns a textual representation of this descriptor (the Java signature).- Overrides:
toStringin classjava.lang.Object- Returns:
- the textual representation
-
isTypeSelect
public boolean isTypeSelect()
Returns whether this operation is a type select operation (non-static, collection return, parameter is type).- Returns:
trueif it is a type select operation,falseelse
-
isGenericCollectionOperation
public boolean isGenericCollectionOperation()
Returns whether this operation is a generic collection operation, i.e., whether the collection itself determines the return type (non-static, collection return, implicit parameter is generic collection).- Returns:
trueif it is a generic collection operation,falseelse
-
isIteratingCollectionOperation
public boolean isIteratingCollectionOperation()
Return whether this operation returns the result of iterating over a collection. Such an operation may be a quantor, a collector or a selector. Therefore, the operation must not be static, belong to a collection (first parameter type) and accept exactly oneExpressionEvaluator(typically the only additional parameter).- Returns:
trueof this operation is an iterating operation,falseelse
-
isConversion
public boolean isConversion()
Returns whether this operation descriptor is a conversion.- Returns:
trueif it is a conversion,falseelse
-
useGenericParameterAsReturn
public abstract int useGenericParameterAsReturn()
Returns whether a generc parameter of the operand shall be used as return type.- Returns:
- the parameter to be used as index number, negative if none
-
useParameterAsReturn
public abstract int useParameterAsReturn()
Returns whether a parameter shall be used as return type.- Returns:
- the parameter to be used as index number, negative if none
-
storeArtifactsBeforeExecution
public abstract boolean storeArtifactsBeforeExecution()
Returns whether artifacts shall be stored before execution of this operation.- Returns:
trueif artifacts shall be stored,falseelse
-
requiresDynamicExpressionProcessing
public boolean requiresDynamicExpressionProcessing()
Indicates whether this function requires dynamic expression processing and may cause problems with serialized models in standalone settings without xText.- Returns:
trueif this function requires dynamic exception processing,falseelse
-
trace
public boolean trace()
Returns whether an execution of this descriptor shall be traced. Conversions shall not be traced by default as well as some operation types.- Returns:
trueif it shall be traced,false
-
specializeFor
public OperationDescriptor specializeFor(TypeDescriptor<?> declaringType)
Tries to specialize this operation descriptor for the given type, e.g., to consider the specific generic parameters of that type.- Parameters:
declaringType- the declaring type to specialize for- Returns:
- either this if no specialization is needed or a specializing instance
-
allowsAggregation
public boolean allowsAggregation()
Returns whether this operation allows iterator aggregation.- Returns:
trueif allowed,false
-
composeExceptionMessage
protected java.lang.String composeExceptionMessage(java.lang.Throwable ex, java.lang.Object[] args)Composes an execution exception message from a given (Java) exception.- Parameters:
ex- the original exceptionargs- the call arguments- Returns:
- the execution message
-
convertVariables
protected void convertVariables(java.lang.Object[] params)
Converts variables to objects, e.g., for reflection calls.- Parameters:
params- the parameters (may be changed as a side effect)
-
isOclCompliant
public boolean isOclCompliant()
Returns whether this operation is OCL compliant or flagged as not compliant.- Returns:
truefor compliant,falseelse
-
useAny
public boolean useAny()
When resolving expression types, use any as return type if object is given and do not try to override this.- Returns:
truefor use any,falseelse (default)
-
flatten
public boolean flatten()
When resolving expression types, flatten the final return type.- Returns:
truefor use any,falseelse (default)
-
useOperandTypeAsParameter
public boolean useOperandTypeAsParameter()
When resolving the return type, use the actual operand type as return generics.- Returns:
truefor use return type,falseelse (default)
-
-