flutter / flutter/flutter-intellij

The order of 'Encapsulate field' loses dartdocs.

Open
#2,111 8 comments 0 reactions 1 assignee Claimed by @scheglov View on GitHub
dependency: dart sdk
Dominant language
Java
Stars
2k
Forks
356
Avg merge
1d 11h
Merged PRs (30d)
27

Description

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:
```dart
/// Counts the foos in a bar.
int foo;
```
and you run "Encapsulate field" on `foo`, then you get:

```dart
/// 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:
```dart
/// Counts the foos in a bar.
int get foo => _foo;

int _foo;

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.