Class AbstractVarModelWriter

java.lang.Object
net.ssehub.easy.varModel.model.AbstractVisitor
net.ssehub.easy.varModel.persistency.AbstractVarModelWriter
All Implemented Interfaces:
IConstraintTreeVisitor, ICustomDatatypeVisitor, IModelVisitor, IValueVisitor
Direct Known Subclasses:
IVMLWriter

public abstract class AbstractVarModelWriter extends AbstractVisitor implements IValueVisitor, IConstraintTreeVisitor
Super class for translating the variability model to a StringBuffer, which can be used for saving.
Author:
El-Sharkawy
See Also:
  • Field Details

    • DUMMY_PARENT

      protected static final ModelElement DUMMY_PARENT
      Defines a dummy model element for additional formatting.
    • indentStep

      private static String indentStep
      The number of whitespaces per indentation (if useWhitespace is enabled), otherwise one tab is inserted. Currently we assume that one central configuration for the indentation is sufficient and that it will not be changed during the output of this or subclasses.
    • useWhitespace

      private static boolean useWhitespace
      Use whitespaces or tabs. Currently we assume that one central configuration for the indentation is sufficient and that it will not be changed during the output of this or subclasses.
    • oclCompliance

      private static boolean oclCompliance
      Detect, warn, report about and write to avoid OCL compliance problems.
    • myIndentStep

      private String myIndentStep
    • myUseWhitespace

      private boolean myUseWhitespace
    • additionalIndentation

      private int additionalIndentation
    • parents

      private List<IModelElement> parents
      Stores the all parents of the currently visited element.
      Can be an empty list in case of root elements.
    • out

      private Writer out
      This attribute should be used for storing the output.
    • expressionContext

      private IModelElement expressionContext
  • Constructor Details

    • AbstractVarModelWriter

      protected AbstractVarModelWriter(Writer writer)
      Sole constructor for this class.
      Parameters:
      writer - Writer which should be used for writing the output.
  • Method Details

    • setExpressionContext

      protected void setExpressionContext(IModelElement expressionContext)
      Changes the expression context.
      Parameters:
      expressionContext - the expression context
    • getExpressionContext

      protected IModelElement getExpressionContext()
      Returns the expression context.
      Returns:
      the expression context
    • setIndentStep

      public static void setIndentStep(int count)
      Defines the number of spaces used in one indentation step if useWhitespace.
      Parameters:
      count - the number of spaces (negative values are ignored)
    • setIndentationStep

      public void setIndentationStep(int count)
      Defines the number of spaces used in one indentation step if useWhitespace for this writer.
      Parameters:
      count - the number of spaces (negative values are ignored)
    • setOclCompliance

      public static void setOclCompliance(boolean compliance)
      Changes the OCL compliance setting.
      Parameters:
      compliance - operate with OCL compliance (true), allow both IVML + OCL (false
    • considerOclCompliance

      public static boolean considerOclCompliance()
      Returns whether OCL compliance shall be considered.
      Returns:
      true for OCL compliance, false else
    • setUseWhitespaces

      public void setUseWhitespaces(boolean useWhitespaces)
      Defines whether whitespaces or tabs shall be used for indentation in this editor.
      Parameters:
      useWhitespaces - if true whitespaces, tabs if false
    • deriveIndentStep

      private static String deriveIndentStep(int count)
      Creates the indentation step in terms of numbers of spaces to be used.
      Parameters:
      count - the number of spaces (negative values are ignored)
      Returns:
      the indentation step
    • getIvmlIndentStep

      public static String getIvmlIndentStep()
      Return the indent-step for ivml.
      Returns:
      indent step.
    • setUseIvmlWhitespace

      public static void setUseIvmlWhitespace(boolean use)
      Defines whether whitespaces or tabs shall be used for indentation.
      Parameters:
      use - if true whitespaces, tabs if false
    • getUseIvmlWhitespace

      public static boolean getUseIvmlWhitespace()
      Defines whether whitespaces or tabs shall be used for indentation.
      Returns:
      useWhitespace if true whitespaces, tabs if false
    • setWriter

      public void setWriter(Writer writer)
      Changes the writer. (for reuse)
      Parameters:
      writer - the new writer
    • getWriter

      public Writer getWriter()
      Returns the actual writer.
      Returns:
      the actual writer
    • appendOutput

      protected final void appendOutput(String appendableOutput)
      Method to append the output.
      Parameters:
      appendableOutput - String containing the output, which should be added.
    • appendOutput

      protected final void appendOutput(char appendableOutput)
      Method to append the output.
      Parameters:
      appendableOutput - char containing the output, which should be added.
    • appendIndentation

      protected final void appendIndentation()
      Method to append the current indentation.
    • flush

      public final void flush() throws IOException
      Flushes the writer. Should be used if there aren't any more elements to read.
      Throws:
      IOException - If an I/O error occurs
    • getIndentation

      protected StringBuffer getIndentation()
      Returns the current indentation for (nested) elements.
      Returns:
      The correct indentation for nested elements or an empty StringBuffer in case of an top level element.
    • getParent

      protected IModelElement getParent()
      Returns the direct parent of the current visited object. Ignors DUMMY_PARENT.
      Returns:
      The direct parent or null in case of an element from the top layer.
    • getParent

      protected <T extends IModelElement> T getParent(Class<T> type)
      Returns the latest parent with the given type.
      Type Parameters:
      T - the actual type of the parent to be returned
      Parameters:
      type - the type to search for
      Returns:
      the latest parent with given type or getParent() if type==null
    • removeLastParent

      protected void removeLastParent()
      Removes the last parent from the list of all parents. This method should be used inside the after visit methods.
    • addParent

      protected void addParent(IModelElement parent)
      Adds the given element to the list of all parents.
      Parameters:
      parent - the parent to be added
    • emitComments

      public abstract boolean emitComments()
      Returns whether comments are emitted by this writer.
      Returns:
      true if comments are emitted, false else
    • printDefaultSpace

      protected abstract void printDefaultSpace(AbstractVarModelWriter.DefaultSpace location)
      Prints default spaces.
      Parameters:
      location - the intended location of the space
    • processVersion

      protected abstract void processVersion(net.ssehub.easy.basics.modelManagement.Version version)
      Processes a version information.
      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 AbstractVisitor
      Parameters:
      project - The project which should be visited.
    • visitOrderedEnum

      public void visitOrderedEnum(OrderedEnum eenum)
      Method for visiting an orded enum.
      Specified by:
      visitOrderedEnum in interface ICustomDatatypeVisitor
      Overrides:
      visitOrderedEnum in class AbstractVisitor
      Parameters:
      eenum - The enum which should be visited.
    • 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 AbstractVisitor
      Parameters:
      compound - The compound which should be visited.
    • visitAttributeAssignment

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

      protected abstract void startWritingCompound(Compound compound)
      Method for writing a compound, first part.
      Parameters:
      compound - The compound which should be saved.
    • endWritingCompound

      protected abstract void endWritingCompound(Compound compound)
      Method for writing a compound, second part.
      Parameters:
      compound - The compound which should be saved.
    • startWritingProject

      protected abstract void startWritingProject(Project project)
      Method for writing a project, first part.
      Parameters:
      project - The project which should be saved.
    • endWritingProject

      protected abstract void endWritingProject(Project project)
      Method for writing a project, second part.
      Parameters:
      project - The project which should be saved.
    • visitConstantValue

      public void visitConstantValue(ConstantValue value)
      Description copied from interface: IConstraintTreeVisitor
      Visits a constant value.
      Specified by:
      visitConstantValue in interface IConstraintTreeVisitor
      Parameters:
      value - the value which should be visited
    • visitConstraintValue

      public void visitConstraintValue(ConstraintValue value)
      Description copied from interface: IValueVisitor
      This method is used for visiting ConstraintValue.
      Specified by:
      visitConstraintValue in interface IValueVisitor
      Parameters:
      value - One ConstraintValue which should be visited.
    • visitConstraint

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

      protected void emitConstraintExpression(IModelElement context, ConstraintSyntaxTree constraint)
      Visits the expression of a constraint (for extension).
      Parameters:
      context - the visiting context
      constraint - the (specified) constraint;
    • visitPartialEvaluationBlock

      public void visitPartialEvaluationBlock(PartialEvaluationBlock block)
      Description copied from interface: IModelVisitor
      Method for visiting a partial evaluation block.
      Specified by:
      visitPartialEvaluationBlock in interface IModelVisitor
      Parameters:
      block - The partial evaluation block 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
      Parameters:
      freeze - The freeze block which should be visited.
    • visitUnresolvedExpression

      public void visitUnresolvedExpression(UnresolvedExpression expression)
      Description copied from interface: IConstraintTreeVisitor
      Visits an unresolved expression. Please note that an unresolved expression may represent a leaf as well as an inner tree node. Typically, visitors shall continue visiting transparently at UnresolvedExpression.getActualExpression().
      Specified by:
      visitUnresolvedExpression in interface IConstraintTreeVisitor
      Parameters:
      expression - the expression
    • beforeNestedElement

      protected void beforeNestedElement(Object element)
      This method is called before a nested element is emitted. This enables the output of comments before the element etc.
      Parameters:
      element - the element (no specific type needed, see Comment
    • getParentCount

      protected int getParentCount()
      Returns the number of hierarchically visited parents.
      Returns:
      the number of hierarchically visited parents
    • getParent

      protected IModelElement getParent(int index)
      Returns the specified hierarchically visited parent.
      Parameters:
      index - the 0-based index of the visited parent
      Returns:
      the specified visited parent
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >= getParentCount()
    • increaseAdditionalIndentation

      protected void increaseAdditionalIndentation()
      Increases the additional indentation.
    • decreaseAdditionalIndentation

      protected void decreaseAdditionalIndentation()
      Decreases the additional indentation.
    • getLogger

      protected net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger getLogger()
      Returns the actual logger instance.
      Returns:
      the logger instance