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 aStringBuffer, which can be used for saving.- Author:
- El-Sharkawy
- See Also:
IValueVisitor,Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractVarModelWriter.DefaultSpaceDefines default space locations.
-
Field Summary
Fields Modifier and Type Field Description private intadditionalIndentationprotected static ModelElementDUMMY_PARENTDefines a dummy model element for additional formatting.private IModelElementexpressionContextprivate static java.lang.StringindentStepThe number of whitespaces per indentation (ifuseWhitespaceis enabled), otherwise one tab is inserted.private java.lang.StringmyIndentStepprivate booleanmyUseWhitespaceprivate static booleanoclComplianceDetect, warn, report about and write to avoid OCL compliance problems.private java.io.WriteroutThis attribute should be used for storing the output.private java.util.List<IModelElement>parentsStores the all parents of the currently visited element.
Can be an empty list in case of root elements.private static booleanuseWhitespaceUse whitespaces or tabs.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractVarModelWriter(java.io.Writer writer)Sole constructor for this class.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddParent(IModelElement parent)Adds the given element to the list of all parents.protected voidappendIndentation()Method to append the current indentation.protected voidappendOutput(char appendableOutput)Method to append the output.protected voidappendOutput(java.lang.String appendableOutput)Method to append the output.protected voidbeforeNestedElement(java.lang.Object element)This method is called before a nested element is emitted.static booleanconsiderOclCompliance()Returns whether OCL compliance shall be considered.protected voiddecreaseAdditionalIndentation()Decreases the additional indentation.private static java.lang.StringderiveIndentStep(int count)Creates the indentation step in terms of numbers of spaces to be used.abstract booleanemitComments()Returns whether comments are emitted by this writer.protected voidemitConstraintExpression(IModelElement context, ConstraintSyntaxTree constraint)Visits the expression of a constraint (for extension).protected abstract voidendWritingCompound(Compound compound)Method for writing a compound, second part.protected abstract voidendWritingProject(Project project)Method for writing a project, second part.voidflush()Flushes the writer.protected IModelElementgetExpressionContext()Returns the expression context.protected java.lang.StringBuffergetIndentation()Returns the current indentation for (nested) elements.static java.lang.StringgetIvmlIndentStep()Return the indent-step for ivml.protected EASyLoggerFactory.EASyLoggergetLogger()Returns the actual logger instance.protected IModelElementgetParent()Returns the direct parent of the current visited object.protected IModelElementgetParent(int index)Returns the specified hierarchically visited parent.protected <T extends IModelElement>
TgetParent(java.lang.Class<T> type)Returns the latest parent with the giventype.protected intgetParentCount()Returns the number of hierarchically visited parents.static booleangetUseIvmlWhitespace()Defines whether whitespaces or tabs shall be used for indentation.java.io.WritergetWriter()Returns the actual writer.protected voidincreaseAdditionalIndentation()Increases the additional indentation.protected abstract voidprintDefaultSpace(AbstractVarModelWriter.DefaultSpace location)Prints default spaces.protected abstract voidprocessVersion(Version version)Processes a version information.protected voidremoveLastParent()Removes the last parent from the list of all parents.protected voidsetExpressionContext(IModelElement expressionContext)Changes the expression context.voidsetIndentationStep(int count)Defines the number of spaces used in one indentation step ifuseWhitespacefor this writer.static voidsetIndentStep(int count)Defines the number of spaces used in one indentation step ifuseWhitespace.static voidsetOclCompliance(boolean compliance)Changes the OCL compliance setting.static voidsetUseIvmlWhitespace(boolean use)Defines whether whitespaces or tabs shall be used for indentation.voidsetUseWhitespaces(boolean useWhitespaces)Defines whether whitespaces or tabs shall be used for indentation in this editor.voidsetWriter(java.io.Writer writer)Changes the writer.protected abstract voidstartWritingCompound(Compound compound)Method for writing a compound, first part.protected abstract voidstartWritingProject(Project project)Method for writing a project, first part.voidvisitAttributeAssignment(AttributeAssignment assignment)Visits an attribute assignment.voidvisitCompound(Compound compound)Method for visiting a compound.voidvisitConstantValue(ConstantValue value)Visits a constant value.voidvisitConstraint(Constraint constraint)Method for visiting a constraint.voidvisitConstraintValue(ConstraintValue value)This method is used for visiting ConstraintValue.voidvisitFreezeBlock(FreezeBlock freeze)Method for visiting a freeze block.voidvisitOrderedEnum(OrderedEnum eenum)Method for visiting an orded enum.voidvisitPartialEvaluationBlock(PartialEvaluationBlock block)Method for visiting a partial evaluation block.voidvisitProject(Project project)Method for visiting a project.voidvisitUnresolvedExpression(UnresolvedExpression expression)Visits an unresolved expression.-
Methods inherited from class net.ssehub.easy.varModel.model.AbstractVisitor
visitEnum
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
visitAnnotationVariable, visitBlockExpression, visitComment, visitCompoundAccess, visitCompoundInitializer, visitContainerInitializer, visitContainerOperationCall, visitIfThen, visitLet, visitMultiAndExpression, visitOclFeatureCall, visitParenthesis, visitSelf, visitVariable
-
Methods inherited from interface net.ssehub.easy.varModel.model.datatypes.ICustomDatatypeVisitor
visitDerivedDatatype, visitEnumLiteral, visitReference, visitSequence, visitSet
-
Methods inherited from interface net.ssehub.easy.varModel.model.IModelVisitor
visitAttribute, visitComment, visitCompoundAccessStatement, visitDecisionVariableDeclaration, visitOperationDefinition, visitProjectImport, visitProjectInterface
-
Methods inherited from interface net.ssehub.easy.varModel.model.values.IValueVisitor
visitBooleanValue, visitCompoundValue, visitContainerValue, visitEnumValue, visitIntValue, visitMetaTypeValue, visitNullValue, visitRealValue, visitReferenceValue, visitStringValue, visitVersionValue
-
-
-
-
Field Detail
-
DUMMY_PARENT
protected static final ModelElement DUMMY_PARENT
Defines a dummy model element for additional formatting.
-
indentStep
private static java.lang.String indentStep
The number of whitespaces per indentation (ifuseWhitespaceis 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 java.lang.String myIndentStep
-
myUseWhitespace
private boolean myUseWhitespace
-
additionalIndentation
private int additionalIndentation
-
parents
private java.util.List<IModelElement> parents
Stores the all parents of the currently visited element.
Can be an empty list in case of root elements.
-
out
private java.io.Writer out
This attribute should be used for storing the output.
-
expressionContext
private IModelElement expressionContext
-
-
Method Detail
-
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 ifuseWhitespace.- 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 ifuseWhitespacefor 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:
truefor OCL compliance,falseelse
-
setUseWhitespaces
public void setUseWhitespaces(boolean useWhitespaces)
Defines whether whitespaces or tabs shall be used for indentation in this editor.- Parameters:
useWhitespaces- iftruewhitespaces, tabs iffalse
-
deriveIndentStep
private static java.lang.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 java.lang.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- iftruewhitespaces, tabs iffalse
-
getUseIvmlWhitespace
public static boolean getUseIvmlWhitespace()
Defines whether whitespaces or tabs shall be used for indentation.- Returns:
- useWhitespace if
truewhitespaces, tabs iffalse
-
setWriter
public void setWriter(java.io.Writer writer)
Changes the writer. (for reuse)- Parameters:
writer- the new writer
-
getWriter
public java.io.Writer getWriter()
Returns the actual writer.- Returns:
- the actual writer
-
appendOutput
protected final void appendOutput(java.lang.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 java.io.IOExceptionFlushes the writer. Should be used if there aren't any more elements to read.- Throws:
java.io.IOException- If an I/O error occurs
-
getIndentation
protected java.lang.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. IgnorsDUMMY_PARENT.- Returns:
- The direct parent or null in case of an element from the top layer.
-
getParent
protected <T extends IModelElement> T getParent(java.lang.Class<T> type)
Returns the latest parent with the giventype.- 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
typeorgetParent()iftype==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:
trueif comments are emitted,falseelse
-
printDefaultSpace
protected abstract void printDefaultSpace(AbstractVarModelWriter.DefaultSpace location)
Prints default spaces.- Parameters:
location- the intended location of the space
-
processVersion
protected abstract void processVersion(Version version)
Processes a version information.- Parameters:
version- the version to be processed
-
visitProject
public void visitProject(Project project)
Description copied from interface:IModelVisitorMethod for visiting a project.- Specified by:
visitProjectin interfaceIModelVisitor- Overrides:
visitProjectin classAbstractVisitor- Parameters:
project- The project which should be visited.
-
visitOrderedEnum
public void visitOrderedEnum(OrderedEnum eenum)
Method for visiting an orded enum.- Specified by:
visitOrderedEnumin interfaceICustomDatatypeVisitor- Overrides:
visitOrderedEnumin classAbstractVisitor- Parameters:
eenum- The enum which should be visited.
-
visitCompound
public void visitCompound(Compound compound)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a compound.- Specified by:
visitCompoundin interfaceICustomDatatypeVisitor- Overrides:
visitCompoundin classAbstractVisitor- Parameters:
compound- The compound which should be visited.
-
visitAttributeAssignment
public void visitAttributeAssignment(AttributeAssignment assignment)
Description copied from interface:IModelVisitorVisits an attribute assignment.- Specified by:
visitAttributeAssignmentin interfaceIModelVisitor- 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:IConstraintTreeVisitorVisits a constant value.- Specified by:
visitConstantValuein interfaceIConstraintTreeVisitor- Parameters:
value- the value which should be visited
-
visitConstraintValue
public void visitConstraintValue(ConstraintValue value)
Description copied from interface:IValueVisitorThis method is used for visiting ConstraintValue.- Specified by:
visitConstraintValuein interfaceIValueVisitor- Parameters:
value- One ConstraintValue which should be visited.
-
visitConstraint
public void visitConstraint(Constraint constraint)
Description copied from interface:IModelVisitorMethod for visiting a constraint.- Specified by:
visitConstraintin interfaceIModelVisitor- 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 contextconstraint- the (specified) constraint;
-
visitPartialEvaluationBlock
public void visitPartialEvaluationBlock(PartialEvaluationBlock block)
Description copied from interface:IModelVisitorMethod for visiting a partial evaluation block.- Specified by:
visitPartialEvaluationBlockin interfaceIModelVisitor- Parameters:
block- The partial evaluation block which should be visited.
-
visitFreezeBlock
public void visitFreezeBlock(FreezeBlock freeze)
Description copied from interface:IModelVisitorMethod for visiting a freeze block.- Specified by:
visitFreezeBlockin interfaceIModelVisitor- Parameters:
freeze- The freeze block which should be visited.
-
visitUnresolvedExpression
public void visitUnresolvedExpression(UnresolvedExpression expression)
Description copied from interface:IConstraintTreeVisitorVisits 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 atUnresolvedExpression.getActualExpression().- Specified by:
visitUnresolvedExpressionin interfaceIConstraintTreeVisitor- Parameters:
expression- the expression
-
beforeNestedElement
protected void beforeNestedElement(java.lang.Object element)
This method is called before a nested element is emitted. This enables the output of comments before theelementetc.- Parameters:
element- the element (no specific type needed, seeComment
-
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:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getParentCount()
-
increaseAdditionalIndentation
protected void increaseAdditionalIndentation()
Increases the additional indentation.
-
decreaseAdditionalIndentation
protected void decreaseAdditionalIndentation()
Decreases the additional indentation.
-
getLogger
protected EASyLoggerFactory.EASyLogger getLogger()
Returns the actual logger instance.- Returns:
- the logger instance
-
-