I thinks there is a mismatch between the relection library
and the language specification
.
From language specification:
"Metadata can appear before a library, part header, class, typedef, type parameter, constructor, factory, function, field, parameter, or variable declaration and before an import, export or part directive".
That is, metadata
can appear before variable declaration
.
Now look at variable declaration
definition.
variableDeclaration:
declaredIdentifier (',' identifier)*
;
declaredIdentifier:
metadata finalConstVarOrType identifier
That is, variable declaration
may consist from these parts:
- Metadata, that applied to this declaration.
- final/const/var/type specifier
- List of identifiers in this declaration.
This means that one variable declaration
can declare unlimited number of variables.
But it will still be one declaration, but not many different declarations in one declaration.
This only means that this variable declaration
declares a set of variables
.
Also, if metadata
can appear before variable declaration
it must be applied to all elements in this declaration.
This is because, as states language specification, metadata
can appear only before declaration
but not before some part
in this declaration.
This is because, as states language specification, we have not THREE variable declarations but ONE variable declaration that declared THREE variables in this declaration.
var a, b, c;
So, if annotate this variable declaration.
@Foo var a, b, c;
Then, as states language specification, if metadata can apear before variable declaration then this metadata must be applied to whole declaration but not only to the first element in this declaration.
P.S.
This conclusions that can be made on the basis of this document:
https://www.dartlang.org/docs/spec/latest/dart-language-specification.html