Package net.ssehub.easy.varModel.cst
Class BasicCopyVisitor
- java.lang.Object
-
- net.ssehub.easy.varModel.cst.BasicCopyVisitor
-
- All Implemented Interfaces:
IConstraintTreeVisitor
- Direct Known Subclasses:
CopyVisitor,SubstitutionVisitor
public class BasicCopyVisitor extends java.lang.Object implements IConstraintTreeVisitor
Implements a basic constraint copy visitor. Allows leaving variable nodes as they are as well as mapping variables (although no mapping happens in this class).- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private booleancopyConstantsprivate booleancopyExpressionsprivate booleancopyVariablesprivate booleandoInferDatatypeprivate ConstraintSyntaxTreeresult
-
Constructor Summary
Constructors Modifier Constructor Description protectedBasicCopyVisitor()Creates a copy visitor leaving variable nodes as they are, copying constants, not inferring types on intermediary expressions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this visitor for reuse.protected booleangetCopyExpressions()Returns whether (partial) expressions shall always be copied or only if needed.protected booleangetCopyVariables()Returns variables shall always be copied or whether instances shall be reused if possible.protected EASyLoggerFactory.EASyLoggergetLogger()Returns the logger.ConstraintSyntaxTreegetResult()Returns the copied syntax tree.protected ConstraintSyntaxTreeinferDatatype(ConstraintSyntaxTree cst)Performs datatype validation if requested.protected AbstractVariablemapVariable(AbstractVariable var)Maps a variable.protected DecisionVariableDeclarationmapVariable(DecisionVariableDeclaration var)Maps a variable.protected voidsetCopyConstants(boolean copyConstants)Defines whetherConstraintSytaxTree#inferDatatypeshall be called on each partial expression.protected voidsetCopyExpressions(boolean copyExpressions)Defines whether (partial) expressions shall always be copied or only if needed.protected voidsetCopyVariables(boolean copyVariables)Defines whether variables shall always be copied or whether instances shall be reused if possible.protected voidsetDoInferDatatype(boolean doInferDatatype)Defines whetherConstraintSytaxTree#inferDatatypeshall be called on each partial expression.protected voidsetResult(ConstraintSyntaxTree cst)Allows inherited classed to overwrite visiting method and to return a partially translated cst.voidvisitAnnotationVariable(AttributeVariable variable)Visits aAttributeVariable.voidvisitBlockExpression(BlockExpression block)Visits the block.voidvisitComment(Comment comment)Visits a comment.voidvisitCompoundAccess(CompoundAccess access)Visits a compound access node.voidvisitCompoundInitializer(CompoundInitializer initializer)Visits a compound initializer.voidvisitConstantValue(ConstantValue value)Visits a constant value.voidvisitContainerInitializer(ContainerInitializer initializer)Visits a container initializer.voidvisitContainerOperationCall(ContainerOperationCall call)Visits a container operation call (e.g.voidvisitDeferInitExpression(DeferInitExpression expression)Visits a default init expression.voidvisitIfThen(IfThen ifThen)Visits an if-then-else expression.voidvisitLet(Let let)Visits a let expression.voidvisitMultiAndExpression(MultiAndExpression expression)Visits a multi-and expression.voidvisitOclFeatureCall(OCLFeatureCall call)Visits an OCL feature call.voidvisitParenthesis(Parenthesis parenthesis)Visits a parenthesis.voidvisitSelf(Self self)Visits self.voidvisitUnresolvedExpression(UnresolvedExpression expression)Visits an unresolved expression.voidvisitVariable(Variable variable)Visits a variable.
-
-
-
Field Detail
-
result
private ConstraintSyntaxTree result
-
copyVariables
private boolean copyVariables
-
doInferDatatype
private boolean doInferDatatype
-
copyConstants
private boolean copyConstants
-
copyExpressions
private boolean copyExpressions
-
-
Method Detail
-
setCopyVariables
protected void setCopyVariables(boolean copyVariables)
Defines whether variables shall always be copied or whether instances shall be reused if possible.- Parameters:
copyVariables- copy variable node instances iftrue, reuse them iffalse
-
getCopyVariables
protected boolean getCopyVariables()
Returns variables shall always be copied or whether instances shall be reused if possible.- Returns:
- copy variable node instances if
true, reuse them iffalse
-
setDoInferDatatype
protected void setDoInferDatatype(boolean doInferDatatype)
Defines whetherConstraintSytaxTree#inferDatatypeshall be called on each partial expression.- Parameters:
doInferDatatype- call/validate the datatypes,falseelse (then caller is required to infer the datatype before usage of the resulting constraint)
-
setCopyConstants
protected void setCopyConstants(boolean copyConstants)
Defines whetherConstraintSytaxTree#inferDatatypeshall be called on each partial expression.- Parameters:
copyConstants- copy all constant nodes (true), reuse constant nodes (false))
-
setCopyExpressions
protected void setCopyExpressions(boolean copyExpressions)
Defines whether (partial) expressions shall always be copied or only if needed.- Parameters:
copyExpressions-truefor copy always,falseelse
-
getCopyExpressions
protected boolean getCopyExpressions()
Returns whether (partial) expressions shall always be copied or only if needed.- Returns:
truefor copy always,falseelse
-
setResult
protected void setResult(ConstraintSyntaxTree cst)
Allows inherited classed to overwrite visiting method and to return a partially translated cst.- Parameters:
cst- A partially copied cst.
-
getResult
public ConstraintSyntaxTree getResult()
Returns the copied syntax tree.- Returns:
- the copied tree (may be null if no tree was visited).
-
clear
public void clear()
Clears this visitor for reuse.
-
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
-
visitVariable
public void visitVariable(Variable variable)
Description copied from interface:IConstraintTreeVisitorVisits a variable.- Specified by:
visitVariablein interfaceIConstraintTreeVisitor- Parameters:
variable- the variable which should be visited
-
mapVariable
protected DecisionVariableDeclaration mapVariable(DecisionVariableDeclaration var)
Maps a variable.- Parameters:
var- the variable to be mapped- Returns:
- the mapped variable or
var
-
mapVariable
protected AbstractVariable mapVariable(AbstractVariable var)
Maps a variable.- Parameters:
var- the variable to be mapped- Returns:
- the mapped variable or
var
-
visitParenthesis
public void visitParenthesis(Parenthesis parenthesis)
Description copied from interface:IConstraintTreeVisitorVisits a parenthesis.- Specified by:
visitParenthesisin interfaceIConstraintTreeVisitor- Parameters:
parenthesis- the parenthesis which should be visited
-
visitComment
public void visitComment(Comment comment)
Description copied from interface:IConstraintTreeVisitorVisits a comment.- Specified by:
visitCommentin interfaceIConstraintTreeVisitor- Parameters:
comment- the comment node which should be visited
-
visitOclFeatureCall
public void visitOclFeatureCall(OCLFeatureCall call)
Description copied from interface:IConstraintTreeVisitorVisits an OCL feature call.- Specified by:
visitOclFeatureCallin interfaceIConstraintTreeVisitor- Parameters:
call- the feature call which should be visited
-
visitMultiAndExpression
public void visitMultiAndExpression(MultiAndExpression expression)
Description copied from interface:IConstraintTreeVisitorVisits a multi-and expression.- Specified by:
visitMultiAndExpressionin interfaceIConstraintTreeVisitor- Parameters:
expression- the expression to be visited
-
visitDeferInitExpression
public void visitDeferInitExpression(DeferInitExpression expression)
Visits a default init expression.- Specified by:
visitDeferInitExpressionin interfaceIConstraintTreeVisitor- Parameters:
expression- the expression
-
visitLet
public void visitLet(Let let)
Description copied from interface:IConstraintTreeVisitorVisits a let expression.- Specified by:
visitLetin interfaceIConstraintTreeVisitor- Parameters:
let- the let expression which should be visited
-
visitIfThen
public void visitIfThen(IfThen ifThen)
Description copied from interface:IConstraintTreeVisitorVisits an if-then-else expression.- Specified by:
visitIfThenin interfaceIConstraintTreeVisitor- Parameters:
ifThen- the if-then-else expression which should be visited
-
visitContainerOperationCall
public void visitContainerOperationCall(ContainerOperationCall call)
Description copied from interface:IConstraintTreeVisitorVisits a container operation call (e.g. quantors, iterators).- Specified by:
visitContainerOperationCallin interfaceIConstraintTreeVisitor- Parameters:
call- the container operation call
-
visitCompoundAccess
public void visitCompoundAccess(CompoundAccess access)
Description copied from interface:IConstraintTreeVisitorVisits a compound access node.- Specified by:
visitCompoundAccessin interfaceIConstraintTreeVisitor- Parameters:
access- the compound access node
-
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
-
visitCompoundInitializer
public void visitCompoundInitializer(CompoundInitializer initializer)
Description copied from interface:IConstraintTreeVisitorVisits a compound initializer.- Specified by:
visitCompoundInitializerin interfaceIConstraintTreeVisitor- Parameters:
initializer- the compound initializer node
-
visitContainerInitializer
public void visitContainerInitializer(ContainerInitializer initializer)
Description copied from interface:IConstraintTreeVisitorVisits a container initializer.- Specified by:
visitContainerInitializerin interfaceIConstraintTreeVisitor- Parameters:
initializer- the container initializer node
-
visitSelf
public void visitSelf(Self self)
Description copied from interface:IConstraintTreeVisitorVisits self.- Specified by:
visitSelfin interfaceIConstraintTreeVisitor- Parameters:
self- the self object to visit
-
visitAnnotationVariable
public void visitAnnotationVariable(AttributeVariable variable)
Description copied from interface:IConstraintTreeVisitorVisits aAttributeVariable.- Specified by:
visitAnnotationVariablein interfaceIConstraintTreeVisitor- Parameters:
variable- the attribute variable which should be visited
-
visitBlockExpression
public void visitBlockExpression(BlockExpression block)
Description copied from interface:IConstraintTreeVisitorVisits the block.- Specified by:
visitBlockExpressionin interfaceIConstraintTreeVisitor- Parameters:
block- the block to be visited
-
inferDatatype
protected ConstraintSyntaxTree inferDatatype(ConstraintSyntaxTree cst)
Performs datatype validation if requested.- Parameters:
cst- the constraint expression to perform the validation on- Returns:
cst- Throws:
CSTSemanticException- if validation fails
-
getLogger
protected EASyLoggerFactory.EASyLogger getLogger()
Returns the logger.- Returns:
- the logger
-
-