Skip to content
Snippets Groups Projects
Commit ce264fd7 authored by Simon Barner's avatar Simon Barner
Browse files

YELLOW

getModelElementAncestor():
 - Actually return null if levelsUp > depth(modelElement)
 - Additionally, also return null if levelsUp < 0
refs 2490
parent 51d4f8d7
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: F0DBBD05D8DFBB7937EB53D25F86A65A
* @ConQAT.Rating YELLOW Hash: 4E50E2E5CCE10F860A7F387B0F593E41
*/
public class EcoreUtils {
......@@ -426,17 +426,18 @@ public class EcoreUtils {
/**
* Returns the ancestor of the {@link EObject} {@code o} that is {@code levelsUp} levels above
* model element in the hierarchy, or {@code null}, in case {@code levelsUp >
* depth(modelElement)}.
* model element in the hierarchy, or {@code null}, in case {@code levelsUp < 0} or
* {@code levelsUp > depth(modelElement)}.
*/
public static EObject getModelElementAncestor(EObject o, int levelsUp) {
// FIXME (FH): this method never returns null (as stated in the comment)
if(levelsUp < 0) {
return null;
}
while(o.eContainer() != null && levelsUp > 0) {
o = o.eContainer();
levelsUp--;
}
return o;
return levelsUp == 0 ? o : null;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment