Class ProjectRewriteVisitor
- java.lang.Object
-
- net.ssehub.easy.varModel.model.rewrite.ProjectRewriteVisitor
-
- All Implemented Interfaces:
ICustomDatatypeVisitor,IModelVisitor
public class ProjectRewriteVisitor extends java.lang.Object implements IModelVisitor
Visitor for modifying a (copied) project. This can be used to filter a project for specific demands, e.g., aProjectwithout constraints containing frozen variables.
This visitor modifies the given project. For this reason, it is recommended to use theProjectCopyVisitorbefore 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
Fields Modifier and Type Field Description private RewriteContextcontextprivate ProjectcurrentProjectprivate java.util.Set<Project>doneprivate FilterTypefilterTypeSpecifies whether project imports shall be considered or not.private java.util.List<IProjectImportFilter>importModifiersprivate java.util.Map<java.lang.Class<? extends ModelElement>,java.util.List<IModelElementFilter<?>>>modifiersprivate ProjectoriginProjectThe project where the visiting has been started.private java.util.List<IProjectModifier>projectModifiers
-
Constructor Summary
Constructors Constructor Description ProjectRewriteVisitor(Project originProject, FilterType filterType)Default constructor for this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddCopiedElement(ContainableModelElement copy)Adds 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 voidrevisit(Project project)Starts 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.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.
-
-
-
Field Detail
-
originProject
private Project originProject
The project where the visiting has been started.
-
filterType
private FilterType filterType
Specifies whether project imports shall be considered or not.
-
modifiers
private java.util.Map<java.lang.Class<? extends ModelElement>,java.util.List<IModelElementFilter<?>>> modifiers
-
importModifiers
private java.util.List<IProjectImportFilter> importModifiers
-
projectModifiers
private java.util.List<IProjectModifier> projectModifiers
-
currentProject
private Project currentProject
-
done
private java.util.Set<Project> done
-
context
private RewriteContext context
-
-
Constructor Detail
-
ProjectRewriteVisitor
public ProjectRewriteVisitor(Project originProject, FilterType filterType)
Default constructor for this class.- Parameters:
originProject- The project where the visiting shall startfilterType- Specifies whether project imports shall be considered or not.
-
-
Method Detail
-
reset
public void reset(Project originProject, FilterType filterType)
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
public void addModelCopyModifier(IModelElementFilter<? extends ModelElement> modifier)
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
public void addImportModifier(IProjectImportFilter modifier)
Adds a new modifier for filteringProjectImports.- Parameters:
modifier- A modifier for filteringProjectImports.
-
addProjectModifier
public void addProjectModifier(IProjectModifier modifier)
Adds a new modifier to modify complete Projects at the end of their visitation.- Parameters:
modifier- A modifier to change projects.
-
visitDecisionVariableDeclaration
public void visitDecisionVariableDeclaration(DecisionVariableDeclaration decl)
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
public void visitAttribute(Attribute attribute)
Description copied from interface:IModelVisitorMethod for visiting an attribute.- Specified by:
visitAttributein interfaceIModelVisitor- Parameters:
attribute- The attribute which should be visited.
-
visitConstraint
public void visitConstraint(Constraint constraint)
Description copied from interface:IModelVisitorMethod for visiting a constraint.- Specified by:
visitConstraintin interfaceIModelVisitor- Parameters:
constraint- The constraint which should be visited.
-
copyConstraint
private void copyConstraint(Constraint constraint)
Copies the given Constraint.- Parameters:
constraint- A constraints, which syntax is not null
-
visitFreezeBlock
public void visitFreezeBlock(FreezeBlock freeze)
Description copied from interface:IModelVisitorMethod for visiting a freeze block.- Specified by:
visitFreezeBlockin interfaceIModelVisitor- 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.- Specified by:
visitOperationDefinitionin interfaceIModelVisitor- 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.- Specified by:
visitPartialEvaluationBlockin interfaceIModelVisitor- 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.- Specified by:
visitProjectInterfacein interfaceIModelVisitor- Parameters:
iface- The interface which should be visited.
-
visitComment
public void visitComment(Comment comment)
Description copied from interface:IModelVisitorMethod for visiting a comment.- Specified by:
visitCommentin interfaceIModelVisitor- Parameters:
comment- the comment to visit
-
visitAttributeAssignment
public void visitAttributeAssignment(AttributeAssignment assignment)
Description copied from interface:IModelVisitorVisits an attribute assignment.- Specified by:
visitAttributeAssignmentin interfaceIModelVisitor- 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.- Specified by:
visitCompoundAccessStatementin interfaceIModelVisitor- Parameters:
access- the access statement
-
visitEnum
public void visitEnum(Enum eenum)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum.- Specified by:
visitEnumin interfaceICustomDatatypeVisitor- Parameters:
eenum- The enum which should be visited.
-
visitOrderedEnum
public void visitOrderedEnum(OrderedEnum eenum)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an ordered enum.- Specified by:
visitOrderedEnumin interfaceICustomDatatypeVisitor- Parameters:
eenum- The enum which should be visited.
-
visitCompound
public void visitCompound(Compound compound)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a compound.- Specified by:
visitCompoundin interfaceICustomDatatypeVisitor- Parameters:
compound- The compound which should be visited.
-
visitDerivedDatatype
public void visitDerivedDatatype(DerivedDatatype datatype)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a derived datatype.- Specified by:
visitDerivedDatatypein interfaceICustomDatatypeVisitor- Parameters:
datatype- The datatype which should be visited.
-
visitEnumLiteral
public void visitEnumLiteral(EnumLiteral literal)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting an enum literal.- Specified by:
visitEnumLiteralin interfaceICustomDatatypeVisitor- Parameters:
literal- The literal which should be visited.
-
visitReference
public void visitReference(Reference reference)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a reference.- Specified by:
visitReferencein interfaceICustomDatatypeVisitor- Parameters:
reference- The reference which should be visited.
-
visitSequence
public void visitSequence(Sequence sequence)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a sequence.- Specified by:
visitSequencein interfaceICustomDatatypeVisitor- Parameters:
sequence- The sequence which should be visited.
-
visitSet
public void visitSet(Set set)
Description copied from interface:ICustomDatatypeVisitorMethod for visiting a set.- Specified by:
visitSetin interfaceICustomDatatypeVisitor- Parameters:
set- The set which should be visited.
-
filter
private ContainableModelElement filter(ContainableModelElement original)
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(ContainableModelElement)
-
addCopiedElement
private void addCopiedElement(ContainableModelElement copy)
Adds a modified and filtered element to thecurrentProject, part of thefilter(ContainableModelElement)method.- Parameters:
copy- The copied instance, maybe null if filtered completely.
-
visitProject
public void visitProject(Project project)
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
private void revisit(Project project)
Starts a new visitation to clean up inconsistent data.- Parameters:
project- The original project which was used to start the whole visitation process.
-
visitProjectImport
public void visitProjectImport(ProjectImport pImport)
Description copied from interface:IModelVisitorThis method is used for visiting a ProjectImport.- Specified by:
visitProjectImportin interfaceIModelVisitor- Parameters:
pImport- One ProjectImport which should be visited.
-
-