Class ProjectCopyVisitor
- java.lang.Object
-
- net.ssehub.easy.varModel.model.AbstractProjectVisitor
-
- net.ssehub.easy.varModel.model.rewrite.ProjectCopyVisitor
-
- All Implemented Interfaces:
ICustomDatatypeVisitor,IModelVisitor
public class ProjectCopyVisitor extends AbstractProjectVisitor
Creates a deep copy of aProject.
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:
will be translated toproject p { CP1 decl; compound CP1 {} }project p { compound CP1 {} CP1 decl; }- Author:
- El-Sharkawy
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<AbstractVariable,AbstractVariable>copiedDeclarationsSub set ofcopiedElementswith (oldDeclaration, copiedDeclaration).private java.util.Map<ContainableModelElement,ContainableModelElement>copiedElementsTuple of (oldElement, copiedElement) containing the mapping of copied model elements.private ProjectcopiedProjectThe copied projects (starting point).private java.util.Map<Project,Project>copiedProjectsTuple of (oldProject, copiedProject) containing the mapping of copied projects.private IFreezable[]currentlyFrozenTemporary frozen elements, needed for creatingFreezeVariableType.private booleanfrozenElementsOKprivate UncopiedElementsContainerincompleteElementsStores elements which could not be copied (completely).private java.util.Deque<IModelElement>parentsAlready translated model elements, which should be used as current parent of a model element.private java.util.Map<IDatatype,Project>projectTypesDirty but needed forgetTranslatedType(IDatatype): Tuple of (original project type, copied project).private booleanrestranslationSucceededprivate booleanvisitLocalElementsIndicates that the currently visited elements shall not be added to the current parent, i.e., are local elements.
-
Constructor Summary
Constructors Constructor Description ProjectCopyVisitor(Project originProject, FilterType filterType)Sole constructor for creating a copy of aProject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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.java.util.Set<Project>getAllCopiedProjects()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).ProjectgetCopiedProject()Returns the copy of the visited project.(package private) java.util.Map<AbstractVariable,AbstractVariable>getDeclarationMapping()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.java.util.List<UncopiedElement>getUncopiedElements()Maybe called after visiting to verify that all elements could successfully be copied.private voidreCopyUnresolvedElements()Tries to translate elements at the end of the visitation, which could not be translated during the regular visitation, because of missing elements.private booleanresolveIncompleteAssignBlocks()Part of the end of the coping: Tries to fixAttributeAssignment.Assignments of incomplete copiedAttributeAssignments.private booleanresolveIncompleteOperations()Part of the end of the coping: Tries to fixConstraintSyntaxTrees of incomplete copiedOperationDefinitions.private booleanresolveUncopyableCSTs()Part of the end of the coping: Tries to fix csts of incomplete copiedAbstractVariables and Constraints.private booleanretryCopy(java.util.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.voidvisitCompoundAccessStatement(CompoundAccessStatement access)Visits a compound access statement (may occur in freeze blocks.voidvisitConstraint(Constraint constraint)Method for visiting a constraint.voidvisitDecisionVariableDeclaration(DecisionVariableDeclaration decl)This method is used for visiting a decision variable declaration.voidvisitDerivedDatatype(DerivedDatatype datatype)Method for visiting a derived datatype.voidvisitEnum(Enum eenum)Method for visiting an enum.voidvisitEnumLiteral(EnumLiteral literal)Method for visiting an enum literal.voidvisitFreezeBlock(FreezeBlock freeze)Method for visiting a freeze block.voidvisitOperationDefinition(OperationDefinition opdef)Method for visiting an operation definition.voidvisitOrderedEnum(OrderedEnum eenum)Method for visiting an ordered enum.voidvisitPartialEvaluationBlock(PartialEvaluationBlock block)Method 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.voidvisitProjectInterface(ProjectInterface iface)Method for visiting a project interface.voidvisitReference(Reference reference)Method for visiting a reference.voidvisitSequence(Sequence sequence)Method for visiting a sequence.voidvisitSet(Set set)Method for visiting a set.-
Methods inherited from class net.ssehub.easy.varModel.model.AbstractProjectVisitor
clear, getFilterType, getStartingProject
-
-
-
-
Field Detail
-
copiedProjects
private java.util.Map<Project,Project> copiedProjects
Tuple of (oldProject, copiedProject) containing the mapping of copied projects.
-
copiedElements
private java.util.Map<ContainableModelElement,ContainableModelElement> 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
private java.util.Map<AbstractVariable,AbstractVariable> copiedDeclarations
Sub set ofcopiedElementswith (oldDeclaration, copiedDeclaration). This map is useful for theCSTCopyVisitor.
-
incompleteElements
private UncopiedElementsContainer incompleteElements
Stores elements which could not be copied (completely).
-
parents
private java.util.Deque<IModelElement> parents
Already translated model elements, which should be used as current parent of a model element. Used as a Stack.
-
copiedProject
private Project copiedProject
The copied projects (starting point). Will be null if only imports are translated.
-
visitLocalElements
private boolean visitLocalElements
Indicates that the currently visited elements shall not be added to the current parent, i.e., are local elements. true: Elements shall not be added false: Usual behavior
-
projectTypes
private java.util.Map<IDatatype,Project> projectTypes
Dirty but needed forgetTranslatedType(IDatatype): Tuple of (original project type, copied project).
-
currentlyFrozen
private IFreezable[] 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 Detail
-
ProjectCopyVisitor
public ProjectCopyVisitor(Project originProject, FilterType filterType)
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 Detail
-
getCopiedElement
ContainableModelElement getCopiedElement(ContainableModelElement orgElement)
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
IModelElement getCopiedParent(IModelElement orgParent)
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
java.util.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
ICustomOperationAccessor getCopiedAccessor(ICustomOperationAccessor orgAccessor)
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
public void visitProjectImport(ProjectImport pImport)
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
public void visitProject(Project project)
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:
- true if at least one element was resolved, false no 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:
- true if at least one element was resolved, false no 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:
- true if at least one element was resolved, false no elements have been resolved, maybe because there was nothing to do.
-
retryCopy
private boolean retryCopy(java.util.Iterator<? extends IModelElement> itr)
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:
- true if at least one element was resolved, false no elements have been resolved, maybe because there was nothing to do.
-
buildParents
private boolean buildParents(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. 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:
- true if the copied parents could be retrieved correctly, false if 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
public Project 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
public java.util.List<UncopiedElement> 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
public java.util.Set<Project> getAllCopiedProjects()
Returns a set of all copied projects (including copies of imported projects).- Returns:
- All copied projects.
-
addToCurrentParent
private void addToCurrentParent(ContainableModelElement copiedElement)
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
private void addToParent(ContainableModelElement copiedElement, IModelElement parent)
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
IDatatype getTranslatedType(IDatatype originalType)
Returns the copiedIDatatypefor the given one.
-
getTranslatedContainer
private IDatatype getTranslatedContainer(Container originalType)
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
public void visitDecisionVariableDeclaration(DecisionVariableDeclaration decl)
Description copied from interface:IModelVisitorThis method is used for visiting a decision variable declaration.- Parameters:
decl- One declaration which should be visited.
-
copyDefaultValue
private void copyDefaultValue(AbstractVariable decl, AbstractVariable copiedDecl)
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
public void visitAttribute(Attribute attribute)
Description copied from interface:IModelVisitorMethod for visiting an attribute.- Parameters:
attribute- The attribute which should be visited.
-
visitConstraint
public void visitConstraint(Constraint constraint)
Description copied from interface:IModelVisitorMethod for visiting a constraint.- Parameters:
constraint- The constraint which should be visited.
-
visitFreezeBlock
public void visitFreezeBlock(FreezeBlock freeze)
Description copied from interface:IModelVisitorMethod for visiting a freeze block.- Parameters:
freeze- The freeze block which should be visited.
-
visitOperationDefinition
public void visitOperationDefinition(OperationDefinition opdef)
Description copied from interface:IModelVisitorMethod for visiting an operation definition.- Parameters:
opdef- The operation definition which should be visited.
-
visitPartialEvaluationBlock
public void visitPartialEvaluationBlock(PartialEvaluationBlock block)
Description copied from interface:IModelVisitorMethod for visiting a partial evaluation block.- Parameters:
block- The partial evaluation block which should be visited.
-
visitProjectInterface
public void visitProjectInterface(ProjectInterface iface)
Description copied from interface:IModelVisitorMethod for visiting a project interface.- Parameters:
iface- The interface which should be visited.
-
visitComment
public void visitComment(Comment comment)
Description copied from interface:IModelVisitorMethod for visiting a comment.- Parameters:
comment- the comment to visit
-
visitAttributeAssignment
public void visitAttributeAssignment(AttributeAssignment assignment)
Description copied from interface:IModelVisitorVisits an attribute assignment.- Parameters:
assignment- the assignment to visit
-
visitCompoundAccessStatement
public void visitCompoundAccessStatement(CompoundAccessStatement access)
Description copied from interface:IModelVisitorVisits a compound access statement (may occur in freeze blocks.- Parameters:
access- the access statement
-
visitEnum
public void visitEnum(Enum eenum)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum.- Parameters:
eenum- The enum which should be visited.
-
visitOrderedEnum
public void visitOrderedEnum(OrderedEnum eenum)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an ordered enum.- Parameters:
eenum- The enum which should be visited.
-
visitCompound
public void visitCompound(Compound compound)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a compound.- Parameters:
compound- The compound which should be visited.
-
visitDerivedDatatype
public void visitDerivedDatatype(DerivedDatatype datatype)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a derived datatype.- Parameters:
datatype- The datatype which should be visited.
-
visitEnumLiteral
public void visitEnumLiteral(EnumLiteral literal)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum literal.- Parameters:
literal- The literal which should be visited.
-
visitReference
public void visitReference(Reference reference)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a reference.- Parameters:
reference- The reference which should be visited.
-
visitSequence
public void visitSequence(Sequence sequence)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a sequence.- Parameters:
sequence- The sequence which should be visited.
-
visitSet
public void visitSet(Set set)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a set.- Parameters:
set- The set which should be visited.
-
-