org.eclipse.emf.emfstore.modelmutator
Class ESModelMutatorUtil

java.lang.Object
  extended by org.eclipse.emf.emfstore.modelmutator.ESModelMutatorUtil

public final class ESModelMutatorUtil
extends Object

Util class for the ModelMutator.

Since:
2.0
Author:
Eugen Neufeld, Stephan Koehler, Philip Achenbach, Dmitry Litvinov, Julian Sommerfeldt

Field Summary
static int DELETE_CUT_CONTAINMENT
          Indicates deleting through removing containment references.
static int DELETE_DELETE_COMMAND
          Indicates deleting with the DeleteCommand.
static int DELETE_ECORE
          Indicates deleting with the EcoreUtil.delete(EObject) method.
 
Constructor Summary
ESModelMutatorUtil(ESModelMutatorConfiguration config)
          A new ESModelMutatorUtil.
 
Method Summary
 void addedEObject(org.eclipse.emf.ecore.EObject addedEObject)
          Notifies this util that a new object has been added to maintain the index of offering and suitable objects.
 void addPerCommand(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EStructuralFeature feature, Collection<?> objects)
          Adds all objects to the many-valued feature of eObject using an AddCommand.
 void addPerCommand(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EStructuralFeature feature, Object newValue, Integer index)
          Adds newValue to the many-valued feature of eObject using an AddCommand.
static boolean canHaveInstance(org.eclipse.emf.ecore.EClass eClass)
          Returns whether eClass can be instantiated or not.
 Object createNewAttribute(org.eclipse.emf.ecore.EAttribute eAttribute)
          Creates a random attribute value for the given EAttribute.
 org.eclipse.emf.ecore.EObject createOfType(org.eclipse.emf.ecore.EClass eClass)
           
 void deletedEObject(org.eclipse.emf.ecore.EObject deletedEObject)
          Notifies this util that an object has been deleted to maintain the index of offering and suitable objects.
static Map<org.eclipse.emf.ecore.EClass,List<org.eclipse.emf.ecore.EObject>> getAllClassesAndObjects(org.eclipse.emf.ecore.EObject rootObject)
          Returns all direct and indirect contents of rootObject as a map.
 List<org.eclipse.emf.ecore.EClass> getAllEClasses()
          Iterates over all registered EPackages in order to retrieve all available EClasses, excluding abstract classes and interfaces, and returns them as a Set.
 List<org.eclipse.emf.ecore.EClass> getAllEClasses(Collection<org.eclipse.emf.ecore.EPackage> ePackages)
          Get all EClasses in the EPackages.
 List<org.eclipse.emf.ecore.EClass> getAllEClasses(org.eclipse.emf.ecore.EPackage ePackage)
          Retrieve all EClasses that are contained in ePackage.
 List<org.eclipse.emf.ecore.EClass> getAllEContainments(org.eclipse.emf.ecore.EReference reference)
          Get all containments of a reference.
static Map<org.eclipse.emf.ecore.EClass,List<org.eclipse.emf.ecore.EObject>> getAllObjects(org.eclipse.emf.ecore.EObject root)
          Returns all contents of the given EObject sorted by the EClass of the contained children.
static int getAllObjectsCount(org.eclipse.emf.ecore.EObject obj)
           
 List<org.eclipse.emf.ecore.EClass> getAllSubEClasses(org.eclipse.emf.ecore.EClass eClass)
          Returns all subclasses of an EClass, excluding abstract classes and interfaces.
 Map<org.eclipse.emf.ecore.EClassifier,AttributeSetter<?>> getAttributeSetters()
          Returns a map containing an AttributeSetter-instance for each attribute type, granting access to all AttributeSetters.
 Iterable<org.eclipse.emf.ecore.EStructuralFeature> getAvailableFeatures()
          Returns the features that are currently available for mutation.
 Iterable<org.eclipse.emf.ecore.EStructuralFeature> getAvailableFeatures(com.google.common.base.Predicate<? super org.eclipse.emf.ecore.EStructuralFeature> predicate)
          Returns the features that are currently available for mutation filtered by the given predicate.
 List<Integer> getDeleteModes()
          Returns the delete modes.
