Skip to content

Commit 4296db0

Browse files
bwilkersonCommit Queue
authored andcommitted
Migrate protocol tests
Change-Id: I70f30a904a0c22a5858febea8550773588ea58d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400141 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 09730f9 commit 4296db0

File tree

2 files changed

+47
-49
lines changed

2 files changed

+47
-49
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ lib/src/services/search/element_visitors.dart
2828
lib/src/services/search/search_engine.dart
2929
lib/src/services/search/search_engine_internal.dart
3030
test/abstract_single_unit.dart
31-
test/plugin/protocol_dart_test.dart
3231
test/services/correction/status_test.dart
3332
test/services/refactoring/legacy/abstract_rename.dart
3433
test/services/refactoring/legacy/rename_import_test.dart

pkg/analysis_server/test/plugin/protocol_dart_test.dart

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/plugin/protocol/protocol_dart.dart';
6-
import 'package:analyzer/dart/element/element.dart' as engine;
6+
import 'package:analyzer/dart/element/element2.dart' as engine;
77
import 'package:analyzer/src/dart/element/element.dart' as engine;
88
import 'package:analyzer_plugin/protocol/protocol_common.dart';
99
import 'package:test/test.dart';
@@ -26,9 +26,9 @@ class ConvertElementTest extends AbstractSingleUnitTest {
2626
abstract class _A {}
2727
class B<K, V> {}''');
2828
{
29-
var engineElement = findElement.class_('_A');
29+
var engineElement = findElement2.class_('_A');
3030
// create notification Element
31-
var element = convertElement(engineElement);
31+
var element = convertElement2(engineElement);
3232
expect(element.kind, ElementKind.CLASS);
3333
expect(element.name, '_A');
3434
expect(element.typeParameters, isNull);
@@ -47,9 +47,9 @@ class B<K, V> {}''');
4747
);
4848
}
4949
{
50-
var engineElement = findElement.class_('B');
50+
var engineElement = findElement2.class_('B');
5151
// create notification Element
52-
var element = convertElement(engineElement);
52+
var element = convertElement2(engineElement);
5353
expect(element.kind, ElementKind.CLASS);
5454
expect(element.name, 'B');
5555
expect(element.typeParameters, '<K, V>');
@@ -62,9 +62,9 @@ class B<K, V> {}''');
6262
class A {
6363
const A.myConstructor(int a, [String? b]);
6464
}''');
65-
var engineElement = findElement.constructor('myConstructor');
65+
var engineElement = findElement2.constructor('myConstructor');
6666
// create notification Element
67-
var element = convertElement(engineElement);
67+
var element = convertElement2(engineElement);
6868
expect(element.kind, ElementKind.CONSTRUCTOR);
6969
expect(element.name, 'A.myConstructor');
7070
expect(element.typeParameters, isNull);
@@ -89,9 +89,9 @@ class A {
8989
const A.myConstructor(int a, {int? b, required int c});
9090
}''');
9191

92-
var engineElement = findElement.constructor('myConstructor');
92+
var engineElement = findElement2.constructor('myConstructor');
9393
// create notification Element
94-
var element = convertElement(engineElement);
94+
var element = convertElement2(engineElement);
9595
expect(element.parameters, '(int a, {required int c, int? b})');
9696
}
9797

@@ -104,9 +104,9 @@ class A {
104104
const A.myConstructor(int a, {int? b, required int d, required int c});
105105
}''');
106106

