| OLD | NEW |
| 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 test.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 new isInstanceOf<LibraryErrorsReadyTask>(); | 108 new isInstanceOf<LibraryErrorsReadyTask>(); |
| 109 isInstanceOf isLibraryUnitErrorsTask = | 109 isInstanceOf isLibraryUnitErrorsTask = |
| 110 new isInstanceOf<LibraryUnitErrorsTask>(); | 110 new isInstanceOf<LibraryUnitErrorsTask>(); |
| 111 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); | 111 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); |
| 112 isInstanceOf isPartiallyResolveUnitReferencesTask = | 112 isInstanceOf isPartiallyResolveUnitReferencesTask = |
| 113 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); | 113 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); |
| 114 isInstanceOf isResolveFunctionBodiesInUnitTask = | 114 isInstanceOf isResolveFunctionBodiesInUnitTask = |
| 115 new isInstanceOf<ResolveFunctionBodiesInUnitTask>(); | 115 new isInstanceOf<ResolveFunctionBodiesInUnitTask>(); |
| 116 isInstanceOf isResolveLibraryTypeNamesTask = | 116 isInstanceOf isResolveLibraryTypeNamesTask = |
| 117 new isInstanceOf<ResolveLibraryTypeNamesTask>(); | 117 new isInstanceOf<ResolveLibraryTypeNamesTask>(); |
| 118 isInstanceOf isResolveUnitReferencesTask = | |
| 119 new isInstanceOf<ResolveUnitReferencesTask>(); | |
| 120 isInstanceOf isResolveUnitTypeNamesTask = | 118 isInstanceOf isResolveUnitTypeNamesTask = |
| 121 new isInstanceOf<ResolveUnitTypeNamesTask>(); | 119 new isInstanceOf<ResolveUnitTypeNamesTask>(); |
| 122 isInstanceOf isResolveVariableReferencesTask = | 120 isInstanceOf isResolveVariableReferencesTask = |
| 123 new isInstanceOf<ResolveVariableReferencesTask>(); | 121 new isInstanceOf<ResolveVariableReferencesTask>(); |
| 124 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); | 122 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); |
| 125 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); | 123 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); |
| 126 | 124 |
| 127 @reflectiveTest | 125 @reflectiveTest |
| 128 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 126 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 129 Source source; | 127 Source source; |
| (...skipping 2552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2682 { | 2680 { |
| 2683 ClassElement clazz = library.getType('A'); | 2681 ClassElement clazz = library.getType('A'); |
| 2684 expect(clazz.displayName, 'A'); | 2682 expect(clazz.displayName, 'A'); |
| 2685 clazz = clazz.supertype.element; | 2683 clazz = clazz.supertype.element; |
| 2686 expect(clazz.displayName, 'B'); | 2684 expect(clazz.displayName, 'B'); |
| 2687 } | 2685 } |
| 2688 } | 2686 } |
| 2689 } | 2687 } |
| 2690 | 2688 |
| 2691 @reflectiveTest | 2689 @reflectiveTest |
| 2692 class ResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { | |
| 2693 test_perform() { | |
| 2694 Source source = newSource( | |
| 2695 '/test.dart', | |
| 2696 ''' | |
| 2697 class A { | |
| 2698 m() {} | |
| 2699 } | |
| 2700 main(A a) { | |
| 2701 a.m(); | |
| 2702 } | |
| 2703 '''); | |
| 2704 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | |
| 2705 // prepare unit and "a.m()" invocation | |
| 2706 computeResult(target, RESOLVED_UNIT8, matcher: isResolveUnitReferencesTask); | |
| 2707 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | |
| 2708 // walk the AST | |
| 2709 FunctionDeclaration function = unit.declarations[1]; | |
| 2710 BlockFunctionBody body = function.functionExpression.body; | |
| 2711 ExpressionStatement statement = body.block.statements[0]; | |
| 2712 MethodInvocation invocation = statement.expression; | |
| 2713 expect(unit, same(outputs[RESOLVED_UNIT8])); | |
| 2714 // a.m() is resolved now | |
| 2715 expect(invocation.methodName.staticElement, isNotNull); | |
| 2716 } | |
| 2717 | |
| 2718 test_perform_errors() { | |
| 2719 Source source = newSource( | |
| 2720 '/test.dart', | |
| 2721 ''' | |
| 2722 class A { | |
| 2723 } | |
| 2724 main(A a) { | |
| 2725 a.unknownMethod(); | |
| 2726 } | |
| 2727 '''); | |
| 2728 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | |
| 2729 computeResult(target, RESOLVED_UNIT8, matcher: isResolveUnitReferencesTask); | |
| 2730 // validate | |
| 2731 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | |
| 2732 errorListener.assertErrorsWithCodes( | |
| 2733 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | |
| 2734 } | |
| 2735 | |
| 2736 test_perform_importExport() { | |
| 2737 newSource( | |
| 2738 '/a.dart', | |
| 2739 ''' | |
| 2740 library a; | |
| 2741 class A<T> { | |
| 2742 T m() {} | |
| 2743 } | |
| 2744 '''); | |
| 2745 newSource( | |
| 2746 '/b.dart', | |
| 2747 ''' | |
| 2748 library b; | |
| 2749 export 'a.dart'; | |
| 2750 '''); | |
| 2751 Source sourceC = newSource( | |
| 2752 '/c.dart', | |
| 2753 ''' | |
| 2754 library c; | |
| 2755 import 'b.dart'; | |
| 2756 main() { | |
| 2757 new A<int>().m(); | |
| 2758 } | |
| 2759 '''); | |
| 2760 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT8, | |
| 2761 matcher: isResolveUnitReferencesTask); | |
| 2762 // validate | |
| 2763 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | |
| 2764 expect(unit, isNotNull); | |
| 2765 FunctionDeclaration functionDeclaration = unit.declarations[0]; | |
| 2766 BlockFunctionBody body = functionDeclaration.functionExpression.body; | |
| 2767 List<Statement> statements = body.block.statements; | |
| 2768 ExpressionStatement statement = statements[0]; | |
| 2769 MethodInvocation invocation = statement.expression; | |
| 2770 MethodElement methodElement = invocation.methodName.staticElement; | |
| 2771 expect(methodElement, isNotNull); | |
| 2772 expect(methodElement.type, isNotNull); | |
| 2773 expect(methodElement.returnType.toString(), 'int'); | |
| 2774 } | |
| 2775 } | |
| 2776 | |
| 2777 @reflectiveTest | |
| 2778 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 2690 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 2779 test_perform() { | 2691 test_perform() { |
| 2780 Source source = newSource( | 2692 Source source = newSource( |
| 2781 '/test.dart', | 2693 '/test.dart', |
| 2782 ''' | 2694 ''' |
| 2783 class A {} | 2695 class A {} |
| 2784 class B extends A {} | 2696 class B extends A {} |
| 2785 int f(String p) => p.length; | 2697 int f(String p) => p.length; |
| 2786 '''); | 2698 '''); |
| 2787 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2699 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3211 /** | 3123 /** |
| 3212 * Fill [errorListener] with [result] errors in the current [task]. | 3124 * Fill [errorListener] with [result] errors in the current [task]. |
| 3213 */ | 3125 */ |
| 3214 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 3126 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 3215 List<AnalysisError> errors = task.outputs[result]; | 3127 List<AnalysisError> errors = task.outputs[result]; |
| 3216 expect(errors, isNotNull, reason: result.name); | 3128 expect(errors, isNotNull, reason: result.name); |
| 3217 errorListener = new GatheringErrorListener(); | 3129 errorListener = new GatheringErrorListener(); |
| 3218 errorListener.addAll(errors); | 3130 errorListener.addAll(errors); |
| 3219 } | 3131 } |
| 3220 } | 3132 } |
| OLD | NEW |