| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 3268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3279 findExecutable('', executables: serializeClassText(r''' | 3279 findExecutable('', executables: serializeClassText(r''' |
| 3280 class C { | 3280 class C { |
| 3281 C([this.x() = foo]); | 3281 C([this.x() = foo]); |
| 3282 final x; | 3282 final x; |
| 3283 } | 3283 } |
| 3284 int foo() => 0; | 3284 int foo() => 0; |
| 3285 ''').executables); | 3285 ''').executables); |
| 3286 UnlinkedParam param = executable.parameters[0]; | 3286 UnlinkedParam param = executable.parameters[0]; |
| 3287 expect(param.isFunctionTyped, isTrue); | 3287 expect(param.isFunctionTyped, isTrue); |
| 3288 expect(param.kind, UnlinkedParamKind.positional); | 3288 expect(param.kind, UnlinkedParamKind.positional); |
| 3289 expect(param.defaultValueCode, 'foo'); |
| 3289 _assertUnlinkedConst(param.defaultValue, operators: [ | 3290 _assertUnlinkedConst(param.defaultValue, operators: [ |
| 3290 UnlinkedConstOperation.pushReference | 3291 UnlinkedConstOperation.pushReference |
| 3291 ], referenceValidators: [ | 3292 ], referenceValidators: [ |
| 3292 (EntityRef r) => checkTypeRef(r, null, null, 'foo', | 3293 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 3293 expectedKind: ReferenceKind.topLevelFunction) | 3294 expectedKind: ReferenceKind.topLevelFunction) |
| 3294 ]); | 3295 ]); |
| 3295 } | 3296 } |
| 3296 | 3297 |
| 3297 test_constructor_initializing_formal_implicit_type() { | 3298 test_constructor_initializing_formal_implicit_type() { |
| 3298 // Note: the implicit type of an initializing formal is the type of the | 3299 // Note: the implicit type of an initializing formal is the type of the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3312 expect(parameter.name, 'x'); | 3313 expect(parameter.name, 'x'); |
| 3313 } | 3314 } |
| 3314 | 3315 |
| 3315 test_constructor_initializing_formal_named() { | 3316 test_constructor_initializing_formal_named() { |
| 3316 UnlinkedExecutable executable = findExecutable('', | 3317 UnlinkedExecutable executable = findExecutable('', |
| 3317 executables: serializeClassText('class C { C({this.x}); final x; }') | 3318 executables: serializeClassText('class C { C({this.x}); final x; }') |
| 3318 .executables); | 3319 .executables); |
| 3319 UnlinkedParam parameter = executable.parameters[0]; | 3320 UnlinkedParam parameter = executable.parameters[0]; |
| 3320 expect(parameter.kind, UnlinkedParamKind.named); | 3321 expect(parameter.kind, UnlinkedParamKind.named); |
| 3321 expect(parameter.defaultValue, isNull); | 3322 expect(parameter.defaultValue, isNull); |
| 3323 expect(parameter.defaultValueCode, isEmpty); |
| 3322 } | 3324 } |
| 3323 | 3325 |
| 3324 test_constructor_initializing_formal_named_withDefault() { | 3326 test_constructor_initializing_formal_named_withDefault() { |
| 3325 UnlinkedExecutable executable = findExecutable('', | 3327 UnlinkedExecutable executable = findExecutable('', |
| 3326 executables: serializeClassText('class C { C({this.x: 42}); final x; }') | 3328 executables: serializeClassText('class C { C({this.x: 42}); final x; }') |
| 3327 .executables); | 3329 .executables); |
| 3328 UnlinkedParam parameter = executable.parameters[0]; | 3330 UnlinkedParam parameter = executable.parameters[0]; |
| 3329 expect(parameter.kind, UnlinkedParamKind.named); | 3331 expect(parameter.kind, UnlinkedParamKind.named); |
| 3330 expect(parameter.initializer, isNotNull); | 3332 expect(parameter.initializer, isNotNull); |
| 3333 expect(parameter.defaultValueCode, '42'); |
| 3331 _assertUnlinkedConst(parameter.defaultValue, | 3334 _assertUnlinkedConst(parameter.defaultValue, |
| 3332 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 3335 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 3333 } | 3336 } |
| 3334 | 3337 |
| 3335 test_constructor_initializing_formal_non_function_typed() { | 3338 test_constructor_initializing_formal_non_function_typed() { |
| 3336 UnlinkedExecutable executable = findExecutable('', | 3339 UnlinkedExecutable executable = findExecutable('', |
| 3337 executables: | 3340 executables: |
| 3338 serializeClassText('class C { C(this.x); final x; }').executables); | 3341 serializeClassText('class C { C(this.x); final x; }').executables); |
| 3339 UnlinkedParam parameter = executable.parameters[0]; | 3342 UnlinkedParam parameter = executable.parameters[0]; |
| 3340 expect(parameter.isFunctionTyped, isFalse); | 3343 expect(parameter.isFunctionTyped, isFalse); |
| 3341 } | 3344 } |
| 3342 | 3345 |
| 3343 test_constructor_initializing_formal_positional() { | 3346 test_constructor_initializing_formal_positional() { |
| 3344 UnlinkedExecutable executable = findExecutable('', | 3347 UnlinkedExecutable executable = findExecutable('', |
| 3345 executables: serializeClassText('class C { C([this.x]); final x; }') | 3348 executables: serializeClassText('class C { C([this.x]); final x; }') |
| 3346 .executables); | 3349 .executables); |
| 3347 UnlinkedParam parameter = executable.parameters[0]; | 3350 UnlinkedParam parameter = executable.parameters[0]; |
| 3348 expect(parameter.kind, UnlinkedParamKind.positional); | 3351 expect(parameter.kind, UnlinkedParamKind.positional); |
| 3349 expect(parameter.defaultValue, isNull); | 3352 expect(parameter.defaultValue, isNull); |
| 3353 expect(parameter.defaultValueCode, isEmpty); |
| 3350 } | 3354 } |
| 3351 | 3355 |
| 3352 test_constructor_initializing_formal_positional_withDefault() { | 3356 test_constructor_initializing_formal_positional_withDefault() { |
| 3353 UnlinkedExecutable executable = findExecutable('', | 3357 UnlinkedExecutable executable = findExecutable('', |
| 3354 executables: | 3358 executables: |
| 3355 serializeClassText('class C { C([this.x = 42]); final x; }') | 3359 serializeClassText('class C { C([this.x = 42]); final x; }') |
| 3356 .executables); | 3360 .executables); |
| 3357 UnlinkedParam parameter = executable.parameters[0]; | 3361 UnlinkedParam parameter = executable.parameters[0]; |
| 3358 expect(parameter.kind, UnlinkedParamKind.positional); | 3362 expect(parameter.kind, UnlinkedParamKind.positional); |
| 3359 expect(parameter.initializer, isNotNull); | 3363 expect(parameter.initializer, isNotNull); |
| 3364 expect(parameter.defaultValueCode, '42'); |
| 3360 _assertUnlinkedConst(parameter.defaultValue, | 3365 _assertUnlinkedConst(parameter.defaultValue, |
| 3361 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 3366 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 3362 } | 3367 } |
| 3363 | 3368 |
| 3364 test_constructor_initializing_formal_required() { | 3369 test_constructor_initializing_formal_required() { |
| 3365 UnlinkedExecutable executable = findExecutable('', | 3370 UnlinkedExecutable executable = findExecutable('', |
| 3366 executables: | 3371 executables: |
| 3367 serializeClassText('class C { C(this.x); final x; }').executables); | 3372 serializeClassText('class C { C(this.x); final x; }').executables); |
| 3368 UnlinkedParam parameter = executable.parameters[0]; | 3373 UnlinkedParam parameter = executable.parameters[0]; |
| 3369 expect(parameter.kind, UnlinkedParamKind.required); | 3374 expect(parameter.kind, UnlinkedParamKind.required); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3381 | 3386 |
| 3382 test_constructor_initializing_formal_withDefault() { | 3387 test_constructor_initializing_formal_withDefault() { |
| 3383 UnlinkedExecutable executable = | 3388 UnlinkedExecutable executable = |
| 3384 findExecutable('', executables: serializeClassText(r''' | 3389 findExecutable('', executables: serializeClassText(r''' |
| 3385 class C { | 3390 class C { |
| 3386 C([this.x = 42]); | 3391 C([this.x = 42]); |
| 3387 final int x; | 3392 final int x; |
| 3388 }''').executables); | 3393 }''').executables); |
| 3389 UnlinkedParam param = executable.parameters[0]; | 3394 UnlinkedParam param = executable.parameters[0]; |
| 3390 expect(param.kind, UnlinkedParamKind.positional); | 3395 expect(param.kind, UnlinkedParamKind.positional); |
| 3396 expect(param.defaultValueCode, '42'); |
| 3391 _assertUnlinkedConst(param.defaultValue, | 3397 _assertUnlinkedConst(param.defaultValue, |
| 3392 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 3398 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 3393 } | 3399 } |
| 3394 | 3400 |
| 3395 test_constructor_named() { | 3401 test_constructor_named() { |
| 3396 String text = 'class C { C.foo(); }'; | 3402 String text = 'class C { C.foo(); }'; |
| 3397 UnlinkedExecutable executable = findExecutable('foo', | 3403 UnlinkedExecutable executable = findExecutable('foo', |
| 3398 executables: serializeClassText(text).executables); | 3404 executables: serializeClassText(text).executables); |
| 3399 expect(executable.name, 'foo'); | 3405 expect(executable.name, 'foo'); |
| 3400 expect(executable.nameOffset, text.indexOf('foo')); | 3406 expect(executable.nameOffset, text.indexOf('foo')); |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4578 } | 4584 } |
| 4579 | 4585 |
| 4580 test_executable_param_function_typed_withDefault() { | 4586 test_executable_param_function_typed_withDefault() { |
| 4581 UnlinkedExecutable executable = serializeExecutableText(r''' | 4587 UnlinkedExecutable executable = serializeExecutableText(r''' |
| 4582 f([int p(int a2, String b2) = foo]) {} | 4588 f([int p(int a2, String b2) = foo]) {} |
| 4583 int foo(int a, String b) => 0; | 4589 int foo(int a, String b) => 0; |
| 4584 '''); | 4590 '''); |
| 4585 UnlinkedParam param = executable.parameters[0]; | 4591 UnlinkedParam param = executable.parameters[0]; |
| 4586 expect(param.kind, UnlinkedParamKind.positional); | 4592 expect(param.kind, UnlinkedParamKind.positional); |
| 4587 expect(param.initializer, isNotNull); | 4593 expect(param.initializer, isNotNull); |
| 4594 expect(param.defaultValueCode, 'foo'); |
| 4588 _assertUnlinkedConst(param.defaultValue, operators: [ | 4595 _assertUnlinkedConst(param.defaultValue, operators: [ |
| 4589 UnlinkedConstOperation.pushReference | 4596 UnlinkedConstOperation.pushReference |
| 4590 ], referenceValidators: [ | 4597 ], referenceValidators: [ |
| 4591 (EntityRef r) => checkTypeRef(r, null, null, 'foo', | 4598 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 4592 expectedKind: ReferenceKind.topLevelFunction) | 4599 expectedKind: ReferenceKind.topLevelFunction) |
| 4593 ]); | 4600 ]); |
| 4594 } | 4601 } |
| 4595 | 4602 |
| 4596 test_executable_param_kind_named() { | 4603 test_executable_param_kind_named() { |
| 4597 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}'); | 4604 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}'); |
| 4598 UnlinkedParam param = executable.parameters[0]; | 4605 UnlinkedParam param = executable.parameters[0]; |
| 4599 expect(param.kind, UnlinkedParamKind.named); | 4606 expect(param.kind, UnlinkedParamKind.named); |
| 4600 expect(param.initializer, isNull); | 4607 expect(param.initializer, isNull); |
| 4601 expect(param.defaultValue, isNull); | 4608 expect(param.defaultValue, isNull); |
| 4609 expect(param.defaultValueCode, isEmpty); |
| 4602 } | 4610 } |
| 4603 | 4611 |
| 4604 test_executable_param_kind_named_withDefault() { | 4612 test_executable_param_kind_named_withDefault() { |
| 4605 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}'); | 4613 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}'); |
| 4606 UnlinkedParam param = executable.parameters[0]; | 4614 UnlinkedParam param = executable.parameters[0]; |
| 4607 expect(param.kind, UnlinkedParamKind.named); | 4615 expect(param.kind, UnlinkedParamKind.named); |
| 4608 expect(param.initializer, isNotNull); | 4616 expect(param.initializer, isNotNull); |
| 4617 expect(param.defaultValueCode, '42'); |
| 4609 _assertUnlinkedConst(param.defaultValue, | 4618 _assertUnlinkedConst(param.defaultValue, |
| 4610 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 4619 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 4611 } | 4620 } |
| 4612 | 4621 |
| 4613 test_executable_param_kind_positional() { | 4622 test_executable_param_kind_positional() { |
| 4614 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); | 4623 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); |
| 4615 UnlinkedParam param = executable.parameters[0]; | 4624 UnlinkedParam param = executable.parameters[0]; |
| 4616 expect(param.kind, UnlinkedParamKind.positional); | 4625 expect(param.kind, UnlinkedParamKind.positional); |
| 4617 expect(param.initializer, isNull); | 4626 expect(param.initializer, isNull); |
| 4618 expect(param.defaultValue, isNull); | 4627 expect(param.defaultValue, isNull); |
| 4628 expect(param.defaultValueCode, isEmpty); |
| 4619 } | 4629 } |
| 4620 | 4630 |
| 4621 test_executable_param_kind_positional_withDefault() { | 4631 test_executable_param_kind_positional_withDefault() { |
| 4622 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}'); | 4632 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}'); |
| 4623 UnlinkedParam param = executable.parameters[0]; | 4633 UnlinkedParam param = executable.parameters[0]; |
| 4624 expect(param.kind, UnlinkedParamKind.positional); | 4634 expect(param.kind, UnlinkedParamKind.positional); |
| 4625 expect(param.initializer, isNotNull); | 4635 expect(param.initializer, isNotNull); |
| 4636 expect(param.defaultValueCode, '42'); |
| 4626 _assertUnlinkedConst(param.defaultValue, | 4637 _assertUnlinkedConst(param.defaultValue, |
| 4627 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 4638 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 4628 } | 4639 } |
| 4629 | 4640 |
| 4630 test_executable_param_kind_required() { | 4641 test_executable_param_kind_required() { |
| 4631 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); | 4642 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); |
| 4632 UnlinkedParam param = executable.parameters[0]; | 4643 UnlinkedParam param = executable.parameters[0]; |
| 4633 expect(param.kind, UnlinkedParamKind.required); | 4644 expect(param.kind, UnlinkedParamKind.required); |
| 4634 expect(param.initializer, isNull); | 4645 expect(param.initializer, isNull); |
| 4635 expect(param.defaultValue, isNull); | 4646 expect(param.defaultValue, isNull); |
| 4647 expect(param.defaultValueCode, isEmpty); |
| 4636 } | 4648 } |
| 4637 | 4649 |
| 4638 test_executable_param_name() { | 4650 test_executable_param_name() { |
| 4639 String text = 'f(x) {}'; | 4651 String text = 'f(x) {}'; |
| 4640 UnlinkedExecutable executable = serializeExecutableText(text); | 4652 UnlinkedExecutable executable = serializeExecutableText(text); |
| 4641 expect(executable.parameters, hasLength(1)); | 4653 expect(executable.parameters, hasLength(1)); |
| 4642 expect(executable.parameters[0].name, 'x'); | 4654 expect(executable.parameters[0].name, 'x'); |
| 4643 expect(executable.parameters[0].nameOffset, text.indexOf('x')); | 4655 expect(executable.parameters[0].nameOffset, text.indexOf('x')); |
| 4644 } | 4656 } |
| 4645 | 4657 |
| (...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7288 class _PrefixExpectation { | 7300 class _PrefixExpectation { |
| 7289 final ReferenceKind kind; | 7301 final ReferenceKind kind; |
| 7290 final String name; | 7302 final String name; |
| 7291 final String absoluteUri; | 7303 final String absoluteUri; |
| 7292 final String relativeUri; | 7304 final String relativeUri; |
| 7293 final int numTypeParameters; | 7305 final int numTypeParameters; |
| 7294 | 7306 |
| 7295 _PrefixExpectation(this.kind, this.name, | 7307 _PrefixExpectation(this.kind, this.name, |
| 7296 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 7308 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 7297 } | 7309 } |
| OLD | NEW |