| 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 3231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 expect(parameter.kind, UnlinkedParamKind.named); | 3242 expect(parameter.kind, UnlinkedParamKind.named); |
| 3243 expect(parameter.defaultValue, isNull); | 3243 expect(parameter.defaultValue, isNull); |
| 3244 } | 3244 } |
| 3245 | 3245 |
| 3246 test_constructor_initializing_formal_named_withDefault() { | 3246 test_constructor_initializing_formal_named_withDefault() { |
| 3247 UnlinkedExecutable executable = findExecutable('', | 3247 UnlinkedExecutable executable = findExecutable('', |
| 3248 executables: serializeClassText('class C { C({this.x: 42}); final x; }') | 3248 executables: serializeClassText('class C { C({this.x: 42}); final x; }') |
| 3249 .executables); | 3249 .executables); |
| 3250 UnlinkedParam parameter = executable.parameters[0]; | 3250 UnlinkedParam parameter = executable.parameters[0]; |
| 3251 expect(parameter.kind, UnlinkedParamKind.named); | 3251 expect(parameter.kind, UnlinkedParamKind.named); |
| 3252 expect(parameter.initializer, isNotNull); |
| 3252 _assertUnlinkedConst(parameter.defaultValue, | 3253 _assertUnlinkedConst(parameter.defaultValue, |
| 3253 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 3254 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 3254 } | 3255 } |
| 3255 | 3256 |
| 3256 test_constructor_initializing_formal_non_function_typed() { | 3257 test_constructor_initializing_formal_non_function_typed() { |
| 3257 UnlinkedExecutable executable = findExecutable('', | 3258 UnlinkedExecutable executable = findExecutable('', |
| 3258 executables: | 3259 executables: |
| 3259 serializeClassText('class C { C(this.x); final x; }').executables); | 3260 serializeClassText('class C { C(this.x); final x; }').executables); |
| 3260 UnlinkedParam parameter = executable.parameters[0]; | 3261 UnlinkedParam parameter = executable.parameters[0]; |
| 3261 expect(parameter.isFunctionTyped, isFalse); | 3262 expect(parameter.isFunctionTyped, isFalse); |
| 3262 } | 3263 } |
| 3263 | 3264 |
| 3264 test_constructor_initializing_formal_positional() { | 3265 test_constructor_initializing_formal_positional() { |
| 3265 UnlinkedExecutable executable = findExecutable('', | 3266 UnlinkedExecutable executable = findExecutable('', |
| 3266 executables: serializeClassText('class C { C([this.x]); final x; }') | 3267 executables: serializeClassText('class C { C([this.x]); final x; }') |
| 3267 .executables); | 3268 .executables); |
| 3268 UnlinkedParam parameter = executable.parameters[0]; | 3269 UnlinkedParam parameter = executable.parameters[0]; |
| 3269 expect(parameter.kind, UnlinkedParamKind.positional); | 3270 expect(parameter.kind, UnlinkedParamKind.positional); |
| 3270 expect(parameter.defaultValue, isNull); | 3271 expect(parameter.defaultValue, isNull); |
| 3271 } | 3272 } |
| 3272 | 3273 |
| 3273 test_constructor_initializing_formal_positional_withDefault() { | 3274 test_constructor_initializing_formal_positional_withDefault() { |
| 3274 UnlinkedExecutable executable = findExecutable('', | 3275 UnlinkedExecutable executable = findExecutable('', |
| 3275 executables: | 3276 executables: |
| 3276 serializeClassText('class C { C([this.x = 42]); final x; }') | 3277 serializeClassText('class C { C([this.x = 42]); final x; }') |
| 3277 .executables); | 3278 .executables); |
| 3278 UnlinkedParam parameter = executable.parameters[0]; | 3279 UnlinkedParam parameter = executable.parameters[0]; |
| 3279 expect(parameter.kind, UnlinkedParamKind.positional); | 3280 expect(parameter.kind, UnlinkedParamKind.positional); |
| 3281 expect(parameter.initializer, isNotNull); |
| 3280 _assertUnlinkedConst(parameter.defaultValue, | 3282 _assertUnlinkedConst(parameter.defaultValue, |
| 3281 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 3283 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 3282 } | 3284 } |
| 3283 | 3285 |
| 3284 test_constructor_initializing_formal_required() { | 3286 test_constructor_initializing_formal_required() { |
| 3285 UnlinkedExecutable executable = findExecutable('', | 3287 UnlinkedExecutable executable = findExecutable('', |
| 3286 executables: | 3288 executables: |
| 3287 serializeClassText('class C { C(this.x); final x; }').executables); | 3289 serializeClassText('class C { C(this.x); final x; }').executables); |
| 3288 UnlinkedParam parameter = executable.parameters[0]; | 3290 UnlinkedParam parameter = executable.parameters[0]; |
| 3289 expect(parameter.kind, UnlinkedParamKind.required); | 3291 expect(parameter.kind, UnlinkedParamKind.required); |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4411 checkVoidTypeRef(executable.parameters[0].type); | 4413 checkVoidTypeRef(executable.parameters[0].type); |
| 4412 } | 4414 } |
| 4413 | 4415 |
| 4414 test_executable_param_function_typed_withDefault() { | 4416 test_executable_param_function_typed_withDefault() { |
| 4415 UnlinkedExecutable executable = serializeExecutableText(r''' | 4417 UnlinkedExecutable executable = serializeExecutableText(r''' |
| 4416 f([int p(int a2, String b2) = foo]) {} | 4418 f([int p(int a2, String b2) = foo]) {} |
| 4417 int foo(int a, String b) => 0; | 4419 int foo(int a, String b) => 0; |
| 4418 '''); | 4420 '''); |
| 4419 UnlinkedParam param = executable.parameters[0]; | 4421 UnlinkedParam param = executable.parameters[0]; |
| 4420 expect(param.kind, UnlinkedParamKind.positional); | 4422 expect(param.kind, UnlinkedParamKind.positional); |
| 4423 expect(param.initializer, isNotNull); |
| 4421 _assertUnlinkedConst(param.defaultValue, operators: [ | 4424 _assertUnlinkedConst(param.defaultValue, operators: [ |
| 4422 UnlinkedConstOperation.pushReference | 4425 UnlinkedConstOperation.pushReference |
| 4423 ], referenceValidators: [ | 4426 ], referenceValidators: [ |
| 4424 (EntityRef r) => checkTypeRef(r, null, null, 'foo', | 4427 (EntityRef r) => checkTypeRef(r, null, null, 'foo', |
| 4425 expectedKind: ReferenceKind.topLevelFunction) | 4428 expectedKind: ReferenceKind.topLevelFunction) |
| 4426 ]); | 4429 ]); |
| 4427 } | 4430 } |
| 4428 | 4431 |
| 4429 test_executable_param_kind_named() { | 4432 test_executable_param_kind_named() { |
| 4430 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}'); | 4433 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}'); |
| 4431 UnlinkedParam param = executable.parameters[0]; | 4434 UnlinkedParam param = executable.parameters[0]; |
| 4432 expect(param.kind, UnlinkedParamKind.named); | 4435 expect(param.kind, UnlinkedParamKind.named); |
| 4436 expect(param.initializer, isNull); |
| 4433 expect(param.defaultValue, isNull); | 4437 expect(param.defaultValue, isNull); |
| 4434 } | 4438 } |
| 4435 | 4439 |
| 4436 test_executable_param_kind_named_withDefault() { | 4440 test_executable_param_kind_named_withDefault() { |
| 4437 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}'); | 4441 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}'); |
| 4438 UnlinkedParam param = executable.parameters[0]; | 4442 UnlinkedParam param = executable.parameters[0]; |
| 4439 expect(param.kind, UnlinkedParamKind.named); | 4443 expect(param.kind, UnlinkedParamKind.named); |
| 4444 expect(param.initializer, isNotNull); |
| 4440 _assertUnlinkedConst(param.defaultValue, | 4445 _assertUnlinkedConst(param.defaultValue, |
| 4441 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 4446 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 4442 } | 4447 } |
| 4443 | 4448 |
| 4444 test_executable_param_kind_positional() { | 4449 test_executable_param_kind_positional() { |
| 4445 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); | 4450 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); |
| 4446 UnlinkedParam param = executable.parameters[0]; | 4451 UnlinkedParam param = executable.parameters[0]; |
| 4447 expect(param.kind, UnlinkedParamKind.positional); | 4452 expect(param.kind, UnlinkedParamKind.positional); |
| 4453 expect(param.initializer, isNull); |
| 4448 expect(param.defaultValue, isNull); | 4454 expect(param.defaultValue, isNull); |
| 4449 } | 4455 } |
| 4450 | 4456 |
| 4451 test_executable_param_kind_positional_withDefault() { | 4457 test_executable_param_kind_positional_withDefault() { |
| 4452 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}'); | 4458 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}'); |
| 4453 UnlinkedParam param = executable.parameters[0]; | 4459 UnlinkedParam param = executable.parameters[0]; |
| 4454 expect(param.kind, UnlinkedParamKind.positional); | 4460 expect(param.kind, UnlinkedParamKind.positional); |
| 4461 expect(param.initializer, isNotNull); |
| 4455 _assertUnlinkedConst(param.defaultValue, | 4462 _assertUnlinkedConst(param.defaultValue, |
| 4456 operators: [UnlinkedConstOperation.pushInt], ints: [42]); | 4463 operators: [UnlinkedConstOperation.pushInt], ints: [42]); |
| 4457 } | 4464 } |
| 4458 | 4465 |
| 4459 test_executable_param_kind_required() { | 4466 test_executable_param_kind_required() { |
| 4460 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); | 4467 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); |
| 4461 UnlinkedParam param = executable.parameters[0]; | 4468 UnlinkedParam param = executable.parameters[0]; |
| 4462 expect(param.kind, UnlinkedParamKind.required); | 4469 expect(param.kind, UnlinkedParamKind.required); |
| 4470 expect(param.initializer, isNull); |
| 4463 expect(param.defaultValue, isNull); | 4471 expect(param.defaultValue, isNull); |
| 4464 } | 4472 } |
| 4465 | 4473 |
| 4466 test_executable_param_name() { | 4474 test_executable_param_name() { |
| 4467 String text = 'f(x) {}'; | 4475 String text = 'f(x) {}'; |
| 4468 UnlinkedExecutable executable = serializeExecutableText(text); | 4476 UnlinkedExecutable executable = serializeExecutableText(text); |
| 4469 expect(executable.parameters, hasLength(1)); | 4477 expect(executable.parameters, hasLength(1)); |
| 4470 expect(executable.parameters[0].name, 'x'); | 4478 expect(executable.parameters[0].name, 'x'); |
| 4471 expect(executable.parameters[0].nameOffset, text.indexOf('x')); | 4479 expect(executable.parameters[0].nameOffset, text.indexOf('x')); |
| 4472 } | 4480 } |
| (...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6690 test_variable_inferred_type_implicit_initialized() { | 6698 test_variable_inferred_type_implicit_initialized() { |
| 6691 UnlinkedVariable v = serializeVariableText('var v = 0;'); | 6699 UnlinkedVariable v = serializeVariableText('var v = 0;'); |
| 6692 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int'); | 6700 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int'); |
| 6693 } | 6701 } |
| 6694 | 6702 |
| 6695 test_variable_inferred_type_implicit_uninitialized() { | 6703 test_variable_inferred_type_implicit_uninitialized() { |
| 6696 UnlinkedVariable v = serializeVariableText('var v;'); | 6704 UnlinkedVariable v = serializeVariableText('var v;'); |
| 6697 expect(v.inferredTypeSlot, 0); | 6705 expect(v.inferredTypeSlot, 0); |
| 6698 } | 6706 } |
| 6699 | 6707 |
| 6708 test_variable_initializer_literal() { |
| 6709 UnlinkedVariable variable = serializeVariableText('var v = 42;'); |
| 6710 UnlinkedExecutable initializer = variable.initializer; |
| 6711 expect(initializer, isNotNull); |
| 6712 expect(initializer.nameOffset, 8); |
| 6713 expect(initializer.name, isEmpty); |
| 6714 expect(initializer.localFunctions, isEmpty); |
| 6715 expect(initializer.localVariables, isEmpty); |
| 6716 } |
| 6717 |
| 6718 test_variable_initializer_noInitializer() { |
| 6719 UnlinkedVariable variable = serializeVariableText('var v;'); |
| 6720 expect(variable.initializer, isNull); |
| 6721 } |
| 6722 |
| 6723 test_variable_initializer_withLocals() { |
| 6724 String text = |
| 6725 'var v = {"1": () { f1() {} var v1; }, "2": () { f2() {} var v2; }};'; |
| 6726 UnlinkedVariable variable = serializeVariableText(text); |
| 6727 UnlinkedExecutable initializer = variable.initializer; |
| 6728 expect(initializer, isNotNull); |
| 6729 expect(initializer.nameOffset, text.indexOf('{"1')); |
| 6730 expect(initializer.name, isEmpty); |
| 6731 expect(initializer.localFunctions, hasLength(2)); |
| 6732 // closure: () { f1() {} var v1; } |
| 6733 { |
| 6734 UnlinkedExecutable closure = initializer.localFunctions[0]; |
| 6735 expect(closure.nameOffset, text.indexOf('() { f1()')); |
| 6736 expect(closure.name, isEmpty); |
| 6737 // closure - f1 |
| 6738 expect(closure.localFunctions, hasLength(1)); |
| 6739 expect(closure.localFunctions[0].name, 'f1'); |
| 6740 expect(closure.localFunctions[0].nameOffset, text.indexOf('f1()')); |
| 6741 // closure - v1 |
| 6742 expect(closure.localVariables, hasLength(1)); |
| 6743 expect(closure.localVariables[0].name, 'v1'); |
| 6744 expect(closure.localVariables[0].nameOffset, text.indexOf('v1;')); |
| 6745 } |
| 6746 // closure: () { f2() {} var v2; } |
| 6747 { |
| 6748 UnlinkedExecutable closure = initializer.localFunctions[1]; |
| 6749 expect(closure.nameOffset, text.indexOf('() { f2()')); |
| 6750 expect(closure.name, isEmpty); |
| 6751 // closure - f1 |
| 6752 expect(closure.localFunctions, hasLength(1)); |
| 6753 expect(closure.localFunctions[0].name, 'f2'); |
| 6754 expect(closure.localFunctions[0].nameOffset, text.indexOf('f2()')); |
| 6755 // closure - v1 |
| 6756 expect(closure.localVariables, hasLength(1)); |
| 6757 expect(closure.localVariables[0].name, 'v2'); |
| 6758 expect(closure.localVariables[0].nameOffset, text.indexOf('v2;')); |
| 6759 } |
| 6760 } |
| 6761 |
| 6700 test_variable_name() { | 6762 test_variable_name() { |
| 6701 UnlinkedVariable variable = | 6763 UnlinkedVariable variable = |
| 6702 serializeVariableText('int i;', variableName: 'i'); | 6764 serializeVariableText('int i;', variableName: 'i'); |
| 6703 expect(variable.name, 'i'); | 6765 expect(variable.name, 'i'); |
| 6704 } | 6766 } |
| 6705 | 6767 |
| 6706 test_variable_no_flags() { | 6768 test_variable_no_flags() { |
| 6707 UnlinkedVariable variable = | 6769 UnlinkedVariable variable = |
| 6708 serializeVariableText('int i;', variableName: 'i'); | 6770 serializeVariableText('int i;', variableName: 'i'); |
| 6709 expect(variable.isStatic, isFalse); | 6771 expect(variable.isStatic, isFalse); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6905 final String absoluteUri; | 6967 final String absoluteUri; |
| 6906 final String relativeUri; | 6968 final String relativeUri; |
| 6907 final int numTypeParameters; | 6969 final int numTypeParameters; |
| 6908 | 6970 |
| 6909 _PrefixExpectation(this.kind, this.name, | 6971 _PrefixExpectation(this.kind, this.name, |
| 6910 {this.inLibraryDefiningUnit: false, | 6972 {this.inLibraryDefiningUnit: false, |
| 6911 this.absoluteUri, | 6973 this.absoluteUri, |
| 6912 this.relativeUri, | 6974 this.relativeUri, |
| 6913 this.numTypeParameters: 0}); | 6975 this.numTypeParameters: 0}); |
| 6914 } | 6976 } |
| OLD | NEW |