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

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

Issue 1677683002: Include default parameter values into summary. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 2646 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 executables: 2657 executables:
2658 serializeClassText('class C { C(int this.x()); Function x; }') 2658 serializeClassText('class C { C(int this.x()); Function x; }')
2659 .executables); 2659 .executables);
2660 UnlinkedParam parameter = executable.parameters[0]; 2660 UnlinkedParam parameter = executable.parameters[0];
2661 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int'); 2661 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int');
2662 } 2662 }
2663 2663
2664 test_constructor_initializing_formal_function_typed_implicit_return_type() { 2664 test_constructor_initializing_formal_function_typed_implicit_return_type() {
2665 if (!checkAstDerivedData) { 2665 if (!checkAstDerivedData) {
2666 // TODO(paulberry): this test fails when building the summary from the 2666 // TODO(paulberry): this test fails when building the summary from the
2667 // element model because the elment model doesn't record whether a 2667 // element model because the element model doesn't record whether a
2668 // function-typed parameter's return type is implicit. 2668 // function-typed parameter's return type is implicit.
2669 return; 2669 return;
2670 } 2670 }
2671 UnlinkedExecutable executable = findExecutable('', 2671 UnlinkedExecutable executable = findExecutable('',
2672 executables: serializeClassText('class C { C(this.x()); Function x; }') 2672 executables: serializeClassText('class C { C(this.x()); Function x; }')
2673 .executables); 2673 .executables);
2674 UnlinkedParam parameter = executable.parameters[0]; 2674 UnlinkedParam parameter = executable.parameters[0];
2675 expect(parameter.isFunctionTyped, isTrue); 2675 expect(parameter.isFunctionTyped, isTrue);
2676 expect(parameter.type, isNull); 2676 expect(parameter.type, isNull);
2677 } 2677 }
(...skipping 17 matching lines...) Expand all
2695 test_constructor_initializing_formal_function_typed_parameter_order() { 2695 test_constructor_initializing_formal_function_typed_parameter_order() {
2696 UnlinkedExecutable executable = findExecutable('', 2696 UnlinkedExecutable executable = findExecutable('',
2697 executables: serializeClassText('class C { C(this.x(a, b)); final x; }') 2697 executables: serializeClassText('class C { C(this.x(a, b)); final x; }')
2698 .executables); 2698 .executables);
2699 UnlinkedParam parameter = executable.parameters[0]; 2699 UnlinkedParam parameter = executable.parameters[0];
2700 expect(parameter.parameters, hasLength(2)); 2700 expect(parameter.parameters, hasLength(2));
2701 expect(parameter.parameters[0].name, 'a'); 2701 expect(parameter.parameters[0].name, 'a');
2702 expect(parameter.parameters[1].name, 'b'); 2702 expect(parameter.parameters[1].name, 'b');
2703 } 2703 }
2704 2704
2705 test_constructor_initializing_formal_function_typed_withDefault() {
2706 UnlinkedExecutable executable =
2707 findExecutable('', executables: serializeClassText(r'''
2708 class C {
2709 C([this.x() = foo]);
2710 final x;
2711 }
2712 int foo() => 0;
2713 ''').executables);
2714 UnlinkedParam param = executable.parameters[0];
2715 expect(param.isFunctionTyped, isTrue);
2716 expect(param.kind, UnlinkedParamKind.positional);
2717 _assertUnlinkedConst(param.defaultValue, operators: [
2718 UnlinkedConstOperation.pushReference
2719 ], referenceValidators: [
2720 (EntityRef r) => checkTypeRef(r, null, null, 'foo',
2721 expectedKind: ReferenceKind.topLevelFunction)
2722 ]);
2723 }
2724
2705 test_constructor_initializing_formal_implicit_type() { 2725 test_constructor_initializing_formal_implicit_type() {
2706 // Note: the implicit type of an initializing formal is the type of the 2726 // Note: the implicit type of an initializing formal is the type of the
2707 // field. 2727 // field.
2708 UnlinkedExecutable executable = findExecutable('', 2728 UnlinkedExecutable executable = findExecutable('',
2709 executables: 2729 executables:
2710 serializeClassText('class C { C(this.x); int x; }').executables); 2730 serializeClassText('class C { C(this.x); int x; }').executables);
2711 UnlinkedParam parameter = executable.parameters[0]; 2731 UnlinkedParam parameter = executable.parameters[0];
2712 expect(parameter.type, isNull); 2732 expect(parameter.type, isNull);
2713 } 2733 }
2714 2734
2715 test_constructor_initializing_formal_name() { 2735 test_constructor_initializing_formal_name() {
2716 UnlinkedExecutable executable = findExecutable('', 2736 UnlinkedExecutable executable = findExecutable('',
2717 executables: 2737 executables:
2718 serializeClassText('class C { C(this.x); final x; }').executables); 2738 serializeClassText('class C { C(this.x); final x; }').executables);
2719 UnlinkedParam parameter = executable.parameters[0]; 2739 UnlinkedParam parameter = executable.parameters[0];
2720 expect(parameter.name, 'x'); 2740 expect(parameter.name, 'x');
2721 } 2741 }
2722 2742
2723 test_constructor_initializing_formal_named() { 2743 test_constructor_initializing_formal_named() {
2724 // TODO(paulberry): also test default value
2725 UnlinkedExecutable executable = findExecutable('', 2744 UnlinkedExecutable executable = findExecutable('',
2726 executables: serializeClassText('class C { C({this.x}); final x; }') 2745 executables: serializeClassText('class C { C({this.x}); final x; }')
2727 .executables); 2746 .executables);
2728 UnlinkedParam parameter = executable.parameters[0]; 2747 UnlinkedParam parameter = executable.parameters[0];
2729 expect(parameter.kind, UnlinkedParamKind.named); 2748 expect(parameter.kind, UnlinkedParamKind.named);
2749 expect(parameter.defaultValue, isNull);
2750 }
2751
2752 test_constructor_initializing_formal_named_withDefault() {
2753 UnlinkedExecutable executable = findExecutable('',
2754 executables: serializeClassText('class C { C({this.x: 42}); final x; }')
2755 .executables);
2756 UnlinkedParam parameter = executable.parameters[0];
2757 expect(parameter.kind, UnlinkedParamKind.named);
2758 _assertUnlinkedConst(parameter.defaultValue,
2759 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
2730 } 2760 }
2731 2761
2732 test_constructor_initializing_formal_non_function_typed() { 2762 test_constructor_initializing_formal_non_function_typed() {
2733 UnlinkedExecutable executable = findExecutable('', 2763 UnlinkedExecutable executable = findExecutable('',
2734 executables: 2764 executables:
2735 serializeClassText('class C { C(this.x); final x; }').executables); 2765 serializeClassText('class C { C(this.x); final x; }').executables);
2736 UnlinkedParam parameter = executable.parameters[0]; 2766 UnlinkedParam parameter = executable.parameters[0];
2737 expect(parameter.isFunctionTyped, isFalse); 2767 expect(parameter.isFunctionTyped, isFalse);
2738 } 2768 }
2739 2769
2740 test_constructor_initializing_formal_positional() { 2770 test_constructor_initializing_formal_positional() {
2741 // TODO(paulberry): also test default value
2742 UnlinkedExecutable executable = findExecutable('', 2771 UnlinkedExecutable executable = findExecutable('',
2743 executables: serializeClassText('class C { C([this.x]); final x; }') 2772 executables: serializeClassText('class C { C([this.x]); final x; }')
2744 .executables); 2773 .executables);
2745 UnlinkedParam parameter = executable.parameters[0]; 2774 UnlinkedParam parameter = executable.parameters[0];
2746 expect(parameter.kind, UnlinkedParamKind.positional); 2775 expect(parameter.kind, UnlinkedParamKind.positional);
2776 expect(parameter.defaultValue, isNull);
2777 }
2778
2779 test_constructor_initializing_formal_positional_withDefault() {
2780 UnlinkedExecutable executable = findExecutable('',
2781 executables:
2782 serializeClassText('class C { C([this.x = 42]); final x; }')
2783 .executables);
2784 UnlinkedParam parameter = executable.parameters[0];
2785 expect(parameter.kind, UnlinkedParamKind.positional);
2786 _assertUnlinkedConst(parameter.defaultValue,
2787 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
2747 } 2788 }
2748 2789
2749 test_constructor_initializing_formal_required() { 2790 test_constructor_initializing_formal_required() {
2750 UnlinkedExecutable executable = findExecutable('', 2791 UnlinkedExecutable executable = findExecutable('',
2751 executables: 2792 executables:
2752 serializeClassText('class C { C(this.x); final x; }').executables); 2793 serializeClassText('class C { C(this.x); final x; }').executables);
2753 UnlinkedParam parameter = executable.parameters[0]; 2794 UnlinkedParam parameter = executable.parameters[0];
2754 expect(parameter.kind, UnlinkedParamKind.required); 2795 expect(parameter.kind, UnlinkedParamKind.required);
2755 } 2796 }
2756 2797
2757 test_constructor_initializing_formal_typedef() { 2798 test_constructor_initializing_formal_typedef() {
2758 UnlinkedExecutable executable = findExecutable('', 2799 UnlinkedExecutable executable = findExecutable('',
2759 executables: serializeClassText( 2800 executables: serializeClassText(
2760 'typedef F<T>(T x); class C<X> { C(this.f); F<X> f; }') 2801 'typedef F<T>(T x); class C<X> { C(this.f); F<X> f; }')
2761 .executables); 2802 .executables);
2762 UnlinkedParam parameter = executable.parameters[0]; 2803 UnlinkedParam parameter = executable.parameters[0];
2763 expect(parameter.isFunctionTyped, isFalse); 2804 expect(parameter.isFunctionTyped, isFalse);
2764 expect(parameter.parameters, isEmpty); 2805 expect(parameter.parameters, isEmpty);
2765 } 2806 }
2766 2807
2808 test_constructor_initializing_formal_withDefault() {
2809 UnlinkedExecutable executable =
2810 findExecutable('', executables: serializeClassText(r'''
2811 class C {
2812 C([this.x = 42]);
2813 final int x;
2814 }''').executables);
2815 UnlinkedParam param = executable.parameters[0];
2816 expect(param.kind, UnlinkedParamKind.positional);
2817 _assertUnlinkedConst(param.defaultValue,
2818 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
2819 }
2820
2767 test_constructor_named() { 2821 test_constructor_named() {
2768 String text = 'class C { C.foo(); }'; 2822 String text = 'class C { C.foo(); }';
2769 UnlinkedExecutable executable = findExecutable('foo', 2823 UnlinkedExecutable executable = findExecutable('foo',
2770 executables: serializeClassText(text).executables); 2824 executables: serializeClassText(text).executables);
2771 expect(executable.name, 'foo'); 2825 expect(executable.name, 'foo');
2772 expect(executable.nameOffset, text.indexOf('foo')); 2826 expect(executable.nameOffset, text.indexOf('foo'));
2773 } 2827 }
2774 2828
2775 test_constructor_non_const() { 2829 test_constructor_non_const() {
2776 UnlinkedExecutable executable = findExecutable('', 2830 UnlinkedExecutable executable = findExecutable('',
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 UnlinkedExecutable executable = serializeExecutableText('f(g()) {}'); 3361 UnlinkedExecutable executable = serializeExecutableText('f(g()) {}');
3308 expect(executable.parameters[0].isFunctionTyped, isTrue); 3362 expect(executable.parameters[0].isFunctionTyped, isTrue);
3309 expect(executable.parameters[0].type, isNull); 3363 expect(executable.parameters[0].type, isNull);
3310 } 3364 }
3311 3365
3312 test_executable_param_function_typed_return_type_void() { 3366 test_executable_param_function_typed_return_type_void() {
3313 UnlinkedExecutable executable = serializeExecutableText('f(void g()) {}'); 3367 UnlinkedExecutable executable = serializeExecutableText('f(void g()) {}');
3314 checkVoidTypeRef(executable.parameters[0].type); 3368 checkVoidTypeRef(executable.parameters[0].type);
3315 } 3369 }
3316 3370
3371 test_executable_param_function_typed_withDefault() {
3372 UnlinkedExecutable executable = serializeExecutableText(r'''
3373 f([int p(int a2, String b2) = foo]) {}
3374 int foo(int a, String b) => 0;
3375 ''');
3376 UnlinkedParam param = executable.parameters[0];
3377 expect(param.kind, UnlinkedParamKind.positional);
3378 _assertUnlinkedConst(param.defaultValue, operators: [
3379 UnlinkedConstOperation.pushReference
3380 ], referenceValidators: [
3381 (EntityRef r) => checkTypeRef(r, null, null, 'foo',
3382 expectedKind: ReferenceKind.topLevelFunction)
3383 ]);
3384 }
3385
3317 test_executable_param_kind_named() { 3386 test_executable_param_kind_named() {
3318 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}'); 3387 UnlinkedExecutable executable = serializeExecutableText('f({x}) {}');
3319 expect(executable.parameters[0].kind, UnlinkedParamKind.named); 3388 UnlinkedParam param = executable.parameters[0];
3389 expect(param.kind, UnlinkedParamKind.named);
3390 expect(param.defaultValue, isNull);
3391 }
3392
3393 test_executable_param_kind_named_withDefault() {
3394 UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}');
3395 UnlinkedParam param = executable.parameters[0];
3396 expect(param.kind, UnlinkedParamKind.named);
3397 _assertUnlinkedConst(param.defaultValue,
3398 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
3320 } 3399 }
3321 3400
3322 test_executable_param_kind_positional() { 3401 test_executable_param_kind_positional() {
3323 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); 3402 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}');
3324 expect(executable.parameters[0].kind, UnlinkedParamKind.positional); 3403 UnlinkedParam param = executable.parameters[0];
3404 expect(param.kind, UnlinkedParamKind.positional);
3405 expect(param.defaultValue, isNull);
3406 }
3407
3408 test_executable_param_kind_positional_withDefault() {
3409 UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}');
3410 UnlinkedParam param = executable.parameters[0];
3411 expect(param.kind, UnlinkedParamKind.positional);
3412 _assertUnlinkedConst(param.defaultValue,
3413 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
3325 } 3414 }
3326 3415
3327 test_executable_param_kind_required() { 3416 test_executable_param_kind_required() {
3328 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); 3417 UnlinkedExecutable executable = serializeExecutableText('f(x) {}');
3329 expect(executable.parameters[0].kind, UnlinkedParamKind.required); 3418 UnlinkedParam param = executable.parameters[0];
3419 expect(param.kind, UnlinkedParamKind.required);
3420 expect(param.defaultValue, isNull);
3330 } 3421 }
3331 3422
3332 test_executable_param_name() { 3423 test_executable_param_name() {
3333 String text = 'f(x) {}'; 3424 String text = 'f(x) {}';
3334 UnlinkedExecutable executable = serializeExecutableText(text); 3425 UnlinkedExecutable executable = serializeExecutableText(text);
3335 expect(executable.parameters, hasLength(1)); 3426 expect(executable.parameters, hasLength(1));
3336 expect(executable.parameters[0].name, 'x'); 3427 expect(executable.parameters[0].name, 'x');
3337 expect(executable.parameters[0].nameOffset, text.indexOf('x')); 3428 expect(executable.parameters[0].nameOffset, text.indexOf('x'));
3338 } 3429 }
3339 3430
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after
5261 final String absoluteUri; 5352 final String absoluteUri;
5262 final String relativeUri; 5353 final String relativeUri;
5263 final int numTypeParameters; 5354 final int numTypeParameters;
5264 5355
5265 _PrefixExpectation(this.kind, this.name, 5356 _PrefixExpectation(this.kind, this.name,
5266 {this.inLibraryDefiningUnit: false, 5357 {this.inLibraryDefiningUnit: false,
5267 this.absoluteUri, 5358 this.absoluteUri,
5268 this.relativeUri, 5359 this.relativeUri,
5269 this.numTypeParameters: 0}); 5360 this.numTypeParameters: 0});
5270 } 5361 }
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