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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumDefines default space locations. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprotected static final ModelElementDefines a dummy model element for additional formatting.private IModelElementprivate static StringThe number of whitespaces per indentation (ifuseWhitespaceis enabled), otherwise one tab is inserted.private Stringprivate booleanprivate static booleanDetect, warn, report about and write to avoid OCL compliance problems.private WriterThis attribute should be used for storing the output.private List<IModelElement> Stores the all parents of the currently visited element.
Can be an empty list in case of root elements.private static booleanUse whitespaces or tabs. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractVarModelWriter(Writer writer) Sole constructor for this class. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddParent(IModelElement parent) Adds the given element to the list of all parents.protected final voidMethod to append the current indentation.protected final voidappendOutput(char appendableOutput) Method to append the output.protected final voidappendOutput(String appendableOutput) Method to append the output.protected voidbeforeNestedElement(Object element) This method is called before a nested element is emitted.static booleanReturns whether OCL compliance shall be considered.protected voidDecreases the additional indentation.private static StringderiveIndentStep(int count) Creates the indentation step in terms of numbers of spaces to be used.abstract booleanReturns 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.final voidflush()Flushes the writer.protected IModelElementReturns the expression context.protected StringBufferReturns the current indentation for (nested) elements.static StringReturn the indent-step for ivml.protected net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLoggerReturns the actual logger instance.protected IModelElementReturns the direct parent of the current visited object.protected IModelElementgetParent(int index) Returns the specified hierarchically visited parent.protected <T extends IModelElement>
TReturns the latest parent with the giventype.protected intReturns the number of hierarchically visited parents.static booleanDefines whether whitespaces or tabs shall be used for indentation.Returns the actual writer.protected voidIncreases the additional indentation.protected abstract voidPrints default spaces.protected abstract voidprocessVersion(net.ssehub.easy.basics.modelManagement.Version version) Processes a version information.protected voidRemoves 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.voidChanges 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.voidThis method is used for visiting ConstraintValue.voidvisitFreezeBlock(FreezeBlock freeze) Method for visiting a freeze block.voidvisitOrderedEnum(OrderedEnum eenum) Method for visiting an orded enum.voidMethod 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
visitEnumMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
visitAnnotationVariable, visitBlockExpression, visitComment, visitCompoundAccess, visitCompoundInitializer, visitContainerInitializer, visitContainerOperationCall, visitDeferInitExpression, visitIfThen, visitLet, visitMultiAndExpression, visitOclFeatureCall, visitParenthesis, visitSelf, visitVariableMethods inherited from interface net.ssehub.easy.varModel.model.datatypes.ICustomDatatypeVisitor
visitDerivedDatatype, visitEnumLiteral, visitReference, visitSequence, visitSetMethods inherited from interface net.ssehub.easy.varModel.model.IModelVisitor
visitAttribute, visitComment, visitCompoundAccessStatement, visitDecisionVariableDeclaration, visitOperationDefinition, visitProjectImport, visitProjectInterfaceMethods inherited from interface net.ssehub.easy.varModel.model.values.IValueVisitor
visitBooleanValue, visitCompoundValue, visitContainerValue, visitEnumValue, visitIntValue, visitMetaTypeValue, visitNullValue, visitRealValue, visitReferenceValue, visitStringValue, visitVersionValue
-
Field Details
-
DUMMY_PARENT
Defines a dummy model element for additional formatting. -
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 useWhitespaceUse 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 oclComplianceDetect, warn, report about and write to avoid OCL compliance problems. -
myIndentStep
-
myUseWhitespace
private boolean myUseWhitespace -
additionalIndentation
private int additionalIndentation -
parents
Stores the all parents of the currently visited element.
Can be an empty list in case of root elements. -
out
This attribute should be used for storing the output. -
expressionContext
-
-
Constructor Details
-
AbstractVarModelWriter
Sole constructor for this class.- Parameters:
writer- Writer which should be used for writing the output.
-
-
Method Details
-
setExpressionContext
Changes the expression context.- Parameters:
expressionContext- the expression context
-
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
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
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
Changes the writer. (for reuse)- Parameters:
writer- the new writer
-
getWriter
Returns the actual writer.- Returns:
- the actual writer
-
appendOutput
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
Flushes the writer. Should be used if there aren't any more elements to read.- Throws:
IOException- If an I/O error occurs
-
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
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
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
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
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
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
Method for visiting an orded enum.- Specified by:
visitOrderedEnumin interfaceICustomDatatypeVisitor- Overrides:
visitOrderedEnumin classAbstractVisitor- Parameters:
eenum- The enum which should be visited.
-
visitCompound
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
Description copied from interface:IModelVisitorVisits an attribute assignment.- Specified by:
visitAttributeAssignmentin interfaceIModelVisitor- Parameters:
assignment- the assignment to visit
-
startWritingCompound
Method for writing a compound, first part.- Parameters:
compound- The compound which should be saved.
-
endWritingCompound
Method for writing a compound, second part.- Parameters:
compound- The compound which should be saved.
-
startWritingProject
Method for writing a project, first part.- Parameters:
project- The project which should be saved.
-
endWritingProject
Method for writing a project, second part.- Parameters:
project- The project which should be saved.
-
visitConstantValue
Description copied from interface:IConstraintTreeVisitorVisits a constant value.- Specified by:
visitConstantValuein interfaceIConstraintTreeVisitor- Parameters:
value- the value which should be visited
-
visitConstraintValue
Description copied from interface:IValueVisitorThis method is used for visiting ConstraintValue.- Specified by:
visitConstraintValuein interfaceIValueVisitor- Parameters:
value- One ConstraintValue which should be visited.
-
visitConstraint
Description copied from interface:IModelVisitorMethod for visiting a constraint.- Specified by:
visitConstraintin interfaceIModelVisitor- Parameters:
constraint- The constraint which should be visited.
-
emitConstraintExpression
Visits the expression of a constraint (for extension).- Parameters:
context- the visiting contextconstraint- the (specified) constraint;
-
visitPartialEvaluationBlock
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
Description copied from interface:IModelVisitorMethod for visiting a freeze block.- Specified by:
visitFreezeBlockin interfaceIModelVisitor- Parameters:
freeze- The freeze block which should be visited.
-
visitUnresolvedExpression
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
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
Returns the specified hierarchically visited parent.- Parameters:
index- the 0-based index of the visited parent- Returns:
- the specified visited parent
- Throws:
IndexOutOfBoundsException- ifindex < 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
-