From b06b60702b9e85585c3979c69ca91df85204173f Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 7 Dec 2021 22:45:59 +0000 Subject: [PATCH] analysis_server: Enforce strict-casts Bug: https://github.com/dart-lang/sdk/issues/41651 Change-Id: I9be21ab7e8f8b61707a75d7d4b5f9a872ad0fb95 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222220 Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins --- pkg/analysis_server/analysis_options.yaml | 6 +- .../protocol_custom_generated.dart | 8 +- .../lib/lsp_protocol/protocol_generated.dart | 289 +++++++++--------- .../lib/src/plugin/result_merger.dart | 6 +- .../lib/src/server/sdk_configuration.dart | 17 +- .../lib/src/services/pub/pub_api.dart | 4 +- .../lib/src/services/pub/pub_command.dart | 2 +- pkg/analysis_server/lib/src/status/pages.dart | 2 +- .../lib/src/utilities/extensions/yaml.dart | 5 +- .../lib/src/utilities/profiling.dart | 2 +- .../lib/src/utilities/yaml_node_locator.dart | 2 +- pkg/analysis_server/test/benchmarks_test.dart | 4 +- .../test/client/impl/expect_mixin.dart | 2 +- .../test/stress/replay/operation.dart | 2 +- .../test/stress/utilities/server.dart | 2 +- .../completion_metrics/metrics_util_test.dart | 2 +- .../test/tool/lsp_spec/json_test.dart | 27 +- .../tool/code_completion/corpus.dart | 10 +- .../tool/instrumentation/log/log.dart | 40 +-- .../tool/instrumentation/log_viewer.dart | 4 +- .../tool/instrumentation/page/log_page.dart | 4 +- .../tool/lsp_spec/codegen_dart.dart | 6 +- .../tool/lsp_spec/generate_all.dart | 13 +- 23 files changed, 236 insertions(+), 223 deletions(-) diff --git a/pkg/analysis_server/analysis_options.yaml b/pkg/analysis_server/analysis_options.yaml index e737f277a04..fdda3f29484 100644 --- a/pkg/analysis_server/analysis_options.yaml +++ b/pkg/analysis_server/analysis_options.yaml @@ -1,10 +1,8 @@ include: package:pedantic/analysis_options.1.9.0.yaml analyzer: - # This currently finds ~1,200 implicit-casts issues when enabled. - # TODO(srawlins): Switch to strict-casts - # strong-mode: - # implicit-casts: false + language: + strict-casts: true exclude: - test/mock_packages/** errors: diff --git a/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart b/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart index 03ef62f166b..5c222c3a91f 100644 --- a/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart +++ b/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart @@ -846,7 +846,7 @@ class FlutterOutline implements ToJsonable { try { final attributes = obj['attributes']; if (attributes != null && - !((attributes is List && + !((attributes is List && (attributes.every((item) => FlutterOutlineAttribute.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -905,7 +905,7 @@ class FlutterOutline implements ToJsonable { try { final children = obj['children']; if (children != null && - !((children is List && + !((children is List && (children.every( (item) => FlutterOutline.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -1168,7 +1168,7 @@ class Outline implements ToJsonable { try { final children = obj['children']; if (children != null && - !((children is List && + !((children is List && (children .every((item) => Outline.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -1376,7 +1376,7 @@ class PublishClosingLabelsParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((labels is List && + if (!((labels is List && (labels.every((item) => ClosingLabel.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; diff --git a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart index e7923754bcf..e8de391aa45 100644 --- a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart +++ b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart @@ -452,7 +452,7 @@ class CallHierarchyIncomingCall implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((fromRanges is List && + if (!((fromRanges is List && (fromRanges.every((item) => Range.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -741,7 +741,7 @@ class CallHierarchyItem implements ToJsonable { try { final tags = obj['tags']; if (tags != null && - !((tags is List && + !((tags is List && (tags.every((item) => SymbolTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -963,7 +963,7 @@ class CallHierarchyOutgoingCall implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((fromRanges is List && + if (!((fromRanges is List && (fromRanges.every((item) => Range.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -1298,7 +1298,7 @@ class CallHierarchyRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -2585,7 +2585,7 @@ class CodeAction implements ToJsonable { try { final diagnostics = obj['diagnostics']; if (diagnostics != null && - !((diagnostics is List && + !((diagnostics is List && (diagnostics .every((item) => Diagnostic.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -2926,7 +2926,7 @@ class CodeActionClientCapabilitiesCodeActionKind implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((valueSet is List && + if (!((valueSet is List && (valueSet .every((item) => CodeActionKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -3071,7 +3071,7 @@ class CodeActionClientCapabilitiesResolveSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((properties is List && + if (!((properties is List && (properties.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -3160,7 +3160,7 @@ class CodeActionContext implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((diagnostics is List && + if (!((diagnostics is List && (diagnostics .every((item) => Diagnostic.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -3173,7 +3173,7 @@ class CodeActionContext implements ToJsonable { try { final only = obj['only']; if (only != null && - !((only is List && + !((only is List && (only.every( (item) => CodeActionKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -3280,7 +3280,7 @@ class CodeActionKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -3402,7 +3402,7 @@ class CodeActionOptions implements WorkDoneProgressOptions, ToJsonable { try { final codeActionKinds = obj['codeActionKinds']; if (codeActionKinds != null && - !((codeActionKinds is List && + !((codeActionKinds is List && (codeActionKinds.every( (item) => CodeActionKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -3712,7 +3712,7 @@ class CodeActionRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -3725,7 +3725,7 @@ class CodeActionRegistrationOptions try { final codeActionKinds = obj['codeActionKinds']; if (codeActionKinds != null && - !((codeActionKinds is List && + !((codeActionKinds is List && (codeActionKinds.every( (item) => CodeActionKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -4262,7 +4262,7 @@ class CodeLensRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -4698,7 +4698,7 @@ class ColorPresentation implements ToJsonable { try { final additionalTextEdits = obj['additionalTextEdits']; if (additionalTextEdits != null && - !((additionalTextEdits is List && + !((additionalTextEdits is List && (additionalTextEdits .every((item) => TextEdit.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -4990,7 +4990,8 @@ class Command implements ToJsonable { try { final arguments = obj['arguments']; if (arguments != null && - !((arguments is List && (arguments.every((item) => true))))) { + !((arguments is List && + (arguments.every((item) => true))))) { reporter.reportError('must be of type List'); return false; } @@ -5323,7 +5324,7 @@ class CompletionClientCapabilitiesCompletionItem implements ToJsonable { try { final documentationFormat = obj['documentationFormat']; if (documentationFormat != null && - !((documentationFormat is List && + !((documentationFormat is List && (documentationFormat .every((item) => MarkupKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -5482,7 +5483,7 @@ class CompletionClientCapabilitiesCompletionItemKind implements ToJsonable { try { final valueSet = obj['valueSet']; if (valueSet != null && - !((valueSet is List && + !((valueSet is List && (valueSet.every( (item) => CompletionItemKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -5554,7 +5555,7 @@ class CompletionClientCapabilitiesInsertTextModeSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((valueSet is List && + if (!((valueSet is List && (valueSet .every((item) => InsertTextMode.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -5627,7 +5628,7 @@ class CompletionClientCapabilitiesResolveSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((properties is List && + if (!((properties is List && (properties.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -5698,7 +5699,7 @@ class CompletionClientCapabilitiesTagSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((valueSet is List && + if (!((valueSet is List && (valueSet.every( (item) => CompletionItemTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -6124,7 +6125,7 @@ class CompletionItem implements ToJsonable { try { final tags = obj['tags']; if (tags != null && - !((tags is List && + !((tags is List && (tags.every( (item) => CompletionItemTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -6245,7 +6246,7 @@ class CompletionItem implements ToJsonable { try { final additionalTextEdits = obj['additionalTextEdits']; if (additionalTextEdits != null && - !((additionalTextEdits is List && + !((additionalTextEdits is List && (additionalTextEdits .every((item) => TextEdit.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -6258,7 +6259,7 @@ class CompletionItem implements ToJsonable { try { final commitCharacters = obj['commitCharacters']; if (commitCharacters != null && - !((commitCharacters is List && + !((commitCharacters is List && (commitCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -6353,7 +6354,7 @@ class CompletionItemKind { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -6403,7 +6404,7 @@ class CompletionItemTag { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -6483,7 +6484,7 @@ class CompletionList implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((items is List && + if (!((items is List && (items .every((item) => CompletionItem.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -6600,7 +6601,7 @@ class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { try { final triggerCharacters = obj['triggerCharacters']; if (triggerCharacters != null && - !((triggerCharacters is List && + !((triggerCharacters is List && (triggerCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -6612,7 +6613,7 @@ class CompletionOptions implements WorkDoneProgressOptions, ToJsonable { try { final allCommitCharacters = obj['allCommitCharacters']; if (allCommitCharacters != null && - !((allCommitCharacters is List && + !((allCommitCharacters is List && (allCommitCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -6946,7 +6947,7 @@ class CompletionRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -6959,7 +6960,7 @@ class CompletionRegistrationOptions try { final triggerCharacters = obj['triggerCharacters']; if (triggerCharacters != null && - !((triggerCharacters is List && + !((triggerCharacters is List && (triggerCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -6971,7 +6972,7 @@ class CompletionRegistrationOptions try { final allCommitCharacters = obj['allCommitCharacters']; if (allCommitCharacters != null && - !((allCommitCharacters is List && + !((allCommitCharacters is List && (allCommitCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -7042,7 +7043,7 @@ class CompletionTriggerKind { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { switch (obj) { case 1: case 2: @@ -7183,7 +7184,7 @@ class ConfigurationParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((items is List && + if (!((items is List && (items.every( (item) => ConfigurationItem.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -7473,7 +7474,7 @@ class CreateFilesParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((files is List && + if (!((files is List && (files.every((item) => FileCreate.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -7869,7 +7870,7 @@ class DeclarationRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -8252,7 +8253,7 @@ class DefinitionRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -8554,7 +8555,7 @@ class DeleteFilesParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((files is List && + if (!((files is List && (files.every((item) => FileDelete.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -8788,7 +8789,7 @@ class Diagnostic implements ToJsonable { try { final tags = obj['tags']; if (tags != null && - !((tags is List && + !((tags is List && (tags.every( (item) => DiagnosticTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -8801,7 +8802,7 @@ class Diagnostic implements ToJsonable { try { final relatedInformation = obj['relatedInformation']; if (relatedInformation != null && - !((relatedInformation is List && + !((relatedInformation is List && (relatedInformation.every((item) => DiagnosticRelatedInformation.canParse(item, reporter)))))) { reporter.reportError( @@ -8954,7 +8955,7 @@ class DiagnosticSeverity { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is num; } @@ -8989,7 +8990,7 @@ class DiagnosticTag { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is num; } @@ -9211,7 +9212,7 @@ class DidChangeTextDocumentParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((contentChanges is List && + if (!((contentChanges is List && (contentChanges.every((item) => (TextDocumentContentChangeEvent1.canParse(item, reporter) || TextDocumentContentChangeEvent2.canParse( @@ -9356,7 +9357,7 @@ class DidChangeWatchedFilesParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((changes is List && + if (!((changes is List && (changes.every((item) => FileEvent.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -9427,7 +9428,7 @@ class DidChangeWatchedFilesRegistrationOptions implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((watchers is List && + if (!((watchers is List && (watchers.every( (item) => FileSystemWatcher.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -10040,7 +10041,7 @@ class DocumentColorRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -10493,7 +10494,7 @@ class DocumentFormattingRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -10693,7 +10694,7 @@ class DocumentHighlightKind { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -10982,7 +10983,7 @@ class DocumentHighlightRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -11492,7 +11493,7 @@ class DocumentLinkRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -11672,7 +11673,7 @@ class DocumentOnTypeFormattingOptions implements ToJsonable { try { final moreTriggerCharacter = obj['moreTriggerCharacter']; if (moreTriggerCharacter != null && - !((moreTriggerCharacter is List && + !((moreTriggerCharacter is List && (moreTriggerCharacter.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -11919,7 +11920,7 @@ class DocumentOnTypeFormattingRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -11950,7 +11951,7 @@ class DocumentOnTypeFormattingRegistrationOptions try { final moreTriggerCharacter = obj['moreTriggerCharacter']; if (moreTriggerCharacter != null && - !((moreTriggerCharacter is List && + !((moreTriggerCharacter is List && (moreTriggerCharacter.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -12310,7 +12311,7 @@ class DocumentRangeFormattingRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -12512,7 +12513,7 @@ class DocumentSymbol implements ToJsonable { try { final tags = obj['tags']; if (tags != null && - !((tags is List && + !((tags is List && (tags.every((item) => SymbolTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -12570,7 +12571,7 @@ class DocumentSymbol implements ToJsonable { try { final children = obj['children']; if (children != null && - !((children is List && + !((children is List && (children.every( (item) => DocumentSymbol.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -12818,7 +12819,7 @@ class DocumentSymbolClientCapabilitiesSymbolKind implements ToJsonable { try { final valueSet = obj['valueSet']; if (valueSet != null && - !((valueSet is List && + !((valueSet is List && (valueSet .every((item) => SymbolKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -12890,7 +12891,7 @@ class DocumentSymbolClientCapabilitiesTagSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((valueSet is List && + if (!((valueSet is List && (valueSet.every((item) => SymbolTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -13189,7 +13190,7 @@ class DocumentSymbolRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -13252,7 +13253,7 @@ class ErrorCodes { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -13402,7 +13403,7 @@ class ExecuteCommandOptions implements WorkDoneProgressOptions, ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((commands is List && + if (!((commands is List && (commands.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -13515,7 +13516,8 @@ class ExecuteCommandParams implements WorkDoneProgressParams, ToJsonable { try { final arguments = obj['arguments']; if (arguments != null && - !((arguments is List && (arguments.every((item) => true))))) { + !((arguments is List && + (arguments.every((item) => true))))) { reporter.reportError('must be of type List'); return false; } @@ -13606,7 +13608,7 @@ class ExecuteCommandRegistrationOptions reporter.reportError('must not be null'); return false; } - if (!((commands is List && + if (!((commands is List && (commands.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -13656,7 +13658,7 @@ class FailureHandlingKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { switch (obj) { case 'abort': case 'transactional': @@ -13704,7 +13706,7 @@ class FileChangeType { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -14160,7 +14162,7 @@ class FileOperationPatternKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -14281,7 +14283,7 @@ class FileOperationRegistrationOptions implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((filters is List && + if (!((filters is List && (filters.every( (item) => FileOperationFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -14781,7 +14783,7 @@ class FoldingRangeKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -15048,7 +15050,7 @@ class FoldingRangeRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -15408,7 +15410,7 @@ class HoverClientCapabilities implements ToJsonable { try { final contentFormat = obj['contentFormat']; if (contentFormat != null && - !((contentFormat is List && + !((contentFormat is List && (contentFormat .every((item) => MarkupKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -15663,7 +15665,7 @@ class HoverRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -16066,7 +16068,7 @@ class ImplementationRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -16356,7 +16358,7 @@ class InitializeParams implements WorkDoneProgressParams, ToJsonable { try { final workspaceFolders = obj['workspaceFolders']; if (workspaceFolders != null && - !((workspaceFolders is List && + !((workspaceFolders is List && (workspaceFolders.every( (item) => WorkspaceFolder.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -16831,7 +16833,7 @@ class InsertTextFormat { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { switch (obj) { case 1: case 2: @@ -16870,7 +16872,7 @@ class InsertTextMode { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is num; } @@ -17203,7 +17205,7 @@ class LinkedEditingRangeRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -17308,7 +17310,7 @@ class LinkedEditingRanges implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((ranges is List && + if (!((ranges is List && (ranges.every((item) => Range.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -17955,7 +17957,7 @@ class MarkupKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { switch (obj) { case 'plaintext': case 'markdown': @@ -18118,7 +18120,7 @@ class MessageType { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -18152,7 +18154,7 @@ class Method { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -18624,7 +18626,7 @@ class MonikerKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -18904,7 +18906,7 @@ class MonikerRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -19567,7 +19569,7 @@ class PrepareSupportDefaultBehavior { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is num; } @@ -19859,7 +19861,7 @@ class PublishDiagnosticsClientCapabilitiesTagSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((valueSet is List && + if (!((valueSet is List && (valueSet .every((item) => DiagnosticTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -19975,7 +19977,7 @@ class PublishDiagnosticsParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((diagnostics is List && + if (!((diagnostics is List && (diagnostics .every((item) => Diagnostic.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -20584,7 +20586,7 @@ class ReferenceRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -20765,7 +20767,7 @@ class RegistrationParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((registrations is List && + if (!((registrations is List && (registrations .every((item) => Registration.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -21317,7 +21319,7 @@ class RenameFilesParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((files is List && + if (!((files is List && (files.every((item) => FileRename.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -21630,7 +21632,7 @@ class RenameRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -21822,7 +21824,7 @@ class ResourceOperationKind { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { switch (obj) { case 'create': case 'rename': @@ -22440,7 +22442,7 @@ class SelectionRangeParams reporter.reportError('must not be null'); return false; } - if (!((positions is List && + if (!((positions is List && (positions.every((item) => Position.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -22567,7 +22569,7 @@ class SelectionRangeRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -22620,7 +22622,7 @@ class SemanticTokenModifiers { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -22653,7 +22655,7 @@ class SemanticTokenTypes { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -22749,7 +22751,7 @@ class SemanticTokens implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((data is List && (data.every((item) => item is int))))) { + if (!((data is List && (data.every((item) => item is int))))) { reporter.reportError('must be of type List'); return false; } @@ -22917,7 +22919,7 @@ class SemanticTokensClientCapabilities implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((tokenTypes is List && + if (!((tokenTypes is List && (tokenTypes.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -22936,7 +22938,7 @@ class SemanticTokensClientCapabilities implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((tokenModifiers is List && + if (!((tokenModifiers is List && (tokenModifiers.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -22955,7 +22957,7 @@ class SemanticTokensClientCapabilities implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((formats is List && + if (!((formats is List && (formats.every((item) => TokenFormat.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -23284,7 +23286,7 @@ class SemanticTokensDelta implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((edits is List && + if (!((edits is List && (edits.every( (item) => SemanticTokensEdit.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -23509,7 +23511,7 @@ class SemanticTokensDeltaPartialResult implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((edits is List && + if (!((edits is List && (edits.every( (item) => SemanticTokensEdit.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -23622,7 +23624,7 @@ class SemanticTokensEdit implements ToJsonable { try { final data = obj['data']; if (data != null && - !((data is List && (data.every((item) => item is int))))) { + !((data is List && (data.every((item) => item is int))))) { reporter.reportError('must be of type List'); return false; } @@ -23700,7 +23702,7 @@ class SemanticTokensLegend implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((tokenTypes is List && + if (!((tokenTypes is List && (tokenTypes.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -23719,7 +23721,7 @@ class SemanticTokensLegend implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((tokenModifiers is List && + if (!((tokenModifiers is List && (tokenModifiers.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -24162,7 +24164,7 @@ class SemanticTokensPartialResult implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((data is List && (data.every((item) => item is int))))) { + if (!((data is List && (data.every((item) => item is int))))) { reporter.reportError('must be of type List'); return false; } @@ -24452,7 +24454,7 @@ class SemanticTokensRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -26627,7 +26629,7 @@ class ShowMessageRequestParams implements ToJsonable { try { final actions = obj['actions']; if (actions != null && - !((actions is List && + !((actions is List && (actions.every( (item) => MessageActionItem.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -26735,7 +26737,7 @@ class SignatureHelp implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((signatures is List && + if (!((signatures is List && (signatures.every( (item) => SignatureInformation.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -27036,7 +27038,7 @@ class SignatureHelpClientCapabilitiesSignatureInformation try { final documentationFormat = obj['documentationFormat']; if (documentationFormat != null && - !((documentationFormat is List && + !((documentationFormat is List && (documentationFormat .every((item) => MarkupKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -27312,7 +27314,7 @@ class SignatureHelpOptions implements WorkDoneProgressOptions, ToJsonable { try { final triggerCharacters = obj['triggerCharacters']; if (triggerCharacters != null && - !((triggerCharacters is List && + !((triggerCharacters is List && (triggerCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -27324,7 +27326,7 @@ class SignatureHelpOptions implements WorkDoneProgressOptions, ToJsonable { try { final retriggerCharacters = obj['retriggerCharacters']; if (retriggerCharacters != null && - !((retriggerCharacters is List && + !((retriggerCharacters is List && (retriggerCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -27598,7 +27600,7 @@ class SignatureHelpRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -27611,7 +27613,7 @@ class SignatureHelpRegistrationOptions try { final triggerCharacters = obj['triggerCharacters']; if (triggerCharacters != null && - !((triggerCharacters is List && + !((triggerCharacters is List && (triggerCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -27623,7 +27625,7 @@ class SignatureHelpRegistrationOptions try { final retriggerCharacters = obj['retriggerCharacters']; if (retriggerCharacters != null && - !((retriggerCharacters is List && + !((retriggerCharacters is List && (retriggerCharacters.every((item) => item is String))))) { reporter.reportError('must be of type List'); return false; @@ -27683,7 +27685,7 @@ class SignatureHelpTriggerKind { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is num; } @@ -27815,7 +27817,7 @@ class SignatureInformation implements ToJsonable { try { final parameters = obj['parameters']; if (parameters != null && - !((parameters is List && + !((parameters is List && (parameters.every((item) => ParameterInformation.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -28077,7 +28079,7 @@ class SymbolInformation implements ToJsonable { try { final tags = obj['tags']; if (tags != null && - !((tags is List && + !((tags is List && (tags.every((item) => SymbolTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; @@ -28159,7 +28161,7 @@ class SymbolKind { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -28209,7 +28211,7 @@ class SymbolTag { final num _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is num; } @@ -28292,7 +28294,7 @@ class TextDocumentChangeRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -29338,7 +29340,7 @@ class TextDocumentEdit implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((edits is List && + if (!((edits is List && (edits.every((item) => (SnippetTextEdit.canParse(item, reporter) || AnnotatedTextEdit.canParse(item, reporter) || TextEdit.canParse(item, reporter))))))) { @@ -29850,7 +29852,7 @@ class TextDocumentRegistrationOptions implements ToJsonable { } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -29891,7 +29893,7 @@ class TextDocumentSaveReason { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -29973,7 +29975,7 @@ class TextDocumentSaveRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -30146,7 +30148,7 @@ class TextDocumentSyncKind { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -30433,7 +30435,7 @@ class TokenFormat { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -30807,7 +30809,7 @@ class TypeDefinitionRegistrationOptions } final documentSelector = obj['documentSelector']; if (documentSelector != null && - !((documentSelector is List && + !((documentSelector is List && (documentSelector.every( (item) => DocumentFilter.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -30871,7 +30873,7 @@ class UniquenessLevel { final String _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is String; } @@ -31027,7 +31029,7 @@ class UnregistrationParams implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((unregisterations is List && + if (!((unregisterations is List && (unregisterations .every((item) => Unregistration.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -31159,7 +31161,7 @@ class WatchKind { final int _value; - static bool canParse(Object obj, LspJsonReporter reporter) { + static bool canParse(Object? obj, LspJsonReporter reporter) { return obj is int; } @@ -32116,15 +32118,14 @@ class WorkspaceEdit implements ToJsonable { final documentChangesJson = json['documentChanges']; final documentChanges = documentChangesJson == null ? null - : ((documentChangesJson is List && + : ((documentChangesJson is List && (documentChangesJson.every((item) => TextDocumentEdit.canParse(item, nullLspJsonReporter)))) - ? Either2, List>>.t1( - (documentChangesJson) - .map((item) => - TextDocumentEdit.fromJson(item as Map)) - .toList()) - : ((documentChangesJson is List && + ? Either2, List>>.t1((documentChangesJson) + .map((item) => + TextDocumentEdit.fromJson(item as Map)) + .toList()) + : ((documentChangesJson is List && (documentChangesJson.every((item) => (TextDocumentEdit.canParse(item, nullLspJsonReporter) || CreateFile.canParse(item, nullLspJsonReporter) || @@ -32194,7 +32195,7 @@ class WorkspaceEdit implements ToJsonable { !((changes is Map && (changes.keys.every((item) => item is String && - changes.values.every((item) => (item is List && + changes.values.every((item) => (item is List && (item.every((item) => TextEdit.canParse(item, reporter)))))))))) { reporter.reportError('must be of type Map>'); @@ -32207,10 +32208,10 @@ class WorkspaceEdit implements ToJsonable { try { final documentChanges = obj['documentChanges']; if (documentChanges != null && - !(((documentChanges is List && + !(((documentChanges is List && (documentChanges.every((item) => TextDocumentEdit.canParse(item, reporter)))) || - (documentChanges is List && + (documentChanges is List && (documentChanges.every((item) => (TextDocumentEdit.canParse(item, reporter) || CreateFile.canParse(item, reporter) || @@ -32368,7 +32369,7 @@ class WorkspaceEditClientCapabilities implements ToJsonable { try { final resourceOperations = obj['resourceOperations']; if (resourceOperations != null && - !((resourceOperations is List && + !((resourceOperations is List && (resourceOperations.every((item) => ResourceOperationKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -32642,7 +32643,7 @@ class WorkspaceFoldersChangeEvent implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((added is List && + if (!((added is List && (added .every((item) => WorkspaceFolder.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -32662,7 +32663,7 @@ class WorkspaceFoldersChangeEvent implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((removed is List && + if (!((removed is List && (removed .every((item) => WorkspaceFolder.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -32945,7 +32946,7 @@ class WorkspaceSymbolClientCapabilitiesSymbolKind implements ToJsonable { try { final valueSet = obj['valueSet']; if (valueSet != null && - !((valueSet is List && + !((valueSet is List && (valueSet .every((item) => SymbolKind.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); @@ -33017,7 +33018,7 @@ class WorkspaceSymbolClientCapabilitiesTagSupport implements ToJsonable { reporter.reportError('must not be null'); return false; } - if (!((valueSet is List && + if (!((valueSet is List && (valueSet.every((item) => SymbolTag.canParse(item, reporter)))))) { reporter.reportError('must be of type List'); return false; diff --git a/pkg/analysis_server/lib/src/plugin/result_merger.dart b/pkg/analysis_server/lib/src/plugin/result_merger.dart index 6e1257a9b0f..e8e51f3a6f4 100644 --- a/pkg/analysis_server/lib/src/plugin/result_merger.dart +++ b/pkg/analysis_server/lib/src/plugin/result_merger.dart @@ -239,9 +239,9 @@ class ResultMerger { /// Return the index of the region in the collection of [mergedRegions] that /// covers exactly the same region as the [newRegion], or `-1` if there is /// no such region. - int matchingRegion(newRegion) { - int newOffset = newRegion.offset; - int newLength = newRegion.length; + int matchingRegion(NavigationRegion newRegion) { + var newOffset = newRegion.offset; + var newLength = newRegion.length; for (var i = 0; i < mergedRegions.length; i++) { var mergedRegion = mergedRegions[i]; if (newOffset == mergedRegion.offset && diff --git a/pkg/analysis_server/lib/src/server/sdk_configuration.dart b/pkg/analysis_server/lib/src/server/sdk_configuration.dart index 39eb0d14f6a..23d6a76f950 100644 --- a/pkg/analysis_server/lib/src/server/sdk_configuration.dart +++ b/pkg/analysis_server/lib/src/server/sdk_configuration.dart @@ -40,19 +40,21 @@ class SdkConfiguration { } /// Whether analytics is forced on. - bool? get analyticsForceEnabled => _values['server.analytics.forceEnabled']; + bool? get analyticsForceEnabled => + _values['server.analytics.forceEnabled'] as bool?; /// Return an override value for the analysis server's google analytics ID, or /// `null` if the default value should be used. - String? get analyticsId => _values['server.analytics.id']; + String? get analyticsId => _values['server.analytics.id'] as String?; /// Whether crash reporting is forced on. bool? get crashReportingForceEnabled => - _values['server.crash.reporting.forceEnabled']; + _values['server.crash.reporting.forceEnabled'] as bool?; /// Return an override value for the analysis server's crash reporting product /// ID, or `null` if the default value should be used. - String? get crashReportingId => _values['server.crash.reporting.id']; + String? get crashReportingId => + _values['server.crash.reporting.id'] as String?; /// Return a string describing the contents of this SDK configuration. String get displayString { @@ -67,9 +69,10 @@ class SdkConfiguration { void _readFromFile(File file) { try { - Map m = jsonDecode(file.readAsStringSync()); - for (var key in m.keys) { - _values[key] = m[key]; + var content = + jsonDecode(file.readAsStringSync()) as Map; + for (var key in content.keys) { + _values[key as String] = content[key]; } } catch (_) { // ignore issues reading the file diff --git a/pkg/analysis_server/lib/src/services/pub/pub_api.dart b/pkg/analysis_server/lib/src/services/pub/pub_api.dart index d89d16545d9..b2f9fe1279b 100644 --- a/pkg/analysis_server/lib/src/services/pub/pub_api.dart +++ b/pkg/analysis_server/lib/src/services/pub/pub_api.dart @@ -59,7 +59,7 @@ class PubApi { final packageNames = json['packages']; return packageNames is List - ? packageNames.map((name) => PubApiPackage(name)).toList() + ? packageNames.map((name) => PubApiPackage(name as String)).toList() : null; } @@ -103,7 +103,7 @@ class PubApi { await httpClient.get(Uri.parse(url), headers: _headers); if (response.statusCode == 200) { instrumentationService.logInfo('Pub API request successful for $url'); - return jsonDecode(response.body); + return jsonDecode(response.body) as Map?; } else if (response.statusCode >= 400 && response.statusCode < 500) { // Do not retry 4xx responses. instrumentationService.logError( diff --git a/pkg/analysis_server/lib/src/services/pub/pub_command.dart b/pkg/analysis_server/lib/src/services/pub/pub_command.dart index f6188e086d5..23514419997 100644 --- a/pkg/analysis_server/lib/src/services/pub/pub_command.dart +++ b/pkg/analysis_server/lib/src/services/pub/pub_command.dart @@ -136,7 +136,7 @@ class PubCommand { try { final results = jsonDecode(stdout); _instrumentationService.logInfo('pub command completed successfully'); - return results; + return results as Map?; } catch (e) { _instrumentationService .logError('pub command returned invalid JSON: $e.'); diff --git a/pkg/analysis_server/lib/src/status/pages.dart b/pkg/analysis_server/lib/src/status/pages.dart index e626e024efc..e0a24ca8fd0 100644 --- a/pkg/analysis_server/lib/src/status/pages.dart +++ b/pkg/analysis_server/lib/src/status/pages.dart @@ -15,7 +15,7 @@ String printInteger(int value) => numberFormat.format(value); String printMilliseconds(num value) => '${numberFormat.format(value)} ms'; -String printPercentage(num value, [fractionDigits = 1]) => +String printPercentage(num value, [int fractionDigits = 1]) => '${(value * 100).toStringAsFixed(fractionDigits)}%'; /// An entity that knows how to serve itself over http. diff --git a/pkg/analysis_server/lib/src/utilities/extensions/yaml.dart b/pkg/analysis_server/lib/src/utilities/extensions/yaml.dart index 474b711fca9..b3c0c2e0b79 100644 --- a/pkg/analysis_server/lib/src/utilities/extensions/yaml.dart +++ b/pkg/analysis_server/lib/src/utilities/extensions/yaml.dart @@ -29,8 +29,9 @@ extension YamlNodeExtensions on YamlNode { var nextEntryOffset = i + 1 < entries.length ? (entries[i + 1].key as YamlNode).span.start.offset : null; - if ((entry.key as YamlNode).containsOffset(offset)) { - return entry.key; + var key = entry.key as YamlNode; + if (key.containsOffset(offset)) { + return key; } var value = entry.value; if (value.containsOffset(offset) || diff --git a/pkg/analysis_server/lib/src/utilities/profiling.dart b/pkg/analysis_server/lib/src/utilities/profiling.dart index b5e41fbc155..f1fcddb969e 100644 --- a/pkg/analysis_server/lib/src/utilities/profiling.dart +++ b/pkg/analysis_server/lib/src/utilities/profiling.dart @@ -56,7 +56,7 @@ class _PosixProcessProfiler extends ProcessProfiler { return Future.value(null); } - return Future.value(_parse(result.stdout)); + return Future.value(_parse(result.stdout as String)); }); } catch (e) { return Future.error(e); diff --git a/pkg/analysis_server/lib/src/utilities/yaml_node_locator.dart b/pkg/analysis_server/lib/src/utilities/yaml_node_locator.dart index c8c49ef47cc..c04e29e195e 100644 --- a/pkg/analysis_server/lib/src/utilities/yaml_node_locator.dart +++ b/pkg/analysis_server/lib/src/utilities/yaml_node_locator.dart @@ -49,7 +49,7 @@ class YamlNodeLocator { } else if (node is YamlMap) { var nodeMap = node.nodes; for (var entry in nodeMap.entries) { - _searchWithin(path, entry.key); + _searchWithin(path, entry.key as YamlNode); if (path.isNotEmpty) { path.add(node); return; diff --git a/pkg/analysis_server/test/benchmarks_test.dart b/pkg/analysis_server/test/benchmarks_test.dart index 87a822e746d..30e5da633ff 100644 --- a/pkg/analysis_server/test/benchmarks_test.dart +++ b/pkg/analysis_server/test/benchmarks_test.dart @@ -61,7 +61,7 @@ List _listBenchmarks() { [path.join('benchmark', 'benchmarks.dart'), 'list', '--machine'], workingDirectory: _serverSourcePath, ); - Map m = json.decode(result.stdout); - List benchmarks = m['benchmarks']; + var output = json.decode(result.stdout as String) as Map; + var benchmarks = (output['benchmarks'] as List).cast>(); return benchmarks.map((b) => b['id']).cast().toList(); } diff --git a/pkg/analysis_server/test/client/impl/expect_mixin.dart b/pkg/analysis_server/test/client/impl/expect_mixin.dart index 7f75f640d6b..67cdc1ccc6c 100644 --- a/pkg/analysis_server/test/client/impl/expect_mixin.dart +++ b/pkg/analysis_server/test/client/impl/expect_mixin.dart @@ -30,7 +30,7 @@ class ExpectMixin { } else if (x is _Predicate) { // x is a unary predicate, but expects a specific type // so wrap it. - return predicate((a) => (x as dynamic)(a)); + return predicate((a) => (x as dynamic)(a) as bool); } else { return equals(x); } diff --git a/pkg/analysis_server/test/stress/replay/operation.dart b/pkg/analysis_server/test/stress/replay/operation.dart index a83d8b8ee8c..b8d58b8918b 100644 --- a/pkg/analysis_server/test/stress/replay/operation.dart +++ b/pkg/analysis_server/test/stress/replay/operation.dart @@ -11,7 +11,7 @@ class Analysis_UpdateContent extends ServerOperation { final String filePath; /// The overlay used to update the content. - final dynamic overlay; + final Object overlay; /// Initialize an operation to send an 'analysis.updateContent' request with /// the given [filePath] and [overlay] as parameters. diff --git a/pkg/analysis_server/test/stress/utilities/server.dart b/pkg/analysis_server/test/stress/utilities/server.dart index 888056a68bf..b2eefa35d66 100644 --- a/pkg/analysis_server/test/stress/utilities/server.dart +++ b/pkg/analysis_server/test/stress/utilities/server.dart @@ -766,7 +766,7 @@ class Server { return; } logger?.log(fromServer, '$trimmedLine'); - var message = asMap(json.decoder.convert(trimmedLine)); + var message = asMap(json.decoder.convert(trimmedLine) as Object); if (message.containsKey('id')) { // The message is a response. var response = Response.fromJson(message)!; diff --git a/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart b/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart index 265ac050288..639b3eb44a4 100644 --- a/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart +++ b/pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart @@ -185,7 +185,7 @@ void main() { } /// Returns matcher that can compare double values. -Matcher doubleEquals(expected) => _DoubleEquals(expected); +Matcher doubleEquals(double expected) => _DoubleEquals(expected); class _DoubleEquals extends Matcher { final double _value; diff --git a/pkg/analysis_server/test/tool/lsp_spec/json_test.dart b/pkg/analysis_server/test/tool/lsp_spec/json_test.dart index 824217e9930..04a78a691f7 100644 --- a/pkg/analysis_server/test/tool/lsp_spec/json_test.dart +++ b/pkg/analysis_server/test/tool/lsp_spec/json_test.dart @@ -334,7 +334,8 @@ void main() { group('fromJson', () { test('parses JSON for types with unions (left side)', () { final input = '{"id":1,"method":"shutdown","jsonrpc":"test"}'; - final message = RequestMessage.fromJson(jsonDecode(input)); + final message = + RequestMessage.fromJson(jsonDecode(input) as Map); expect(message.id, equals(Either2.t1(1))); expect(message.id.valueEquals(1), isTrue); expect(message.jsonrpc, 'test'); @@ -343,7 +344,8 @@ void main() { test('parses JSON for types with unions (right side)', () { final input = '{"id":"one","method":"shutdown","jsonrpc":"test"}'; - final message = RequestMessage.fromJson(jsonDecode(input)); + final message = + RequestMessage.fromJson(jsonDecode(input) as Map); expect(message.id, equals(Either2.t2('one'))); expect(message.id.valueEquals('one'), isTrue); expect(message.jsonrpc, 'test'); @@ -352,13 +354,15 @@ void main() { test('parses JSON with nulls for unions that allow null', () { final input = '{"id":null,"jsonrpc":"test"}'; - final message = ResponseMessage.fromJson(jsonDecode(input)); + final message = + ResponseMessage.fromJson(jsonDecode(input) as Map); expect(message.id, isNull); }); test('parses JSON with nulls for unions that allow null', () { final input = '{"method":"test","jsonrpc":"test"}'; - final message = NotificationMessage.fromJson(jsonDecode(input)); + final message = NotificationMessage.fromJson( + jsonDecode(input) as Map); expect(message.params, isNull); }); @@ -370,7 +374,8 @@ void main() { version: 111, uri: 'file:///foo/bar.dart'), position: Position(line: 1, character: 1), ).toJson()); - final params = TextDocumentPositionParams.fromJson(jsonDecode(input)); + final params = TextDocumentPositionParams.fromJson( + jsonDecode(input) as Map); expect(params.textDocument, const TypeMatcher()); }); @@ -378,7 +383,8 @@ void main() { test('parses JSON with unknown fields', () { final input = '{"id":1,"invalidField":true,"method":"foo","jsonrpc":"test"}'; - final message = RequestMessage.fromJson(jsonDecode(input)); + final message = + RequestMessage.fromJson(jsonDecode(input) as Map); expect(message.id.valueEquals(1), isTrue); expect(message.method, equals(Method('foo'))); expect(message.params, isNull); @@ -401,7 +407,8 @@ void main() { workspaceFolders: workspaceFolders, ); final json = jsonEncode(obj); - final restoredObj = InitializeParams.fromJson(jsonDecode(json)); + final restoredObj = + InitializeParams.fromJson(jsonDecode(json) as Map); final restoredWorkspaceFolders = restoredObj.workspaceFolders!; expect(restoredWorkspaceFolders, hasLength(workspaceFolders.length)); @@ -420,7 +427,8 @@ void main() { endCharacter: 4, kind: FoldingRangeKind.Comment); final json = jsonEncode(obj); - final restoredObj = FoldingRange.fromJson(jsonDecode(json)); + final restoredObj = + FoldingRange.fromJson(jsonDecode(json) as Map); expect(restoredObj.startLine, equals(obj.startLine)); expect(restoredObj.startCharacter, equals(obj.startCharacter)); @@ -438,7 +446,8 @@ void main() { 'fileB': [TextEdit(range: range, newText: 'text B')] }); final json = jsonEncode(obj); - final restoredObj = WorkspaceEdit.fromJson(jsonDecode(json)); + final restoredObj = + WorkspaceEdit.fromJson(jsonDecode(json) as Map); expect(restoredObj.documentChanges, equals(obj.documentChanges)); expect(restoredObj.changes, equals(obj.changes)); diff --git a/pkg/analysis_server/tool/code_completion/corpus.dart b/pkg/analysis_server/tool/code_completion/corpus.dart index 2bde6fe1035..d7f02f2fd56 100644 --- a/pkg/analysis_server/tool/code_completion/corpus.dart +++ b/pkg/analysis_server/tool/code_completion/corpus.dart @@ -18,7 +18,7 @@ Future main(List args) async { exit(1); } - final repos = []; + final repos = []; if (args.length == 1 && !Directory(args[0]).existsSync()) { final contents = File(args[0]).readAsStringSync(); repos.addAll(LineSplitter().convert(contents)); @@ -86,7 +86,7 @@ Future _clone(String repo) async { result = await Process.run( 'git', ['clone', '--recurse-submodules', '$repo.git', cloneDir]); } - return CloneResult(result.exitCode, cloneDir, msg: result.stderr); + return CloneResult(result.exitCode, cloneDir, msg: result.stderr as String); } Future _getBody(String url) async => (await _getResponse(url)).body; @@ -105,11 +105,11 @@ Future _runPubGet(FileSystemEntity dir) async { if (_hasPubspec(dir)) { final packageFile = path.join(dir.path, _package_config); if (!File(packageFile).existsSync() || forcePubUpdate) { - print( - 'Getting pub dependencies for "${path.relative(dir.path, from: _appDir)}"...'); + final relativeDirPath = path.relative(dir.path, from: _appDir); + print('Getting pub dependencies for "$relativeDirPath"...'); final pubRun = await _runPub(dir.path); if (pubRun.exitCode != 0) { - print('Error: ' + pubRun.stderr); + print('Error: ${pubRun.stderr}'); } } } diff --git a/pkg/analysis_server/tool/instrumentation/log/log.dart b/pkg/analysis_server/tool/instrumentation/log/log.dart index 503f991eaa7..4ede5ea2d06 100644 --- a/pkg/analysis_server/tool/instrumentation/log/log.dart +++ b/pkg/analysis_server/tool/instrumentation/log/log.dart @@ -307,7 +307,7 @@ class InstrumentationLog { if (entry.isServerStatus) { var analysisStatus = entry.param('analysis'); if (analysisStatus is Map) { - if (analysisStatus['isAnalyzing']) { + if (analysisStatus['isAnalyzing'] as bool) { if (analysisStartEntry != null) { analysisStartEntry.recordProblem( 'Analysis started without being terminated.'); @@ -331,7 +331,7 @@ class InstrumentationLog { } var pubStatus = entry.param('pub'); if (pubStatus is Map) { - if (pubStatus['isListingPackageDirs']) { + if (pubStatus['isListingPackageDirs'] as bool) { if (pubStartEntry != null) { pubStartEntry.recordProblem( 'Pub started without previous being terminated.'); @@ -441,9 +441,9 @@ abstract class JsonBasedEntry extends LogEntry { object.forEach((key, value) { var newIndent = indent + singleIndent; buffer.write(newIndent); - _format(buffer, newIndent, key); + _format(buffer, newIndent, key as Object); buffer.write(' : '); - _format(buffer, newIndent, value); + _format(buffer, newIndent, value as Object); buffer.write('
'); }); buffer.write(indent); @@ -453,7 +453,7 @@ abstract class JsonBasedEntry extends LogEntry { object.forEach((element) { var newIndent = indent + singleIndent; buffer.write(newIndent); - _format(buffer, newIndent, element); + _format(buffer, newIndent, element as Object); buffer.write('
'); }); buffer.write(indent); @@ -578,7 +578,7 @@ abstract class LogEntry { } else if (entryKind == InstrumentationLogAdapter.TAG_LOG_ENTRY) { // Fall through } else if (entryKind == InstrumentationLogAdapter.TAG_NOTIFICATION) { - Map requestData = json.decode(components[2]); + var requestData = json.decode(components[2]) as Map; return NotificationEntry(index, timeStamp, requestData); } else if (entryKind == InstrumentationLogAdapter.TAG_PLUGIN_ERROR) { return PluginErrorEntry(index, timeStamp, entryKind, @@ -588,25 +588,25 @@ abstract class LogEntry { components.sublist(2, 5), components.sublist(5)); } else if (entryKind == InstrumentationLogAdapter.TAG_PLUGIN_NOTIFICATION) { - Map requestData = json.decode(components[2]); + var requestData = json.decode(components[2]) as Map; return PluginNotificationEntry( index, timeStamp, requestData, components.sublist(3)); } else if (entryKind == InstrumentationLogAdapter.TAG_PLUGIN_REQUEST) { - Map requestData = json.decode(components[2]); + var requestData = json.decode(components[2]) as Map; return PluginRequestEntry( index, timeStamp, requestData, components.sublist(3)); } else if (entryKind == InstrumentationLogAdapter.TAG_PLUGIN_RESPONSE) { - Map responseData = json.decode(components[2]); + var responseData = json.decode(components[2]) as Map; return PluginResponseEntry( index, timeStamp, responseData, components.sublist(3)); } else if (entryKind == InstrumentationLogAdapter.TAG_PLUGIN_TIMEOUT) { return PluginErrorEntry(index, timeStamp, entryKind, components.sublist(2, 3), components.sublist(3)); } else if (entryKind == InstrumentationLogAdapter.TAG_REQUEST) { - Map requestData = json.decode(components[2]); + var requestData = json.decode(components[2]) as Map; return RequestEntry(index, timeStamp, requestData); } else if (entryKind == InstrumentationLogAdapter.TAG_RESPONSE) { - Map responseData = json.decode(components[2]); + var responseData = json.decode(components[2]) as Map; return ResponseEntry(index, timeStamp, responseData); } else if (entryKind == InstrumentationLogAdapter.TAG_VERSION) { // Fall through @@ -675,7 +675,7 @@ class NotificationEntry extends JsonBasedEntry { : super(index, timeStamp, notificationData); /// Return the event field of the request. - String get event => data['event']; + String get event => data['event'] as String; /// Return `true` if this is a server error notification. bool get isServerError => event == 'server.error'; @@ -747,7 +747,7 @@ class PluginNotificationEntry extends JsonBasedPluginEntry { : super(index, timeStamp, notificationData, pluginData); /// Return the event field of the notification. - String get event => data['event']; + String get event => data['event'] as String; @override String get kind => 'PluginNoti'; @@ -773,13 +773,13 @@ class PluginRequestEntry extends JsonBasedPluginEntry { : super(index, timeStamp, requestData, pluginData); /// Return the id field of the request. - String get id => data['id']; + String get id => data['id'] as String; @override String get kind => 'PluginReq'; /// Return the method field of the request. - String get method => data['method']; + String get method => data['method'] as String; /// Return the value of the parameter with the given [parameterName], or /// `null` if there is no such parameter. @@ -802,7 +802,7 @@ class PluginResponseEntry extends JsonBasedPluginEntry { : super(index, timeStamp, responseData, pluginData); /// Return the id field of the response. - String get id => data['id']; + String get id => data['id'] as String; @override String get kind => 'PluginRes'; @@ -827,16 +827,16 @@ class RequestEntry extends JsonBasedEntry { : super(index, timeStamp, requestData); /// Return the clientRequestTime field of the request. - int get clientRequestTime => data['clientRequestTime']; + int get clientRequestTime => data['clientRequestTime'] as int; /// Return the id field of the request. - String get id => data['id']; + String get id => data['id'] as String; @override String get kind => 'Req'; /// Return the method field of the request. - String get method => data['method']; + String get method => data['method'] as String; /// Return the value of the parameter with the given [parameterName], or /// `null` if there is no such parameter. @@ -858,7 +858,7 @@ class ResponseEntry extends JsonBasedEntry { : super(index, timeStamp, responseData); /// Return the id field of the response. - String get id => data['id']; + String get id => data['id'] as String; @override String get kind => 'Res'; diff --git a/pkg/analysis_server/tool/instrumentation/log_viewer.dart b/pkg/analysis_server/tool/instrumentation/log_viewer.dart index f3e5379d051..6273c47853f 100644 --- a/pkg/analysis_server/tool/instrumentation/log_viewer.dart +++ b/pkg/analysis_server/tool/instrumentation/log_viewer.dart @@ -70,14 +70,14 @@ class Driver { void start(List args) { var parser = createParser(); var options = parser.parse(args); - if (options[helpFlag]) { + if (options[helpFlag] as bool) { printUsage(parser); return; } var port = defaultPortNumber; try { - port = int.parse(options[portOption]); + port = int.parse(options[portOption] as String); } catch (exception) { printUsage(parser, error: 'Invalid port number'); return; diff --git a/pkg/analysis_server/tool/instrumentation/page/log_page.dart b/pkg/analysis_server/tool/instrumentation/page/log_page.dart index 9288cf542dd..addd9dc9cdb 100644 --- a/pkg/analysis_server/tool/instrumentation/page/log_page.dart +++ b/pkg/analysis_server/tool/instrumentation/page/log_page.dart @@ -142,7 +142,7 @@ function selectEntryGroup(pageStart) { if (entry.isServerStatus) { var analysisStatus = entry.param('analysis'); if (analysisStatus is Map) { - if (analysisStatus['isAnalyzing']) { + if (analysisStatus['isAnalyzing'] as bool) { description = '$description (analyzing)'; } else { var duration = _getDuration(pairedEntry, entry); @@ -152,7 +152,7 @@ function selectEntryGroup(pageStart) { } var pubStatus = entry.param('pub'); if (pubStatus is Map) { - if (pubStatus['isListingPackageDirs']) { + if (pubStatus['isListingPackageDirs'] as bool) { description = '$description (pub)'; } else { var duration = _getDuration(pairedEntry, entry); diff --git a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart index 7b95c29da30..5383d50bece 100644 --- a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart +++ b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart @@ -60,7 +60,7 @@ void recordTypes(List types) { .forEach((namespace) => _namespaces[namespace.name] = namespace); } -TypeBase resolveTypeAlias(TypeBase type, {resolveEnumClasses = false}) { +TypeBase resolveTypeAlias(TypeBase type, {bool resolveEnumClasses = false}) { if (type is Type) { // The LSP spec contains type aliases for `integer` and `uinteger` that map // into the `number` type, with comments stating they must be integers. To @@ -380,7 +380,7 @@ void _writeEnumClass(IndentableStringBuffer buffer, Namespace namespace) { ..writeIndentedln('final ${typeOfValues.dartTypeWithTypeArgs} _value;') ..writeln() ..writeIndentedln( - 'static bool canParse(Object obj, LspJsonReporter reporter) {') + 'static bool canParse(Object? obj, LspJsonReporter reporter) {') ..indent(); if (allowsAnyValue) { buffer.writeIndentedln('return '); @@ -866,7 +866,7 @@ void _writeTypeCheckCondition(IndentableStringBuffer buffer, } else if (_isSpecType(type)) { buffer.write('$dartType.canParse($valueCode, $reporter)'); } else if (type is ArrayType) { - buffer.write('($valueCode is List'); + buffer.write('($valueCode is List'); if (fullDartType != 'Object?') { // TODO(dantup): If we're happy to assume we never have two lists in a union // we could skip this bit. diff --git a/pkg/analysis_server/tool/lsp_spec/generate_all.dart b/pkg/analysis_server/tool/lsp_spec/generate_all.dart index 24a06eddd48..f1783c251a8 100644 --- a/pkg/analysis_server/tool/lsp_spec/generate_all.dart +++ b/pkg/analysis_server/tool/lsp_spec/generate_all.dart @@ -16,7 +16,8 @@ import 'typescript_parser.dart'; Future main(List arguments) async { final args = argParser.parse(arguments); - if (args[argHelp]) { + var help = args[argHelp] as bool; + if (help) { print(argParser.usage); return; } @@ -189,15 +190,14 @@ List getCustomClasses() { Field field( String name, { required String type, - array = false, - canBeNull = false, - canBeUndefined = false, + bool array = false, + bool canBeUndefined = false, }) { var fieldType = array ? ArrayType(Type.identifier(type)) : Type.identifier(type); return Field( - null, Token.identifier(name), fieldType, canBeNull, canBeUndefined); + null, Token.identifier(name), fieldType, false, canBeUndefined); } final customTypes = [ @@ -302,7 +302,8 @@ List getCustomClasses() { } Future> getSpecClasses(ArgResults args) async { - if (args[argDownload]) { + var download = args[argDownload] as bool; + if (download) { await downloadSpec(); } final spec = await readSpec();