Skip to content

Commit b4ce309

Browse files
author
Dart CI
committed
Version 2.18.0-241.0.dev
Merge commit 'a8541852d582b34b1fc3fb790dcec92410e76d81' into 'dev'
2 parents 9b7a734 + a854185 commit b4ce309

File tree

7 files changed

+45
-25
lines changed

7 files changed

+45
-25
lines changed

pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:analyzer/dart/element/nullability_suffix.dart';
2323
import 'package:analyzer/dart/element/type.dart';
2424
import 'package:analyzer/src/dart/element/element.dart';
2525
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
26+
import 'package:analyzer/src/utilities/extensions/object.dart';
2627
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
2728
import 'package:analyzer_plugin/utilities/range_factory.dart';
2829

@@ -1645,11 +1646,3 @@ class _ElementDocumentation {
16451646
required this.summary,
16461647
});
16471648
}
1648-
1649-
extension on Object? {
1650-
/// If the target is [T], return it, otherwise `null`.
1651-
T? ifTypeOrNull<T>() {
1652-
final self = this;
1653-
return self is T ? self : null;
1654-
}
1655-
}

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import 'package:analyzer/src/generated/error_detection_helpers.dart';
4646
import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
4747
import 'package:analyzer/src/generated/this_access_tracker.dart';
4848
import 'package:analyzer/src/summary2/macro_application_error.dart';
49+
import 'package:analyzer/src/utilities/extensions/object.dart';
4950
import 'package:analyzer/src/utilities/extensions/string.dart';
5051
import 'package:collection/collection.dart';
5152

@@ -5339,11 +5340,3 @@ class _UninstantiatedBoundChecker extends RecursiveAstVisitor<void> {
53395340
}
53405341
}
53415342
}
5342-
5343-
extension on Object? {
5344-
/// If the target is [T], return it, otherwise `null`.
5345-
T? ifTypeOrNull<T>() {
5346-
final self = this;
5347-
return self is T ? self : null;
5348-
}
5349-
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
extension NullableObjectExtension on Object? {
6+
/// If the target is [T], return it, otherwise `null`.
7+
T? ifTypeOrNull<T>() {
8+
final self = this;
9+
return self is T ? self : null;
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/utilities/extensions/object.dart';
6+
import 'package:test/test.dart';
7+
import 'package:test_reflective_loader/test_reflective_loader.dart';
8+
9+
main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(NullableObjectExtensionTest);
12+
});
13+
}
14+
15+
@reflectiveTest
16+
class NullableObjectExtensionTest {
17+
test_ifTypeOrNull_int() {
18+
expect(0.ifTypeOrNull<int>(), 0);
19+
expect(0.ifTypeOrNull<num>(), 0);
20+
expect(0.ifTypeOrNull<Object>(), 0);
21+
expect(0.ifTypeOrNull<String>(), isNull);
22+
}
23+
24+
test_ifTypeOrNull_null() {
25+
expect(null.ifTypeOrNull<Object>(), isNull);
26+
expect(null.ifTypeOrNull<int>(), isNull);
27+
}
28+
}

pkg/analyzer/test/src/utilities/extensions/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import 'package:test_reflective_loader/test_reflective_loader.dart';
66

77
import 'collection_test.dart' as collection;
8+
import 'object_test.dart' as object;
89
import 'stream_test.dart' as stream;
910
import 'string_test.dart' as string;
1011

1112
main() {
1213
defineReflectiveSuite(() {
1314
collection.main();
15+
object.main();
1416
stream.main();
1517
string.main();
1618
}, name: 'extensions');

pkg/analyzer_plugin/lib/src/utilities/completion/completion_target.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analyzer/dart/element/element.dart';
99
import 'package:analyzer/dart/element/type.dart';
1010
import 'package:analyzer/src/dart/ast/token.dart';
1111
import 'package:analyzer/src/generated/source.dart';
12+
import 'package:analyzer/src/utilities/extensions/object.dart';
1213

1314
/// A CompletionTarget represents an edge in the parse tree which connects an
1415
/// AST node (the [containingNode] of the completion) to one of its children
@@ -697,11 +698,3 @@ class CompletionTarget {
697698
}
698699
}
699700
}
700-
701-
extension on Object? {
702-
/// If the target is [T], return it, otherwise `null`.
703-
T? ifTypeOrNull<T>() {
704-
final self = this;
705-
return self is T ? self : null;
706-
}
707-
}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 18
2929
PATCH 0
30-
PRERELEASE 240
30+
PRERELEASE 241
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)