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 Detail

      • POOL

        private static final java.util.List<IVMLWriter> POOL
      • nestedValues

        private java.util.Stack<Value> nestedValues
      • emitComments

        private boolean emitComments
      • lastComment

        private java.util.Stack<Comment> lastComment
      • handled

        private java.util.Set<Attribute> handled
      • formatInitializer

        private boolean formatInitializer
      • forceCompoundTypes

        private boolean forceCompoundTypes
    • Constructor Detail

      • IVMLWriter

        public IVMLWriter​(java.io.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​(java.io.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 Detail

      • 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
      • getInstance

        public static final IVMLWriter getInstance​(java.io.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
      • 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
      • 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.
      • 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.
      • 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,
                                         java.util.Set<java.lang.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,
                                                           java.util.Set<java.lang.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.
      • 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.
      • 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​(java.lang.Object context,
                                                         java.lang.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
      • 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
      • 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).
      • 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​(java.lang.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
      • 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