-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/dotnet/ReSharperPlugin.SpecflowRiderPlugin/Extensions/TreeNodeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
|
||
namespace ReSharperPlugin.SpecflowRiderPlugin.Extensions | ||
{ | ||
public static class TreeNodeExtensions | ||
{ | ||
public static ITreeNode GetLastNodeInLine(this ITreeNode node) | ||
{ | ||
while (node.NextSibling != null) | ||
node = node.NextSibling; | ||
return node; | ||
} | ||
|
||
public static IEnumerable<ITreeNode> GetChildrenInSubtrees( | ||
[NotNull] this ITreeNode node) | ||
{ | ||
if (node.FirstChild != null) | ||
{ | ||
ITreeNode child; | ||
for (child = node.FirstChild; child != null; child = child.NextSibling) | ||
{ | ||
yield return child; | ||
foreach (ITreeNode childrenInSubtree in child.GetChildrenInSubtrees()) | ||
yield return childrenInSubtree; | ||
} | ||
child = (ITreeNode) null; | ||
} | ||
} | ||
|
||
public static IEnumerable<T> GetChildrenInSubtrees<T>([NotNull] this ITreeNode node) where T : class, ITreeNode | ||
{ | ||
if (node.FirstChild != null) | ||
{ | ||
ITreeNode child; | ||
for (child = node.FirstChild; child != null; child = child.NextSibling) | ||
{ | ||
if (child is T obj) | ||
yield return obj; | ||
foreach (T childrenInSubtree in child.GetChildrenInSubtrees<T>()) | ||
yield return childrenInSubtree; | ||
} | ||
child = (ITreeNode) null; | ||
} | ||
} | ||
|
||
public static T GetParentOfType<T>([NotNull] this ITreeNode node) where T : class, ITreeNode | ||
{ | ||
for (; node != null; node = node.Parent) | ||
{ | ||
if (node is T obj) | ||
return obj; | ||
} | ||
return default(T); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters