Class Def
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.templateModel.AbstractTemplateElement
-
- net.ssehub.easy.instantiation.core.model.templateModel.TemplateBlock
-
- net.ssehub.easy.instantiation.core.model.templateModel.Def
-
- All Implemented Interfaces:
ILanguageElement,IParameterizable<VariableDeclaration>,IResolvableOperation<VariableDeclaration>,ITemplateElement,ITemplateLangElement,IMetaOperation,IStringValueProvider
public class Def extends TemplateBlock implements ITemplateLangElement, IResolvableOperation<VariableDeclaration>, IStringValueProvider
Implements a template language subtemplate ('def').- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IMetaOperation
IMetaOperation.CompatibilityResult
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description private booleanisProtectedprivate java.lang.Stringnameprivate java.util.Map<java.lang.String,VariableDeclaration>namedParamprivate VariableDeclaration[]paramprivate Templateparentprivate TypeDescriptor<?>specifiedType
-
Constructor Summary
Constructors Constructor Description Def()Constructor for serialization.Def(java.lang.String name, VariableDeclaration[] param, ITemplateElement[] body, TypeDescriptor<?> specifiedType, Template parent)Creates a new sub-template ('def').
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IVisitor visitor)Accepts the visitor for visiting.booleanacceptsNamedParameters()Returns whether the operation accepts named parameters.private booleancheckEmptyContainerIntializerCompliance(TypeDescriptor<?> result, TypeDescriptor<?> specifiedType)Checks the given inferredresulttype and the specified result typespecifiedTypefor type compliance against direct return of an empty container initializer.IMetaTypegetDeclaringType()Returns the declaring type.java.lang.StringgetJavaSignature()Returns the java-like signature of this operation.java.lang.StringgetName()Returns the name of this template.VariableDeclarationgetParameter(int index)Get the parameter of this rule at the specified index.VariableDeclarationgetParameter(java.lang.String name)Returns a named parameter declaration.intgetParameterCount()Get the number of parameters of this rule.IMetaTypegetParameterType(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 (in terms of VIL types where possible).TypeDescriptor<?>getSpecifiedType()The specified type.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.TypeDescriptor<?>inferType()Infers the type of this language element.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.booleanisConstructor()Returns whether this operation represents a constructor.booleanisFirstParameterOperand()Returns whether the first parameter is the operand.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.booleanisProtected()Returns whether this Def is protected in visibility.booleanisStatic()Returns whether this operation is static.protected voidsetParent(ILanguageElement parent)Changes the parent.voidsetProtected(boolean isProtected)Changes whether this Def is protected in visibility.java.lang.StringtoString()-
Methods inherited from class net.ssehub.easy.instantiation.core.model.templateModel.TemplateBlock
endsWithContentStatement, getBodyElement, getBodyElementCount, getTypeDefiningElement, isBlock, setBody
-
Methods inherited from class net.ssehub.easy.instantiation.core.model.templateModel.AbstractTemplateElement
getParent
-
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.common.ILanguageElement
getParent
-
-
-
-
Field Detail
-
parent
private Template parent
-
name
private java.lang.String name
-
param
private VariableDeclaration[] param
-
namedParam
private java.util.Map<java.lang.String,VariableDeclaration> namedParam
-
specifiedType
private TypeDescriptor<?> specifiedType
-
isProtected
private boolean isProtected
-
-
Constructor Detail
-
Def
Def()
Constructor for serialization.
-
Def
public Def(java.lang.String name, VariableDeclaration[] param, ITemplateElement[] body, TypeDescriptor<?> specifiedType, Template parent)Creates a new sub-template ('def').- Parameters:
name- the name of the templateparam- the parameter of the template (may be null)body- the body elements (may be null)parent- the declaring templatespecifiedType- the specified type (may be null if none is given)
-
-
Method Detail
-
isProtected
public boolean isProtected()
Returns whether this Def is protected in visibility.- Returns:
trueif it is protected,falseelse
-
setProtected
public void setProtected(boolean isProtected)
Changes whether this Def is protected in visibility.- Parameters:
isProtected-trueif it is protected,falseelse
-
getName
public java.lang.String getName()
Returns the name of this template.- Specified by:
getNamein interfaceIMetaOperation- Returns:
- the name
-
getSpecifiedType
public TypeDescriptor<?> getSpecifiedType()
The specified type. For the actual type seeinferType().- Returns:
- the specified type, may be null if none is given
-
getParameterCount
public int getParameterCount()
Description copied from interface:IParameterizableGet the number of parameters of this rule.- Specified by:
getParameterCountin interfaceIMetaOperation- Specified by:
getParameterCountin interfaceIParameterizable<VariableDeclaration>- Returns:
- The number of parameters of this rule.
-
getParameter
public VariableDeclaration getParameter(int index)
Description copied from interface:IParameterizableGet the parameter of this rule at the specified index.- Specified by:
getParameterin interfaceIParameterizable<VariableDeclaration>- Parameters:
index- The 0-based index of the rule parameter to be returned.- Returns:
- The rule parameter at the given index.
-
getRequiredParameterCount
public int getRequiredParameterCount()
Description copied from interface:IParameterizableReturns the number of required parameters, i.e., non-default and non-named parameters.- Specified by:
getRequiredParameterCountin interfaceIMetaOperation- Specified by:
getRequiredParameterCountin interfaceIParameterizable<VariableDeclaration>- Returns:
- the number of required parameters
-
getParameter
public VariableDeclaration getParameter(java.lang.String name)
Description copied from interface:IParameterizableReturns a named parameter declaration.- Specified by:
getParameterin interfaceIMetaOperation- Specified by:
getParameterin interfaceIParameterizable<VariableDeclaration>- Parameters:
name- the name of the parameter- Returns:
- the declaration or null if there is none
-
accept
public java.lang.Object accept(IVisitor visitor) throws VilException
Description copied from interface:ITemplateLangElementAccepts the visitor for visiting.- Specified by:
acceptin interfaceITemplateLangElement- Overrides:
acceptin classTemplateBlock- Parameters:
visitor- the visitor to be used- Returns:
- the result of visiting this instance (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
getParameterType
public IMetaType getParameterType(int index)
Description copied from interface:IMetaOperationReturns the specified parameter type.- Specified by:
getParameterTypein interfaceIMetaOperation- Parameters:
index- the index of the parameter to return- Returns:
- the specified parameter type
-
getJavaSignature
public java.lang.String getJavaSignature()
Description copied from interface:IMetaOperationReturns the java-like signature of this operation.- Specified by:
getJavaSignaturein interfaceIMetaOperation- Returns:
- the java-like Java signature of this operation
-
getSignature
public java.lang.String getSignature()
Description copied from interface:IMetaOperationReturns the signature of the method (in terms of VIL types where possible).- Specified by:
getSignaturein interfaceIMetaOperation- Returns:
- the signature of the method
-
getReturnType
public TypeDescriptor<?> getReturnType()
Description copied from interface:IResolvableOperationReturns the return type of this operation.- Specified by:
getReturnTypein interfaceIMetaOperation- Specified by:
getReturnTypein interfaceIResolvableOperation<VariableDeclaration>- Returns:
- the return type
-
acceptsNamedParameters
public boolean acceptsNamedParameters()
Description copied from interface:IMetaOperationReturns whether the operation accepts named parameters.- Specified by:
acceptsNamedParametersin interfaceIMetaOperation- Returns:
trueif it accepts named parameters,falseelse
-
inferType
public TypeDescriptor<?> inferType() throws VilException
Description copied from interface:ITemplateElementInfers the type of this language element.- Specified by:
inferTypein interfaceITemplateElement- Overrides:
inferTypein classTemplateBlock- Returns:
- the type of this language element
- Throws:
VilException- in case that type errors occur
-
checkEmptyContainerIntializerCompliance
private boolean checkEmptyContainerIntializerCompliance(TypeDescriptor<?> result, TypeDescriptor<?> specifiedType)
Checks the given inferredresulttype and the specified result typespecifiedTypefor type compliance against direct return of an empty container initializer.- Parameters:
result- the inferred result typespecifiedType- the specified result type- Returns:
truefor compliance,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
-
isStatic
public boolean isStatic()
Description copied from interface:IMetaOperationReturns whether this operation is static.- Specified by:
isStaticin interfaceIMetaOperation- Returns:
trueif it is static,falseelse
-
getDeclaringType
public IMetaType getDeclaringType()
Description copied from interface:IMetaOperationReturns the declaring type.- Specified by:
getDeclaringTypein interfaceIMetaOperation- Returns:
- the declaring type (may be null in case of a wrapped external Java method)
-
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
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setParent
protected void setParent(ILanguageElement parent)
Description copied from class:AbstractTemplateElementChanges the parent. Please override if children must be adjusted according. Shall be called only once per instance, but there is no limitation.- Overrides:
setParentin classTemplateBlock- Parameters:
parent- the parent
-
isCompatible
public IMetaOperation.CompatibilityResult isCompatible(java.lang.Class<?> retType, java.lang.Object... params)
Description copied from interface:IMetaOperationReturns 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
-
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...)
-
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
-
-