static org.eclipse.emf.ecore.EPackage getEPackage(String nsURI)
          Returns the EPackage to the specified nsURI.
 ESModelMutatorConfiguration getModelMutatorConfiguration()
          Returns the model mutator configuration.
 Iterable<org.eclipse.emf.ecore.EObject> getOfferingEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature)
          Returns the currently existing objects to be mutated that offer the given feature.
 Iterable<org.eclipse.emf.ecore.EObject> getOfferingEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature, com.google.common.base.Predicate<? super org.eclipse.emf.ecore.EObject> predicate)
          Returns the currently existing objects to be mutated that offer the given feature filtered by the given predicate.
 int getRandomDeleteMode()
          Returns a random delete mode.
 Set<org.eclipse.emf.ecore.EClass> getReferenceClasses(org.eclipse.emf.ecore.EReference reference, Set<org.eclipse.emf.ecore.EClass> allEClasses)
          Retrieves all EClasses from allEClasses that can possibly be referenced by reference and returns them as a set.
 Iterable<org.eclipse.emf.ecore.EObject> getSuitableEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature)
          Returns currently existing objects that are suitable to act as values for the given feature filtered by the given predicate.
 Iterable<org.eclipse.emf.ecore.EObject> getSuitableEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature, com.google.common.base.Predicate<? super org.eclipse.emf.ecore.EObject> predicate)
          Returns currently existing objects that are suitable to act as values for the given feature.
 List<org.eclipse.emf.ecore.EReference> getValidContainmentReferences(org.eclipse.emf.ecore.EObject eObject)
          Returns all valid containment references for an EObject.
 List<org.eclipse.emf.ecore.EReference> getValidCrossReferences(org.eclipse.emf.ecore.EObject eObject)
          Returns all valid references for an EObject.
 boolean isUniqueID(Object id)
           
 boolean isValid(org.eclipse.emf.ecore.EStructuralFeature feature, org.eclipse.emf.ecore.EObject eObject)
          Returns whether an EStructuralFeature is valid for an EObject or not.
 void movePerCommand(org.eclipse.emf.ecore.EObject parent, org.eclipse.emf.ecore.EStructuralFeature feature, Object objectToMove, Integer index)
          Move an object.
 void registerID(Object id)
           
 void removeFullPerCommand(org.eclipse.emf.ecore.EObject eObject, int howToDelete)
          Deletes the EObject using the specified howToDelete.
 void removePerCommand(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EStructuralFeature feature, Collection<?> objects)
          Removes objects from a feature of eObject using a RemoveCommand.
 void setEObjectAttributes(org.eclipse.emf.ecore.EObject eObject)
          Sets all possible attributes of known types to random values using AttributeSetter and SetCommands/AddCommands.
 void setEObjectAttributes(org.eclipse.emf.ecore.EObject eObject, int maxNumber, Set<org.eclipse.emf.ecore.EStructuralFeature> ignoredFeatures)
          Sets all possible attributes of known types to random values using AttributeSetter and SetCommands/AddCommands.
 void setEObjectAttributes(org.eclipse.emf.ecore.EObject eObject, Set<org.eclipse.emf.ecore.EStructuralFeature> ignoredFeatures)
          Sets all possible attributes of known types to random values using AttributeSetter and SetCommands/AddCommands.
 org.eclipse.emf.ecore.EObject setPerCommand(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EStructuralFeature feature, Object newValue)
          Sets a feature between eObject and newValue using a SetCommand.
 org.eclipse.emf.ecore.EObject setPerCommand(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EStructuralFeature feature, Object newValue, Integer index)
          Sets a feature between eObject and newValue using a SetCommand.
 void setReference(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EClass referenceClass, org.eclipse.emf.ecore.EReference reference, Map<org.eclipse.emf.ecore.EClass,List<org.eclipse.emf.ecore.EObject>> allEObjects)
          Sets or adds to a reference for an EObject with any generated instance of referenceClass using SetCommand/AddCommand.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELETE_DELETE_COMMAND

