Skip to content

Inconsistent behavior of beginToken for some analyzer AST nodes with doc comments #56313

Open
@stereotype441

Description

@stereotype441

The following analyzer AST node kinds support a documentationComment getter:

  • AugmentationImportDirective
  • ClassDeclaration
  • ClassTypeAlias
  • ConstructorDeclaration
  • DeclaredIdentifier
  • EnumConstantDeclaration
  • EnumDeclaration
  • ExportDirective
  • ExtensionDeclaration
  • ExtensionTypeDeclaration
  • FieldDeclaration
  • FieldFormalParameter
  • FunctionDeclaration
  • FunctionTypeAlias
  • FunctionTypedFormalParameter
  • GenericTypeAlias
  • ImportDirective
  • LibraryAugmentationDirective
  • LibraryDirective
  • MethodDeclaration
  • MixinDeclaration
  • PartDirective
  • PartOfDirective
  • PatternVariableDeclaration
  • SimpleFormalParameter
  • SuperFormalParameter
  • TopLevelVariableDeclaration
  • TypeParameter
  • VariableDeclaration
  • VariableDeclarationList

For nearly all of these node kinds, if the documentationComment is non-null, and the documentation comment precedes the first annotation, the beginToken getter returns the first token of the documentation comment. This is consistent with the behavior of the visitChildren method, which visits any annotations as well as the documentation comment (if present), in source order, prior to visiting the remaining children of the node.

However, for these 4 node kinds, beginToken always returns the first non-comment token of the declaration, ignoring the documentationComment:

  • FieldFormalParameter
  • FunctionTypedFormalParameter
  • SimpleFormalParameter
  • SuperFormalParameter

But visitChildren still visits the documentation comment (if present), so visitChildren and beginToken behave inconsistently for these 4 node kinds.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onanalyzer-apiIssues that impact the public API of the analyzer packagearea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions