Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 2010993002: Migrate UnlinkedParam.defaultValue to UnlinkedExecutable.bodyExpr. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3684 matching lines...) Expand 10 before | Expand all | Expand 10 after
3695 class C { 3695 class C {
3696 C([this.x() = foo]); 3696 C([this.x() = foo]);
3697 final x; 3697 final x;
3698 } 3698 }
3699 int foo() => 0; 3699 int foo() => 0;
3700 ''').executables); 3700 ''').executables);
3701 UnlinkedParam param = executable.parameters[0]; 3701 UnlinkedParam param = executable.parameters[0];
3702 expect(param.isFunctionTyped, isTrue); 3702 expect(param.isFunctionTyped, isTrue);
3703 expect(param.kind, UnlinkedParamKind.positional); 3703 expect(param.kind, UnlinkedParamKind.positional);
3704 expect(param.defaultValueCode, 'foo'); 3704 expect(param.defaultValueCode, 'foo');
3705 _assertUnlinkedConst(param.defaultValue, operators: [ 3705 _assertUnlinkedConst(param.initializer.bodyExpr, operators: [
3706 UnlinkedConstOperation.pushReference 3706 UnlinkedConstOperation.pushReference
3707 ], referenceValidators: [ 3707 ], referenceValidators: [
3708 (EntityRef r) => checkTypeRef(r, null, null, 'foo', 3708 (EntityRef r) => checkTypeRef(r, null, null, 'foo',
3709 expectedKind: ReferenceKind.topLevelFunction) 3709 expectedKind: ReferenceKind.topLevelFunction)
3710 ]); 3710 ]);
3711 } 3711 }
3712 3712
3713 test_constructor_initializing_formal_implicit_type() { 3713 test_constructor_initializing_formal_implicit_type() {
3714 // Note: the implicit type of an initializing formal is the type of the 3714 // Note: the implicit type of an initializing formal is the type of the
3715 // field. 3715 // field.
(...skipping 11 matching lines...) Expand all
3727 UnlinkedParam parameter = executable.parameters[0]; 3727 UnlinkedParam parameter = executable.parameters[0];
3728 expect(parameter.name, 'x'); 3728 expect(parameter.name, 'x');
3729 } 3729 }
3730 3730
3731 test_constructor_initializing_formal_named() { 3731 test_constructor_initializing_formal_named() {
3732 UnlinkedExecutable executable = findExecutable('', 3732 UnlinkedExecutable executable = findExecutable('',
3733 executables: serializeClassText('class C { C({this.x}); final x; }') 3733 executables: serializeClassText('class C { C({this.x}); final x; }')
3734 .executables); 3734 .executables);
3735 UnlinkedParam parameter = executable.parameters[0]; 3735 UnlinkedParam parameter = executable.parameters[0];
3736 expect(parameter.kind, UnlinkedParamKind.named); 3736 expect(parameter.kind, UnlinkedParamKind.named);
3737 expect(parameter.defaultValue, isNull); 3737 expect(parameter.initializer, isNull);
3738 expect(parameter.defaultValueCode, isEmpty); 3738 expect(parameter.defaultValueCode, isEmpty);
3739 } 3739 }
3740 3740
3741 test_constructor_initializing_formal_named_withDefault() { 3741 test_constructor_initializing_formal_named_withDefault() {
3742 UnlinkedExecutable executable = findExecutable('', 3742 UnlinkedExecutable executable = findExecutable('',
3743 executables: serializeClassText('class C { C({this.x: 42}); final x; }') 3743 executables: serializeClassText('class C { C({this.x: 42}); final x; }')
3744 .executables); 3744 .executables);
3745 UnlinkedParam parameter = executable.parameters[0]; 3745 UnlinkedParam parameter = executable.parameters[0];
3746 expect(parameter.kind, UnlinkedParamKind.named); 3746 expect(parameter.kind, UnlinkedParamKind.named);
3747 expect(parameter.initializer, isNotNull); 3747 expect(parameter.initializer, isNotNull);
3748 expect(parameter.defaultValueCode, '42'); 3748 expect(parameter.defaultValueCode, '42');
3749 _assertCodeRange(parameter.codeRange, 13, 10); 3749 _assertCodeRange(parameter.codeRange, 13, 10);
3750 _assertUnlinkedConst(parameter.defaultValue, 3750 _assertUnlinkedConst(parameter.initializer.bodyExpr,
3751 operators: [UnlinkedConstOperation.pushInt], ints: [42]); 3751 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
3752 } 3752 }
3753 3753
3754 test_constructor_initializing_formal_non_function_typed() { 3754 test_constructor_initializing_formal_non_function_typed() {
3755 UnlinkedExecutable executable = findExecutable('', 3755 UnlinkedExecutable executable = findExecutable('',
3756 executables: 3756 executables:
3757 serializeClassText('class C { C(this.x); final x; }').executables); 3757 serializeClassText('class C { C(this.x); final x; }').executables);
3758 UnlinkedParam parameter = executable.parameters[0]; 3758 UnlinkedParam parameter = executable.parameters[0];
3759 expect(parameter.isFunctionTyped, isFalse); 3759 expect(parameter.isFunctionTyped, isFalse);
3760 } 3760 }
3761 3761
3762 test_constructor_initializing_formal_positional() { 3762 test_constructor_initializing_formal_positional() {
3763 UnlinkedExecutable executable = findExecutable('', 3763 UnlinkedExecutable executable = findExecutable('',
3764 executables: serializeClassText('class C { C([this.x]); final x; }') 3764 executables: serializeClassText('class C { C([this.x]); final x; }')
3765 .executables); 3765 .executables);
3766 UnlinkedParam parameter = executable.parameters[0]; 3766 UnlinkedParam parameter = executable.parameters[0];
3767 expect(parameter.kind, UnlinkedParamKind.positional); 3767 expect(parameter.kind, UnlinkedParamKind.positional);
3768 expect(parameter.defaultValue, isNull); 3768 expect(parameter.initializer, isNull);
3769 expect(parameter.defaultValueCode, isEmpty); 3769 expect(parameter.defaultValueCode, isEmpty);
3770 } 3770 }
3771 3771
3772 test_constructor_initializing_formal_positional_withDefault() { 3772 test_constructor_initializing_formal_positional_withDefault() {
3773 UnlinkedExecutable executable = findExecutable('', 3773 UnlinkedExecutable executable = findExecutable('',
3774 executables: 3774 executables:
3775 serializeClassText('class C { C([this.x = 42]); final x; }') 3775 serializeClassText('class C { C([this.x = 42]); final x; }')
3776 .executables); 3776 .executables);
3777 UnlinkedParam parameter = executable.parameters[0]; 3777 UnlinkedParam parameter = executable.parameters[0];
3778 expect(parameter.kind, UnlinkedParamKind.positional); 3778 expect(parameter.kind, UnlinkedParamKind.positional);
3779 expect(parameter.initializer, isNotNull); 3779 expect(parameter.initializer, isNotNull);
3780 expect(parameter.defaultValueCode, '42'); 3780 expect(parameter.defaultValueCode, '42');
3781 _assertCodeRange(parameter.codeRange, 13, 11); 3781 _assertCodeRange(parameter.codeRange, 13, 11);
3782 _assertUnlinkedConst(parameter.defaultValue, 3782 _assertUnlinkedConst(parameter.initializer.bodyExpr,
3783 operators: [UnlinkedConstOperation.pushInt], ints: [42]); 3783 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
3784 } 3784 }
3785 3785
3786 test_constructor_initializing_formal_required() { 3786 test_constructor_initializing_formal_required() {
3787 UnlinkedExecutable executable = findExecutable('', 3787 UnlinkedExecutable executable = findExecutable('',
3788 executables: 3788 executables:
3789 serializeClassText('class C { C(this.x); final x; }').executables); 3789 serializeClassText('class C { C(this.x); final x; }').executables);
3790 UnlinkedParam parameter = executable.parameters[0]; 3790 UnlinkedParam parameter = executable.parameters[0];
3791 expect(parameter.kind, UnlinkedParamKind.required); 3791 expect(parameter.kind, UnlinkedParamKind.required);
3792 } 3792 }
(...skipping 11 matching lines...) Expand all
3804 test_constructor_initializing_formal_withDefault() { 3804 test_constructor_initializing_formal_withDefault() {
3805 UnlinkedExecutable executable = 3805 UnlinkedExecutable executable =
3806 findExecutable('', executables: serializeClassText(r''' 3806 findExecutable('', executables: serializeClassText(r'''
3807 class C { 3807 class C {
3808 C([this.x = 42]); 3808 C([this.x = 42]);
3809 final int x; 3809 final int x;
3810 }''').executables); 3810 }''').executables);
3811 UnlinkedParam param = executable.parameters[0]; 3811 UnlinkedParam param = executable.parameters[0];
3812 expect(param.kind, UnlinkedParamKind.positional); 3812 expect(param.kind, UnlinkedParamKind.positional);
3813 expect(param.defaultValueCode, '42'); 3813 expect(param.defaultValueCode, '42');
3814 _assertUnlinkedConst(param.defaultValue, 3814 _assertUnlinkedConst(param.initializer.bodyExpr,
3815 operators: [UnlinkedConstOperation.pushInt], ints: [42]); 3815 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
3816 } 3816 }
3817 3817
3818 test_constructor_named() { 3818 test_constructor_named() {
3819 String text = 'class C { C.foo(); }'; 3819 String text = 'class C { C.foo(); }';
3820 UnlinkedExecutable executable = findExecutable('foo', 3820 UnlinkedExecutable executable = findExecutable('foo',
3821 executables: serializeClassText(text).executables); 3821 executables: serializeClassText(text).executables);
3822 expect(executable.name, 'foo'); 3822 expect(executable.name, 'foo');
3823 expect(executable.nameOffset, text.indexOf('foo')); 3823 expect(executable.nameOffset, text.indexOf('foo'));
3824 expect(executable.periodOffset, text.indexOf('.foo')); 3824 expect(executable.periodOffset, text.indexOf('.foo'));
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after
5799 5799
5800 test_executable_param_function_typed_withDefault() { 5800 test_executable_param_function_typed_withDefault() {
5801 UnlinkedExecutable executable = serializeExecutableText(r''' 5801 UnlinkedExecutable executable = serializeExecutableText(r'''
5802 f([int p(int a2, String b2) = foo]) {} 5802 f([int p(int a2, String b2) = foo]) {}
5803 int foo(int a, String b) => 0; 5803 int foo(int a, String b) => 0;
5804 '''); 5804 ''');
5805 UnlinkedParam param = executable.parameters[0]; 5805 UnlinkedParam param = executable.parameters[0];
5806 expect(param.kind, UnlinkedParamKind.positional); 5806 expect(param.kind, UnlinkedParamKind.positional);
5807 expect(param.initializer, isNotNull); 5807 expect(param.initializer, isNotNull);
5808 expect(param.defaultValueCode, 'foo'); 5808 expect(param.defaultValueCode, 'foo');
5809 _assertUnlinkedConst(param.defaultValue, operators: [ 5809 _assertUnlinkedConst(param.initializer.bodyExpr, operators: [
5810 UnlinkedConstOperation.pushReference 5810 UnlinkedConstOperation.pushReference
5811 ], referenceValidators: [ 5811 ], referenceValidators: [
5812 (EntityRef r) => checkTypeRef(r, null, null, 'foo', 5812 (EntityRef r) => checkTypeRef(r, null, null, 'foo',
5813 expectedKind: ReferenceKind.topLevelFunction) 5813 expectedKind: ReferenceKind.topLevelFunction)
5814 ]); 5814 ]);
5815 } 5815 }
5816 5816
5817 test_executable_param_kind_named() { 5817 test_executable_param_kind_named() {
5818 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}'); 5818 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}');
5819 UnlinkedParam param = executable.parameters[0]; 5819 UnlinkedParam param = executable.parameters[0];
5820 expect(param.kind, UnlinkedParamKind.named); 5820 expect(param.kind, UnlinkedParamKind.named);
5821 expect(param.initializer, isNull); 5821 expect(param.initializer, isNull);
5822 expect(param.defaultValue, isNull);
5823 expect(param.defaultValueCode, isEmpty); 5822 expect(param.defaultValueCode, isEmpty);
5824 } 5823 }
5825 5824
5826 test_executable_param_kind_named_withDefault() { 5825 test_executable_param_kind_named_withDefault() {
5827 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}'); 5826 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}');
5828 UnlinkedParam param = executable.parameters[0]; 5827 UnlinkedParam param = executable.parameters[0];
5829 expect(param.kind, UnlinkedParamKind.named); 5828 expect(param.kind, UnlinkedParamKind.named);
5830 expect(param.initializer, isNotNull); 5829 expect(param.initializer, isNotNull);
5831 expect(param.defaultValueCode, '42'); 5830 expect(param.defaultValueCode, '42');
5832 _assertCodeRange(param.codeRange, 3, 5); 5831 _assertCodeRange(param.codeRange, 3, 5);
5833 _assertUnlinkedConst(param.defaultValue, 5832 _assertUnlinkedConst(param.initializer.bodyExpr,
5834 operators: [UnlinkedConstOperation.pushInt], ints: [42]); 5833 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
5835 } 5834 }
5836 5835
5837 test_executable_param_kind_positional() { 5836 test_executable_param_kind_positional() {
5838 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); 5837 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}');
5839 UnlinkedParam param = executable.parameters[0]; 5838 UnlinkedParam param = executable.parameters[0];
5840 expect(param.kind, UnlinkedParamKind.positional); 5839 expect(param.kind, UnlinkedParamKind.positional);
5841 expect(param.initializer, isNull); 5840 expect(param.initializer, isNull);
5842 expect(param.defaultValue, isNull);
5843 expect(param.defaultValueCode, isEmpty); 5841 expect(param.defaultValueCode, isEmpty);
5844 } 5842 }
5845 5843
5846 test_executable_param_kind_positional_withDefault() { 5844 test_executable_param_kind_positional_withDefault() {
5847 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}'); 5845 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}');
5848 UnlinkedParam param = executable.parameters[0]; 5846 UnlinkedParam param = executable.parameters[0];
5849 expect(param.kind, UnlinkedParamKind.positional); 5847 expect(param.kind, UnlinkedParamKind.positional);
5850 expect(param.initializer, isNotNull); 5848 expect(param.initializer, isNotNull);
5851 expect(param.defaultValueCode, '42'); 5849 expect(param.defaultValueCode, '42');
5852 _assertCodeRange(param.codeRange, 3, 6); 5850 _assertCodeRange(param.codeRange, 3, 6);
5853 _assertUnlinkedConst(param.defaultValue, 5851 _assertUnlinkedConst(param.initializer.bodyExpr,
5854 operators: [UnlinkedConstOperation.pushInt], ints: [42]); 5852 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
5855 } 5853 }
5856 5854
5857 test_executable_param_kind_required() { 5855 test_executable_param_kind_required() {
5858 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); 5856 UnlinkedExecutable executable = serializeExecutableText('f(x) {}');
5859 UnlinkedParam param = executable.parameters[0]; 5857 UnlinkedParam param = executable.parameters[0];
5860 expect(param.kind, UnlinkedParamKind.required); 5858 expect(param.kind, UnlinkedParamKind.required);
5861 expect(param.initializer, isNull); 5859 expect(param.initializer, isNull);
5862 expect(param.defaultValue, isNull);
5863 expect(param.defaultValueCode, isEmpty); 5860 expect(param.defaultValueCode, isEmpty);
5864 } 5861 }
5865 5862
5866 test_executable_param_name() { 5863 test_executable_param_name() {
5867 String text = 'f(x) {}'; 5864 String text = 'f(x) {}';
5868 UnlinkedExecutable executable = serializeExecutableText(text); 5865 UnlinkedExecutable executable = serializeExecutableText(text);
5869 expect(executable.parameters, hasLength(1)); 5866 expect(executable.parameters, hasLength(1));
5870 expect(executable.parameters[0].name, 'x'); 5867 expect(executable.parameters[0].name, 'x');
5871 expect(executable.parameters[0].nameOffset, text.indexOf('x')); 5868 expect(executable.parameters[0].nameOffset, text.indexOf('x'));
5872 } 5869 }
(...skipping 4398 matching lines...) Expand 10 before | Expand all | Expand 10 after
10271 class _PrefixExpectation { 10268 class _PrefixExpectation {
10272 final ReferenceKind kind; 10269 final ReferenceKind kind;
10273 final String name; 10270 final String name;
10274 final String absoluteUri; 10271 final String absoluteUri;
10275 final String relativeUri; 10272 final String relativeUri;
10276 final int numTypeParameters; 10273 final int numTypeParameters;
10277 10274
10278 _PrefixExpectation(this.kind, this.name, 10275 _PrefixExpectation(this.kind, this.name,
10279 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 10276 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
10280 } 10277 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698