public static final int DELETE_DELETE_COMMAND
Indicates deleting with the DeleteCommand.

See Also:
Constant Field Values

DELETE_CUT_CONTAINMENT

public static final int DELETE_CUT_CONTAINMENT
Indicates deleting through removing containment references.

See Also:
Constant Field Values

DELETE_ECORE

public static final int DELETE_ECORE
Indicates deleting with the EcoreUtil.delete(EObject) method.

See Also:
Constant Field Values
Constructor Detail

ESModelMutatorUtil

public ESModelMutatorUtil(ESModelMutatorConfiguration config)
A new ESModelMutatorUtil.

Parameters:
config - The ESModelMutatorConfiguration of the ESModelMutatorUtil.
Method Detail

getEPackage

public static org.eclipse.emf.ecore.EPackage getEPackage(String nsURI)
Returns the EPackage to the specified nsURI.

Parameters:
nsURI - the NsUri of the EPackage to get
Returns:
the EPackage belonging to nsURI
See Also:
EPackage.Registry.getEPackage(String)

getValidContainmentReferences

public List<org.eclipse.emf.ecore.EReference> getValidContainmentReferences(org.eclipse.emf.ecore.EObject eObject)
Returns all valid containment references for an EObject. A reference is valid if it is neither derived nor volatile and if it is changeable and either many-valued or not already set.

Parameters:
eObject - the EObject to get references for
Returns:
all valid references as a list

getValidCrossReferences

public List<org.eclipse.emf.ecore.EReference> getValidCrossReferences(org.eclipse.emf.ecore.EObject eObject)
Returns all valid references for an EObject. This excludes container/containment references. A reference is valid if it is neither derived nor volatile and if it is changeable and either many-valued or not already set.

Parameters:
eObject - the EObject to get references for
Returns:
all valid references as a list

isValid

public boolean isValid(org.eclipse.emf.ecore.EStructuralFeature feature,
                       org.eclipse.emf.ecore.EObject eObject)
Returns whether an EStructuralFeature is valid for an EObject or not. A reference is valid, if it can be set or added to.

Parameters:
feature - the EStructuralFeature in question
eObject - the EObject to check the feature for
Returns:
if the feature can be set or added to

getAllEContainments

public List<org.eclipse.emf.ecore.EClass> getAllEContainments(org.eclipse.emf.ecore.EReference reference)
Get all containments of a reference.

Parameters:
reference - The EReference for which to get all containments.
Returns:
All containments of the EReference.

canHaveInstance

public static boolean canHaveInstance(org.eclipse.emf.ecore.EClass eClass)
Returns whether eClass can be instantiated or not. An EClass can be instantiated, if it is neither an interface nor abstract.

Parameters:
eClass - the EClass in question
Returns:
whether eClass can be instantiated or not.

getAllSubEClasses

public List<org.eclipse.emf.ecore.EClass> getAllSubEClasses(org.eclipse.emf.ecore.EClass eClass)
Returns all subclasses of an EClass, excluding abstract classes and interfaces.

Parameters:
eClass - the EClass to get subclasses for
Returns:
all subclasses of eClass

getAllEClasses

public List<org.eclipse.emf.ecore.EClass> getAllEClasses()
Iterates over all registered EPackages in order to retrieve all available EClasses, excluding abstract classes and interfaces, and returns them as a Set.

Returns:
a set of all EClasses that are contained in registered EPackages
See Also:
EPackage.Registry

getAllEClasses

public List<org.eclipse.emf.ecore.EClass> getAllEClasses(Collection<org.eclipse.emf.ecore.EPackage> ePackages)
Get all EClasses in the EPackages.

Parameters:
ePackages - The EPackages containg the EClasses.
Returns:
The EClasses contained in the EPackages.

getAllEClasses

public List<org.eclipse.emf.ecore.EClass> getAllEClasses(org.eclipse.emf.ecore.EPackage ePackage)
Retrieve all EClasses that are contained in ePackage.

