question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The order of 'Encapsulate field' loses dartdocs.

See original GitHub issue

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;
  }

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
scheglovcommented, Apr 25, 2018

Ah, I see. Of course Flutter has a bit different code style.

Hm… Honestly I’m not sure what to do here. This is not what most of the other code does.

We could go the way of making a lot of code style settings, somewhere in analysis_options.yaml - order of declarations, adding type for extracted locals, add or omit new keyword. Support for settings costs something, but if it is important, we could do this. @devoncarew @bwilkerson

0reactions
gspencergoogcommented, Apr 26, 2018

Well, it sure would be useful to have these actions be configurable. If you had those options, then you could also do something along the line of “Sort class members”, but have it apply the ordering in the options instead of sorting alphabetically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Effective Dart: Usage
If a field doesn't depend on any constructor parameters, it can and should be initialized at its declaration. It takes less code and...
Read more >
Encapsulate Fields | IntelliJ IDEA Documentation - JetBrains
The Encapsulate Fields refactoring lets you hide your data and create the necessary accessors. Hiding your data and accessing it through an outward ......
Read more >
dartdoc 0.36.2 | Dart Package - Pub.dev
A non-interactive HTML documentation generator for Dart source code.
Read more >
CHANGELOG.md
#3220; Make ModelElement.element a getter; subclasses provide the field. ... BREAKING CHANGE: Many breaking changes to dartdoc API, as part of the broad ......
Read more >
Intro to encapsulation and decapsulation in networking
Encapsulation and decapsulation in networking are foundational concepts in data transfer. Learn how they work with the layers of the OSI and TCP/IP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found