-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The order of 'Encapsulate field' loses dartdocs. #2111
Comments
That change looks like I'll end up with this instead: int _foo;
/// Counts the foos in a bar.
int get foo => _foo;
set foo(int foo) {
_foo = foo;
} That's not horrible (at least the docs are preserved), but real-world usage looks more like this, which makes it seem like the private var isn't really part of the "grouping" that goes together when you read the code, which is why I mentioned having the private after the getter instead: ParentData _parentData;
/// Data for use by the parent render object.
///
/// The parent data is used by the render object that lays out this object
/// (typically this object's parent in the render tree) to store information
/// relevant to itself and to any other nodes who happen to know exactly what
/// the data means. The parent data is opaque to the child.
///
/// * The parent data field must not be directly set, except by calling
/// [setupParentData] on the parent node.
/// * The parent data can be set before the child is added to the parent, by
/// calling [setupParentData] on the future parent node.
/// * The conventions for using the parent data depend on the layout protocol
/// used between the parent and child. For example, in box layout, the
/// parent data is completely opaque but in sector layout the child is
/// permitted to read some fields of the parent data.
ParentData get parentData => _parentData;
set parentData(ParentData parentData) {
_parentData = parentData;
} |
This is a slightly different problem - we put getter/setter right after the field. Alternatively |
Maybe the field could come last (getter, setter, field)? That would also keep them grouped. |
Oh, it seems that we have quite different ideas about the order of members in classes. The order we use in Analyzer is: constants, static fields, static accessors, instance fields, constructors, instance getters, instance methods, static methods. Inside each group we sort members alphabetically. I have never before seen grouping fields and accessors together in Dart code. Which projects do this? |
Flutter does. From our style guide: "The methods, properties, and other members of a class should be in an order that will help readers understand how the class works." "...Mutable properties, each in the order getter, private field, setter, without newlines separating them." |
R=brianwilkerson@google.com Bug: flutter/flutter-intellij#2111 Change-Id: If971e72b2cde15b7183f148da9da4d0dfed4ae05 Reviewed-on: https://dart-review.googlesource.com/52267 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Ah, I see. Of course Flutter has a bit different code style. Hm... Honestly I'm not sure what to do here. We could go the way of making a lot of code style settings, somewhere in |
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. |
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:
and you run "Encapsulate field" on
foo
, then you get: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:
The text was updated successfully, but these errors were encountered: