Class RewriteContext
- java.lang.Object
-
- net.ssehub.easy.varModel.model.rewrite.RewriteContext
-
public class RewriteContext extends java.lang.ObjectUsed as part ofProjectRewriteVisitorto store translated Objects.- Author:
- El-Sharkawy
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<ContainableModelElement>>elementsOfRemovedImportsElements of a removed import.private booleanelementsWereRemovedprivate java.util.Set<java.lang.String>projectQualifierSet of identifiers (name + version) of projects which will be kept.private java.util.Map<java.lang.Class<?>,java.util.Set<ContainableModelElement>>removedElementsprivate VariableLookUpTablevariablesTable
-
Constructor Summary
Constructors Modifier Constructor Description protectedRewriteContext()Avoid instantiation from outside.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddUsedProject(Project project)Marks that a project was used, i.e., is still part of the overall structure and should not be removed.(package private) voidclear()Resets the internal temporary knowledge if the same projects should be filtered a second time.(package private) booleandeclarationKnown(AbstractVariable declaration)Checks whether the declaration is known or whether the declaration is a local declaration used as an iterator of a constraint.booleanelementesWereRemoved()Returns whether elements were removed during the last iteration.booleanelementWasRemoved(ContainableModelElement elememt)Returns whether the given element was removed from the project.private java.lang.StringgenerateQualifiedName(Project project)Returns the qualified name of a project as unique identifier for comparison whether the project was deleted.java.util.Set<IDecisionVariable>getInstancesForDeclaration(Configuration config, AbstractVariable declaration)Returns the set of instances of the givenAbstractVariabledeclaration.java.util.Set<IDecisionVariable>getInstancesForType(Configuration config, IDatatype type)Returns the set of instances of the givenIDatatype.(package private) VariableLookUpTablegetLookUpTable()Getter for theVariableLookUpTable, for initialization inside the visitor.booleanhasRemovedElementsOfType(java.lang.Class<? extends ContainableModelElement> type)Checks whether elements of the givenContainableModelElementwas removed.(package private) voidmarkForImportRemoval(Project declaringProject, ContainableModelElement nestedElement)Marks an element of an imported project for removal if the relatedProjectImportwas deleted.(package private) voidnewRun()Resets the internal temporary knowledge if anew project should be filtered based on the knowledge of a previous filtering.booleanprojectIsStillPresent(Project project)Tests whether the project is still part of the main project (via an import).voidremoveElement(ContainableModelElement removedElememt)Stores the information that a model element was removed.(package private) voidremoveElementsOfRemovedImports()Removes elements of removedProjectImport, must be called after theProjectRewriteVisitoris finished with a complete visitation iteration and beforeclear().
-
-
-
Field Detail
-
projectQualifier
private java.util.Set<java.lang.String> projectQualifier
Set of identifiers (name + version) of projects which will be kept. Needed for removal of elements, which belong to a removed import. A string is used instead of projects to simplify comparison if references change...
-
removedElements
private java.util.Map<java.lang.Class<?>,java.util.Set<ContainableModelElement>> removedElements
-
elementsOfRemovedImports
private java.util.Map<java.lang.String,java.util.List<ContainableModelElement>> elementsOfRemovedImports
Elements of a removed import. As long as it is unclear whether another project is till importing this project, the elements cannot be removed. At the end of visitation, this map can be used to cleanup the main project.
-
elementsWereRemoved
private boolean elementsWereRemoved
-
variablesTable
private VariableLookUpTable variablesTable
-
-
Method Detail
-
getLookUpTable
VariableLookUpTable getLookUpTable()
Getter for theVariableLookUpTable, for initialization inside the visitor.- Returns:
- The (empty)
VariableLookUpTable.
-
generateQualifiedName
private java.lang.String generateQualifiedName(Project project)
Returns the qualified name of a project as unique identifier for comparison whether the project was deleted.- Parameters:
project- The project for which the qualified name shall be generated.- Returns:
- projectName[+Version].
-
removeElement
public void removeElement(ContainableModelElement removedElememt)
Stores the information that a model element was removed. Helpful for removing all instances pointing to this variable.- Parameters:
removedElememt- The removed element.
-
elementWasRemoved
public boolean elementWasRemoved(ContainableModelElement elememt)
Returns whether the given element was removed from the project.- Parameters:
elememt- An element to test.- Returns:
- true if the element was removed, false if the element still exist.
-
hasRemovedElementsOfType
public boolean hasRemovedElementsOfType(java.lang.Class<? extends ContainableModelElement> type)
Checks whether elements of the givenContainableModelElementwas removed.- Parameters:
type- A class, visited byIModelVisitor.- Returns:
- true if at least one element of this class was removed.
-
elementesWereRemoved
public boolean elementesWereRemoved()
Returns whether elements were removed during the last iteration.- Returns:
- true if at least one element was removed, false otherwise.
-
clear
void clear()
Resets the internal temporary knowledge if the same projects should be filtered a second time.
-
newRun
void newRun()
Resets the internal temporary knowledge if anew project should be filtered based on the knowledge of a previous filtering.
-
projectIsStillPresent
public boolean projectIsStillPresent(Project project)
Tests whether the project is still part of the main project (via an import).- Parameters:
project- The project to test- Returns:
- trueproject is still part of the main project, false it is unclear.
-
markForImportRemoval
void markForImportRemoval(Project declaringProject, ContainableModelElement nestedElement)
Marks an element of an imported project for removal if the relatedProjectImportwas deleted.- Parameters:
declaringProject- The project were the element was created.nestedElement- The element itself.
-
removeElementsOfRemovedImports
void removeElementsOfRemovedImports()
Removes elements of removedProjectImport, must be called after theProjectRewriteVisitoris finished with a complete visitation iteration and beforeclear().
-
getInstancesForType
public java.util.Set<IDecisionVariable> getInstancesForType(Configuration config, IDatatype type)
Returns the set of instances of the givenIDatatype.- Parameters:
config- The configuration which is used to retrieve allIDecisionVariables.type- The exactIDatatypefor which the instances shall be returned, will not considerIDatatype.isAssignableFrom(IDatatype).- Returns:
- The instances for the given type or null if no instances exist.
-
getInstancesForDeclaration
public java.util.Set<IDecisionVariable> getInstancesForDeclaration(Configuration config, AbstractVariable declaration)
Returns the set of instances of the givenAbstractVariabledeclaration.- Parameters:
config- The configuration which is used to retrieve allIDecisionVariables.declaration- The declaration for which the instances shall be returned. If the declaration is nested inside a compound which was multiple times instantiated, this single declaration could return multipleIDecisionVariables.- Returns:
- The instances for the given declaration or null if no instances exist.
-
declarationKnown
boolean declarationKnown(AbstractVariable declaration)
Checks whether the declaration is known or whether the declaration is a local declaration used as an iterator of a constraint. Needs that the internalVariableLookUpTablewas already initialized with aConfiguration.- Parameters:
declaration- The declaration to check.- Returns:
- true if the declaration is used for a
IDecisionVariableof the configuration or if the internal table was not initialized with aConfiguration, false otherwise.
-
addUsedProject
public void addUsedProject(Project project)
Marks that a project was used, i.e., is still part of the overall structure and should not be removed.- Parameters:
project- A visited project, which is may be imported.- See Also:
#projectIsStillPressent(Project)
-
-