Encapsulate Field shouldn't give void as setter return type.
See original GitHub issueSteps to Reproduce
I selected a member variable, and hit alt-enter, and selected “Encapsulate field”. I got the following result:
Directory _outputDirectory;
Directory get outputDirectory => _outputDirectory;
void set outputDirectory(Directory outputDirectory) {
_outputDirectory = outputDirectory;
}
And some analysis warnings:
“Avoid wrapping fields in getters and setters just to be “safe”” (which I expected, since that’s exactly what the warning is for), but also: “Avoid return types on setters”, which is why I filed this bug: the template shouldn’t include the “void” return type for the setter.
Version info
[✓] Flutter (Channel widget_image, v0.3.1-pre.37, on Linux, locale en_US.UTF-8)
• Flutter version 0.3.1-pre.37 at /usr/local/google/home/gspencer/code/flutter
• Framework revision 0a76df892b (18 hours ago), 2018-04-18 16:21:38 -0700
• Engine revision 8973c733a5
• Dart version 2.0.0-dev.48.0.flutter-fe606f890b
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.2)
• Android SDK at /usr/local/google/home/gspencer/Android/Sdk
• Android NDK at /usr/local/google/home/gspencer/Android/Sdk/ndk-bundle
• Platform android-27, build-tools 27.0.2
• ANDROID_HOME = /usr/local/google/home/gspencer/Android/Sdk
• Java binary at: /opt/android-studio-with-blaze-3.0/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)
• All Android licenses accepted.
[✓] Android Studio (version 3.0)
• Android Studio at /opt/android-studio-with-blaze-3.0
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)
[✓] Android Studio (version 2.3)
• Android Studio at /opt/android-studio-with-blaze-2.3
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] IntelliJ IDEA Community Edition (version 2017.1)
• IntelliJ at /opt/intellij-ce-2017.1
• Flutter plugin version 18.4
• Dart plugin version 171.4694.29
[✓] IntelliJ IDEA Community Edition (version 2017.2)
• IntelliJ at /opt/intellij-ce-2017.2
• Flutter plugin version 21.2.2
• Dart plugin version 172.4343.25
[✓] IntelliJ IDEA Community Edition (version 2017.3)
• IntelliJ at /opt/intellij-ce-2017.3
• Flutter plugin version 23.2.2
• Dart plugin version 173.4700
[✓] IntelliJ IDEA Ultimate Edition (version 2017.1)
• IntelliJ at /opt/intellij-ue-2017.1
• Flutter plugin version 18.2
• Dart plugin version 171.4694.29
[✓] Connected devices (1 available)
• Nexus 6P • 84B7N15A07007628 • android-arm64 • Android 8.1.0 (API 27)
• No issues found!
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
java - why do we need it when setters are already public?
I understand the usage of encapsulation but when we are making the setters as public what is the point behind keeping the variables...
Read more >Avoid getters and setters whenever possible
The argument is that getters/setters and properties VIOLATE ENCAPSULATION by exposing internals as properties rather than mutating through ...
Read more >Why getter and setter methods are evil - InfoWorld
First, as I discussed earlier, it's okay for a method to return an object in terms of an interface that the object implements...
Read more >Backing Fields - EF Core - Microsoft Learn
This can be useful when encapsulation in the class is being used to restrict the use of and/or enhance the semantics around access...
Read more >Effective Dart: Usage
The initializer list gives you access to constructor parameters and lets you initialize fields before they can be read. So, if it's possible...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://dart-review.googlesource.com/c/sdk/+/52180
Thanks @gspencergoog!