Parameters:
ePackage - the package to get contained EClasses from
Returns:
a set of EClasses contained in ePackage

getAllClassesAndObjects

public static Map<org.eclipse.emf.ecore.EClass,List<org.eclipse.emf.ecore.EObject>> getAllClassesAndObjects(org.eclipse.emf.ecore.EObject rootObject)
Returns all direct and indirect contents of rootObject as a map. All EObjects that appear in these contents are mapped to their corresponding EClass.
NOTE: this is a very expensive method!

Parameters:
rootObject - the EObject to get contents for
Returns:
all contents as a map from EClass to lists of EObjects

addPerCommand

public void addPerCommand(org.eclipse.emf.ecore.EObject eObject,
                          org.eclipse.emf.ecore.EStructuralFeature feature,
                          Object newValue,
                          Integer index)
Adds newValue to the many-valued feature of eObject using an AddCommand. Exceptions are caught if ignoreAndLog is true, otherwise a RuntimeException might be thrown if the command fails.

Parameters:
eObject - the EObject to which newObject shall be added
feature - the EStructuralFeature that newObject shall be added to
newValue - the Object that shall be added to feature
index - the index where to add the object or null if it should be added to the end.
See Also:
AddCommand.AddCommand(EditingDomain, EObject, EStructuralFeature, Object)

addPerCommand

public void addPerCommand(org.eclipse.emf.ecore.EObject eObject,
                          org.eclipse.emf.ecore.EStructuralFeature feature,
                          Collection<?> objects)
Adds all objects to the many-valued feature of eObject using an AddCommand. Exceptions are caught if ignoreAndLog is true, otherwise a RuntimeException might be thrown if the command fails.

Parameters:
eObject - the EObject to which objects shall be added
feature - the EReference that objects shall be added to
objects - collection of objects that shall be added to feature

movePerCommand

public void movePerCommand(org.eclipse.emf.ecore.EObject parent,
                           org.eclipse.emf.ecore.EStructuralFeature feature,
                           Object objectToMove,
                           Integer index)
Move an object.

Parameters:
parent - The parent object.
feature - The feature of the parent object.
objectToMove - The object to move within the parents feature.
index - The index where to move the object to.

setPerCommand

public org.eclipse.emf.ecore.EObject setPerCommand(org.eclipse.emf.ecore.EObject eObject,
                                                   org.eclipse.emf.ecore.EStructuralFeature feature,
                                                   Object newValue,
                                                   Integer index)
Sets a feature between eObject and newValue using a SetCommand. Exceptions are caught if ignoreAndLog is true, otherwise a RuntimeException might be thrown if the command fails.

Parameters:
eObject - the EObject for which feature shall be set
feature - the EStructuralFeature that shall be set
newValue - the Object that shall be set as a feature in parentEObject
index - Where to set to object to or null if it should be set to the end.
Returns:
newValue if the SetCommand was performed successful or null if it failed
See Also:
SetCommand

setPerCommand

public org.eclipse.emf.ecore.EObject setPerCommand(org.eclipse.emf.ecore.EObject eObject,
                                                   org.eclipse.emf.ecore.EStructuralFeature feature,
                                                   Object newValue)
Sets a feature between eObject and newValue using a SetCommand. Exceptions are caught if ignoreAndLog is true, otherwise a RuntimeException might be thrown if the command fails.

Parameters:
eObject - the EObject for which feature shall be set
feature - the EStructuralFeature that shall be set
newValue - the Object that shall be set as a feature in parentEObject
Returns:
newValue if the SetCommand was performed successful or null if it failed
See Also:
SetCommand

removePerCommand

public void removePerCommand(org.eclipse.emf.ecore.EObject eObject,
                             org.eclipse.emf.ecore.EStructuralFeature feature,
                             Collection<?> objects)
Removes objects from a feature of eObject using a RemoveCommand. Exceptions are caught if ignoreAndLog is true, otherwise a RuntimeException might be thrown if the command fails.

