public final class ModelUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
NO_CHECKSUM
Constant that may be used in case no checksum computation has taken place.
|
static org.eclipse.emf.common.util.URI |
VIRTUAL_URI
URI used to serialize EObject with the model util.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areEqual(IdEObjectCollection collectionA,
IdEObjectCollection collectionB)
Compares two
IdEObjectCollections. |
static <T extends org.eclipse.emf.ecore.EObject> |
clone(List<T> list)
Clone a list of EObjects.
|
static <T extends org.eclipse.emf.ecore.EObject> |
clone(T eObject)
Clone any EObject.
|
static List<SettingWithReferencedElement> |
collectOutgoingCrossReferences(IdEObjectCollection collection,
Set<org.eclipse.emf.ecore.EObject> modelElements)
Retrieve all outgoing connections from the model elements to other elements in the collection.
|
static long |
computeChecksum(org.eclipse.emf.ecore.EObject eObject)
Computes the checksum for a given
EObject. |
static long |
computeChecksum(IdEObjectCollection collection)
Computes the checksum for a given
IdEObjectCollection. |
static long |
computeChecksumLegacy(org.eclipse.emf.ecore.EObject eObject)
Computes the checksum for a given
EObject. |
static IdEObjectCollection |
copyIdEObjectCollection(IdEObjectCollection collection,
org.eclipse.emf.ecore.xmi.XMIResource res)
Copies the given
IdEObjectCollection and writes the IDs it contains into the given XMIResource. |
static ModelElementId |
createModelElementId(String id)
Creates a ModelElementId object from a string.
|
static org.eclipse.emf.ecore.resource.ResourceSet |
createResourceSetForURI(org.eclipse.emf.common.util.URI resourceURI)
Creates and returns a new ResourceSet which may be used to load the given URI.
|
static void |
deleteIncomingCrossReferencesToElement(org.eclipse.emf.ecore.EObject element,
Collection<org.eclipse.emf.ecore.EStructuralFeature.Setting> inverseReferences,
Set<org.eclipse.emf.ecore.EObject> referenceSourceElementsToIgnore)
Delete the given incoming cross references to the given model element from any
other model element in the given collection except for the set of source elements
to ignore.
|
static void |
deleteOutgoingCrossReferences(IdEObjectCollection collection,
org.eclipse.emf.ecore.EObject modelElement)
Delete all outgoing cross references of the given model element to any element in the given collection.
|
static void |
deleteResourcesWithPrefix(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
String prefix)
Deletes all resources from resourceSet, which string representation of URI starts with prefix.
|
static String |
eObjectToString(org.eclipse.emf.ecore.EObject eObject)
Copies the given EObject and converts it to a string.
|
static String |
eObjectToString(org.eclipse.emf.ecore.EObject eObject,
Map<?,?> saveOptions)
Copies the given EObject and converts it to a string.
|
static <T extends org.eclipse.emf.ecore.EObject> |
flatCloneList(List<T> originalList)
Create a flat clone of the list, the list if cloned but ot its content.
|
static Set<org.eclipse.emf.ecore.EObject> |
getAllContainedModelElements(Collection<org.eclipse.emf.ecore.EObject> modelElements,
boolean includeTransientContainments,
boolean ignoreSingletonDatatypes)
Get all contained elements of a given collection of model elements.
|
static Set<org.eclipse.emf.ecore.EObject> |
getAllContainedModelElements(org.eclipse.emf.ecore.EObject modelElement,
boolean includeTransientContainments)
Get all contained elements of a given element.
|
static Set<org.eclipse.emf.ecore.EObject> |
getAllContainedModelElements(org.eclipse.emf.ecore.EObject modelElement,
boolean includeTransientContainments,
boolean ignoreSingletonDatatypes)
Get all contained elements of a given element.
|
static Set<org.eclipse.emf.ecore.EObject> |
getAllContainedModelElements(org.eclipse.emf.ecore.resource.Resource resource,
boolean includeTransientContainments,
boolean ignoreSingletonDatatypes)
Get all contained elements of a given resource.
|
static List<org.eclipse.emf.ecore.EObject> |
getAllContainedModelElementsAsList(org.eclipse.emf.ecore.EObject modelElement,
boolean includeTransientContainments)
Get all contained elements of a given element as a list.
|
static Set<org.eclipse.emf.ecore.EClass> |
getAllMETypes(org.eclipse.emf.ecore.EPackage ePackage)
Recursively goes through package and returns a list of all EClasses
inheriting ModelElement (abstract classes and interfaces are also
include).
|
static Map<Object,Object> |
getChecksumSaveOptions()
Delivers a map of options that is used while computing a checksum.
|
static org.eclipse.emf.ecore.EObject |
getContainerModelElement(org.eclipse.emf.ecore.EObject modelElement)
Get the container of an EObject.
|
static ModelElementId |
getModelElementId(org.eclipse.emf.ecore.EObject modelElement)
Searches for the project and then looks for the modelelement id.
|
static Set<org.eclipse.emf.ecore.EClass> |
getNonAbstractMETypes(org.eclipse.emf.ecore.EPackage ePackage)
Recursively goes through model and create a list of all non-Abstract
classes.
|
static <T extends org.eclipse.emf.ecore.EObject> |
getParent(Class<T> parent,
org.eclipse.emf.ecore.EObject child)
Get the EContainer that contains the given model element and whose
eContainer is null. |
static Project |
getProject(org.eclipse.emf.ecore.EObject modelElement)
Get Project that contains a model element.
|
static Map<Object,Object> |
getResourceLoadOptions()
Delivers a map of options for loading resources.
|
static IResourceLogger |
getResourceLogger()
Returns the resource logger.
|
static Map<Object,Object> |
getResourceSaveOptions()
Delivers a map of mandatory options for saving resources.
|
static org.eclipse.emf.ecore.EObject |
getSingleton(ModelElementId singletonId)
Get the singleton instance for a given model element id.
|
static ModelElementId |
getSingletonModelElementId(org.eclipse.emf.ecore.EObject singleton)
Get the singleton id for a singleton instance.
|
static boolean |
isAssociationClassElement(org.eclipse.emf.ecore.EClass eClazz)
Whether a
EClass is a association class. |
static boolean |
isSingleton(org.eclipse.emf.ecore.EObject eObject)
Return whether the given eObject instance is a singleton.
|
static <T extends org.eclipse.emf.ecore.EObject> |
loadEObjectFromResource(org.eclipse.emf.ecore.EClass eClass,
org.eclipse.emf.common.util.URI resourceURI,
boolean checkConstraints)
Load an EObject from a resource, the resource is supposed to contain only
one root object of the given EClass type.
|
static void |
loadResource(org.eclipse.emf.ecore.resource.Resource resource,
IResourceLogger logger)
Loads a given resource and logs any warning and/or errors.
|
static void |
log(String message,
Throwable exception,
int statusInt)
This will add a new entry to error log view of eclipse.
|
static void |
logError(String message)
Log a error to the platform log.
|
static void |
logException(String message,
Throwable exception)
Log an exception to the platform log.
|
static void |
logException(Throwable exception)
Log an exception to the platform log.
|
static void |
logInfo(String message)
Log an exception to the platform log.
|
static void |
logProjectDetails(String message,
String user,
String projectName,
String projectId,
String branch,
int revision)
Logs detailed information about the project state.
|
static void |
logWarning(String message)
Log a warning to the platform log.
|
static void |
logWarning(String message,
Throwable exception)
Log a warning to the platform log.
|
static void |
saveEObjectToResource(org.eclipse.emf.ecore.EObject eObject,
org.eclipse.emf.common.util.URI resourceURI)
Save an EObject to a resource.
|
static void |
saveEObjectToResource(List<? extends org.eclipse.emf.ecore.EObject> eObjects,
org.eclipse.emf.common.util.URI resourceURI)
Save a list of EObjects to the resource with the given URI.
|
static void |
saveEObjectToResource(List<? extends org.eclipse.emf.ecore.EObject> eObjects,
org.eclipse.emf.common.util.URI resourceURI,
Map<Object,Object> options)
Save a list of EObjects to the resource with the given URI.
|
static void |
saveResource(org.eclipse.emf.ecore.resource.Resource resource,
IResourceLogger logger)
Saves a given resource and logs any warning and/or errors.
|
static void |
setXmiIdsOnResource(Project project,
org.eclipse.emf.ecore.xmi.XMIResource xmiResource)
Set all IDs contained in the project as XMI IDs for the model elements in
the project.
|
static boolean |
shouldBeCollected(IdEObjectCollection collection,
Set<org.eclipse.emf.ecore.EObject> allModelElements,
org.eclipse.emf.ecore.EObject referencedElement)
Checks if the referenced elements is an element in the given collection which is not a singleton, not an ignored
data type and not already contained in the given set of elements.
|
public static final long NO_CHECKSUM
public static final org.eclipse.emf.common.util.URI VIRTUAL_URI
public static ModelElementId createModelElementId(String id)
id - as stringpublic static boolean areEqual(IdEObjectCollection collectionA, IdEObjectCollection collectionB)
IdEObjectCollections. Order of the model elements at root level
of a collection does not influence the outcome of this operationscollectionA - the first collectioncollectionB - the second collectionpublic static String eObjectToString(org.eclipse.emf.ecore.EObject eObject) throws SerializationException
eObject - the eObject to be serializedeObjectSerializationException - if a serialization problem occurspublic static String eObjectToString(org.eclipse.emf.ecore.EObject eObject, Map<?,?> saveOptions) throws SerializationException
eObject - the eObject to be serializedsaveOptions - the EMF save options to be used during serializationeObjectSerializationException - if a serialization problem occurspublic static long computeChecksumLegacy(org.eclipse.emf.ecore.EObject eObject)
throws SerializationException
EObject.eObject - the EObject for which to compute a checksumSerializationException - in case any errors occur during computation of the checksumpublic static long computeChecksum(org.eclipse.emf.ecore.EObject eObject)
throws SerializationException
EObject.eObject - the EObject for which to compute a checksumSerializationException - in case any errors occur during computation of the checksumpublic static long computeChecksum(IdEObjectCollection collection) throws SerializationException
IdEObjectCollection.
The checksum for a collection is independent of the order of the
collection's elements at the root level.collection - the collection for which to compute a checksumSerializationException - in case any errors occur during computation of the checksumpublic static IResourceLogger getResourceLogger()
public static IdEObjectCollection copyIdEObjectCollection(IdEObjectCollection collection, org.eclipse.emf.ecore.xmi.XMIResource res)
IdEObjectCollection and writes the IDs it contains into the given XMIResource.collection - the collection to be copiedres - the resource into which the collection's IDs should be written intopublic static Map<Object,Object> getResourceLoadOptions()
XMLResource.OPTION_DEFER_IDREF_RESOLUTION
which speeds up loading
due to our id based resources.XMIResource or XMLResource.public static Map<Object,Object> getResourceSaveOptions()
XMIResource or XMLResource.public static Map<Object,Object> getChecksumSaveOptions()
XMIResource or XMLResource.public static void saveResource(org.eclipse.emf.ecore.resource.Resource resource,
IResourceLogger logger)
throws IOException
resource - the resource to be savedlogger - a logger instance which will be used to log warnings and errors on resourcesIOException - in case an exception occurs during savepublic static void loadResource(org.eclipse.emf.ecore.resource.Resource resource,
IResourceLogger logger)
throws IOException
resource - the resource to be loadedlogger - a logger instance which will be used to log warnings and errors on resourcesIOException - in case an exception occurs during loadpublic static Set<org.eclipse.emf.ecore.EClass> getNonAbstractMETypes(org.eclipse.emf.ecore.EPackage ePackage)
ePackage - the package to start with.public static Set<org.eclipse.emf.ecore.EClass> getAllMETypes(org.eclipse.emf.ecore.EPackage ePackage)
ePackage - starting packagepublic static void log(String message, Throwable exception, int statusInt)
message - messageexception - exceptionstatusInt - severity. Use one of constants in
org.eclipse.core.runtime.Status class.public static void logException(String message, Throwable exception)
message - the messageexception - the exceptionpublic static void logException(Throwable exception)
exception - the exceptionpublic static void logWarning(String message, Throwable exception)
message - the messageexception - the exceptionpublic static void logWarning(String message)
message - the message being loggedpublic static void logError(String message)
message - the message being loggedpublic static void logInfo(String message)
message - the messagepublic static void logProjectDetails(String message, String user, String projectName, String projectId, String branch, int revision)
message - the messageuser - the user nameprojectName - the project nameprojectId - the project idbranch - the branchrevision - the revisionpublic static <T extends org.eclipse.emf.ecore.EObject> T clone(T eObject)
T - the Eobject sub typeeObject - the Eobject instancepublic static <T extends org.eclipse.emf.ecore.EObject> List<T> clone(List<T> list)
T - the EObject sub type the list consists oflist - the list instancepublic static <T extends org.eclipse.emf.ecore.EObject> List<T> flatCloneList(List<T> originalList)
T - the list type parameteroriginalList - the original listpublic static <T extends org.eclipse.emf.ecore.EObject> T loadEObjectFromResource(org.eclipse.emf.ecore.EClass eClass,
org.eclipse.emf.common.util.URI resourceURI,
boolean checkConstraints)
throws IOException
T - Type of the EObjecteClass - the EClass of the EObjectresourceURI - the resources URIcheckConstraints - whether to perform additional sanity checks. These checks
basically try to enforce that a resource contains exactly one
object.IOException - if loading the object from the resource fails.public static org.eclipse.emf.ecore.resource.ResourceSet createResourceSetForURI(org.eclipse.emf.common.util.URI resourceURI)
resourceURI - the resource URIpublic static void saveEObjectToResource(List<? extends org.eclipse.emf.ecore.EObject> eObjects, org.eclipse.emf.common.util.URI resourceURI, Map<Object,Object> options) throws IOException
eObjects - the EObjects to be savedresourceURI - the URI of the resource, which should be used to save the
EObjectsoptions - The save options for the resource.IOException - if saving to the resource failspublic static void saveEObjectToResource(List<? extends org.eclipse.emf.ecore.EObject> eObjects, org.eclipse.emf.common.util.URI resourceURI) throws IOException
eObjects - the EObjects to be savedresourceURI - the URI of the resource, which should be used to save the
EObjectsIOException - if saving to the resource failspublic static void setXmiIdsOnResource(Project project, org.eclipse.emf.ecore.xmi.XMIResource xmiResource)
project - a projectxmiResource - the resource that will contain the XMI IDspublic static void saveEObjectToResource(org.eclipse.emf.ecore.EObject eObject,
org.eclipse.emf.common.util.URI resourceURI)
throws IOException
eObject - the objectresourceURI - the resources URIIOException - if saving to the resource fails.public static void deleteResourcesWithPrefix(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
String prefix)
throws IOException
resourceSet - resource setprefix - string prefix of the resource pathIOException - if deleting the resource failspublic static Project getProject(org.eclipse.emf.ecore.EObject modelElement)
modelElement - the model elementpublic static ModelElementId getModelElementId(org.eclipse.emf.ecore.EObject modelElement)
modelElement - mepublic static <T extends org.eclipse.emf.ecore.EObject> T getParent(Class<T> parent, org.eclipse.emf.ecore.EObject child)
eContainer is null.T - type of the parent classparent - the class of the parentchild - the model element whose container should get returnedpublic static boolean isAssociationClassElement(org.eclipse.emf.ecore.EClass eClazz)
EClass is a association class. Association classes are
not displayed as dedicated elements. A link from one element to another
which goes over an association class is displayed by a dedicated widget.
This widgets allows to trace transparently without seeing the association
class.eClazz - the EClasspublic static Set<org.eclipse.emf.ecore.EObject> getAllContainedModelElements(org.eclipse.emf.ecore.EObject modelElement, boolean includeTransientContainments)
modelElement - the model elementincludeTransientContainments - true if transient containments should be included in the
resultpublic static Set<org.eclipse.emf.ecore.EObject> getAllContainedModelElements(org.eclipse.emf.ecore.EObject modelElement, boolean includeTransientContainments, boolean ignoreSingletonDatatypes)
modelElement - the model elementincludeTransientContainments - true if transient containments should be included in the
resultignoreSingletonDatatypes - whether to ignore singleton datatypes like, for example,
EStringpublic static Set<org.eclipse.emf.ecore.EObject> getAllContainedModelElements(org.eclipse.emf.ecore.resource.Resource resource, boolean includeTransientContainments, boolean ignoreSingletonDatatypes)
resource - the resourceincludeTransientContainments - true if transient containments should be included in the
resultignoreSingletonDatatypes - whether to ignore singleton datatypes like, for example,
EStringpublic static Set<org.eclipse.emf.ecore.EObject> getAllContainedModelElements(Collection<org.eclipse.emf.ecore.EObject> modelElements, boolean includeTransientContainments, boolean ignoreSingletonDatatypes)
modelElements - a collection of elementsincludeTransientContainments - true if transient containments should be included in the
resultignoreSingletonDatatypes - whether to ignore singleton datatypes like, for example,
EStringpublic static org.eclipse.emf.ecore.EObject getContainerModelElement(org.eclipse.emf.ecore.EObject modelElement)
modelElement - the model elementpublic static List<org.eclipse.emf.ecore.EObject> getAllContainedModelElementsAsList(org.eclipse.emf.ecore.EObject modelElement, boolean includeTransientContainments)
modelElement - the model elementincludeTransientContainments - true if transient containments should be included in the
resultpublic static void deleteIncomingCrossReferencesToElement(org.eclipse.emf.ecore.EObject element,
Collection<org.eclipse.emf.ecore.EStructuralFeature.Setting> inverseReferences,
Set<org.eclipse.emf.ecore.EObject> referenceSourceElementsToIgnore)
inverseReferences - a collection of inverse referenceselement - the model elementreferenceSourceElementsToIgnore - the set of all elements referencing the element to be ignoredpublic static void deleteOutgoingCrossReferences(IdEObjectCollection collection, org.eclipse.emf.ecore.EObject modelElement)
collection - the collectionmodelElement - the model elementpublic static List<SettingWithReferencedElement> collectOutgoingCrossReferences(IdEObjectCollection collection, Set<org.eclipse.emf.ecore.EObject> modelElements)
collection - the collectionmodelElements - the model elementspublic static boolean shouldBeCollected(IdEObjectCollection collection, Set<org.eclipse.emf.ecore.EObject> allModelElements, org.eclipse.emf.ecore.EObject referencedElement)
collection - the collectionallModelElements - the set of model elementsreferencedElement - the referenced elementpublic static org.eclipse.emf.ecore.EObject getSingleton(ModelElementId singletonId)
singletonId - the idpublic static ModelElementId getSingletonModelElementId(org.eclipse.emf.ecore.EObject singleton)
singleton - the singletonESSingletonIdResolver.getSingletonModelElementId(org.eclipse.emf.ecore.EObject)public static boolean isSingleton(org.eclipse.emf.ecore.EObject eObject)
eObject - the instanceESSingletonIdResolver.isSingleton(org.eclipse.emf.ecore.EObject)Copyright © 2017. All rights reserved.