Enable prefer_final_fields in three packages
Other than the updates to analysis options files, these changes are all
from dartfix.
Change-Id: I517b0601e36d5456960d81be9a429cbacf711141
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131342
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/analysis_options.yaml b/pkg/analysis_server/analysis_options.yaml
index fcdfa5a..f20b958 100644
--- a/pkg/analysis_server/analysis_options.yaml
+++ b/pkg/analysis_server/analysis_options.yaml
@@ -39,7 +39,7 @@
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- #- prefer_final_fields # 35
+ - prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
#- prefer_if_null_operators # 22
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart
index 4c26bb0..eeee66f 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart
@@ -9,6 +9,83 @@
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';
+/// Helper for reading client dynamic registrations which may be ommitted by the
+/// client.
+class ClientDynamicRegistrations {
+ /// All dynamic registrations supported by the Dart LSP server.
+ ///
+ /// Anything listed here and supported by the client will not send a static
+ /// registration but intead dynamically register (usually only for a subset of
+ /// files such as for .dart/pubspec.yaml/etc).
+ ///
+ /// When adding new capabilities that will be registered dynamically, the
+ /// test_dynamicRegistration_XXX tests in `lsp/initialization_test.dart` should
+ /// also be updated to ensure no double-registrations.
+ static const supported = [
+ Method.textDocument_didOpen,
+ Method.textDocument_didChange,
+ Method.textDocument_didClose,
+ Method.textDocument_completion,
+ Method.textDocument_hover,
+ Method.textDocument_signatureHelp,
+ Method.textDocument_references,
+ Method.textDocument_documentHighlight,
+ Method.textDocument_formatting,
+ Method.textDocument_onTypeFormatting,
+ Method.textDocument_definition,
+ Method.textDocument_codeAction,
+ Method.textDocument_rename,
+ Method.textDocument_foldingRange,
+ ];
+ final ClientCapabilities _capabilities;
+
+ ClientDynamicRegistrations(this._capabilities);
+
+ bool get codeActions =>
+ _capabilities.textDocument?.foldingRange?.dynamicRegistration ?? false;
+
+ bool get completion =>
+ _capabilities.textDocument?.completion?.dynamicRegistration ?? false;
+
+ bool get definition =>
+ _capabilities.textDocument?.definition?.dynamicRegistration ?? false;
+
+ bool get documentHighlights =>
+ _capabilities.textDocument?.documentHighlight?.dynamicRegistration ??
+ false;
+
+ bool get documentSymbol =>
+ _capabilities.textDocument?.documentSymbol?.dynamicRegistration ?? false;
+
+ bool get folding =>
+ _capabilities.textDocument?.foldingRange?.dynamicRegistration ?? false;
+
+ bool get formatting =>
+ _capabilities.textDocument?.formatting?.dynamicRegistration ?? false;
+
+ bool get hover =>
+ _capabilities.textDocument?.hover?.dynamicRegistration ?? false;
+
+ bool get implementation =>
+ _capabilities.textDocument?.implementation?.dynamicRegistration ?? false;
+
+ bool get references =>
+ _capabilities.textDocument?.references?.dynamicRegistration ?? false;
+
+ bool get rename =>
+ _capabilities.textDocument?.rename?.dynamicRegistration ?? false;
+
+ bool get signatureHelp =>
+ _capabilities.textDocument?.signatureHelp?.dynamicRegistration ?? false;
+
+ bool get textSync =>
+ _capabilities.textDocument?.synchronization?.dynamicRegistration ?? false;
+
+ bool get typeFormatting =>
+ _capabilities.textDocument?.onTypeFormatting?.dynamicRegistration ??
+ false;
+}
+
class InitializeMessageHandler
extends MessageHandler<InitializeParams, InitializeResult> {
InitializeMessageHandler(LspAnalysisServer server) : super(server);
@@ -143,80 +220,3 @@
return success(InitializeResult(server.capabilities));
}
}
-
-/// Helper for reading client dynamic registrations which may be ommitted by the
-/// client.
-class ClientDynamicRegistrations {
- ClientCapabilities _capabilities;
- ClientDynamicRegistrations(this._capabilities);
-
- /// All dynamic registrations supported by the Dart LSP server.
- ///
- /// Anything listed here and supported by the client will not send a static
- /// registration but intead dynamically register (usually only for a subset of
- /// files such as for .dart/pubspec.yaml/etc).
- ///
- /// When adding new capabilities that will be registered dynamically, the
- /// test_dynamicRegistration_XXX tests in `lsp/initialization_test.dart` should
- /// also be updated to ensure no double-registrations.
- static const supported = [
- Method.textDocument_didOpen,
- Method.textDocument_didChange,
- Method.textDocument_didClose,
- Method.textDocument_completion,
- Method.textDocument_hover,
- Method.textDocument_signatureHelp,
- Method.textDocument_references,
- Method.textDocument_documentHighlight,
- Method.textDocument_formatting,
- Method.textDocument_onTypeFormatting,
- Method.textDocument_definition,
- Method.textDocument_codeAction,
- Method.textDocument_rename,
- Method.textDocument_foldingRange,
- ];
-
- bool get textSync =>
- _capabilities.textDocument?.synchronization?.dynamicRegistration ?? false;
-
- bool get hover =>
- _capabilities.textDocument?.hover?.dynamicRegistration ?? false;
-
- bool get completion =>
- _capabilities.textDocument?.completion?.dynamicRegistration ?? false;
-
- bool get signatureHelp =>
- _capabilities.textDocument?.signatureHelp?.dynamicRegistration ?? false;
-
- bool get definition =>
- _capabilities.textDocument?.definition?.dynamicRegistration ?? false;
-
- bool get implementation =>
- _capabilities.textDocument?.implementation?.dynamicRegistration ?? false;
-
- bool get references =>
- _capabilities.textDocument?.references?.dynamicRegistration ?? false;
-
- bool get documentHighlights =>
- _capabilities.textDocument?.documentHighlight?.dynamicRegistration ??
- false;
-
- bool get documentSymbol =>
- _capabilities.textDocument?.documentSymbol?.dynamicRegistration ?? false;
-
- bool get formatting =>
- _capabilities.textDocument?.formatting?.dynamicRegistration ?? false;
-
- bool get typeFormatting =>
- _capabilities.textDocument?.onTypeFormatting?.dynamicRegistration ??
- false;
-
- bool get folding =>
- _capabilities.textDocument?.foldingRange?.dynamicRegistration ?? false;
-
- bool get codeActions =>
- _capabilities.textDocument?.foldingRange?.dynamicRegistration ?? false;
-
- bool get rename =>
- _capabilities.textDocument?.rename?.dynamicRegistration ?? false;
-}
diff --git a/pkg/analysis_server/test/integration/support/integration_tests.dart b/pkg/analysis_server/test/integration/support/integration_tests.dart
index a7b0193..c5beb46 100644
--- a/pkg/analysis_server/test/integration/support/integration_tests.dart
+++ b/pkg/analysis_server/test/integration/support/integration_tests.dart
@@ -488,7 +488,7 @@
/**
* Stopwatch that we use to generate timing information for debug output.
*/
- Stopwatch _time = Stopwatch();
+ final Stopwatch _time = Stopwatch();
/**
* The [currentElapseTime] at which the last communication was received from the server
diff --git a/pkg/analysis_server_client/analysis_options.yaml b/pkg/analysis_server_client/analysis_options.yaml
index 3368902..38ce34f 100644
--- a/pkg/analysis_server_client/analysis_options.yaml
+++ b/pkg/analysis_server_client/analysis_options.yaml
@@ -33,7 +33,7 @@
- prefer_conditional_assignment
- prefer_contains
- prefer_equal_for_default_values
- #- prefer_final_fields # 2
+ - prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
- prefer_if_null_operators
diff --git a/pkg/analysis_server_client/lib/handler/connection_handler.dart b/pkg/analysis_server_client/lib/handler/connection_handler.dart
index 1360506..aada7f4 100644
--- a/pkg/analysis_server_client/lib/handler/connection_handler.dart
+++ b/pkg/analysis_server_client/lib/handler/connection_handler.dart
@@ -21,7 +21,7 @@
///
/// Clients may mix-in this class, but may not extend or implement it.
mixin ConnectionHandler implements NotificationHandler {
- Completer<bool> _connected = Completer();
+ final Completer<bool> _connected = Completer();
/// Clients should implement this method to return the server being managed.
/// This mixin will stop the server process if a connection cannot be
diff --git a/pkg/analysis_server_client/lib/server.dart b/pkg/analysis_server_client/lib/server.dart
index 6ee864f..f30db66 100644
--- a/pkg/analysis_server_client/lib/server.dart
+++ b/pkg/analysis_server_client/lib/server.dart
@@ -20,7 +20,7 @@
class Server {
/// If not `null`, [_listener] will be sent information
/// about interactions with the server.
- ServerListener _listener;
+ final ServerListener _listener;
/// Server process object, or `null` if server hasn't been started yet
/// or if the server has already been stopped.
diff --git a/pkg/analyzer_plugin/analysis_options.yaml b/pkg/analyzer_plugin/analysis_options.yaml
index d7cced6..2000d43 100644
--- a/pkg/analyzer_plugin/analysis_options.yaml
+++ b/pkg/analyzer_plugin/analysis_options.yaml
@@ -32,7 +32,7 @@
- prefer_conditional_assignment
- prefer_contains
- prefer_equal_for_default_values
- #- prefer_final_fields # 5
+ - prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
#- prefer_if_null_operators # 12
diff --git a/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart b/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
index f727885..afeb695 100644
--- a/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
+++ b/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
@@ -89,7 +89,7 @@
/**
* The port used to send notifications and responses to the server.
*/
- SendPort _sendPort;
+ final SendPort _sendPort;
/**
* The port used to receive requests from the server.
diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
index c9751b8..26e57b4 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
@@ -94,7 +94,7 @@
* An [EditBuilder] used to build edits in Dart files.
*/
class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
- List<String> _KNOWN_METHOD_NAME_PREFIXES = ['get', 'is', 'to'];
+ final List<String> _KNOWN_METHOD_NAME_PREFIXES = ['get', 'is', 'to'];
/**
* Whether [_enclosingClass] and [_enclosingExecutable] have been initialized.
diff --git a/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart b/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart
index 088ab48..57abe69 100644
--- a/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart
+++ b/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart
@@ -353,12 +353,12 @@
* Note: the enumerated values stored in this map are intended to be bitwise
* compared.
*/
- Map<String, int> _completionTypesGenerated = HashMap<String, int>();
+ final Map<String, int> _completionTypesGenerated = HashMap<String, int>();
/**
* Map from completion identifier to completion suggestion
*/
- Map<String, CompletionSuggestion> _suggestionMap =
+ final Map<String, CompletionSuggestion> _suggestionMap =
<String, CompletionSuggestion>{};
/**
diff --git a/pkg/analyzer_plugin/test/integration/support/integration_tests.dart b/pkg/analyzer_plugin/test/integration/support/integration_tests.dart
index a6d839a..a77238c 100644
--- a/pkg/analyzer_plugin/test/integration/support/integration_tests.dart
+++ b/pkg/analyzer_plugin/test/integration/support/integration_tests.dart
@@ -457,7 +457,7 @@
/**
* Stopwatch that we use to generate timing information for debug output.
*/
- Stopwatch _time = Stopwatch();
+ final Stopwatch _time = Stopwatch();
/**
* The [currentElapseTime] at which the last communication was received from the server