Class ProjectCopyVisitor
java.lang.Object
net.ssehub.easy.varModel.model.AbstractProjectVisitor
net.ssehub.easy.varModel.model.rewrite.ProjectCopyVisitor
- All Implemented Interfaces:
ICustomDatatypeVisitor,IModelVisitor
Creates a deep copy of a
This visitor may change the ordering of elements inside the copied projects as it tries first to copy all elements, which do not conflict and retries to copy depending elements after needed elements have been copied. For instance:
Project. This visitor may change the ordering of elements inside the copied projects as it tries first to copy all elements, which do not conflict and retries to copy depending elements after needed elements have been copied. For instance:
project p {
CP1 decl;
compound CP1 {}
}
will be translated to
project p {
compound CP1 {}
CP1 decl;
}
- Author:
- El-Sharkawy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<AbstractVariable, AbstractVariable> Sub set ofcopiedElementswith (oldDeclaration, copiedDeclaration).Tuple of (oldElement, copiedElement) containing the mapping of copied model elements.private ProjectThe copied projects (starting point).Tuple of (oldProject, copiedProject) containing the mapping of copied projects.private IFreezable[]Temporary frozen elements, needed for creatingFreezeVariableType.private booleanprivate UncopiedElementsContainerStores elements which could not be copied (completely).private Deque<IModelElement> Already translated model elements, which should be used as current parent of a model element.Dirty but needed forgetTranslatedType(IDatatype): Tuple of (original project type, copied project).private booleanprivate booleanIndicates that the currently visited elements shall not be added to the current parent, i.e., are local elements. -
Constructor Summary
ConstructorsConstructorDescriptionProjectCopyVisitor(Project originProject, FilterType filterType) Sole constructor for creating a copy of aProject. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddToCurrentParent(ContainableModelElement copiedElement) Adds the copied element to the current parent (parents, considering needed class casts.private voidaddToParent(ContainableModelElement copiedElement, IModelElement parent) Adds the specified element to the given parent.private booleanbuildParents(IModelElement orgElement) Fills up theparentsstack in the correct order for elements which are copied at the end of the visitation process as part of thevisitProject(Project)method.private voidcopyDefaultValue(AbstractVariable decl, AbstractVariable copiedDecl) Copies the default value from the original declaration to the copied declaration.Returns a set of all copied projects (including copies of imported projects).(package private) ICustomOperationAccessorgetCopiedAccessor(ICustomOperationAccessor orgAccessor) Returns a copiedICustomOperationAccessorfor the given original accessor.(package private) ContainableModelElementgetCopiedElement(ContainableModelElement orgElement) Returns a copied element if it was copied already.(package private) IModelElementgetCopiedParent(IModelElement orgParent) Returns the copied parent (should only be used by theCSTCopyVisitor).Returns the copy of the visited project.(package private) Map<AbstractVariable, AbstractVariable> Returns the currently copied declarations, must not be modified from out side.private IDatatypegetTranslatedContainer(Container originalType) Part ofgetTranslatedType(IDatatype): Returns the translated type for containers.(package private) IDatatypegetTranslatedType(IDatatype originalType) Returns the copiedIDatatypefor the given one.Maybe called after visiting to verify that all elements could successfully be copied.private voidTries to translate elements at the end of the visitation, which could not be translated during the regular visitation, because of missing elements.private booleanPart of the end of the coping: Tries to fixAttributeAssignment.Assignments of incomplete copiedAttributeAssignments.private booleanPart of the end of the coping: Tries to fixConstraintSyntaxTrees of incomplete copiedOperationDefinitions.private booleanPart of the end of the coping: Tries to fix csts of incomplete copiedAbstractVariables and Constraints.private booleanretryCopy(Iterator<? extends IModelElement> itr) Retries to copy not copied, original elements.private voidsetComment(ContainableModelElement copiedElement, ContainableModelElement originalElement) Helper method for copying the comment from the original to the copied element.voidvisitAttribute(Attribute attribute) Method for visiting an attribute.voidvisitAttributeAssignment(AttributeAssignment assignment) Visits an attribute assignment.voidvisitComment(Comment comment) Method for visiting a comment.voidvisitCompound(Compound compound) Method for visiting a compound.voidVisits a compound access statement (may occur in freeze blocks.voidvisitConstraint(Constraint constraint) Method for visiting a constraint.voidThis method is used for visiting a decision variable declaration.voidvisitDerivedDatatype(DerivedDatatype datatype) Method for visiting a derived datatype.voidMethod for visiting an enum.voidvisitEnumLiteral(EnumLiteral literal) Method for visiting an enum literal.voidvisitFreezeBlock(FreezeBlock freeze) Method for visiting a freeze block.voidMethod for visiting an operation definition.voidvisitOrderedEnum(OrderedEnum eenum) Method for visiting an ordered enum.voidMethod for visiting a partial evaluation block.voidvisitProject(Project project) Method for visiting a project.voidvisitProjectImport(ProjectImport pImport) This method is used for visiting a ProjectImport.voidMethod for visiting a project interface.voidvisitReference(Reference reference) Method for visiting a reference.voidvisitSequence(Sequence sequence) Method for visiting a sequence.voidMethod for visiting a set.Methods inherited from class net.ssehub.easy.varModel.model.AbstractProjectVisitor
clear, getFilterType, getStartingProject
-
Field Details
-
copiedProjects
Tuple of (oldProject, copiedProject) containing the mapping of copied projects. -
copiedElements
Tuple of (oldElement, copiedElement) containing the mapping of copied model elements. Needed for building parents and references, and to check whether an element was already copied or not. -
copiedDeclarations
Sub set ofcopiedElementswith (oldDeclaration, copiedDeclaration). This map is useful for theCSTCopyVisitor. -
incompleteElements
Stores elements which could not be copied (completely). -
parents
Already translated model elements, which should be used as current parent of a model element. Used as a Stack. -
copiedProject
The copied projects (starting point). Will be null if only imports are translated. -
visitLocalElements
private boolean visitLocalElementsIndicates that the currently visited elements shall not be added to the current parent, i.e., are local elements.true: Elements shall not be addedfalse: Usual behavior -
projectTypes
Dirty but needed forgetTranslatedType(IDatatype): Tuple of (original project type, copied project). -
currentlyFrozen
Temporary frozen elements, needed for creatingFreezeVariableType. Not fine, but this is needed to transfer these elements from one visitation method to another were its needed. Needed to create the data type for the selectorDecisionVariableDeclarationwhile visiting aFreezeBlock. -
frozenElementsOK
private boolean frozenElementsOK -
restranslationSucceeded
private boolean restranslationSucceeded
-
-
Constructor Details
-
ProjectCopyVisitor
Sole constructor for creating a copy of aProject.- Parameters:
originProject- The project where the visiting shall startfilterType- Specifies whether project imports shall be considered or not. All considered projects (and imports) will be deep copied.
-
-
Method Details
-
getCopiedElement
Returns a copied element if it was copied already.- Parameters:
orgElement- The original element, which should be copied- Returns:
- The copied element or null if it was not copied so far.
-
getCopiedParent
Returns the copied parent (should only be used by theCSTCopyVisitor).- Parameters:
orgParent- The original parent of an element which needs to be copied on the fly outside of this visitor.- Returns:
- The copied parent, a
Project, aContainableModelElement, or null if it was not copied so far.
-
getDeclarationMapping
Map<AbstractVariable,AbstractVariable> getDeclarationMapping()Returns the currently copied declarations, must not be modified from out side.- Returns:
- An unmodifiable map of (original element, copied element).
-
getCopiedAccessor
Returns a copiedICustomOperationAccessorfor the given original accessor.- Parameters:
orgAccessor- An original accessor, must not be null.- Returns:
- The copied accessor or null if it was not copied so far.
-
visitProjectImport
Description copied from interface:IModelVisitorThis method is used for visiting a ProjectImport.- Specified by:
visitProjectImportin interfaceIModelVisitor- Overrides:
visitProjectImportin classAbstractProjectVisitor- Parameters:
pImport- One ProjectImport which should be visited.
-
visitProject
Description copied from interface:IModelVisitorMethod for visiting a project.- Specified by:
visitProjectin interfaceIModelVisitor- Overrides:
visitProjectin classAbstractProjectVisitor- Parameters:
project- The project which should be visited.
-
reCopyUnresolvedElements
private void reCopyUnresolvedElements()Tries to translate elements at the end of the visitation, which could not be translated during the regular visitation, because of missing elements. -
resolveUncopyableCSTs
private boolean resolveUncopyableCSTs()Part of the end of the coping: Tries to fix csts of incomplete copiedAbstractVariables and Constraints.- Returns:
trueif at least one element was resolved,falseno elements have been resolved, maybe because there was nothing to do.
-
resolveIncompleteAssignBlocks
private boolean resolveIncompleteAssignBlocks()Part of the end of the coping: Tries to fixAttributeAssignment.Assignments of incomplete copiedAttributeAssignments.- Returns:
trueif at least one element was resolved,falseno elements have been resolved, maybe because there was nothing to do.
-
resolveIncompleteOperations
private boolean resolveIncompleteOperations()Part of the end of the coping: Tries to fixConstraintSyntaxTrees of incomplete copiedOperationDefinitions.- Returns:
trueif at least one element was resolved,falseno elements have been resolved, maybe because there was nothing to do.
-
retryCopy
Retries to copy not copied, original elements. Part of the end of the copying process.- Parameters:
itr- An iterator ofincompleteElements, pointing to original elements, which could not be copied.- Returns:
trueif at least one element was resolved,falseno elements have been resolved, maybe because there was nothing to do.
-
buildParents
Fills up theparentsstack in the correct order for elements which are copied at the end of the visitation process as part of thevisitProject(Project)method. This cleans up the current parent stack before filling it up with the currently needed parents.- Parameters:
orgElement- The element which shall be copied in the next step, for which the parent stack shall be filled correctly.- Returns:
trueif the copied parents could be retrieved correctly,falseif at least one needed parent was not copied and could not be added to the parent stack (in this case the stack is cleaned up).
-
getCopiedProject
Returns the copy of the visited project. This is the starting projects for all copied (imported) projects.
Please note that this will only return any results if the original project was visited by this visitor.- Returns:
- The copied project or null if
FilterType.ONLY_IMPORTSwas passed to this constructor.
-
getUncopiedElements
Maybe called after visiting to verify that all elements could successfully be copied.- Returns:
- A list of failing elements, should be empty if copying was successful.
-
getAllCopiedProjects
Returns a set of all copied projects (including copies of imported projects).- Returns:
- All copied projects.
-
addToCurrentParent
Adds the copied element to the current parent (parents, considering needed class casts.- Parameters:
copiedElement- The copied element to add to the current parent.
-
addToParent
Adds the specified element to the given parent.- Parameters:
copiedElement- The element, which shall be added to the parent (considervisitLocalElements).parent- The parent where to add the element.
-
getTranslatedType
Returns the copiedIDatatypefor the given one. -
getTranslatedContainer
Part ofgetTranslatedType(IDatatype): Returns the translated type for containers. -
setComment
private void setComment(ContainableModelElement copiedElement, ContainableModelElement originalElement) Helper method for copying the comment from the original to the copied element. Should be called after creating the copy and before adding it to the parent.- Parameters:
copiedElement- The currently created copyoriginalElement- The original from which the copy is created from.
-
visitDecisionVariableDeclaration
Description copied from interface:IModelVisitorThis method is used for visiting a decision variable declaration.- Parameters:
decl- One declaration which should be visited.
-
copyDefaultValue
Copies the default value from the original declaration to the copied declaration.- Parameters:
decl- The original declaration from where the default value shall be copied from.copiedDecl- The target declaration.
-
visitAttribute
Description copied from interface:IModelVisitorMethod for visiting an attribute.- Parameters:
attribute- The attribute which should be visited.
-
visitConstraint
Description copied from interface:IModelVisitorMethod for visiting a constraint.- Parameters:
constraint- The constraint which should be visited.
-
visitFreezeBlock
Description copied from interface:IModelVisitorMethod for visiting a freeze block.- Parameters:
freeze- The freeze block which should be visited.
-
visitOperationDefinition
Description copied from interface:IModelVisitorMethod for visiting an operation definition.- Parameters:
opdef- The operation definition which should be visited.
-
visitPartialEvaluationBlock
Description copied from interface:IModelVisitorMethod for visiting a partial evaluation block.- Parameters:
block- The partial evaluation block which should be visited.
-
visitProjectInterface
Description copied from interface:IModelVisitorMethod for visiting a project interface.- Parameters:
iface- The interface which should be visited.
-
visitComment
Description copied from interface:IModelVisitorMethod for visiting a comment.- Parameters:
comment- the comment to visit
-
visitAttributeAssignment
Description copied from interface:IModelVisitorVisits an attribute assignment.- Parameters:
assignment- the assignment to visit
-
visitCompoundAccessStatement
Description copied from interface:IModelVisitorVisits a compound access statement (may occur in freeze blocks.- Parameters:
access- the access statement
-
visitEnum
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum.- Parameters:
eenum- The enum which should be visited.
-
visitOrderedEnum
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an ordered enum.- Parameters:
eenum- The enum which should be visited.
-
visitCompound
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a compound.- Parameters:
compound- The compound which should be visited.
-
visitDerivedDatatype
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a derived datatype.- Parameters:
datatype- The datatype which should be visited.
-
visitEnumLiteral
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum literal.- Parameters:
literal- The literal which should be visited.
-
visitReference
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a reference.- Parameters:
reference- The reference which should be visited.
-
visitSequence
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a sequence.- Parameters:
sequence- The sequence which should be visited.
-
visitSet
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a set.- Parameters:
set- The set which should be visited.
-