Class IVMLWriter

All Implemented Interfaces:
IConstraintTreeVisitor, ICustomDatatypeVisitor, IModelVisitor, IValueVisitor
Direct Known Subclasses:
ConfigurableIVMLWriter, ConstraintSplitWriter

public class IVMLWriter extends AbstractVarModelWriter
Writer for writing the variability model to an IVML output file. Please note that this writer creates output regardless of the correctness of the semantics of the model being visited. However, if the full IVML infrastructure including the IVML parser is used and given interfaces of this model are used properly, the output will be valid. In case that the classes in this model package are directly used from external code, it is strongly advised to use the IvmlValidationVisitor to check the validity of the visited model before producing output.
Author:
El-Sharkawy, Marcel Lueder, Holger Eichelberger
  • Field Details

  • Constructor Details

    • IVMLWriter

      public IVMLWriter(Writer writer)
      Class for writing ivml output appropriate for the EASy-Producer tool.
      Parameters:
      writer - Writer which should be used for writing the output.
    • IVMLWriter

      protected IVMLWriter(Writer writer, boolean emitComments)
      Creates a writer instance. Due to the pooling mechanism, disabling comments can only be done by a non-pooled subclass.
      Parameters:
      writer - the writer which should be used for writing the output
      emitComments - whether comments shall be emitted or ignored
  • Method Details

    • setEmitProjectFreezeDot

      public void setEmitProjectFreezeDot(boolean emitProjectFreezeDot)
      Enables/disables whether a project freeze on itself shall be emitted with a ".".
      Parameters:
      emitProjectFreezeDot - true for enable, false else
    • setEmitFilter

      public void setEmitFilter(IVMLWriter.EmitFilter emitFilter)
      Defines an filter controlling emitting of individual variables/slots.
      Parameters:
      emitFilter - the emit filter
    • setFormatInitializer

      public void setFormatInitializer(boolean formatInitializer)
      Defines whether initializers shall be formatted.
      Parameters:
      formatInitializer - true if initializers shall be formatted, false else
    • forceComponundTypes

      public void forceComponundTypes(boolean forceCompoundTypes)
      Forces the output of compound types and bypasses the automatic detection.
      Parameters:
      forceCompoundTypes - if true, compound types are always emitted at creation, false else
    • emitComments

      public boolean emitComments()
      Description copied from class: AbstractVarModelWriter
      Returns whether comments are emitted by this writer.
      Specified by:
      emitComments in class AbstractVarModelWriter
      Returns:
      true if comments are emitted, false else
    • getInstance

      public static final IVMLWriter getInstance(Writer writer)
      Obtains an instance from the pool (always emitting comments).
      Parameters:
      writer - the target output writer
      Returns:
      the instance, to be released by releaseInstance(IVMLWriter)
    • releaseInstance

      public static final void releaseInstance(IVMLWriter writer)
      Releases an instance to the pool.
      Parameters:
      writer - the instance to be released
    • printDefaultSpace

      protected void printDefaultSpace(AbstractVarModelWriter.DefaultSpace location)
      Description copied from class: AbstractVarModelWriter
      Prints default spaces.
      Specified by:
      printDefaultSpace in class AbstractVarModelWriter
      Parameters:
      location - the intended location of the space
    • startWritingProject

      protected void startWritingProject(Project project)
      Description copied from class: AbstractVarModelWriter
      Method for writing a project, first part.
      Specified by:
      startWritingProject in class AbstractVarModelWriter
      Parameters:
      project - The project which should be saved.
    • endWritingProject

      protected void endWritingProject(Project project)
      Description copied from class: AbstractVarModelWriter
      Method for writing a project, second part.
      Specified by:
      endWritingProject in class AbstractVarModelWriter
      Parameters:
      project - The project which should be saved.
    • processVersion

      protected void processVersion(net.ssehub.easy.basics.modelManagement.Version version)
      Description copied from class: AbstractVarModelWriter
      Processes a version information.
      Specified by:
      processVersion in class AbstractVarModelWriter
      Parameters:
      version - the version to be processed
    • visitProject

      public void visitProject(Project project)
      Description copied from interface: IModelVisitor
      Method for visiting a project.
      Specified by:
      visitProject in interface IModelVisitor
      Overrides:
      visitProject in class AbstractVarModelWriter
      Parameters:
      project - The project which should be visited.
    • visitProjectImport

      public void visitProjectImport(ProjectImport pImport)
      Description copied from interface: IModelVisitor
      This method is used for visiting a ProjectImport.
      Parameters:
      pImport - One ProjectImport which should be visited.
    • startWritingCompound

      protected void startWritingCompound(Compound compound)
      Description copied from class: AbstractVarModelWriter
      Method for writing a compound, first part.
      Specified by:
      startWritingCompound in class AbstractVarModelWriter
      Parameters:
      compound - The compound which should be saved.
    • endWritingCompound

      protected void endWritingCompound(Compound compound)
      Description copied from class: AbstractVarModelWriter
      Method for writing a compound, second part.
      Specified by:
      endWritingCompound in class AbstractVarModelWriter
      Parameters:
      compound - The compound which should be saved.
    • visitEnum

      public void visitEnum(Enum eenum)
      Method for visiting an enum.
      Specified by:
      visitEnum in interface ICustomDatatypeVisitor
      Overrides:
      visitEnum in class AbstractVisitor
      Parameters:
      eenum - The enum which should be visited.
    • visitEnumValue

      public void visitEnumValue(EnumValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting EnumValue.
      Parameters:
      value - One EnumValue which should be visited.
    • visitDecisionVariableDeclaration

      public void visitDecisionVariableDeclaration(DecisionVariableDeclaration decl)
      Description copied from interface: IModelVisitor
      This method is used for visiting a decision variable declaration.
      Parameters:
      decl - One declaration which should be visited.
    • emitDecisionVariableDeclarationExpression

      private void emitDecisionVariableDeclarationExpression(DecisionVariableDeclaration decl, ConstraintSyntaxTree defaultValue)
      Emits the expression part of a variable declaration without the statement part.
      Parameters:
      decl - the declaration to be emitted
      defaultValue - an explicitly given default value that supersedes the one of decl (may be null to force the one given by decl)
    • emitDecisionVariableDeclarationDefault

      protected void emitDecisionVariableDeclarationDefault(DecisionVariableDeclaration decl, ConstraintSyntaxTree defaultValue)
      Emits the default value of a decision variable declaration (for extension).
      Parameters:
      decl - the declaration
      defaultValue - the specified default value
    • visitStringValue

      public void visitStringValue(StringValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting StringValue.
      Parameters:
      value - One StringValue which should be visited.
    • emitType

      private void emitType(IDatatype type, boolean considerValues)
      Emits the type of an initializer if required. Considers forceCompoundTypes, nestedValues and nestedExpressions.
      Parameters:
      type - the actual type of the element
      considerValues - whether nestedValues or nestedExpressions shall be considered
    • visitCompoundValue

      public void visitCompoundValue(CompoundValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting CompoundValue.
      Parameters:
      value - One CompoundValue which should be visited.
    • visitCompoundRefines

      private int visitCompoundRefines(Compound comp, CompoundValue value, int count, Set<String> done)
      Parameters:
      comp - the compound
      value - the compound value
      count - the count
      done - already processed (or null)
      Returns:
      the aggregated count
    • writeValue

      protected boolean writeValue(Value value)
      Returns whether a certain value shall be written.
      Parameters:
      value - the value to be checked
      Returns:
      true if the value shall be written, false else
    • visitCompoundDecisionVariableContainer

      private int visitCompoundDecisionVariableContainer(IDecisionVariableContainer cont, CompoundValue value, int printed, Set<String> done)
      Visits a compound decision variable container for output of configuration values.
      Parameters:
      cont - the container
      value - the container value
      printed - the number of printed elements so far
      done - already processed slots (may be null if not relevant, modified as a side effect)
      Returns:
      the number of printed elements
    • visitIntValue

      public void visitIntValue(IntValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting IntValue.
      Parameters:
      value - One IntValue which should be visited.
    • visitRealValue

      public void visitRealValue(RealValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting RealValue.
      Parameters:
      value - One RealValue which should be visited.
    • visitBooleanValue

      public void visitBooleanValue(BooleanValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting BooleanValue.
      Parameters:
      value - One BooleanValue which should be visited.
    • visitContainerValue

      public void visitContainerValue(ContainerValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting ContainerValue.
      Parameters:
      value - One CompoundValue which should be visited.
    • visitCompoundInitializer

      public void visitCompoundInitializer(CompoundInitializer initializer)
      Visits a compound initializer.
      Parameters:
      initializer - the compound initializer node
    • visitContainerInitializer

      public void visitContainerInitializer(ContainerInitializer initializer)
      Visits a container initializer.
      Parameters:
      initializer - the container initializer node
    • visitAttribute

      public void visitAttribute(Attribute attribute)
      Description copied from interface: IModelVisitor
      Method for visiting an attribute.
      Parameters:
      attribute - The attribute which should be visited.
    • visitFreezeBlock

      public void visitFreezeBlock(FreezeBlock freeze)
      Description copied from interface: IModelVisitor
      Method for visiting a freeze block.
      Specified by:
      visitFreezeBlock in interface IModelVisitor
      Overrides:
      visitFreezeBlock in class AbstractVarModelWriter
      Parameters:
      freeze - The freeze block which should be visited.
    • visitOperationDefinition

      public void visitOperationDefinition(OperationDefinition opdef)
      Description copied from interface: IModelVisitor
      Method for visiting an operation definition.
      Parameters:
      opdef - The operation definition which should be visited.
    • visitPartialEvaluationBlock

      public void visitPartialEvaluationBlock(PartialEvaluationBlock block)
      Description copied from interface: IModelVisitor
      Method for visiting a partial evaluation block.
      Specified by:
      visitPartialEvaluationBlock in interface IModelVisitor
      Overrides:
      visitPartialEvaluationBlock in class AbstractVarModelWriter
      Parameters:
      block - The partial evaluation block which should be visited.
    • visitProjectInterface

      public void visitProjectInterface(ProjectInterface iface)
      Description copied from interface: IModelVisitor
      Method for visiting a project interface.
      Parameters:
      iface - The interface which should be visited.
    • visitDerivedDatatype

      public void visitDerivedDatatype(DerivedDatatype datatype)
      Description copied from interface: ICustomDatatypeVisitor
      Method for visiting a derived datatype.
      Parameters:
      datatype - The datatype which should be visited.
    • visitEnumLiteral

      public void visitEnumLiteral(EnumLiteral literal)
      Description copied from interface: ICustomDatatypeVisitor
      Method for visiting an enum literal.
      Parameters:
      literal - The literal which should be visited.
    • visitReference

      public void visitReference(Reference reference)
      Description copied from interface: ICustomDatatypeVisitor
      Method for visiting a reference.
      Parameters:
      reference - The reference which should be visited.
    • visitSequence

      public void visitSequence(Sequence sequence)
      Description copied from interface: ICustomDatatypeVisitor
      Method for visiting a sequence.
      Parameters:
      sequence - The sequence which should be visited.
    • visitSet

      public void visitSet(Set set)
      Description copied from interface: ICustomDatatypeVisitor
      Method for visiting a set.
      Parameters:
      set - The set which should be visited.
    • visitReferenceValue

      public void visitReferenceValue(ReferenceValue referenceValue)
      Description copied from interface: IValueVisitor
      This method is used for visiting referenceValue.
      Parameters:
      referenceValue - One referenceValue which should be visited.
    • needsQualification

      private boolean needsQualification(AbstractVariable var)
      Determines whether (on-demand) qualification of the given var is needed, i.e., whether its qualified name shall be printed out.
      Parameters:
      var - the variable
      Returns:
      true if it needs to be qualified, false else
    • needsQualificationThroughContext

      private boolean needsQualificationThroughContext(Object context, String name, AbstractVariable var, boolean exclude)
      Returns whether the variable name name of var needs qualification within its context context.
      Parameters:
      context - the context (only considered if IDecisionVariableContainer
      name - the name of the variable to determine qualification need for
      var - the variable itself
      exclude - whether this call is intended to exclude (true) the qualification of var or whether it shall search for the existence of name in context(false)
      Returns:
      whether var needs qualification if exclude is true or whether name was found in context if exclude is false
    • visitVariable

      public void visitVariable(Variable variable)
      Description copied from interface: IConstraintTreeVisitor
      Visits a variable.
      Parameters:
      variable - the variable which should be visited
    • visitAnnotationVariable

      public void visitAnnotationVariable(AttributeVariable variable)
      Description copied from interface: IConstraintTreeVisitor
      Parameters:
      variable - the attribute variable which should be visited
    • visitParenthesis

      public void visitParenthesis(Parenthesis parenthesis)
      Description copied from interface: IConstraintTreeVisitor
      Visits a parenthesis.
      Parameters:
      parenthesis - the parenthesis which should be visited
    • visitOclFeatureCall

      public void visitOclFeatureCall(OCLFeatureCall call)
      Description copied from interface: IConstraintTreeVisitor
      Visits an OCL feature call.
      Parameters:
      call - the feature call which should be visited
    • appendOCLFeatureCall

      protected void appendOCLFeatureCall(OCLFeatureCall call, Operation.FormattingHint hint)
      Does the formatting of an OCL feature call and allows for overwriting.
      Parameters:
      call - the call
      hint - the formatting hint for the call
    • visitDeferInitExpression

      public void visitDeferInitExpression(DeferInitExpression expression)
      Description copied from interface: IConstraintTreeVisitor
      Visits a default init expression.
      Parameters:
      expression - the expression
    • visitMultiAndExpression

      public void visitMultiAndExpression(MultiAndExpression expression)
      Description copied from interface: IConstraintTreeVisitor
      Visits a multi-and expression.
      Parameters:
      expression - the expression to be visited
    • visitConstraint

      public void visitConstraint(Constraint constraint)
      Description copied from interface: IModelVisitor
      Method for visiting a constraint.
      Specified by:
      visitConstraint in interface IModelVisitor
      Overrides:
      visitConstraint in class AbstractVarModelWriter
      Parameters:
      constraint - The constraint which should be visited.
    • visitLet

      public void visitLet(Let let)
      Description copied from interface: IConstraintTreeVisitor
      Visits a let expression.
      Parameters:
      let - the let expression which should be visited
    • visitIfThen

      public void visitIfThen(IfThen ifThen)
      Description copied from interface: IConstraintTreeVisitor
      Visits an if-then-else expression.
      Parameters:
      ifThen - the if-then-else expression which should be visited
    • visitContainerOperationCall

      public void visitContainerOperationCall(ContainerOperationCall call)
      Description copied from interface: IConstraintTreeVisitor
      Visits a container operation call (e.g. quantors, iterators).
      Parameters:
      call - the container operation call
    • visitCompoundAccess

      public void visitCompoundAccess(CompoundAccess access)
      Description copied from interface: IConstraintTreeVisitor
      Visits a compound access node.
      Parameters:
      access - the compound access node
    • visitMetaTypeValue

      public void visitMetaTypeValue(MetaTypeValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting meta type value.
      Parameters:
      value - a value which should be visited.
    • visitNullValue

      public void visitNullValue(NullValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting a null value.
      Parameters:
      value - a value which should be visited (actually NullValue.INSTANCE).
    • visitAttributeAssignment

      public void visitAttributeAssignment(AttributeAssignment assignment)
      Description copied from interface: IModelVisitor
      Visits an attribute assignment.
      Specified by:
      visitAttributeAssignment in interface IModelVisitor
      Overrides:
      visitAttributeAssignment in class AbstractVarModelWriter
      Parameters:
      assignment - the assignment to visit
    • visitComment

      public void visitComment(Comment comment)
      Description copied from interface: IModelVisitor
      Method for visiting a comment.
      Parameters:
      comment - the comment to visit
    • visitComment

      public void visitComment(Comment comment)
      Description copied from interface: IConstraintTreeVisitor
      Visits a comment.
      Parameters:
      comment - the comment node which should be visited
    • beforeNestedElement

      protected void beforeNestedElement(Object element)
      Description copied from class: AbstractVarModelWriter
      This method is called before a nested element is emitted. This enables the output of comments before the element etc.
      Overrides:
      beforeNestedElement in class AbstractVarModelWriter
      Parameters:
      element - the element (no specific type needed, see Comment
    • visitCompound

      public void visitCompound(Compound compound)
      Description copied from interface: ICustomDatatypeVisitor
      Method for visiting a compound.
      Specified by:
      visitCompound in interface ICustomDatatypeVisitor
      Overrides:
      visitCompound in class AbstractVarModelWriter
      Parameters:
      compound - The compound which should be visited.
    • getLastComment

      private Comment getLastComment()
      Returns the last comment from the internal comment stack.
      Returns:
      the last comment
    • dupLastComment

      private void dupLastComment()
      Duplicates the last comment on the stack for nesting.
    • popLastComment

      private Comment popLastComment()
      Removes the comment on top of the stack.
      Returns:
      the comment which was on the top of the stack before this operation
    • setLastComment

      private void setLastComment(Comment comment)
      Defines the next comment on top of the stack (combined pop/push).
      Parameters:
      comment - the new comment to be on the top of the stack
    • visitCompoundAccessStatement

      public void visitCompoundAccessStatement(CompoundAccessStatement access)
      Description copied from interface: IModelVisitor
      Visits a compound access statement (may occur in freeze blocks.
      Parameters:
      access - the access statement
    • visitVersionValue

      public void visitVersionValue(VersionValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting a version value.
      Parameters:
      value - a value which should be visited.
    • visitSelf

      public void visitSelf(Self self)
      Description copied from interface: IConstraintTreeVisitor
      Visits self.
      Parameters:
      self - the self object to visit
    • visitBlockExpression

      public void visitBlockExpression(BlockExpression block)
      Description copied from interface: IConstraintTreeVisitor
      Visits the block.
      Parameters:
      block - the block to be visited