FindNodeRecursive overload or "FindDescendant"?

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
On the AstNodeBase class, might I request a FindNodeRecursive overload (or a FindDescendant method) that looks for a particular type of node?

It would be similar to FindAnscestor, except walking DOWN the tree instead of UP...

It would stop on the first "child" that is of the type requested (if any found).

My naive implementation is:

        public IAstNode FindDescendant(int offset, Type type)
        {
            IAstNode an = this.FindNodeRecursive(offset);
            if (an == null || an.GetType() == type)
                return an;
            else
                return an.FindAncestor(type);
        }
But a faster implementation would walk the tree directly, of course, rather than walking down only to walk back up.

Thanks!

[Modified at 05/09/2007 01:05 PM]

Kelly Leahy Software Architect Milliman, USA

Comments (4)

Posted 12 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
Oh... I forgot. The reason I'm asking you to add it is that I can only add it to my AstNode implementation, but you can add it to the IAstNode interface (so I don't have to cast all my IAstNode's that I want to use it on to AstNode).

Kelly Leahy Software Architect Milliman, USA

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Think this will do the trick?
public IAstNode FindDescendant(Type type, int offset) {
    IAstNode childNode = this.FindNode(offset);
    if (childNode != null) {
        IAstNode childChildNode = childNode.FindDescendant(type, offset);
        if (childChildNode != null)
            return childChildNode;
        else if (type.IsInstanceOfType(childNode)) 
            return childNode;
    }
    return null;
}


Actipro Software Support

Posted 12 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
Seems like it would work.

I guess the biggest thing is I'd want its signature added to the IAstNode interface.

Thanks for the quick response!

Kelly Leahy Software Architect Milliman, USA

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, it's added there and AstNodeBase.


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.