Skip to content

The order of 'Encapsulate field' loses dartdocs. #2111

Open
@gspencergoog

Description

@gspencergoog

Currently when using Encapsulate field, the order of the generated values is private var, getter, setter.

It would make more sense to have the generated order be: getter, private var, then setter, instead of having the private var come first: if you had dartdoc documentation on the original var, then it will get lost when encapsulating, since dartdoc will now think the /// comment is on the private field.

For example, starting with:

  /// Counts the foos in a bar.
  int foo;

and you run "Encapsulate field" on foo, then you get:

  /// Counts the foos in a bar.
  int _foo;

  int get foo => _foo;

  set foo(int foo) {
    _foo = foo;
  }

Which means that dartdoc loses the original documentation, because it now sees that as attached to the private var, and not the getter, and so it needs to be moved manually.

It should generate it like this to retain the docs:

  /// Counts the foos in a bar.
  int get foo => _foo;

  int _foo;

  set foo(int foo) {
    _foo = foo;
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions