PsiElement getChildren getFirstChild question

Hello,

i just came across the fact that getChildren() method of PsiElement returns only nodes which i built with PsiBuilder earlier, however getFirstChild() does not return first of those nodes, but i guess it returns PsiLeafElement (or what?) which wraps my tokens.

I wonder if this is the intended behaviour and why is it so and are there methods to get firstChild from getChildren() array, or getNextSibling() according to parent's getChildren() array?

1 comment
Comment actions Permalink

Hello Jay,

i just came across the fact that getChildren() method of PsiElement
returns only nodes which i built with PsiBuilder earlier, however
getFirstChild() does not return first of those nodes, but i guess it
returns PsiLeafElement (or what?) which wraps my tokens.

I wonder if this is the intended behaviour and why is it so and are
there methods to get firstChild from getChildren() array, or
getNextSibling() according to parent's getChildren() array?


This behavior is indeed confusing, but fixing it at this moment would break
compatibility with a lot of code, so I'm afraid this is going to stay.

You can just navigate the array returned by getChildren() yourself.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.