示例#1
0
        public static IEnumerable <ITreeNode> GetAllDescendants([CanBeNull] this ITreeNode root, HashSet <ITreeNode> visitedNodes = null)
        {
            if (root == null)
            {
                yield break;
            }

            visitedNodes = visitedNodes ?? new HashSet <ITreeNode>();

            foreach (var descendant in root.Descendants())
            {
                if (visitedNodes.Contains(descendant))
                {
                    continue;
                }

                visitedNodes.Add(descendant);
                yield return(descendant);

                foreach (var child in descendant.GetAllDescendants())
                {
                    if (visitedNodes.Contains(child))
                    {
                        continue;
                    }

                    visitedNodes.Add(child);
                    yield return(child);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Returns a collection containing this element and all descendant elements.
        /// </summary>
        public static IEnumerable <ITreeNode <TNode> > SelfAndDescendants <TNode>(this ITreeNode <TNode> adapter)
        {
            yield return(adapter);

            foreach (var descendant in adapter.Descendants())
            {
                yield return(descendant);
            }
        }
        private IInvocationExpression FindChain([NotNull] ITreeNode topLevelNode)
        {
            foreach (var invocation in topLevelNode.Descendants().OfType <IInvocationExpression>())
            {
                if (MatchChain(invocation))
                {
                    return(invocation);
                }
            }

            return(null);
        }
示例#4
0
        private static IEnumerable <IDeclaration> GetDeclarationsInDescendants(this ITreeNode from)
        {
            var result = new HashSet <IDeclaration>();

            foreach (var child in from.Descendants())
            {
                if (child is IDeclaration declaration)
                {
                    result.Add(declaration);
                }
            }

            return(result);
        }
        private static void CollectUsageRanges([NotNull] IDeclaredElement declaredElement, [NotNull] ITreeNode scope, ref LocalList <DocumentRange> ranges)
        {
            foreach (var referenceExpression in scope.Descendants <IReferenceExpression>())
            {
                var currentElement = referenceExpression.Reference.Resolve().DeclaredElement;
                if (currentElement == null)
                {
                    continue;
                }

                if (currentElement.Equals(declaredElement))
                {
                    var range = referenceExpression.GetDocumentRange();
                    ranges.Add(range);
                }
            }
        }
        private static void RenameUsages(
            [NotNull] IDeclaredElement declaredElement, [NotNull] ITreeNode scope, [NotNull] ICSharpIdentifier name)
        {
            foreach (var referenceExpression in scope.Descendants <IReferenceExpression>())
            {
                var currentElement = referenceExpression.Reference.Resolve().DeclaredElement;
                if (currentElement == null)
                {
                    continue;
                }

                if (currentElement.Equals(declaredElement))
                {
                    referenceExpression.SetNameIdentifier(name);
                }
            }
        }