/// <summary> /// Gets value indicating the context is in a function header (either function, method, lambda). /// </summary> /// public static bool IsInFunctionDeclHeader(this ITreeContext context, out Span span) => IsInDeclHeader <DummyFunctionDeclHeader>(context, out span);
/// <summary> /// Determines if the context is in given scopes. /// </summary> public static bool IsIn <T>(this ITreeContext context) where T : AstNode => Get <T>(context) != null;
/// <summary> /// Determines if the context is in given scopes. /// </summary> public static bool IsIn <T>(this ITreeContext context, Func <T, bool> predicate) where T : AstNode => Get <T>(context, predicate) != null;
/// <summary> /// Gets the first scope of type <typeparamref name="T"/> and matching given predicate. /// </summary> /// <typeparam name="T">Node type. Of type <see cref="AstNode"/>.</typeparam> /// <param name="context">Visitor context.</param> /// <param name="predicate">Additional predicate to filter scopes.</param> /// <returns>Node of type <typeparamref name="T"/> or <c>null</c> if the context does not have such scopes.</returns> public static T Get <T>(this ITreeContext context, Func <T, bool> predicate) where T : AstNode => context.Scope.OfType <T>().FirstOrDefault(predicate);
/// <summary> /// Gets the first scope of type <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">Node type. Of type <see cref="AstNode"/>.</typeparam> /// <param name="context">Visitor context.</param> /// <returns>Node of type <typeparamref name="T"/> or <c>null</c> if the context does not have such node.</returns> public static T Get <T>(this ITreeContext context) where T : AstNode => context.Scope.OfType <T>().FirstOrDefault();
/// <summary> /// Counts scopes that causes an indentation by default. /// Gets raugh level of indentation at current context state (blocks, type declaration). /// </summary> public static int CountIndent(this ITreeContext context) => Count(context, s_indentnodes);
/// <summary> /// Counts scopes matching given predicate. /// </summary> public static int Count(this ITreeContext context, Func <AstNode, bool> predicate) => context.Scope.Count(predicate);
/// <summary> /// Gets value indicating the context is in a method header (either function, method, lambda). /// </summary> /// public static bool IsInMethodDeclHeader(this ITreeContext context, out Span span) => IsInDeclHeader <DummyMethodDeclHeader>(context, out span);