Class ProjectRewriteVisitor
java.lang.Object
net.ssehub.easy.varModel.model.rewrite.ProjectRewriteVisitor
- All Implemented Interfaces:
ICustomDatatypeVisitor,IModelVisitor
Visitor for modifying a (copied) project.
This can be used to filter a project for specific demands, e.g., a
This visitor modifies the given project. For this reason, it is recommended to use the
Usage
Project without constraints containing
frozen variables.This visitor modifies the given project. For this reason, it is recommended to use the
ProjectCopyVisitor
before to create a copy first. Usage
- Create visitor for the desired
Projectand specify whether imported projects shall also be rewritten (cf.FilterType) - Add desired
IModelElementFilterandProjectImportfilters - Call
Project.accept(net.ssehub.easy.varModel.model.IModelVisitor) - project will be affected through this visitation and should not be saved.
Project project = ...
Configuration config = new Configuration(project); // Needed for some filter
ProjectRewriteVisitor rewriter = new ProjectRewriteVisitor(project, FilterType.ALL);
rewriter.addModelCopyModifier(new ModelElementFilter(Comment.class));
rewriter.addModelCopyModifier(new FrozenConstraintsFilter(config));
rewriter.addModelCopyModifier(new FrozenTypeDefResolver(config));
rewriter.addModelCopyModifier(new FrozenConstraintVarFilter(config));
rewriter.addModelCopyModifier(new FrozenCompoundConstraintsOmitter(config));
project.accept(rewriter);
- Author:
- El-Sharkawy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate RewriteContextprivate Projectprivate FilterTypeSpecifies whether project imports shall be considered or not.private List<IProjectImportFilter> private Map<Class<? extends ModelElement>, List<IModelElementFilter<?>>> private ProjectThe project where the visiting has been started.private List<IProjectModifier> -
Constructor Summary
ConstructorsConstructorDescriptionProjectRewriteVisitor(Project originProject, FilterType filterType) Default constructor for this class. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdds a modified and filtered element to thecurrentProject, part of thefilter(ContainableModelElement)method.voidaddImportModifier(IProjectImportFilter modifier) Adds a new modifier for filteringProjectImports.voidaddModelCopyModifier(IModelElementFilter<? extends ModelElement> modifier) Adds a newIModelElementFilterto thisProjectRewriteVisitor.voidaddProjectModifier(IProjectModifier modifier) Adds a new modifier to modify complete Projects at the end of their visitation.private voidcopyConstraint(Constraint constraint) Copies the given Constraint.private ContainableModelElementfilter(ContainableModelElement original) Method for filtering (and modifying) the originalContainableModelElementusing theIModelElementFilter.voidreset(Project originProject, FilterType filterType) Resets theProjectRewriteVisitorto use it for a new visitation.private voidStarts a new visitation to clean up inconsistent data.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.
-
Field Details
-
originProject
The project where the visiting has been started. -
filterType
Specifies whether project imports shall be considered or not. -
modifiers
-
importModifiers
-
projectModifiers
-
currentProject
-
done
-
context
-
-
Constructor Details
-
ProjectRewriteVisitor
Default constructor for this class.- Parameters:
originProject- The project where the visiting shall startfilterType- Specifies whether project imports shall be considered or not.
-
-
Method Details
-
reset
Resets theProjectRewriteVisitorto use it for a new visitation. This will keep the internal knowledge and, thus, enable the removal of removed elements in other projects.- Parameters:
originProject- The project where the visiting shall startfilterType- Specifies whether project imports shall be considered or not.
-
addModelCopyModifier
Adds a newIModelElementFilterto thisProjectRewriteVisitor. If none was specified for a givenContainableModelElementtype, these kind of elements will be copied. If aIModelElementFilterwas specified the modifier will be applied to each element of the same type. MultipleIModelElementFiltermay be specified for the sameContainableModelElementtype.- Parameters:
modifier- A IModelCopyModifier for a givenContainableModelElementclass, must not be null.
-
addImportModifier
Adds a new modifier for filteringProjectImports.- Parameters:
modifier- A modifier for filteringProjectImports.
-
addProjectModifier
Adds a new modifier to modify complete Projects at the end of their visitation.- Parameters:
modifier- A modifier to change projects.
-
visitDecisionVariableDeclaration
Description copied from interface:IModelVisitorThis method is used for visiting a decision variable declaration.- Specified by:
visitDecisionVariableDeclarationin interfaceIModelVisitor- Parameters:
decl- One declaration which should be visited.
-
visitAttribute
Description copied from interface:IModelVisitorMethod for visiting an attribute.- Specified by:
visitAttributein interfaceIModelVisitor- Parameters:
attribute- The attribute 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.
-
copyConstraint
Copies the given Constraint.- Parameters:
constraint- A constraints, which syntax is not null
-
visitFreezeBlock
Description copied from interface:IModelVisitorMethod for visiting a freeze block.- Specified by:
visitFreezeBlockin interfaceIModelVisitor- Parameters:
freeze- The freeze block which should be visited.
-
visitOperationDefinition
Description copied from interface:IModelVisitorMethod for visiting an operation definition.- Specified by:
visitOperationDefinitionin interfaceIModelVisitor- Parameters:
opdef- The operation definition which should be visited.
-
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.
-
visitProjectInterface
Description copied from interface:IModelVisitorMethod for visiting a project interface.- Specified by:
visitProjectInterfacein interfaceIModelVisitor- Parameters:
iface- The interface which should be visited.
-
visitComment
Description copied from interface:IModelVisitorMethod for visiting a comment.- Specified by:
visitCommentin interfaceIModelVisitor- Parameters:
comment- the comment to visit
-
visitAttributeAssignment
Description copied from interface:IModelVisitorVisits an attribute assignment.- Specified by:
visitAttributeAssignmentin interfaceIModelVisitor- Parameters:
assignment- the assignment to visit
-
visitCompoundAccessStatement
Description copied from interface:IModelVisitorVisits a compound access statement (may occur in freeze blocks.- Specified by:
visitCompoundAccessStatementin interfaceIModelVisitor- Parameters:
access- the access statement
-
visitEnum
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum.- Specified by:
visitEnumin interfaceICustomDatatypeVisitor- Parameters:
eenum- The enum which should be visited.
-
visitOrderedEnum
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an ordered enum.- Specified by:
visitOrderedEnumin interfaceICustomDatatypeVisitor- Parameters:
eenum- The enum which should be visited.
-
visitCompound
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a compound.- Specified by:
visitCompoundin interfaceICustomDatatypeVisitor- Parameters:
compound- The compound which should be visited.
-
visitDerivedDatatype
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a derived datatype.- Specified by:
visitDerivedDatatypein interfaceICustomDatatypeVisitor- Parameters:
datatype- The datatype which should be visited.
-
visitEnumLiteral
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum literal.- Specified by:
visitEnumLiteralin interfaceICustomDatatypeVisitor- Parameters:
literal- The literal which should be visited.
-
visitReference
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a reference.- Specified by:
visitReferencein interfaceICustomDatatypeVisitor- Parameters:
reference- The reference which should be visited.
-
visitSequence
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a sequence.- Specified by:
visitSequencein interfaceICustomDatatypeVisitor- Parameters:
sequence- The sequence which should be visited.
-
visitSet
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a set.- Specified by:
visitSetin interfaceICustomDatatypeVisitor- Parameters:
set- The set which should be visited.
-
filter
Method for filtering (and modifying) the originalContainableModelElementusing theIModelElementFilter. If none is specified for the given element type, the element will be returned without any modification. The returned element must be added to thecurrentProjectthrough theaddCopiedElement(ContainableModelElement)method. This methods are splitted into two methods, to enable further processing between the filtering and the add method, i.e., adapting to thecurrentProject.- Parameters:
original- AContainableModelElementof thecurrentProjectto be filtered (and modified).- Returns:
- The modified instance (maybe the same instance) or null if it was completely filtered.
- See Also:
-
addCopiedElement
Adds a modified and filtered element to thecurrentProject, part of thefilter(ContainableModelElement)method.- Parameters:
copy- The copied instance, maybe null if filtered completely.
-
visitProject
Method for visiting a project.
Attention: This method will modify the visited project as a side effect. If the original project should not be modified, it is necessary to create a copy first via theProjectCopyVisitor.- Specified by:
visitProjectin interfaceIModelVisitor- Parameters:
project- The project which should be visited.
-
revisit
Starts a new visitation to clean up inconsistent data.- Parameters:
project- The original project which was used to start the whole visitation process.
-
visitProjectImport
Description copied from interface:IModelVisitorThis method is used for visiting a ProjectImport.- Specified by:
visitProjectImportin interfaceIModelVisitor- Parameters:
pImport- One ProjectImport which should be visited.
-