FormalParameter metadata and documentationComment

53 views
Skip to first unread message

Alexandre Ardhuin

unread,
Jun 11, 2021, 5:45:04 PM6/11/21
to analyzer...@dartlang.org
Hi,

I wondered why FormalParameter doesn't extend/implement AnnotatedNode. Looking at the ast tree of objects it seems that's because DefaultFormalParameter doesn't have a documentationComment getter but I don't really understand why. Is it intended?

Alexandre

Brian Wilkerson

unread,
Jun 11, 2021, 6:33:29 PM6/11/21
to Dart Analyzer Discussion
`DefaultFormalParameter` doesn't have a `documentationComment` getter because the documentation comment (if there is one, which is presumably rare) is associated with the `NormalFormalParameter` that's a child of the `DefaultFormalParameter`. In general, we limit the API for each node to only include accessors for the direct children of the node. It might be more appropriate to ask why `FormalParameter` has a getter for the metadata when the metadata is also associated with the `NormalFormalParameter`. I don't have an answer for that one; I can only guess that it was an oversight that was never corrected.

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/CAPiP%2BgsDE0RGpvhX27FVgo%2BtWPutinD5ERSjZ-a0x0shV%3Dxzwg%40mail.gmail.com.

Alexandre Ardhuin

unread,
Jun 14, 2021, 3:30:52 AM6/14/21
to analyzer...@dartlang.org
Hi,

I asked the question because in lib/dart/ast/ast.dart there are only 2 declaration of `get metadata;` (one in AnnotatedNode and one in FormalParameter) and there are only 2 declaration of `get documentationComment;` (one in AnnotatedNode and one in NormalFormalParameter). This looks like an exception that can be fixed by making FormalParameter a subtype of AnnotatedNode (that is only adding `get documentationComment;` on FormalParameter - not a big deal IMHO). 

In my particular case, if FormalParameter was a subtype of AnnotatedNode it would make my code easier because I would be able to rely on firstTokenAfterCommentAndMetadata and sortedCommentAndAnnotations directly from AnnotatedNode. Today I have to make a special case for FormalParameter by simulating those methods.

Alexandre


Brian Wilkerson

unread,
Jun 14, 2021, 10:34:30 AM6/14/21
to Dart Analyzer Discussion, Konstantin Shcheglov
Yeah, I kind of agree. I suspect it would have been better if we had modeled parameters as a single class with optional children (including an optional `DefaultValue` child for the `=` and expression).

However, given that `DefaultFormalParameter` has a `NormalFormalParameter` as a child, and the comment and metadata are associated with the child, I think it would be odd to add the getters `FormalParameter`. I think we've been moving away from having getters on a parent node that return data from the node's children. That said, if we wanted to change the structure of the classes this might be a reasonable first step.

On Mon, Jun 14, 2021 at 12:30 AM Alexandre Ardhuin <alexandr...@gmail.com> wrote:
Hi,

I asked the question because in lib/dart/ast/ast.dart there are only 2 declaration of `get metadata;` (one in AnnotatedNode and one in FormalParameter) and there are only 2 declaration of `get documentationComment;` (one in AnnotatedNode and one in NormalFormalParameter). This looks like an exception that can be fixed by making FormalParameter a subtype of AnnotatedNode (that is only adding `get documentationComment;` on FormalParameter - not a big deal IMHO). 

In my particular case, if FormalParameter was a subtype of AnnotatedNode it would make my code easier because I would be able to rely on firstTokenAfterCommentAndMetadata and sortedCommentAndAnnotations directly from AnnotatedNode. Today I have to make a special case for FormalParameter by simulating those methods.

Alexandre


Le sam. 12 juin 2021 à 00:33, 'Brian Wilkerson' via Dart Analyzer Discussion <analyzer...@dartlang.org> a écrit :
`DefaultFormalParameter` doesn't have a `documentationComment` getter because the documentation comment (if there is one, which is presumably rare) is associated with the `NormalFormalParameter` that's a child of the `DefaultFormalParameter`. In general, we limit the API for each node to only include accessors for the direct children of the node. It might be more appropriate to ask why `FormalParameter` has a getter for the metadata when the metadata is also associated with the `NormalFormalParameter`. I don't have an answer for that one; I can only guess that it was an oversight that was never corrected.

On Fri, Jun 11, 2021 at 2:45 PM Alexandre Ardhuin <alexandr...@gmail.com> wrote:
Hi,

I wondered why FormalParameter doesn't extend/implement AnnotatedNode. Looking at the ast tree of objects it seems that's because DefaultFormalParameter doesn't have a documentationComment getter but I don't really understand why. Is it intended?

Alexandre

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/CAPiP%2BgsDE0RGpvhX27FVgo%2BtWPutinD5ERSjZ-a0x0shV%3Dxzwg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/CAO5M3uhRb7v%3DnnUvBY6SoB%2Bkg3rnHLLgRj%3Drn3CS1f4kpV8KqA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
Reply all
Reply to author
Forward
0 new messages