Skip to content

Commit

Permalink
[analyzer] Migrate remaining LSP code to null-safe
Browse files Browse the repository at this point in the history
Change-Id: I52c7d16bdaf9f68148a8d7a956330bc54608ec43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195980
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
DanTup authored and commit-bot@chromium.org committed Apr 19, 2021
1 parent 543d653 commit 77466f2
Show file tree
Hide file tree
Showing 56 changed files with 869 additions and 791 deletions.
48 changes: 24 additions & 24 deletions pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class CompletionItemResolutionInfo implements ToJsonable {
}

final String file;
final num offset;
final int offset;

Map<String, dynamic> toJson() {
var __result = <String, dynamic>{};
Expand Down Expand Up @@ -226,8 +226,8 @@ class CompletionItemResolutionInfo implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!(obj['offset'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['offset'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down Expand Up @@ -295,11 +295,11 @@ class DartCompletionItemResolutionInfo

final String displayUri;
final String file;
final num iLength;
final num libId;
final num offset;
final num rLength;
final num rOffset;
final int iLength;
final int libId;
final int offset;
final int rLength;
final int rOffset;

Map<String, dynamic> toJson() {
var __result = <String, dynamic>{};
Expand All @@ -325,8 +325,8 @@ class DartCompletionItemResolutionInfo
reporter.reportError('must not be null');
return false;
}
if (!(obj['libId'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['libId'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down Expand Up @@ -359,8 +359,8 @@ class DartCompletionItemResolutionInfo
reporter.reportError('must not be null');
return false;
}
if (!(obj['rOffset'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['rOffset'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand All @@ -376,8 +376,8 @@ class DartCompletionItemResolutionInfo
reporter.reportError('must not be null');
return false;
}
if (!(obj['iLength'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['iLength'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand All @@ -393,8 +393,8 @@ class DartCompletionItemResolutionInfo
reporter.reportError('must not be null');
return false;
}
if (!(obj['rLength'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['rLength'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down Expand Up @@ -427,8 +427,8 @@ class DartCompletionItemResolutionInfo
reporter.reportError('must not be null');
return false;
}
if (!(obj['offset'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['offset'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down Expand Up @@ -484,7 +484,7 @@ class DartDiagnosticServer implements ToJsonable {
return DartDiagnosticServer(port: port);
}

final num port;
final int port;

Map<String, dynamic> toJson() {
var __result = <String, dynamic>{};
Expand All @@ -504,8 +504,8 @@ class DartDiagnosticServer implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!(obj['port'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['port'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down Expand Up @@ -1207,7 +1207,7 @@ class PubPackageCompletionItemResolutionInfo
}

final String file;
final num offset;
final int offset;
final String packageName;

Map<String, dynamic> toJson() {
Expand Down Expand Up @@ -1264,8 +1264,8 @@ class PubPackageCompletionItemResolutionInfo
reporter.reportError('must not be null');
return false;
}
if (!(obj['offset'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['offset'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down
50 changes: 25 additions & 25 deletions pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6320,10 +6320,10 @@ class CompletionItemKind {
const CompletionItemKind(this._value);
const CompletionItemKind.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

static const Text = CompletionItemKind(1);
Expand Down Expand Up @@ -6370,10 +6370,10 @@ class CompletionItemTag {
const CompletionItemTag(this._value);
const CompletionItemTag.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// Render a completion as obsolete, usually using a strike-out.
Expand Down Expand Up @@ -10715,10 +10715,10 @@ class DocumentHighlightKind {
const DocumentHighlightKind(this._value);
const DocumentHighlightKind.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// A textual occurrence.
Expand Down Expand Up @@ -13758,10 +13758,10 @@ class FileChangeType {
const FileChangeType(this._value);
const FileChangeType.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// The file got created.
Expand Down Expand Up @@ -16902,7 +16902,7 @@ class InsertTextFormat {
const InsertTextFormat._(this._value);
const InsertTextFormat.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
switch (obj) {
Expand Down Expand Up @@ -18204,10 +18204,10 @@ class MessageType {
const MessageType(this._value);
const MessageType.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// An error message.
Expand Down Expand Up @@ -19499,10 +19499,10 @@ class Position implements ToJsonable {
///
/// If the character value is greater than the line length it defaults back to
/// the line length.
final num character;
final int character;

/// Line position in a document (zero-based).
final num line;
final int line;

Map<String, dynamic> toJson() {
var __result = <String, dynamic>{};
Expand All @@ -19523,8 +19523,8 @@ class Position implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!(obj['line'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['line'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand All @@ -19540,8 +19540,8 @@ class Position implements ToJsonable {
reporter.reportError('must not be null');
return false;
}
if (!(obj['character'] is num)) {
reporter.reportError('must be of type num');
if (!(obj['character'] is int)) {
reporter.reportError('must be of type int');
return false;
}
} finally {
Expand Down Expand Up @@ -28247,10 +28247,10 @@ class SymbolKind {
const SymbolKind(this._value);
const SymbolKind.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

static const File = SymbolKind(1);
Expand Down Expand Up @@ -29926,10 +29926,10 @@ class TextDocumentSaveReason {
const TextDocumentSaveReason(this._value);
const TextDocumentSaveReason.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// Manually triggered, e.g. by the user pressing save, by starting debugging,
Expand Down Expand Up @@ -30183,10 +30183,10 @@ class TextDocumentSyncKind {
const TextDocumentSyncKind(this._value);
const TextDocumentSyncKind.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// Documents should not be synced at all.
Expand Down Expand Up @@ -31206,10 +31206,10 @@ class WatchKind {
const WatchKind(this._value);
const WatchKind.fromJson(this._value);

final num _value;
final int _value;

static bool canParse(Object obj, LspJsonReporter reporter) {
return obj is num;
return obj is int;
}

/// Interested in create events.
Expand Down
4 changes: 2 additions & 2 deletions pkg/analysis_server/lib/src/analysis_server_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ abstract class AbstractAnalysisServer {
/// The object used to manage the SDK's known to this server.
final DartSdkManager sdkManager;

/// The [SearchEngine] for this server, may be `null` if indexing is disabled.
SearchEngine? searchEngine;
/// The [SearchEngine] for this server.
late SearchEngine searchEngine;

late ByteStore byteStore;

Expand Down
5 changes: 2 additions & 3 deletions pkg/analysis_server/lib/src/edit/edit_domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ class EditDomainHandler extends AbstractRequestHandler {
/// [server].
EditDomainHandler(AnalysisServer server) : super(server) {
var search = searchEngine = server.searchEngine;
refactoringWorkspace = search == null
? null
: RefactoringWorkspace(server.driverMap.values, search);
refactoringWorkspace =
RefactoringWorkspace(server.driverMap.values, search);
_newRefactoringManager();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand Down Expand Up @@ -51,7 +49,7 @@ class LspByteStreamServerChannel implements LspServerCommunicationChannel {

@override
void listen(void Function(Message message) onMessage,
{Function onError, void Function() onDone}) {
{Function? onError, void Function()? onDone}) {
_input.transform(LspPacketTransformer()).listen(
(String data) => _readMessage(data, onMessage),
onError: onError,
Expand Down Expand Up @@ -95,7 +93,7 @@ class LspByteStreamServerChannel implements LspServerCommunicationChannel {
}

/// Sends a message prefixed with the required LSP headers.
void _sendLsp(Map<String, Object> json) {
void _sendLsp(Map<String, dynamic> json) {
// Don't send any further responses after the communication channel is
// closed.
if (_closeRequested) {
Expand Down
2 changes: 0 additions & 2 deletions pkg/analysis_server/lib/src/lsp/channel/lsp_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:analysis_server/lsp_protocol/protocol_special.dart';
import 'package:analysis_server/src/lsp/constants.dart';
Expand All @@ -20,7 +18,7 @@ class OrganizeImportsCommandHandler extends SimpleEditCommandHandler {
String get commandName => 'Organize Imports';

@override
Future<ErrorOr<void>> handle(List<dynamic> arguments,
Future<ErrorOr<void>> handle(List<dynamic>? arguments,
ProgressReporter reporter, CancellationToken cancellationToken) async {
if (arguments == null || arguments.length != 1 || arguments[0] is! String) {
return ErrorOr.error(ResponseError(
Expand All @@ -43,8 +41,8 @@ class OrganizeImportsCommandHandler extends SimpleEditCommandHandler {
}

return result.mapResult((result) {
final code = result.content;
final unit = result.unit;
final code = result.content!;
final unit = result.unit!;

if (hasScanParseErrors(result.errors)) {
// It's not uncommon for editors to run this command automatically on-save
Expand Down

0 comments on commit 77466f2

Please sign in to comment.