Skip to content

Commit 0577ca0

Browse files
bwilkersonCommit Queue
authored andcommitted
[Migrate] error_reporter_test.dart
Change-Id: Iee6e8ec17881bcc514b8cef9039f88e2f5afcde3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403908 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 5862859 commit 0577ca0

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ lib/src/test_utilities/find_element.dart
138138
lib/src/test_utilities/find_node.dart
139139
lib/src/test_utilities/mock_sdk_elements.dart
140140
lib/src/utilities/extensions/element.dart
141-
test/error/error_reporter_test.dart
142141
test/generated/elements_types_mixin.dart
143142
test/generated/non_error_resolver_test.dart
144143
test/generated/resolver_test_case.dart

pkg/analyzer/lib/src/test_utilities/find_element2.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,15 @@ abstract class _FindElementBase {
507507
);
508508
}
509509

510+
ExtensionElement2 unnamedExtension() {
511+
for (var extension_ in libraryElement.extensions) {
512+
if (extension_.name3 == null) {
513+
return extension_;
514+
}
515+
}
516+
throw StateError('Not found: an unnamed extension');
517+
}
518+
510519
T _findInClassesLike<T extends Element2>({
511520
required String? className,
512521
required T? Function(InterfaceElement2 element) fromClass,

pkg/analyzer/test/error/error_reporter_test.dart

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,37 @@ class ErrorReporterTest extends PubPackageResolutionTest {
2424

2525
test_atElement_named() async {
2626
await resolveTestCode('class A {}');
27-
var element = findElement.class_('A');
28-
var reporter = ErrorReporter(listener, element.source);
29-
reporter.atElement(
27+
var element = findElement2.class_('A');
28+
var firstFragment = element.firstFragment;
29+
var reporter =
30+
ErrorReporter(listener, firstFragment.libraryFragment.source);
31+
reporter.atElement2(
3032
element,
3133
CompileTimeErrorCode.CAST_TO_NON_TYPE,
3234
arguments: ['A'],
3335
);
3436

3537
var error = listener.errors[0];
36-
expect(error.offset, element.nameOffset);
38+
expect(error.offset, firstFragment.nameOffset2);
3739
}
3840

3941
test_atElement_unnamed() async {
4042
await resolveTestCode(r'''
41-
import 'dart:async';
42-
import 'dart:math';
43+
extension on int {}
4344
''');
44-
var element = findElement.import('dart:math');
45+
var element = findElement2.unnamedExtension();
4546

46-
var reporter = ErrorReporter(listener, element.source);
47-
reporter.atElement(
47+
var firstFragment = element.firstFragment;
48+
var reporter =
49+
ErrorReporter(listener, firstFragment.libraryFragment.source);
50+
reporter.atElement2(
4851
element,
4952
CompileTimeErrorCode.CAST_TO_NON_TYPE,
5053
arguments: ['A'],
5154
);
5255

5356
var error = listener.errors[0];
54-
expect(error.offset, element.nameOffset);
57+
expect(error.offset, -1);
5558
}
5659

5760
test_atNode_types_differentNames() async {
@@ -65,8 +68,8 @@ main() {
6568
x;
6669
}
6770
''');
68-
var aImport = findElement.importFind('package:test/a.dart');
69-
var bImport = findElement.importFind('package:test/b.dart');
71+
var aImport = findElement2.importFind('package:test/a.dart');
72+
var bImport = findElement2.importFind('package:test/b.dart');
7073

7174
var firstType = aImport.class_('A').instantiate(
7275
typeArguments: [],
@@ -77,7 +80,8 @@ main() {
7780
nullabilitySuffix: NullabilitySuffix.none,
7881
);
7982

80-
var reporter = ErrorReporter(listener, firstType.element.source);
83+
var reporter = ErrorReporter(
84+
listener, firstType.element3.firstFragment.libraryFragment.source);
8185

8286
reporter.atNode(
8387
findNode.simple('x'),
@@ -100,8 +104,8 @@ main() {
100104
x;
101105
}
102106
''');
103-
var aImport = findElement.importFind('package:test/a.dart');
104-
var bImport = findElement.importFind('package:test/b.dart');
107+
var aImport = findElement2.importFind('package:test/a.dart');
108+
var bImport = findElement2.importFind('package:test/b.dart');
105109

106110
var firstType = aImport.class_('A').instantiate(
107111
typeArguments: [],
@@ -112,7 +116,8 @@ main() {
112116
nullabilitySuffix: NullabilitySuffix.none,
113117
);
114118

115-
var reporter = ErrorReporter(listener, firstType.element.source);
119+
var reporter = ErrorReporter(
120+
listener, firstType.element3.firstFragment.libraryFragment.source);
116121
reporter.atNode(
117122
findNode.simple('x'),
118123
CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
@@ -140,7 +145,7 @@ main() {
140145
var fa = findNode.topLevelVariableDeclaration('fa');
141146
var fb = findNode.topLevelVariableDeclaration('fb');
142147

143-
var source = result.unit.declaredElement!.source;
148+
var source = result.unit.declaredFragment!.libraryFragment!.source;
144149
var reporter = ErrorReporter(listener, source);
145150
reporter.atNode(
146151
findNode.simple('x'),
@@ -171,7 +176,7 @@ main() {
171176
var ba = findNode.topLevelVariableDeclaration('ba');
172177
var bb = findNode.topLevelVariableDeclaration('bb');
173178

174-
var source = result.unit.declaredElement!.source;
179+
var source = result.unit.declaredFragment!.libraryFragment!.source;
175180
var reporter = ErrorReporter(listener, source);
176181
reporter.atNode(
177182
findNode.simple('x'),

0 commit comments

Comments
 (0)