Table of Contents

Class Annotations

Namespace
RDCore.SDK.Model.AST
Assembly
RDCore.SDK.dll

The comment annotations of a parsed module (RD-VBAL §3.0.1.1), each bound to its one target: the module, or the declaration it is written above.

public static class Annotations
Inheritance
Annotations
Inherited Members

Remarks

An annotation is trivia (Trivia), which no node of the tree holds, so these readers take the whole parse. For a file that has blocks, they take the parse of one module (ParseOf(Uri)), which holds that module's trivia alone.

Where an annotation is written says what it can annotate: the module, in the module's declarations section or above a block's header; a member, directly above the declaration of a procedure, a Declare or an Event; a variable or a constant, directly above one of the module's. Written on the last lines of the declarations section, directly above the first procedure or above a variable, an annotation could annotate the module or that declaration. An annotation has one target, never two, so what the annotation is decides: the catalogue says what each one annotates (Targets).

  • An annotation the catalogue declares binds to the declaration it is written above when it annotates that kind of declaration, else to the module when it is written where it can annotate the module and it annotates modules, else to nothing: written where its target is not, it is misplaced. '@Folder right above the first procedure is the module's, and '@Description there is the procedure's.
  • An annotation the catalogue does not declare binds to the declaration it is written above, else to the module. An annotation on the last line of the declarations section binds to the first procedure "instead of the module itself" (RD-VBAL §3.0.1.1): the declaration is the nearer target.

Directly above an Enum, a Type or a statement that declares nothing (Option Explicit), an annotation annotates no declaration: written in the declarations section, it is the module's.

Fields

IgnoreAnnotation

The name of the legacy Rubberduck annotation '@Ignore, without the @: deprecated, and kept as a suppression of the codes it lists (RD-VBAL §2.6.4). It suppresses them in the whole file when the file is one module, in a block's module when it is written directly above the block's header, and nowhere else (GetSuppressionAnnotations(ModuleParseResult, bool)).

public const string IgnoreAnnotation = "Ignore"

Field Value

string

IgnoreModuleAnnotation

The name of the legacy Rubberduck annotation '@IgnoreModule, without the @: deprecated, and kept as a suppression of the codes it lists in the module it is written in (RD-VBAL §2.6.4, GetSuppressionAnnotations(ModuleParseResult, bool)).

public const string IgnoreModuleAnnotation = "IgnoreModule"

Field Value

string

Methods

GetAnnotations(ModuleParseResult, SyntaxNode, AnnotationCatalogue)

The annotations of a declaration of the module: those written immediately above it that bind to it, in the order they are written.

public static ImmutableArray<AnnotationTriviaNode> GetAnnotations(this ModuleParseResult parse, SyntaxNode declaration, AnnotationCatalogue catalogue)

Parameters

parse ModuleParseResult

The module's parse.

declaration SyntaxNode

A declaration of the module's tree: one of the children of its ModuleNode, such as a MemberDeclarationNode or a VariableDeclarationNode.

catalogue AnnotationCatalogue

The annotations the platform knows, which say what each annotation annotates.

Returns

ImmutableArray<AnnotationTriviaNode>

The annotations on the comment lines that end on the line before the declaration's first line, with no blank line, no code and no directive written between them, and no code before the comment on its line, that bind to the declaration rather than to the module (Annotations). Empty for a node that is not a child of the module's tree; for an Enum, a Type and a statement that declares nothing, which no annotation annotates; and for a variable declared after another in one statement (b of Dim a, b), which has no lines above it of its own.

Remarks

In a tree that holds the nodes of several files, an annotation and a declaration match only in one file, as each node's Uri says.

Exceptions

ArgumentNullException

catalogue is null.

GetArgumentText(AnnotationTriviaNode, int)

The text of a name or string literal argument of the annotation: RDC00315 of '@Ignore RDC00315, and /orders of '@HttpGet("/orders").

public static string? GetArgumentText(this AnnotationTriviaNode annotation, int index = 0)

Parameters

annotation AnnotationTriviaNode

The annotation.

index int

