Class Template
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.common.AbstractResolvableModel<VariableDeclaration,Template>
-
- net.ssehub.easy.instantiation.core.model.templateModel.Template
-
- All Implemented Interfaces:
IModel,IModelData,IModelListener<Project>,ICompoundReceiver,ILanguageElement,IParameterizable<VariableDeclaration>,IResolvableModel<VariableDeclaration,Template>,ITypedefReceiver,IVariableDeclarationReceiver<VariableDeclaration>,ITemplateLangElement,IMetaType,ITypedModel
public class Template extends AbstractResolvableModel<VariableDeclaration,Template> implements ITemplateLangElement, IResolvableModel<VariableDeclaration,Template>, IVariableDeclarationReceiver<VariableDeclaration>
Represents a VIL template.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<VariableDeclaration>declarationsprivate java.util.List<Def>defsprivate ModelImport<Template>extensionprivate FormattingConfigurationformattingConfigurationprivate IndentationConfigurationindentationConfigurationprivate JavaExtension[]javaExtensionsprivate java.lang.Stringnameprivate java.util.Map<java.lang.String,VariableDeclaration>namedParamsprivate VariableDeclaration[]paramprivate Versionversion
-
Constructor Summary
Constructors Constructor Description Template()Constructor for serialization.Template(java.lang.String name, ModelImport<Template> extension, TemplateDescriptor descriptor, TypeRegistry registry)Creates a VIL template instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IVisitor visitor)Accepts the visitor for visiting.voidaddDef(Def def)Adds a sub-template.IMetaOperationaddPlaceholderOperation(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.voidaddVariableDeclaration(VariableDeclaration var)Adds a variable declaration.protected voidadjustParents()Adjusts the parents.booleancheckConversion(IMetaType param, IMetaOperation conversion)Checks a conversion from this type toparamvia the givenconversion.booleanenableDynamicDispatch()Returns whether this type enables dynamic dispatch of operations.IMetaOperationfindConversion(IMetaType sourceType, IMetaType targetType)Returns the conversion operation from this type to target type (if there is any).IMetaTypegetBaseType()Returns the base type (in case of IVML derived types).java.util.List<IMetaOperation>getCandidates(java.lang.String name, int unnamedArgsCount)Returns operation candidates matching the given name and number of unnamed (required) arguments.DefgetDef(int index)Get the sub-templates of this template at the specified index.intgetDefCount()Get the number of sub-templates of this template.IMetaTypegetExtensionType(int index)Returns the specified extension type.intgetExtensionTypesCount()Returns the number of extension types declared in/by this model.IMetaFieldgetField(int index)Returns the specified field.intgetFieldCount()Returns the number of fields provided by this type.FormattingConfigurationgetFormattingConfiguration()Returns the formatting configuration of this script.intgetGenericParameterCount()Returns the number of generic type parameters.TypeDescriptor<?>getGenericParameterType(int index)Returns the specified generic parameter type.IndentationConfigurationgetIndentationConfiguration()Returns the indentation configuration for this model.JavaExtensiongetJavaExtension(int index)Get the extension of this template at the specified index.intgetJavaExtensionCount()Get the number of extensions of this template.java.lang.StringgetName()Returns the name of the model element.IMetaOperationgetOperation(int index)Returns the specified operation.intgetOperationsCount()Returns the number of operations provided by this type.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.TemplategetParent()Returns the parent element.java.lang.StringgetQualifiedName()Returns the qualified name of this type.intgetRequiredParameterCount()Returns the number of required parameters, i.e., non-default and non-named parameters.IRestrictionEvaluationContextgetRestrictionEvaluationContext()Returns the context for evaluating import / conflict restrictions.ModelImport<Template>getSuper()Returns the reference to the super model (if it exists).IMetaTypegetSuperType()Returns the type this type is refined from.VariableDeclarationgetVariableDeclaration(int index)Get the variable declaration of this template at the specified index.intgetVariableDeclarationCount()Get the number of variable declaration of this template.VersiongetVersion()Returns the version of this model.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.booleanisBasicType()Returns whether this instance represents a basic type.booleanisImplicit(VariableDeclaration decl)Returns whether a variable declaration is implicit (predefined).booleanisInternal()Returns whether this type is internal and shall not be visible to the user.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.protected voidreload()Causes a reload of this model.voidremoveDef(Def def)Adds a sub-template.voidsetVersion(Version version)Changes the version of this model.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.common.AbstractResolvableModel
addCompound, addImport, addRuntimeImport, addTypedef, createImports, dispose, getAdvice, getAdviceCount, getCompound, getCompound, getCompoundCount, getImport, getImports, getImportsCount, getIvmlElement, getTypedef, getTypedef, getTypedefCount, getTypeRegistry, isDirty, notifyReplaced
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.basics.modelManagement.IModel
dispose, getImport, getImportsCount
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.common.IResolvableModel
addRuntimeImport, getCompound, getCompound, getCompoundCount, getIvmlElement, getTypedef, getTypedef, getTypedefCount, getTypeRegistry
-
-
-
-
Field Detail
-
version
private Version version
-
name
private java.lang.String name
-
extension
private ModelImport<Template> extension
-
javaExtensions
private JavaExtension[] javaExtensions
-
declarations
private java.util.List<VariableDeclaration> declarations
-
param
private VariableDeclaration[] param
-
namedParams
private java.util.Map<java.lang.String,VariableDeclaration> namedParams
-
defs
private java.util.List<Def> defs
-
indentationConfiguration
private IndentationConfiguration indentationConfiguration
-
formattingConfiguration
private FormattingConfiguration formattingConfiguration
-
-
Constructor Detail
-
Template
Template()
Constructor for serialization.
-
Template
public Template(java.lang.String name, ModelImport<Template> extension, TemplateDescriptor descriptor, TypeRegistry registry) throws VilExceptionCreates a VIL template instance.- Parameters:
name- the nameextension- the extended template (may be null)descriptor- information to create the template fromregistry- the registry responsible for this template- Throws:
VilException- in case of erroneous input
-
-
Method Detail
-
adjustParents
protected void adjustParents()
Adjusts the parents.
-
getJavaExtensionCount
public int getJavaExtensionCount()
Get the number of extensions of this template.- Returns:
- The number of extensions of this template.
-
getJavaExtension
public JavaExtension getJavaExtension(int index)
Get the extension of this template at the specified index.- Parameters:
index- The 0-based index of the extension to be returned.- Returns:
- The extension at the given index.
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getJavaExtensionCount()
-
isImplicit
public boolean isImplicit(VariableDeclaration decl)
Description copied from interface:IResolvableModelReturns whether a variable declaration is implicit (predefined).- Specified by:
isImplicitin interfaceIResolvableModel<VariableDeclaration,Template>- Parameters:
decl- the declaration to be tested- Returns:
trueif it is implicit,falseelse
-
getName
public java.lang.String getName()
Description copied from interface:IModelReturns the name of the model element.
-
getQualifiedName
public java.lang.String getQualifiedName()
Description copied from interface:IMetaTypeReturns the qualified name of this type.- Specified by:
getQualifiedNamein interfaceIMetaType- Returns:
- the qualified name
-
addVariableDeclaration
public void addVariableDeclaration(VariableDeclaration var)
Description copied from interface:IVariableDeclarationReceiverAdds a variable declaration.- Specified by:
addVariableDeclarationin interfaceIVariableDeclarationReceiver<VariableDeclaration>- Parameters:
var- the variable declaration
-
getVariableDeclarationCount
public int getVariableDeclarationCount()
Get the number of variable declaration of this template.- Specified by:
getVariableDeclarationCountin interfaceIResolvableModel<VariableDeclaration,Template>- Returns:
- The number of variable declaration of this template.
-
getVariableDeclaration
public VariableDeclaration getVariableDeclaration(int index)
Get the variable declaration of this template at the specified index.- Specified by:
getVariableDeclarationin interfaceIResolvableModel<VariableDeclaration,Template>- Parameters:
index- The 0-based index of the variable declaration to be returned.- Returns:
- The variable declaration at the given index.
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getVariableDeclarationCount()
-
getDefCount
public int getDefCount()
Get the number of sub-templates of this template.- Returns:
- The number of sub-templates of this template.
-
addDef
public void addDef(Def def)
Adds a sub-template.- Parameters:
def- the sub-template to be added
-
removeDef
public void removeDef(Def def)
Adds a sub-template. (not nice)- Parameters:
def- the sub-template to be removed
-
getDef
public Def getDef(int index)
Get the sub-templates of this template at the specified index.- Parameters:
index- The 0-based index of the defs to be returned.- Returns:
- The defs at the given index.
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getDefCount()
-
getParameterCount
public int getParameterCount()
Description copied from interface:IParameterizableGet the number of parameters of this rule.- 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 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 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- 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)
-
setVersion
public void setVersion(Version version)
Description copied from interface:IModelChanges the version of this model.- Specified by:
setVersionin interfaceIModel- Parameters:
version- Version to set
-
getVersion
public Version getVersion()
Description copied from interface:IModelReturns the version of this model.- Specified by:
getVersionin interfaceIModel- Specified by:
getVersionin interfaceIModelData- Returns:
- the version or
nullif no version is specified for this model.
-
getSuper
public ModelImport<Template> getSuper()
Description copied from interface:IModelReturns the reference to the super model (if it exists).
-
getOperationsCount
public int getOperationsCount()
Description copied from interface:IMetaTypeReturns the number of operations provided by this type.- Specified by:
getOperationsCountin interfaceIMetaType- Returns:
- the number of operations
-
getOperation
public IMetaOperation getOperation(int index)
Description copied from interface:IMetaTypeReturns the specified operation.- Specified by:
getOperationin interfaceIMetaType- Parameters:
index- the 0-based index of the operation to be returned- Returns:
- the specified operation
-
isAssignableFrom
public boolean isAssignableFrom(IMetaType type)
Description copied from interface:IMetaTypeReturns whether this type is the same or a super class oftype.- Specified by:
isAssignableFromin interfaceIMetaType- Parameters:
type- the descriptor to be tested- Returns:
trueif both types are assignment compatible,falseelse
-
findConversion
public IMetaOperation findConversion(IMetaType sourceType, IMetaType targetType)
Description copied from interface:IMetaTypeReturns the conversion operation from this type to target type (if there is any).- Specified by:
findConversionin interfaceIMetaType- Parameters:
sourceType- the source type to convert fromtargetType- the target type to convert to- Returns:
- the conversion operation as defined in the underlying implementation class, null if no matching can be found
-
getParent
public Template getParent()
Description copied from interface:ILanguageElementReturns the parent element.- Specified by:
getParentin interfaceILanguageElement- Specified by:
getParentin interfaceIResolvableModel<VariableDeclaration,Template>- Returns:
- the parent element (may be null if unknown)
-
getExtensionTypesCount
public int getExtensionTypesCount()
Description copied from interface:IResolvableModelReturns the number of extension types declared in/by this model.- Specified by:
getExtensionTypesCountin interfaceIResolvableModel<VariableDeclaration,Template>- Returns:
- the number of extension types
-
getExtensionType
public IMetaType getExtensionType(int index)
Description copied from interface:IResolvableModelReturns the specified extension type.- Specified by:
getExtensionTypein interfaceIResolvableModel<VariableDeclaration,Template>- Parameters:
index- the 0-based index of the extension type to be returned- Returns:
- the specified extension type
-
getIndentationConfiguration
public IndentationConfiguration getIndentationConfiguration()
Description copied from interface:IModelReturns the indentation configuration for this model. The indentation configuration is considered to be immutable.- Specified by:
getIndentationConfigurationin interfaceIModel- Returns:
- the indentation configuration (disabled if null)
-
getFormattingConfiguration
public FormattingConfiguration getFormattingConfiguration()
Returns the formatting configuration of this script.- Returns:
- the formatting configuration (may be null of there is none)
-
isBasicType
public boolean isBasicType()
Description copied from interface:IMetaTypeReturns whether this instance represents a basic type.- Specified by:
isBasicTypein interfaceIMetaType- Returns:
trueif this instance represents a basic type,falseelse
-
enableDynamicDispatch
public boolean enableDynamicDispatch()
Description copied from interface:IMetaTypeReturns whether this type enables dynamic dispatch of operations.- Specified by:
enableDynamicDispatchin interfaceIMetaType- Returns:
trueif it enables dynamic dispatch,falseelse
-
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.- Specified by:
isPlaceholderin interfaceIMetaType- Returns:
trueif this type is a placeholder,falseelse
-
addPlaceholderOperation
public IMetaOperation addPlaceholderOperation(java.lang.String name, int parameterCount, boolean acceptsNamedParameters)
Description copied from interface:IMetaTypeAdds a placeholder operation, i.e., in case that the original operation cannot be resolved but the script shall remain executable.- Specified by:
addPlaceholderOperationin interfaceIMetaType- Parameters:
name- the name of the operationparameterCount- the number of parameters of the operationacceptsNamedParameters- whether the operation shall accept 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.- Specified by:
isActualTypeOfin interfaceIMetaType- Parameters:
type- the type to be checked- Returns:
trueif this type can act as an actual type oftype,falseelse- See Also:
IActualTypeProvider
-
reload
protected void reload()
Description copied from class:AbstractResolvableModelCauses a reload of this model.- Specified by:
reloadin classAbstractResolvableModel<VariableDeclaration,Template>
-
getRestrictionEvaluationContext
public IRestrictionEvaluationContext getRestrictionEvaluationContext()
Description copied from interface:IModelReturns the context for evaluating import / conflict restrictions. This context shall only contain the information that is necessary to evaluate restriction information.- Specified by:
getRestrictionEvaluationContextin interfaceIModel- Returns:
- the evaluation context
-
getBaseType
public IMetaType getBaseType()
Description copied from interface:IMetaTypeReturns the base type (in case of IVML derived types).- Specified by:
getBaseTypein interfaceIMetaType- Returns:
- the base type or null
-
getFieldCount
public int getFieldCount()
Description copied from interface:IMetaTypeReturns the number of fields provided by this type.- Specified by:
getFieldCountin interfaceIMetaType- Returns:
- the number of fields
-
getField
public IMetaField getField(int index)
Description copied from interface:IMetaTypeReturns the specified field.
-
isInternal
public boolean isInternal()
Description copied from interface:IMetaTypeReturns whether this type is internal and shall not be visible to the user.- Specified by:
isInternalin interfaceIMetaType- Returns:
trueif this type is internal,falseelse
-
getSuperType
public IMetaType getSuperType()
Description copied from interface:IMetaTypeReturns the type this type is refined from.- Specified by:
getSuperTypein interfaceIMetaType- Returns:
- the super type or null if there is none
-
getGenericParameterCount
public int getGenericParameterCount()
Description copied from interface:IMetaTypeReturns the number of generic type parameters.- Specified by:
getGenericParameterCountin interfaceIMetaType- Returns:
- the number of generic type parameters
-
getGenericParameterType
public TypeDescriptor<?> getGenericParameterType(int index)
Description copied from interface:IMetaTypeReturns the specified generic parameter type.- Specified by:
getGenericParameterTypein interfaceIMetaType- Parameters:
index- the index of the parameter type to return- Returns:
- the specified parameter type
-
checkConversion
public boolean checkConversion(IMetaType param, IMetaOperation conversion)
Description copied from interface:IMetaTypeChecks a conversion from this type toparamvia the givenconversion.- Specified by:
checkConversionin interfaceIMetaType- Parameters:
param- the original parameter valueconversion- the conversion function- Returns:
trueif ok,falseelse
-
getCandidates
public java.util.List<IMetaOperation> getCandidates(java.lang.String name, int unnamedArgsCount)
Description copied from interface:IMetaTypeReturns operation candidates matching the given name and number of unnamed (required) arguments.- Specified by:
getCandidatesin interfaceIMetaType- Parameters:
name- the name of the operationunnamedArgsCount- the number of unnamed arguments- Returns:
- the operation candidates
-
-