Best way of traversing a model: bottom up [message #1389132] |
Fri, 27 June 2014 11:37 |
Alexander R Messages: 211 Registered: July 2013 |
Senior Member |
|
|
Hello everyone,
I've implemented a search algorithm, that finds a specific root-element from a start-element in my model. But I'm not really sure if this function is safe enough or not.
Is there maybe a better algorithms in the API who manages the same job?
Here my algorithme:
/**
* Finds the specific root element or a superClass of the specific root
* element. The startingpoint is the startElement.
*
* @param startElement
* : an EObject as a startElement
* @param specificRootElement
* : The root element you are searching or one of its
* superclasses.
* @return EObject: A specific root element
* @throws ClassNotFoundException
*/
public static <T> EObject findSpecificParentElement(EObject startElement, EClass specificRootElement)
throws ClassNotFoundException {
EObject parent = startElement.eContainer();
EClass parentClass = parent.eClass();
// if the searched class is the parentclass or if the searched class is
// one of the superClasses
if ((parent != null && !(parentClass == specificRootElement || EcoreUtil2.getAllSuperTypes(parentClass).contains(
specificRootElement)))) {
return findSpecificParentElement(parent, specificRootElement);
} else {
return parent;
}
}
regards,
Alex
[Updated on: Fri, 27 June 2014 11:43] Report message to a moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04308 seconds