Class Annotations
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.
'@Folderright above the first procedure is the module's, and'@Descriptionthere 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
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
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
parseModuleParseResultThe module's parse.
declarationSyntaxNodeA declaration of the module's tree: one of the children of its ModuleNode, such as a MemberDeclarationNode or a VariableDeclarationNode.
catalogueAnnotationCatalogueThe 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, aTypeand a statement that declares nothing, which no annotation annotates; and for a variable declared after another in one statement (bofDim 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
catalogueis 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
annotationAnnotationTriviaNodeThe annotation.
indexintThe 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
parseModuleParseResultThe 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
parseModuleParseResultThe module's parse.
catalogueAnnotationCatalogueThe 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
catalogueis 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
annotationAnnotationTriviaNodeThe annotation.
indexintThe 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
parseModuleParseResultThe 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)).
fileHasBlocksboolWhether the module's file has blocks (BlockModules is not empty).
Returns
- ImmutableArray<AnnotationTriviaNode>
Every
'@IgnoreModuleof the parse. Every'@Ignoreof 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'@Ignorewritten 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
annotationAnnotationTriviaNodeThe annotation.
namestringThe name, without the
@.