dartdart-mirrors

Dart mirrors reflectss Comments?


In the mirrors.dart source, you can find this:

/**
 * Class used for encoding comments as metadata annotations.
 */
class Comment {
  /**
   * The comment text as written in the source text.
   */
  final String text;

  /**
   * The comment text without the start, end, and padding text.
   *
   * For example, if [text] is [: /** Comment text. */ :] then the [trimmedText]
   * is [: Comment text. :].
   */
  final String trimmedText;

  /**
   * Is [:true:] if this comment is a documentation comment.
   *
   * That is, that the comment is either enclosed in [: /** ... */ :] or starts
   * with [: /// :].
   */
  final bool isDocComment;

  const Comment(this.text, this.trimmedText, this.isDocComment);
}

However that class isn't used anywhere else. How could we get use of that functionality? I would like to reflec field's documentations.


Solution

  • Doc comments are not available via dart:mirrors.

    You can use package:analyzer to access them, though.

    See https://pub.dartlang.org/documentation/analyzer/0.31.1/analyzer.dart.element.element/Element/documentationComment.html