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

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

Issue 1678753002: Summarize constructor initializers. (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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 summarize_elements.serializeLibrary( 46 summarize_elements.serializeLibrary(
47 library, analysisContext.typeProvider, false); 47 library, analysisContext.typeProvider, false);
48 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { 48 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) {
49 uriToNamespace[serializedLibrary.unitUris[i]] = 49 uriToNamespace[serializedLibrary.unitUris[i]] =
50 new UnlinkedUnit.fromBuffer( 50 new UnlinkedUnit.fromBuffer(
51 serializedLibrary.unlinkedUnits[i].toBuffer()) 51 serializedLibrary.unlinkedUnits[i].toBuffer())
52 .publicNamespace; 52 .publicNamespace;
53 } 53 }
54 } 54 }
55 return uriToNamespace; 55 return uriToNamespace;
56 } catch (_) { 56 } catch (_, st) {
57 print(st);
Paul Berry 2016/02/08 14:53:12 Was this temporary code you accidentally forgot to
scheglov 2016/02/08 16:29:51 Another debugging code that accidentally got into
57 return null; 58 return null;
58 } 59 }
59 }(); 60 }();
60 61
61 /** 62 /**
62 * Convert a summary object (or a portion of one) into a canonical form that 63 * Convert a summary object (or a portion of one) into a canonical form that
63 * can be easily compared using [expect]. If [orderByName] is true, and the 64 * can be easily compared using [expect]. If [orderByName] is true, and the
64 * object is a [List], it is sorted by the `name` field of its elements. 65 * object is a [List], it is sorted by the `name` field of its elements.
65 */ 66 */
66 Object canonicalize(Object obj, {bool orderByName: false}) { 67 Object canonicalize(Object obj, {bool orderByName: false}) {
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 } 2685 }
2685 2686
2686 test_constructor_implicit() { 2687 test_constructor_implicit() {
2687 // Implicit constructors are not serialized. 2688 // Implicit constructors are not serialized.
2688 UnlinkedExecutable executable = findExecutable(null, 2689 UnlinkedExecutable executable = findExecutable(null,
2689 executables: serializeClassText('class C { C(); }').executables, 2690 executables: serializeClassText('class C { C(); }').executables,
2690 failIfAbsent: false); 2691 failIfAbsent: false);
2691 expect(executable, isNull); 2692 expect(executable, isNull);
2692 } 2693 }
2693 2694
2695 test_constructor_initializers_field() {
2696 UnlinkedExecutable executable =
2697 findExecutable('', executables: serializeClassText(r'''
2698 class C {
2699 final x;
2700 const C() : x = 42;
2701 }
2702 ''').executables);
2703 expect(executable.constantInitializers, hasLength(1));
2704 UnlinkedConstructorInitializer initializer =
2705 executable.constantInitializers[0];
2706 expect(initializer.kind, UnlinkedConstructorInitializerKind.field);
2707 expect(initializer.name, 'x');
2708 _assertUnlinkedConst(initializer.expression,
2709 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
2710 expect(initializer.arguments, isEmpty);
2711 }
2712
2713 test_constructor_initializers_field_withParameter() {
2714 UnlinkedExecutable executable =
2715 findExecutable('', executables: serializeClassText(r'''
2716 class C {
2717 final x;
2718 const C(int p) : x = p;
2719 }
2720 ''').executables);
2721 expect(executable.constantInitializers, hasLength(1));
2722 UnlinkedConstructorInitializer initializer =
2723 executable.constantInitializers[0];
2724 expect(initializer.kind, UnlinkedConstructorInitializerKind.field);
2725 expect(initializer.name, 'x');
2726 _assertUnlinkedConst(initializer.expression,
2727 operators: [UnlinkedConstOperation.pushConstructorParameter], strings: [ 'p']);
2728 expect(initializer.arguments, isEmpty);
2729 }
2730
2731 test_constructor_initializers_notConst() {
2732 UnlinkedExecutable executable =
2733 findExecutable('', executables: serializeClassText(r'''
2734 class C {
2735 final x;
2736 C() : x = 42;
2737 }
2738 ''').executables);
2739 expect(executable.constantInitializers, isEmpty);
2740 }
2741
2742 test_constructor_initializers_superInvocation() {
Paul Berry 2016/02/08 14:53:12 Also test a super invocation of an unnamed constru
scheglov 2016/02/08 16:29:51 Done.
2743 UnlinkedExecutable executable =
2744 findExecutable('', executables: serializeClassText(r'''
2745 class A {
2746 const A.aaa(int p);
2747 }
2748 class C extends A {
2749 const C() : super.aaa(42);
2750 }
2751 ''').executables);
2752 expect(executable.constantInitializers, hasLength(1));
2753 UnlinkedConstructorInitializer initializer =
2754 executable.constantInitializers[0];
2755 expect(
2756 initializer.kind, UnlinkedConstructorInitializerKind.superInvocation);
2757 expect(initializer.name, 'aaa');
2758 expect(initializer.expression, isNull);
2759 expect(initializer.arguments, hasLength(1));
2760 _assertUnlinkedConst(initializer.arguments[0],
2761 operators: [UnlinkedConstOperation.pushInt], ints: [42]);
2762 }
2763
2764 test_constructor_initializers_thisInvocation_toNamed() {
2765 UnlinkedExecutable executable =
2766 findExecutable('', executables: serializeClassText(r'''
2767 class C {
2768 const C() : this.named(1, 'bbb');
2769 const C.named(int a, String b);
2770 }
2771 ''').executables);
2772 expect(executable.constantInitializers, hasLength(1));
2773 UnlinkedConstructorInitializer initializer =
2774 executable.constantInitializers[0];
2775 expect(initializer.kind, UnlinkedConstructorInitializerKind.thisInvocation);
2776 expect(initializer.name, 'named');
2777 expect(initializer.expression, isNull);
2778 expect(initializer.arguments, hasLength(2));
2779 _assertUnlinkedConst(initializer.arguments[0],
2780 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
2781 _assertUnlinkedConst(initializer.arguments[1],
2782 operators: [UnlinkedConstOperation.pushString], strings: ['bbb']);
2783 }
2784
2785 test_constructor_initializers_thisInvocation_toUnnamed() {
2786 UnlinkedExecutable executable =
2787 findExecutable('named', executables: serializeClassText(r'''
2788 class C {
2789 const C.named() : this(1, 'bbb');
2790 const C(int a, String b);
2791 }
2792 ''').executables);
2793 expect(executable.constantInitializers, hasLength(1));
2794 UnlinkedConstructorInitializer initializer =
2795 executable.constantInitializers[0];
2796 expect(initializer.kind, UnlinkedConstructorInitializerKind.thisInvocation);
2797 expect(initializer.name, '');
2798 expect(initializer.expression, isNull);
2799 expect(initializer.arguments, hasLength(2));
2800 _assertUnlinkedConst(initializer.arguments[0],
2801 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
2802 _assertUnlinkedConst(initializer.arguments[1],
2803 operators: [UnlinkedConstOperation.pushString], strings: ['bbb']);
2804 }
2805
2694 test_constructor_initializing_formal() { 2806 test_constructor_initializing_formal() {
2695 UnlinkedExecutable executable = findExecutable('', 2807 UnlinkedExecutable executable = findExecutable('',
2696 executables: 2808 executables:
2697 serializeClassText('class C { C(this.x); final x; }').executables); 2809 serializeClassText('class C { C(this.x); final x; }').executables);
2698 UnlinkedParam parameter = executable.parameters[0]; 2810 UnlinkedParam parameter = executable.parameters[0];
2699 expect(parameter.isInitializingFormal, isTrue); 2811 expect(parameter.isInitializingFormal, isTrue);
2700 } 2812 }
2701 2813
2702 test_constructor_initializing_formal_explicit_type() { 2814 test_constructor_initializing_formal_explicit_type() {
2703 UnlinkedExecutable executable = findExecutable('', 2815 UnlinkedExecutable executable = findExecutable('',
(...skipping 2749 matching lines...) Expand 10 before | Expand all | Expand 10 after
5453 final String absoluteUri; 5565 final String absoluteUri;
5454 final String relativeUri; 5566 final String relativeUri;
5455 final int numTypeParameters; 5567 final int numTypeParameters;
5456 5568
5457 _PrefixExpectation(this.kind, this.name, 5569 _PrefixExpectation(this.kind, this.name,
5458 {this.inLibraryDefiningUnit: false, 5570 {this.inLibraryDefiningUnit: false,
5459 this.absoluteUri, 5571 this.absoluteUri,
5460 this.relativeUri, 5572 this.relativeUri,
5461 this.numTypeParameters: 0}); 5573 this.numTypeParameters: 0});
5462 } 5574 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698