107-
var engineElement = findElement.constructor('myConstructor');
107+
var engineElement = findElement2.constructor('myConstructor');
108108
// create notification Element
109-
var element = convertElement(engineElement);
109+
var element = convertElement2(engineElement);
110110
expect(
111111
element.parameters,
112112
'(int a, {required int d, required int c, int? b})',
@@ -123,9 +123,9 @@ class A {
123123
const A.myConstructor(int a, {int b, required int d, required int c, int a});
124124
}''');
125125

126-
var engineElement = findElement.constructor('myConstructor');
126+
var engineElement = findElement2.constructor('myConstructor');
127127
// create notification Element
128-
var element = convertElement(engineElement);
128+
var element = convertElement2(engineElement);
129129
expect(
130130
element.parameters,
131131
'(int a, {required int d, required int c, int b, int a})',
@@ -150,10 +150,10 @@ class A {
150150
enum _E1 { one, two }
151151
enum E2 { three, four }''');
152152
{
153-
var engineElement = findElement.enum_('_E1');
154-
expect(engineElement.hasDeprecated, isTrue);
153+
var engineElement = findElement2.enum_('_E1');
154+
expect(engineElement.metadata2.hasDeprecated, isTrue);
155155
// create notification Element
156-
var element = convertElement(engineElement);
156+
var element = convertElement2(engineElement);
157157
expect(element.kind, ElementKind.ENUM);
158158
expect(element.name, '_E1');
159159
expect(element.typeParameters, isNull);
@@ -168,14 +168,14 @@ enum E2 { three, four }''');
168168
expect(element.parameters, isNull);
169169
expect(
170170
element.flags,
171-
(engineElement.hasDeprecated ? Element.FLAG_DEPRECATED : 0) |
171+
(engineElement.metadata2.hasDeprecated ? Element.FLAG_DEPRECATED : 0) |
172172
Element.FLAG_PRIVATE,
173173
);
174174
}
175175
{
176-
var engineElement = findElement.enum_('E2');
176+
var engineElement = findElement2.enum_('E2');
177177
// create notification Element
178-
var element = convertElement(engineElement);
178+
var element = convertElement2(engineElement);
179179
expect(element.kind, ElementKind.ENUM);
180180
expect(element.name, 'E2');
181181
expect(element.typeParameters, isNull);
@@ -189,9 +189,9 @@ enum E2 { three, four }''');
189189
enum _E1 { one, two }
190190
enum E2 { three, four }''');
191191
{
192-
var engineElement = findElement.field('one');
192+
var engineElement = findElement2.field('one');
193193
// create notification Element
194-
var element = convertElement(engineElement);
194+
var element = convertElement2(engineElement);
195195
expect(element.kind, ElementKind.ENUM_CONSTANT);
196196
expect(element.name, 'one');
197197
{
@@ -204,19 +204,18 @@ enum E2 { three, four }''');
204204
}
205205
expect(element.parameters, isNull);
206206
expect(element.returnType, '_E1');
207-
// TODO(danrubel): determine why enum constant is not marked as deprecated
208-
//engine.ClassElement classElement = engineElement.enclosingElement3;
209-
//expect(classElement.isDeprecated, isTrue);
207+
var classElement = engineElement.enclosingElement2;
208+
expect(classElement.metadata2.hasDeprecated, isTrue);
210209
expect(
211210
element.flags,
212211
// Element.FLAG_DEPRECATED |
213212
Element.FLAG_CONST | Element.FLAG_STATIC,
214213
);
215214
}
216215
{
217-
var engineElement = findElement.field('three');
216+
var engineElement = findElement2.field('three');
218217
// create notification Element
219-
var element = convertElement(engineElement);
218+
var element = convertElement2(engineElement);
220219
expect(element.kind, ElementKind.ENUM_CONSTANT);
221220
expect(element.name, 'three');
222221
{
@@ -232,18 +231,18 @@ enum E2 { three, four }''');
232231
expect(element.flags, Element.FLAG_CONST | Element.FLAG_STATIC);
233232
}
234233
{
235-
var engineElement = findElement.field('values', of: 'E2');
234+
var engineElement = findElement2.field('values', of: 'E2');
236235
// create notification Element
237-
var element = convertElement(engineElement);
236+
var element = convertElement2(engineElement);
238237
expect(element.kind, ElementKind.FIELD);
239238
expect(element.name, 'values');
240239
{
241240
var location = element.location!;
242241
expect(location.file, testFile.path);
243-
expect(location.offset, -1);
242+
expect(location.offset, 0);
244243
expect(location.length, 'values'.length);
245244
expect(location.startLine, 1);
246-
expect(location.startColumn, 0);
245+
expect(location.startColumn, 1);
247246
}
248247
expect(element.parameters, isNull);
249248
expect(element.returnType, 'List<E2>');
@@ -256,9 +255,9 @@ enum E2 { three, four }''');
256255
class A {
257256
static const myField = 42;
258257
}''');
259-
var engineElement = findElement.field('myField');
258+
var engineElement = findElement2.field('myField');
260259
// create notification Element
261-
var element = convertElement(engineElement);
260+
var element = convertElement2(engineElement);
262261
expect(element.kind, ElementKind.FIELD);
263262
expect(element.name, 'myField');
264263
{
@@ -278,9 +277,9 @@ class A {
278277
await resolveTestCode('''
279278
typedef F<T> = int Function(String x);
280279
''');
281-
var engineElement = findElement.typeAlias('F');
280+
var engineElement = findElement2.typeAlias('F');
282281
// create notification Element
283-
var element = convertElement(engineElement);
282+
var element = convertElement2(engineElement);
284283
expect(element.kind, ElementKind.TYPE_ALIAS);
285284
expect(element.name, 'F');
286285
expect(element.typeParameters, '<T>');
@@ -301,9 +300,9 @@ typedef F<T> = int Function(String x);
301300
await resolveTestCode('''
302301
typedef F<T> = Map<int, T>;
303302
''');
304-
var engineElement = findElement.typeAlias('F');
303+
var engineElement = findElement2.typeAlias('F');
305304
// create notification Element
306-
var element = convertElement(engineElement);
305+
var element = convertElement2(engineElement);
307306
expect(element.kind, ElementKind.TYPE_ALIAS);
308307
expect(element.name, 'F');
309308
expect(element.typeParameters, '<out T>');
@@ -325,9 +324,9 @@ typedef F<T> = Map<int, T>;
325324
await resolveTestCode('''
326325
typedef int F<T>(String x);
327326
''');
328-
var engineElement = findElement.typeAlias('F');
327+
var engineElement = findElement2.typeAlias('F');
329328
// create notification Element
330-
var element = convertElement(engineElement);
329+
var element = convertElement2(engineElement);
331330
expect(element.kind, ElementKind.TYPE_ALIAS);
332331
expect(element.name, 'F');
333332
expect(element.typeParameters, '<T>');
@@ -350,9 +349,9 @@ typedef int F<T>(String x);
350349
class A {
351350
String get myGetter => 42;
352351
}''');
353-
var engineElement = findElement.getter('myGetter');
352+
var engineElement = findElement2.getter('myGetter');
354353
// create notification Element
355-
var element = convertElement(engineElement);
354+
var element = convertElement2(engineElement);
356355
expect(element.kind, ElementKind.GETTER);
357356
expect(element.name, 'myGetter');
358357
{
@@ -376,9 +375,9 @@ myLabel:
376375
break myLabel;
377376
}
378377
}''');
379-
var engineElement = findElement.label('myLabel');
378+
var engineElement = findElement2.label('myLabel');
380379
// create notification Element
381-
var element = convertElement(engineElement);
380+
var element = convertElement2(engineElement);
382381
expect(element.kind, ElementKind.LABEL);
383382
expect(element.name, 'myLabel');
384383
{
@@ -401,9 +400,9 @@ class A {
401400
return [];
402401
}
403402
}''');
404-
var engineElement = findElement.method('myMethod');
403+
var engineElement = findElement2.method('myMethod');
405404
// create notification Element
406-
var element = convertElement(engineElement);
405+
var element = convertElement2(engineElement);
407406
expect(element.kind, ElementKind.METHOD);
408407
expect(element.name, 'myMethod');
409408
{
@@ -424,9 +423,9 @@ class A {
424423
mixin A {}
425424
''');
426425
{
427-
var engineElement = findElement.mixin('A');
426+
var engineElement = findElement2.mixin('A');
428427
// create notification Element
429-
var element = convertElement(engineElement);
428+
var element = convertElement2(engineElement);
430429
expect(element.kind, ElementKind.MIXIN);
431430
expect(element.name, 'A');
432431
expect(element.typeParameters, isNull);
@@ -448,9 +447,9 @@ mixin A {}
448447
class A {
449448
set mySetter(String x) {}
450449
}''');
451-
var engineElement = findElement.setter('mySetter');
450+
var engineElement = findElement2.setter('mySetter');
452451
// create notification Element
453-
var element = convertElement(engineElement);
452+
var element = convertElement2(engineElement);
454453
expect(element.kind, ElementKind.SETTER);
455454
expect(element.name, 'mySetter');
456455
{

0 commit comments

Comments
 (0)