Package net.ssehub.easy.varModel.model
Class Project
- java.lang.Object
-
- net.ssehub.easy.varModel.model.ModelElement
-
- net.ssehub.easy.varModel.model.Project
-
- All Implemented Interfaces:
IModel,IModelData,ICustomOperationAccessor,IResolutionScope,IAttributableElement,IAttributeAccess,IConstraintHolder,IFreezable,IModelElement
public class Project extends ModelElement implements IModel, IAttributableElement, IResolutionScope, ICustomOperationAccessor, IFreezable, IConstraintHolder
This class holds the project imports, the containable model-, and attributable elements. Project is the top-level element of each VarModel. UsegetVariable()for attributing a project.- Author:
- Marcel Lueder, Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private StructuredCommentcommentComments directly attached to this project (lazy initialization).private java.util.List<ProjectImport>importsprivate intinterfaceCountprivate java.util.List<ContainableModelElement>modelElementsprivate java.util.Map<java.lang.String,ContainableModelElement>namesprivate Projectparentprivate ProjectTypetypeprivate DecisionVariableDeclarationvariableStores the (pseudo) variable for this project.private Versionversion
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(IModelVisitor visitor)Accept method for the visitor.booleanadd(ContainableModelElement element)Method to add an object to the modelElement list of the project.booleanadd(OperationDefinition definition)Method to add an operation definition to the modelElement list of the project.voidaddConstraint(Constraint constraint)Adds a constraint.booleanaddImport(ProjectImport pimport)Adds an import to this project.booleanattribute(Attribute attribute)Attributes this element.voidclear()Removes the content of the project.booleancontainsByName(java.lang.String name)Returns whether this project contains an element and its name.voiddispose()Shall be called at the end of the lifetime of the model in order to clean up references such as listeners.AttributegetAttribute(int index)Returns a specific attribute.AttributegetAttribute(java.lang.String name)Returns a specific (declared) attribute.intgetAttributesCount()Returns the number of (declared) attributes.CommentgetCommentBefore(IModelElement element, boolean ensureStructured)Returns the comment before the specified model element.StructuredCommentgetComments()Returns the structured comment for this project.ContainableModelElementgetElement(int index)Returns a contained model element specified byindex.ContainableModelElementgetElement(java.lang.String name)Returns a contained model element specified by itsname.intgetElementCount()Returns the number of contained elements.ProjectImportgetImport(int index)Returns the project import specified byindex.intgetImportsCount()Returns the number of imports.IndentationConfigurationgetIndentationConfiguration()Returns the indentation configuration for this model.java.lang.StringgetNameSpace()Returns the namespace introduced by this model element.CommentgetNestedComment(java.lang.Object element)Returns a comment for anelementfrom within thegetComments().CustomOperationgetOperation(int index)Returns the operation specified byindex.intgetOperationCount()Returns the number of operations.ProjectgetParent()Returns the parent of this project.IRestrictionEvaluationContextgetRestrictionEvaluationContext()Returns the context for evaluating import / conflict restrictions.ModelImport<Project>getSuper()Returns the reference to the super model (if it exists).IDatatypegetType()Returns the (pseudo) datatype of this project.DecisionVariableDeclarationgetVariable()Returns the (pseudo) variable for this project.VersiongetVersion()Returns the version of this project.booleanhasInterfaces()Returns whether this project has interfaces.booleanisInterface()Returns whether this scope is an interfaces.booleanpropagateAttribute(Attribute attribute)Propagates an attribute application from the parent to this element or contained elements.booleanremove(OperationDefinition definition)Removes the given operation definition.booleanremoveElement(ContainableModelElement element)Removes the specified element from from this project.booleanremoveElements(java.util.List<ContainableModelElement> elementsToRemove)Removes all specified elements from this project.booleanremoveImport(ProjectImport pimport)Removes an import from this project.voidsetComments(StructuredComment comment)Sets a structured comment object for this project.(package private) voidsetParent(Project parent)Changes the parent of this project (intended to be used internally by the copy mechanism).voidsetVersion(Version version)Changes the version of this project.voidsortContainedElements(java.util.Comparator<ContainableModelElement> comp)Sorts the contained elements according to the specified comparator.-
Methods inherited from class net.ssehub.easy.varModel.model.ModelElement
findAttribute, getComment, getName, getQualifiedName, getUniqueName, isTransparent, setComment, setName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.varModel.model.IAttributableElement
getName, getQualifiedName
-
Methods inherited from interface net.ssehub.easy.varModel.model.IFreezable
getName
-
Methods inherited from interface net.ssehub.easy.varModel.model.IModelElement
getComment, getName, getQualifiedName, getUniqueName, isTransparent, setComment
-
Methods inherited from interface net.ssehub.easy.varModel.model.datatypes.IResolutionScope
getName
-
-
-
-
Field Detail
-
modelElements
private java.util.List<ContainableModelElement> modelElements
-
version
private Version version
-
imports
private java.util.List<ProjectImport> imports
-
type
private ProjectType type
-
interfaceCount
private int interfaceCount
-
parent
private Project parent
-
names
private java.util.Map<java.lang.String,ContainableModelElement> names
-
variable
private DecisionVariableDeclaration variable
Stores the (pseudo) variable for this project. We need this variable to attribute a project.
-
comment
private StructuredComment comment
Comments directly attached to this project (lazy initialization).
-
-
Method Detail
-
addImport
public boolean addImport(ProjectImport pimport)
Adds an import to this project. Conflicts are added always, imports are checked for duplicates.- Parameters:
pimport- The import- Returns:
trueif the addition was successful,falseelse due to duplicated names
-
removeImport
public boolean removeImport(ProjectImport pimport)
Removes an import from this project.- Parameters:
pimport- the import to be removed- Returns:
trueif the removal was successful,falseelse due to duplicated names
-
removeElements
public boolean removeElements(java.util.List<ContainableModelElement> elementsToRemove)
Removes all specified elements from this project.- Parameters:
elementsToRemove- elements which should be removed. See Configuration.toProject(false).- Returns:
- true if this project changed as a result of the call
- See Also:
removeElement(ContainableModelElement)
-
removeElement
public boolean removeElement(ContainableModelElement element)
Removes the specified element from from this project.- Parameters:
element- the element that should be removed. See Configuration.toProject(false).- Returns:
- true if this project changed as a result of the call
-
clear
public void clear()
Removes the content of the project. Removes:- All model elements
- All Internal constraints
- All Imports
-
getImportsCount
public int getImportsCount()
Returns the number of imports.- Specified by:
getImportsCountin interfaceICustomOperationAccessor- Specified by:
getImportsCountin interfaceIModel- Specified by:
getImportsCountin interfaceIResolutionScope- Returns:
- the number of imports
-
getImport
public ProjectImport getImport(int index)
Returns the project import specified byindex.- Specified by:
getImportin interfaceICustomOperationAccessor- Specified by:
getImportin interfaceIModel- Specified by:
getImportin interfaceIResolutionScope- Parameters:
index- a 0-based index specifying the import to be returned- Returns:
- the project import
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getImportsCount()
-
setVersion
public void setVersion(Version version)
Changes the version of this project.- Specified by:
setVersionin interfaceIModel- Parameters:
version- Version to set
-
getVersion
public Version getVersion()
Returns the version of this project.- Specified by:
getVersionin interfaceIModel- Specified by:
getVersionin interfaceIModelData- Returns:
- the version or
nullif no version is specified for this project.
-
getElement
public ContainableModelElement getElement(int index)
Returns a contained model element specified byindex.- Specified by:
getElementin interfaceIResolutionScope- Parameters:
index- a 0-based index specifying the operation to be returned- Returns:
- the contained element
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getElementCount()
-
getCommentBefore
public Comment getCommentBefore(IModelElement element, boolean ensureStructured)
Returns the comment before the specified model element.- Parameters:
element- the element to search forensureStructured- whether a default structured comment shall be inserted beforeelementif no comment was found- Returns:
- the comment assigned to
elementor null if none was found orensureStructuredis false, respectively
-
getElementCount
public int getElementCount()
Returns the number of contained elements.- Specified by:
getElementCountin interfaceIResolutionScope- Returns:
- the number of contained elements
-
containsByName
public boolean containsByName(java.lang.String name)
Returns whether this project contains an element and its name.- Parameters:
name- the name to search for- Returns:
trueif this project contains the specified element,falseelse
-
getElement
public ContainableModelElement getElement(java.lang.String name)
Description copied from interface:IResolutionScopeReturns a contained model element specified by itsname.- Specified by:
getElementin interfaceIResolutionScope- Parameters:
name- the qualified or unqualified name to search for- Returns:
- the related element or null if no such element is known
-
add
public boolean add(ContainableModelElement element)
Method to add an object to the modelElement list of the project. Only named elements are considered for checking duplicates!- Parameters:
element- which should be added- Returns:
trueif the addition was successful,falseelse due to duplicated names
-
add
public boolean add(OperationDefinition definition)
Method to add an operation definition to the modelElement list of the project.- Parameters:
definition- the operation definition which should be added- Returns:
trueif the addition was successful,falseelse due to duplicated names
-
remove
public boolean remove(OperationDefinition definition)
Removes the given operation definition.- Parameters:
definition- the definition to be removed- Returns:
trueif the operation was removed,falseelse
-
accept
public void accept(IModelVisitor visitor)
Accept method for the visitor.- Specified by:
acceptin interfaceIFreezable- Specified by:
acceptin interfaceIModelElement- Parameters:
visitor- The visitor, which should process this model element.
-
getOperation
public CustomOperation getOperation(int index)
Returns the operation specified byindex.- Specified by:
getOperationin interfaceICustomOperationAccessor- Parameters:
index- a 0-based index specifying the operation to be returned- Returns:
- the operation
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getOperationCount()
-
getOperationCount
public int getOperationCount()
Returns the number of operations.- Specified by:
getOperationCountin interfaceICustomOperationAccessor- Returns:
- the number of operations
-
getType
public IDatatype getType()
Returns the (pseudo) datatype of this project. The returned type is intended to be used as the operand for custom operations to be added withadd(OperationDefinition).- Specified by:
getTypein interfaceICustomOperationAccessor- Specified by:
getTypein interfaceIFreezable- Returns:
- the datatype
-
getVariable
public DecisionVariableDeclaration getVariable()
Returns the (pseudo) variable for this project. We need this variable to attribute a project.- Returns:
- the (pseudo) variable
-
hasInterfaces
public boolean hasInterfaces()
Returns whether this project has interfaces.- Specified by:
hasInterfacesin interfaceIResolutionScope- Returns:
trueif it has interfaces,falseelse
-
attribute
public boolean attribute(Attribute attribute)
Description copied from interface:IAttributableElementAttributes this element.- Specified by:
attributein interfaceIAttributableElement- Parameters:
attribute- the attribute to be added- Returns:
trueif the operation was successful,falseif the element is about being attributed multiple times with the same attribute
-
getAttributesCount
public int getAttributesCount()
Description copied from interface:IAttributeAccessReturns the number of (declared) attributes.- Specified by:
getAttributesCountin interfaceIAttributeAccess- Returns:
- the number of attributes
-
getAttribute
public Attribute getAttribute(java.lang.String name)
Description copied from interface:IAttributeAccessReturns a specific (declared) attribute.- Specified by:
getAttributein interfaceIAttributeAccess- Parameters:
name- the name of the attribute- Returns:
- the attribute (or null if not found)
-
getAttribute
public Attribute getAttribute(int index)
Description copied from interface:IAttributeAccessReturns a specific attribute.- Specified by:
getAttributein interfaceIAttributeAccess- Parameters:
index- the index of the attribute- Returns:
- the attribute
-
isInterface
public boolean isInterface()
Description copied from interface:IResolutionScopeReturns whether this scope is an interfaces.- Specified by:
isInterfacein interfaceIResolutionScope- Returns:
trueif it is an interface,falseelse
-
getNameSpace
public java.lang.String getNameSpace()
Description copied from interface:IModelElementReturns the namespace introduced by this model element.- Specified by:
getNameSpacein interfaceIModelElement- Overrides:
getNameSpacein classModelElement- Returns:
- the namespace introduced by this model element.
-
getParent
public Project getParent()
Returns the parent of this project.- Specified by:
getParentin interfaceIAttributeAccess- Specified by:
getParentin interfaceIFreezable- Specified by:
getParentin interfaceIModelElement- Specified by:
getParentin interfaceIResolutionScope- Overrides:
getParentin classModelElement- Returns:
- the parent of this project (in case of copied projects, may be null)
-
setParent
void setParent(Project parent)
Changes the parent of this project (intended to be used internally by the copy mechanism).- Parameters:
parent- the new parent
-
setComments
public void setComments(StructuredComment comment)
Sets a structured comment object for this project.- Parameters:
comment- the comment object (may be null)
-
getComments
public StructuredComment getComments()
Returns the structured comment for this project.- Returns:
- structured comment instance
-
getNestedComment
public Comment getNestedComment(java.lang.Object element)
Returns a comment for anelementfrom within thegetComments().- Parameters:
element- the element to return the comment for- Returns:
- the element, may be null
-
sortContainedElements
public void sortContainedElements(java.util.Comparator<ContainableModelElement> comp)
Sorts the contained elements according to the specified comparator. Please note the following requirements for applying this method:- All Elements which were added before this operation must still be member of this project after executing this operation.
- Comments related to an element must occur before the element in the final sequence.
- Parameters:
comp- a comparator which fulfills the requirements above
-
propagateAttribute
public boolean propagateAttribute(Attribute attribute)
Description copied from interface:IModelElementPropagates an attribute application from the parent to this element or contained elements. This may imply the creation of clones of the givenattribute.- Specified by:
propagateAttributein interfaceIModelElement- Overrides:
propagateAttributein classModelElement- Parameters:
attribute- the attribute to be propagated- Returns:
trueif the operation was successful,falseif the element is about being attributed multiple times with the same attribute
-
getSuper
public ModelImport<Project> getSuper()
Returns the reference to the super model (if it exists).
-
getIndentationConfiguration
public IndentationConfiguration getIndentationConfiguration()
Returns 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)
-
dispose
public void dispose()
Description copied from interface:IModelShall be called at the end of the lifetime of the model in order to clean up references such as listeners.
-
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
-
addConstraint
public void addConstraint(Constraint constraint)
Description copied from interface:IConstraintHolderAdds a constraint.- Specified by:
addConstraintin interfaceIConstraintHolder- Parameters:
constraint- the constraint to be added
-
-