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

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

Issue 2432273003: Implement 'local' mode in TypeResolverVisitor. (Closed)
Patch Set: 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
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) {
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 parameter type of "p" is not resolved.
2756 var p = m.parameters.parameters[0] as SimpleFormalParameter;
2757 expect(p.type.type, isNull);
2758 // The type of "v" is resolved.
2759 var mb = m.body as BlockFunctionBody;
2760 var vd = mb.block.statements[0] as VariableDeclarationStatement;
2761 expect(vd.variables.type.type.toString(), 'A');
2762 }
2763 }
2764
2765 // Top-level: f
2766 {
2767 var f = unit.declarations[1] as FunctionDeclaration;
2768 // The return type of "f" is not resolved.
2769 expect(f.returnType.type, isNull);
2770 // The type of the parameter "p" is not resolved.
2771 var fe = f.functionExpression;
2772 var pd = fe.parameters.parameters[0] as DefaultFormalParameter;
2773 var p = pd.parameter as SimpleFormalParameter;
2774 expect(p.type.type, isNull);
2775 // The default value of the parameter "p" is resolved.
2776 var pdd = pd.defaultValue as InstanceCreationExpression;
2777 expect(pdd.constructorName.type.type.toString(), 'A');
2778 // The type of "v1" is resolved.
2779 var fb = fe.body as BlockFunctionBody;
2780 var vd = fb.block.statements[0] as VariableDeclarationStatement;
2781 expect(vd.variables.type.type.toString(), 'A');
2782 // The initializer of "v1" is resolved.
2783 var v = vd.variables.variables[0];
2784 var vi = v.initializer as InstanceCreationExpression;
2785 expect(vi.constructorName.type.type.toString(), 'A');
2786 // Local: f2
2787 {
2788 var f2s = fb.block.statements[1] as FunctionDeclarationStatement;
2789 var f2 = f2s.functionDeclaration;
2790 // The return type of "f2" is resolved.
2791 expect(f2.returnType.type.toString(), 'A');
2792 // The type of the parameter "p2" is resolved.
2793 var f2e = f2.functionExpression;
2794 var p2 = f2e.parameters.parameters[0] as SimpleFormalParameter;
2795 expect(p2.type.type.toString(), 'A');
2796 // The type of "v2" is resolved.
2797 var f2b = f2e.body as BlockFunctionBody;
2798 var v2d = f2b.block.statements[0] as VariableDeclarationStatement;
2799 expect(v2d.variables.type.type.toString(), 'A');
2800 }
2801 }
2802
2803 // Top-level: V
2804 {
2805 var vd = unit.declarations[2] as TopLevelVariableDeclaration;
2806 // The type is not resolved.
2807 expect(vd.variables.type.type, isNull);
2808 // The initializer is resolved.
2809 VariableDeclaration v = vd.variables.variables[0];
2810 var vi = v.initializer as InstanceCreationExpression;
2811 expect(vi.constructorName.type.type.toString(), 'A');
2812 }
2813
2814 // Top-level: G
2815 {
2816 var g = unit.declarations[3] as FunctionDeclaration;
2817 // The return type is not resolved.
2818 expect(g.returnType.type, isNull);
2819 // The body is resolved.
2820 var gb = g.functionExpression.body as ExpressionFunctionBody;
2821 var ge = gb.expression as InstanceCreationExpression;
2822 expect(ge.constructorName.type.type.toString(), 'A');
2823 }
2824 }
2825
2697 void test_visitCatchClause_exception() { 2826 void test_visitCatchClause_exception() {
2698 // catch (e) 2827 // catch (e)
2699 CatchClause clause = AstFactory.catchClause("e"); 2828 CatchClause clause = AstFactory.catchClause("e");
2700 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 2829 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
2701 exceptionParameter.staticElement = 2830 exceptionParameter.staticElement =
2702 new LocalVariableElementImpl.forNode(exceptionParameter); 2831 new LocalVariableElementImpl.forNode(exceptionParameter);
2703 _resolveCatchClause(clause, _typeProvider.dynamicType, null); 2832 _resolveCatchClause(clause, _typeProvider.dynamicType, null);
2704 _listener.assertNoErrors(); 2833 _listener.assertNoErrors();
2705 } 2834 }
2706 2835
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 */ 3425 */
3297 class _StaleElement extends ElementImpl { 3426 class _StaleElement extends ElementImpl {
3298 _StaleElement() : super("_StaleElement", -1); 3427 _StaleElement() : super("_StaleElement", -1);
3299 3428
3300 @override 3429 @override
3301 get kind => throw "_StaleElement's kind shouldn't be accessed"; 3430 get kind => throw "_StaleElement's kind shouldn't be accessed";
3302 3431
3303 @override 3432 @override
3304 accept(_) => throw "_StaleElement shouldn't be visited"; 3433 accept(_) => throw "_StaleElement shouldn't be visited";
3305 } 3434 }
OLDNEW
« pkg/analyzer/lib/src/generated/resolver.dart ('K') | « 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