The zero-based position of the argument in the annotation's argument list; the first argument when omitted.

Returns

string

The name as it is written, or the string the literal writes; null when the annotation has no argument at that position, or when the argument is neither a simple name nor a string literal (a number, a member access).

GetHeaderAnnotations(ModuleParseResult)

The annotations written on the comment lines directly above the header of a block's module (Class Name, Module Name), in the order they are written: the module annotations of the block that are outside it.

public static ImmutableArray<AnnotationTriviaNode> GetHeaderAnnotations(this ModuleParseResult parse)

Parameters

parse ModuleParseResult

The parse of the block's module (ParseOf(Uri)), which holds those comment lines.

Returns

ImmutableArray<AnnotationTriviaNode>

The annotations of the module's file written before the start of the module's tree; empty for a module that is not a block's, whose tree starts where its file starts, and when the module has no tree.

GetModuleAnnotations(ModuleParseResult, AnnotationCatalogue)

The annotations of the module: those written in its declarations section that bind to it, in the order they are written.

public static ImmutableArray<AnnotationTriviaNode> GetModuleAnnotations(this ModuleParseResult parse, AnnotationCatalogue catalogue)

Parameters

parse ModuleParseResult

The module's parse.

catalogue AnnotationCatalogue

The annotations the platform knows, which say what each annotation annotates.

Returns

ImmutableArray<AnnotationTriviaNode>

Each annotation that no procedure of its file starts at or before, and that binds to the module rather than to the declaration it is written above (Annotations); empty when the module has no tree. In a tree that holds the nodes of several files, each annotation is in the declarations section of its own file, as each node's Uri says.

Remarks

The module of a block of a file (BlockModule) has module annotations outside it too: those on the comment lines directly above its header (GetHeaderAnnotations(ModuleParseResult)), which its parse holds (ParseOf(Uri)). They come first, as they are written first, and they are never a member's.

Exceptions

ArgumentNullException

catalogue is null.

GetStringArgument(AnnotationTriviaNode, int)

The value of a string literal argument of the annotation: "/orders" of '@HttpGet("/orders").

public static string? GetStringArgument(this AnnotationTriviaNode annotation, int index = 0)

Parameters

annotation AnnotationTriviaNode

The annotation.

index int

The zero-based position of the argument in the annotation's argument list.

Returns

string

The string the literal writes; null when the annotation has no argument at that position, or when the argument is not a string literal.

GetSuppressionAnnotations(ModuleParseResult, bool)

The annotations that suppress the diagnostics of the module (RD-VBAL §2.6.4), in the order they are written: '@IgnoreModule wherever it is written in the module, and '@Ignore where the file's layout lets it suppress.

public static ImmutableArray<AnnotationTriviaNode> GetSuppressionAnnotations(this ModuleParseResult parse, bool fileHasBlocks)

Parameters

parse ModuleParseResult

The module's parse: the parse of the file when it has no blocks, else the parse of one of its modules, a block's or the file's own module outside every block (ParseOf(Uri)).

fileHasBlocks bool

Whether the module's file has blocks (BlockModules is not empty).

Returns

ImmutableArray<AnnotationTriviaNode>

Every '@IgnoreModule of the parse. Every '@Ignore of the parse when the file has no blocks, where the file is the one module; when it has blocks, only those on the comment lines directly above a block's header (GetHeaderAnnotations(ModuleParseResult)), which are the block module's, and none of the '@Ignore written elsewhere, which suppress nothing: none for the file's own module. Names match in any case (IsNamed(AnnotationTriviaNode, string)).

Remarks

Which diagnostics each of these suppresses, by its arguments, is for the caller: this says only which annotations suppress in the module at all.

IsNamed(AnnotationTriviaNode, string)

Whether the annotation has a name, matched as VBA matches names, whatever their case (MS-VBAL §3.3.5.2): '@ignoremodule is named IgnoreModule.

public static bool IsNamed(this AnnotationTriviaNode annotation, string name)

Parameters

annotation AnnotationTriviaNode

The annotation.

name string

The name, without the @.

Returns

bool

true when the annotation's Name is the name in any case.