DOM: DomElement#getParentOfType


1) Please add javadoc for this method. It's not clear what the "strict" boolean
parameter means.

2) I've getting strange results from this method. Perhaps there were some
changes recently (result caching or similar)?
-


To be precise, in spring plugin I have some code like:

 domElement = ...
DomSpringBean parentBean = domElement.getParentOfType(DomSpringBean.class, 
false);
if (parentBean != null) {
  System.out.println("parent bean: " + parentBean.getBeanClass());
  DomSpringBean grandParentBean = parentBean.getParentOfType(DomSpringBean.class, 
false);
  if (grandParentBean != null) {
    System.out.println("grand parent bean: " + grandParentBean.getBeanClass());
  }
}
]]>


What seems to be happening is that the same bean/DOM element is returned
for both invocations.
The fragment of spring xml that this code is working on looks like:

  
    
      
    
  

]]>


Looking at debugger or output it's clear that the same bean is found for
both getParentOfType(..) calls.
Am I misunderstanding getParentOfType() rules, or has something perhaps recently
changed in the implementation code?

Thanks,

Taras


3 comments
Comment actions Permalink

IMHO the 'strict' parameter has the same meaning as in PsiTreeUtil.getParentOfType (where it isn't documented too...):

strict = false:
If the current element is already of the correct type, then it is returned.

strict = true:
The returned element must be higher in the hierarchy.

So in your case you should pass true for the strict parameter.

0
Comment actions Permalink

Thanks Martin,

Works perfectly of course. I did search for similar "getParent*" methods,
but should have tried a "getParentOfType" search first.

-tt


0

Please sign in to leave a comment.