Parameters:
eObject - the EObject to remove objects from
feature - the EStructuralFeature objects shall be removed from
objects - collection of Objects that shall be removed
See Also:
RemoveCommand

removeFullPerCommand

public void removeFullPerCommand(org.eclipse.emf.ecore.EObject eObject,
                                 int howToDelete)
Deletes the EObject using the specified howToDelete.

Parameters:
eObject - The EObject to delete.
howToDelete - The way to delete: DELETE_ECORE, DELETE_DELETE_COMMAND or DELETE_CUT_CONTAINMENT.

setEObjectAttributes

public void setEObjectAttributes(org.eclipse.emf.ecore.EObject eObject)
Sets all possible attributes of known types to random values using AttributeSetter and SetCommands/AddCommands.

Parameters:
eObject - the EObject to set attributes for
See Also:
AttributeSetter

setEObjectAttributes

public void setEObjectAttributes(org.eclipse.emf.ecore.EObject eObject,
                                 int maxNumber,
                                 Set<org.eclipse.emf.ecore.EStructuralFeature> ignoredFeatures)
Sets all possible attributes of known types to random values using AttributeSetter and SetCommands/AddCommands.

Parameters:
eObject - the EObject to set attributes for
maxNumber - the maximal number of attributes to mutate
ignoredFeatures - a set of attributes to be ignored
See Also:
AttributeSetter

createOfType

public org.eclipse.emf.ecore.EObject createOfType(org.eclipse.emf.ecore.EClass eClass)

getAllObjects

public static Map<org.eclipse.emf.ecore.EClass,List<org.eclipse.emf.ecore.EObject>> getAllObjects(org.eclipse.emf.ecore.EObject root)
Returns all contents of the given EObject sorted by the EClass of the contained children.

Parameters:
root - The root object containing the direct and indirect children.
Returns:
The count of all direct and indirect children of the object.

getAttributeSetters

public Map<org.eclipse.emf.ecore.EClassifier,AttributeSetter<?>> getAttributeSetters()
Returns a map containing an AttributeSetter-instance for each attribute type, granting access to all AttributeSetters.

Returns:
the map that maps every attribute type to its attribute setter
See Also:
AttributeSetter

createNewAttribute

public Object createNewAttribute(org.eclipse.emf.ecore.EAttribute eAttribute)
Creates a random attribute value for the given EAttribute.

Parameters:
eAttribute - the attribute to create a new value for
Returns:
the created attribute value

getReferenceClasses

public Set<org.eclipse.emf.ecore.EClass> getReferenceClasses(org.eclipse.emf.ecore.EReference reference,
                                                             Set<org.eclipse.emf.ecore.EClass> allEClasses)
Retrieves all EClasses from allEClasses that can possibly be referenced by reference and returns them as a set.

Parameters:
reference - the EReference to get EClasses for
allEClasses - set of all potentially possible EClasses
Returns:
set of all EClasses that can be referenced by reference

setReference

public void setReference(org.eclipse.emf.ecore.EObject eObject,
                         org.eclipse.emf.ecore.EClass referenceClass,
                         org.eclipse.emf.ecore.EReference reference,
                         Map<org.eclipse.emf.ecore.EClass,List<org.eclipse.emf.ecore.EObject>> allEObjects)
Sets or adds to a reference for an EObject with any generated instance of referenceClass using SetCommand/AddCommand. If the reference is not required, random decides whether the reference is set or how many EObjects are added to it.

Parameters:
eObject - the EObject to set the reference for
referenceClass - the EClass all referenced EObject shall be instances of
reference - the reference to set
allEObjects - Map containing all available EObjects mapped to their EClasses.
See Also:
addPerCommand(EObject, EStructuralFeature, Collection), addPerCommand(EObject, EStructuralFeature, Object, Integer), setPerCommand(EObject, EStructuralFeature, Object), setPerCommand(EObject, EStructuralFeature, Object, Integer)

getAllObjectsCount

