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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 2432273003: Implement 'local' mode in TypeResolverVisitor. (Closed)
Patch Set: Use if-else sequence, fix method parameters default values resolution. Created 4 years, 2 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/generated/resolver.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 var vd = unit.declarations[2] as TopLevelVariableDeclaration; 2687 var vd = unit.declarations[2] as TopLevelVariableDeclaration;
2688 // The type is resolved. 2688 // The type is resolved.
2689 expect(vd.variables.type.toString(), 'A'); 2689 expect(vd.variables.type.toString(), 'A');
2690 // The initializer is not resolved. 2690 // The initializer is not resolved.
2691 VariableDeclaration v = vd.variables.variables[0]; 2691 VariableDeclaration v = vd.variables.variables[0];
2692 var vi = v.initializer as InstanceCreationExpression; 2692 var vi = v.initializer as InstanceCreationExpression;
2693 expect(vi.constructorName.type.type, isNull); 2693 expect(vi.constructorName.type.type, isNull);
2694 } 2694 }
2695 } 2695 }
2696 2696
2697 void test_modeLocal_noContext() {
2698 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r'''
2699 class C {
2700 A f = new A();
2701 A m([A p = const A()]) {
2702 A v;
2703 }
2704 }
2705 A f([A p = const A()]) {
2706 A v1 = new A();
2707 A f2(A p2) {
2708 A v2;
2709 }
2710 }
2711 A V = new A();
2712 A get G => new A();
2713 ''');
2714 var unitElement = new CompilationUnitElementImpl('/test.dart');
2715 ClassElementImpl A = ElementFactory.classElement2('A');
2716
2717 // Build API elements.
2718 {
2719 var holder = new ElementHolder();
2720 unit.accept(new ElementBuilder(holder, unitElement));
2721 }
2722
2723 // Resolve API types.
2724 {
2725 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
2726 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(
2727 resourceProvider: resourceProvider);
2728 var source = resourceProvider.getFile('/test.dart').createSource();
2729 var libraryElement = new LibraryElementImpl.forNode(context, null)
2730 ..definingCompilationUnit = unitElement;
2731 var libraryScope = new LibraryScope(libraryElement);
2732 var visitor = new TypeResolverVisitor(
2733 libraryElement, source, _typeProvider, _listener,
2734 nameScope: libraryScope, mode: TypeResolverMode.local);
2735 libraryScope.define(A);
2736 unit.accept(visitor);
2737 }
2738
2739 // Top-level: C
2740 {
2741 var c = unit.declarations[0] as ClassDeclaration;
2742 {
2743 var fd = c.members[0] as FieldDeclaration;
2744 // The type of "f" is not resolved.
2745 expect(fd.fields.type.type, isNull);
2746 // The initializer of "f" is resolved.
2747 var f = fd.fields.variables[0];
2748 var fi = f.initializer as InstanceCreationExpression;
2749 expect(fi.constructorName.type.type.toString(), 'A');
2750 }
2751 {
2752 var m = c.members[1] as MethodDeclaration;
2753 // The return type of "m" is not resolved.
2754 expect(m.returnType.type, isNull);
2755 // The type of the parameter "p" is not resolved.
2756 var pd = m.parameters.parameters[0] as DefaultFormalParameter;
2757 var p = pd.parameter as SimpleFormalParameter;
2758 expect(p.type.type, isNull);
2759 // The default value of the parameter "p" is resolved.
2760 var pdd = pd.defaultValue as InstanceCreationExpression;
2761 expect(pdd.constructorName.type.type.toString(), 'A');
2762 // The type of "v" is resolved.
2763 var mb = m.body as BlockFunctionBody;
2764 var vd = mb.block.statements[0] as VariableDeclarationStatement;
2765 expect(vd.variables.type.type.toString(), 'A');
2766 }
2767 }
2768
2769 // Top-level: f
2770 {
2771 var f = unit.declarations[1] as FunctionDeclaration;
2772 // The return type of "f" is not resolved.
2773 expect(f.returnType.type, isNull);
2774 // The type of the parameter "p" is not resolved.
2775 var fe = f.functionExpression;
2776 var pd = fe.parameters.parameters[0] as DefaultFormalParameter;
2777 var p = pd.parameter as SimpleFormalParameter;
2778 expect(p.type.type, isNull);
2779 // The default value of the parameter "p" is resolved.
2780 var pdd = pd.defaultValue as InstanceCreationExpression;
2781 expect(pdd.constructorName.type.type.toString(), 'A');
2782 // The type of "v1" is resolved.
2783 var fb = fe.body as BlockFunctionBody;
2784 var vd = fb.block.statements[0] as VariableDeclarationStatement;
2785 expect(vd.variables.type.type.toString(), 'A');
2786 // The initializer of "v1" is resolved.
2787 var v = vd.variables.variables[0];
2788 var vi = v.initializer as InstanceCreationExpression;
2789 expect(vi.constructorName.type.type.toString(), 'A');
2790 // Local: f2
2791 {
2792 var f2s = fb.block.statements[1] as FunctionDeclarationStatement;
2793 var f2 = f2s.functionDeclaration;
2794 // The return type of "f2" is resolved.
2795 expect(f2.returnType.type.toString(), 'A');
2796 // The type of the parameter "p2" is resolved.
2797 var f2e = f2.functionExpression;
2798 var p2 = f2e.parameters.parameters[0] as SimpleFormalParameter;
2799 expect(p2.type.type.toString(), 'A');
2800 // The type of "v2" is resolved.
2801 var f2b = f2e.body as BlockFunctionBody;
2802 var v2d = f2b.block.statements[0] as VariableDeclarationStatement;
2803 expect(v2d.variables.type.type.toString(), 'A');
2804 }
2805 }
2806
2807 // Top-level: V
2808 {
2809 var vd = unit.declarations[2] as TopLevelVariableDeclaration;
2810 // The type is not resolved.
2811 expect(vd.variables.type.type, isNull);
2812 // The initializer is resolved.
2813 VariableDeclaration v = vd.variables.variables[0];
2814 var vi = v.initializer as InstanceCreationExpression;
2815 expect(vi.constructorName.type.type.toString(), 'A');
2816 }
2817
2818 // Top-level: G
2819 {
2820 var g = unit.declarations[3] as FunctionDeclaration;
2821 // The return type is not resolved.
2822 expect(g.returnType.type, isNull);
2823 // The body is resolved.
2824 var gb = g.functionExpression.body as ExpressionFunctionBody;
2825 var ge = gb.expression as InstanceCreationExpression;
2826 expect(ge.constructorName.type.type.toString(), 'A');
2827 }
2828 }
2829
2697 void test_visitCatchClause_exception() { 2830 void test_visitCatchClause_exception() {
2698 // catch (e) 2831 // catch (e)
2699 CatchClause clause = AstFactory.catchClause("e"); 2832 CatchClause clause = AstFactory.catchClause("e");
2700 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 2833 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
2701 exceptionParameter.staticElement = 2834 exceptionParameter.staticElement =
2702 new LocalVariableElementImpl.forNode(exceptionParameter); 2835 new LocalVariableElementImpl.forNode(exceptionParameter);
2703 _resolveCatchClause(clause, _typeProvider.dynamicType, null); 2836 _resolveCatchClause(clause, _typeProvider.dynamicType, null);
2704 _listener.assertNoErrors(); 2837 _listener.assertNoErrors();
2705 } 2838 }
2706 2839
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 */ 3429 */
3297 class _StaleElement extends ElementImpl { 3430 class _StaleElement extends ElementImpl {
3298 _StaleElement() : super("_StaleElement", -1); 3431 _StaleElement() : super("_StaleElement", -1);
3299 3432
3300 @override 3433 @override
3301 get kind => throw "_StaleElement's kind shouldn't be accessed"; 3434 get kind => throw "_StaleElement's kind shouldn't be accessed";
3302 3435
3303 @override 3436 @override
3304 accept(_) => throw "_StaleElement shouldn't be visited"; 3437 accept(_) => throw "_StaleElement shouldn't be visited";
3305 } 3438 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698