Class Project

java.lang.Object
net.ssehub.easy.varModel.model.ModelElement
net.ssehub.easy.varModel.model.Project
All Implemented Interfaces:
net.ssehub.easy.basics.modelManagement.IModel, net.ssehub.easy.basics.modelManagement.IModelData, ICustomOperationAccessor, IResolutionScope, IAttributableElement, IAttributeAccess, IConstraintHolder, IFreezable, IModelElement

public class Project extends ModelElement implements net.ssehub.easy.basics.modelManagement.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. Use getVariable() for attributing a project.
Author:
Marcel Lueder, Holger Eichelberger
  • Field Details

  • Constructor Details

    • Project

      Project()
      Constructor for serialization.
    • Project

      public Project(String name)
      Constructor for the project.
      Parameters:
      name - Name of project
  • Method Details

    • 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:
      true if the addition was successful, false else due to duplicated names
    • removeImport

      public boolean removeImport(ProjectImport pimport)
      Removes an import from this project.
      Parameters:
      pimport - the import to be removed
      Returns:
      true if the removal was successful, false else due to duplicated names
    • removeElements

      public boolean removeElements(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

      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:
      getImportsCount in interface ICustomOperationAccessor
      Specified by:
      getImportsCount in interface net.ssehub.easy.basics.modelManagement.IModel
      Specified by:
      getImportsCount in interface IResolutionScope
      Returns:
      the number of imports
    • getImport

      public ProjectImport getImport(int index)
      Returns the project import specified by index.
      Specified by:
      getImport in interface ICustomOperationAccessor
      Specified by:
      getImport in interface net.ssehub.easy.basics.modelManagement.IModel
      Specified by:
      getImport in interface IResolutionScope
      Parameters:
      index - a 0-based index specifying the import to be returned
      Returns:
      the project import
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getImportsCount()
    • setVersion

      public void setVersion(net.ssehub.easy.basics.modelManagement.Version version)
      Changes the version of this project.
      Specified by:
      setVersion in interface net.ssehub.easy.basics.modelManagement.IModel
      Parameters:
      version - Version to set
    • getVersion

      public net.ssehub.easy.basics.modelManagement.Version getVersion()
      Returns the version of this project.
      Specified by:
      getVersion in interface net.ssehub.easy.basics.modelManagement.IModel
      Specified by:
      getVersion in interface net.ssehub.easy.basics.modelManagement.IModelData
      Returns:
      the version or null if no version is specified for this project.
    • getElement

      public ContainableModelElement getElement(int index)
      Returns a contained model element specified by index.
      Specified by:
      getElement in interface IResolutionScope
      Parameters:
      index - a 0-based index specifying the operation to be returned
      Returns:
      the contained element
      Throws:
      IndexOutOfBoundsException - if index<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 for
      ensureStructured - whether a default structured comment shall be inserted before element if no comment was found
      Returns:
      the comment assigned to element or null if none was found or ensureStructured is false, respectively
    • getElementCount

      public int getElementCount()
      Returns the number of contained elements.
      Specified by:
      getElementCount in interface IResolutionScope
      Returns:
      the number of contained elements
    • containsByName

      public boolean containsByName(String name)
      Returns whether this project contains an element and its name.
      Parameters:
      name - the name to search for
      Returns:
      true if this project contains the specified element, false else
    • getElement

      public ContainableModelElement getElement(String name)
      Description copied from interface: IResolutionScope
      Returns a contained model element specified by its name.
      Specified by:
      getElement in interface IResolutionScope
      Parameters:
      name - the qualified or unqualified name to search for
      Returns:
      the related element or null if no such element is known
    • addBeforeFreeze

      public boolean addBeforeFreeze(ContainableModelElement element)
      Method to add an object to the modelElement list of the project, but, if already contained, before the first freeze (assuming that freezes as usual are added to the end). Only named elements are considered for checking duplicates!
      Parameters:
      element - which should be added
      Returns:
      true if the addition was successful, false else due to duplicated names
    • 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:
      true if the addition was successful, false else due to duplicated names
    • add

      private boolean add(ContainableModelElement element, Supplier<Integer> position)
      Method to add an object to the modelElement list of the project. Only named elements are considered for checking duplicates!
      Parameters:
      element - element that should be added
      position - optional position provider function for List.add(int, Object), may be null for adding at end
      Returns:
      true if the addition was successful, false else due to duplicated names
    • renameElement

      public boolean renameElement(ContainableModelElement elt, String newName)
      Renames an element. Use renameVariable in configuration if a configuration is defined on this project.
      Parameters:
      elt - the element to be renamed
      newName - the new name
      Returns:
      true if the element was found and renamed, false else
    • renameElement

      public boolean renameElement(String oldName, String newName)
      Renames an element. Use renameVariable in configuration if a configuration is defined on this project.
      Parameters:
      oldName - the old name
      newName - the new name
      Returns:
      true if the element was found and renamed, false else
    • 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:
      true if the addition was successful, false else due to duplicated names
    • remove

      public boolean remove(OperationDefinition definition)
      Removes the given operation definition.
      Parameters:
      definition - the definition to be removed
      Returns:
      true if the operation was removed, false else
    • accept

      public void accept(IModelVisitor visitor)
      Accept method for the visitor.
      Specified by:
      accept in interface IFreezable
      Specified by:
      accept in interface IModelElement
      Parameters:
      visitor - The visitor, which should process this model element.
    • getOperation

      public CustomOperation getOperation(int index)
      Returns the operation specified by index.
      Specified by:
      getOperation in interface ICustomOperationAccessor
      Parameters:
      index - a 0-based index specifying the operation to be returned
      Returns:
      the operation
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getOperationCount()
    • getOperationCount

      public int getOperationCount()
      Returns the number of operations.
      Specified by:
      getOperationCount in interface ICustomOperationAccessor
      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 with add(OperationDefinition).
      Specified by:
      getType in interface ICustomOperationAccessor
      Specified by:
      getType in interface IFreezable
      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:
      hasInterfaces in interface IResolutionScope
      Returns:
      true if it has interfaces, false else
    • attribute

      public boolean attribute(Attribute attribute)
      Description copied from interface: IAttributableElement
      Attributes this element.
      Specified by:
      attribute in interface IAttributableElement
      Parameters:
      attribute - the attribute to be added
      Returns:
      true if the operation was successful, false if the element is about being attributed multiple times with the same attribute
    • getAttributesCount

      public int getAttributesCount()
      Description copied from interface: IAttributeAccess
      Returns the number of (declared) attributes.
      Specified by:
      getAttributesCount in interface IAttributeAccess
      Returns:
      the number of attributes
    • getAttribute

      public Attribute getAttribute(String name)
      Description copied from interface: IAttributeAccess
      Returns a specific (declared) attribute.
      Specified by:
      getAttribute in interface IAttributeAccess
      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: IAttributeAccess
      Returns a specific attribute.
      Specified by:
      getAttribute in interface IAttributeAccess
      Parameters:
      index - the index of the attribute
      Returns:
      the attribute
    • isInterface

      public boolean isInterface()
      Description copied from interface: IResolutionScope
      Returns whether this scope is an interfaces.
      Specified by:
      isInterface in interface IResolutionScope
      Returns:
      true if it is an interface, false else
    • getNameSpace

      public String getNameSpace()
      Description copied from interface: IModelElement
      Returns the namespace introduced by this model element.
      Specified by:
      getNameSpace in interface IModelElement
      Overrides:
      getNameSpace in class ModelElement
      Returns:
      the namespace introduced by this model element.
    • getParent

      public Project getParent()
      Returns the parent of this project.
      Specified by:
      getParent in interface IAttributeAccess
      Specified by:
      getParent in interface IFreezable
      Specified by:
      getParent in interface IModelElement
      Specified by:
      getParent in interface IResolutionScope
      Overrides:
      getParent in class ModelElement
      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(Object element)
      Returns a comment for an element from within the getComments().
      Parameters:
      element - the element to return the comment for
      Returns:
      the element, may be null
    • sortContainedElements

      public void sortContainedElements(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: IModelElement
      Propagates an attribute application from the parent to this element or contained elements. This may imply the creation of clones of the given attribute.
      Specified by:
      propagateAttribute in interface IModelElement
      Overrides:
      propagateAttribute in class ModelElement
      Parameters:
      attribute - the attribute to be propagated
      Returns:
      true if the operation was successful, false if the element is about being attributed multiple times with the same attribute
    • getSuper

      public net.ssehub.easy.basics.modelManagement.ModelImport<Project> getSuper()
      Returns the reference to the super model (if it exists).
      Specified by:
      getSuper in interface net.ssehub.easy.basics.modelManagement.IModel
      Returns:
      always null as this does not exist in IVML
    • getIndentationConfiguration

      public net.ssehub.easy.basics.modelManagement.IndentationConfiguration getIndentationConfiguration()
      Returns the indentation configuration for this model. The indentation configuration is considered to be immutable.
      Specified by:
      getIndentationConfiguration in interface net.ssehub.easy.basics.modelManagement.IModel
      Returns:
      the indentation configuration (disabled if null)
    • dispose

      public void dispose()
      Specified by:
      dispose in interface net.ssehub.easy.basics.modelManagement.IModel
    • getRestrictionEvaluationContext

      public net.ssehub.easy.basics.modelManagement.IRestrictionEvaluationContext getRestrictionEvaluationContext()
      Specified by:
      getRestrictionEvaluationContext in interface net.ssehub.easy.basics.modelManagement.IModel
    • addConstraint

      public void addConstraint(Constraint constraint)
      Description copied from interface: IConstraintHolder
      Adds a constraint.
      Specified by:
      addConstraint in interface IConstraintHolder
      Parameters:
      constraint - the constraint to be added
    • getLastModification

      public long getLastModification()
      Specified by:
      getLastModification in interface net.ssehub.easy.basics.modelManagement.IModel