public static int getAllObjectsCount(org.eclipse.emf.ecore.EObject obj)
Parameters:
obj - The root object containing the direct and indirect children.
Returns:
The count of all direct and indirect children of the object.

setEObjectAttributes

public void setEObjectAttributes(org.eclipse.emf.ecore.EObject eObject,
                                 Set<org.eclipse.emf.ecore.EStructuralFeature> ignoredFeatures)
Sets all possible attributes of known types to random values using AttributeSetter and SetCommands/AddCommands.

Parameters:
eObject - the EObject to set attributes for
ignoredFeatures - a set of attributes to be ignored
See Also:
AttributeSetter

getModelMutatorConfiguration

public ESModelMutatorConfiguration getModelMutatorConfiguration()
Returns the model mutator configuration.

Returns:
the model mutator configuration.

getAvailableFeatures

public Iterable<org.eclipse.emf.ecore.EStructuralFeature> getAvailableFeatures()
Returns the features that are currently available for mutation.

Returns:
The features that can be mutated.

getAvailableFeatures

public Iterable<org.eclipse.emf.ecore.EStructuralFeature> getAvailableFeatures(com.google.common.base.Predicate<? super org.eclipse.emf.ecore.EStructuralFeature> predicate)
Returns the features that are currently available for mutation filtered by the given predicate.

Parameters:
predicate - The predicate to be used for filtering the available features.
Returns:
The filtered features that can be mutated.

getOfferingEObjectsForAvailableFeature

public Iterable<org.eclipse.emf.ecore.EObject> getOfferingEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature)
Returns the currently existing objects to be mutated that offer the given feature.

Parameters:
feature - The feature to get existing objects for.
Returns:
The existing objects offering the given feature.

getOfferingEObjectsForAvailableFeature

public Iterable<org.eclipse.emf.ecore.EObject> getOfferingEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature,
                                                                                      com.google.common.base.Predicate<? super org.eclipse.emf.ecore.EObject> predicate)
Returns the currently existing objects to be mutated that offer the given feature filtered by the given predicate.

Parameters:
feature - The feature to get existing objects for.
predicate - The predicate to be used for filtering the objects.
Returns:
The filtered existing objects offering the given feature.

getSuitableEObjectsForAvailableFeature

public Iterable<org.eclipse.emf.ecore.EObject> getSuitableEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature)
Returns currently existing objects that are suitable to act as values for the given feature filtered by the given predicate.

Parameters:
feature - The feature to get suitable objects for.
Returns:
The existing objects that can be used as values for the given feature.

getSuitableEObjectsForAvailableFeature

public Iterable<org.eclipse.emf.ecore.EObject> getSuitableEObjectsForAvailableFeature(org.eclipse.emf.ecore.EStructuralFeature feature,
                                                                                      com.google.common.base.Predicate<? super org.eclipse.emf.ecore.EObject> predicate)
Returns currently existing objects that are suitable to act as values for the given feature.

Parameters:
feature - The feature to get suitable objects for.
predicate - The predicate to be used for filtering the objects.
Returns:
The existing objects that can be used as values for the given feature.

addedEObject

public void addedEObject(org.eclipse.emf.ecore.EObject addedEObject)
Notifies this util that a new object has been added to maintain the index of offering and suitable objects.

Parameters:
addedEObject - The added object.

deletedEObject

public void deletedEObject(org.eclipse.emf.ecore.EObject deletedEObject)
Notifies this util that an object has been deleted to maintain the index of offering and suitable objects.

Parameters:
deletedEObject - The added object.

getDeleteModes

public List<Integer> getDeleteModes()
Returns the delete modes.

Returns:
The delete modes.

getRandomDeleteMode

public int getRandomDeleteMode()
Returns a random delete mode.

Returns:
A random delete mode.

isUniqueID

public boolean isUniqueID(Object id)
Parameters:
id - the ID to check for uniqueness
Returns:
true if id is unique, false otherwise

registerID

public void registerID(Object id)
Parameters:
id - the ID to register


Copyright © 2015. All Rights Reserved.