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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 class B { | 722 class B { |
723 B(int i); | 723 B(int i); |
724 } | 724 } |
725 class M1 {} | 725 class M1 {} |
726 class M2 {} | 726 class M2 {} |
727 | 727 |
728 class C2 = C1 with M2; | 728 class C2 = C1 with M2; |
729 class C1 = B with M1; | 729 class C1 = B with M1; |
730 class C3 = B with M2; | 730 class C3 = B with M2; |
731 '''); | 731 '''); |
732 _computeResult(source, LIBRARY_ELEMENT); | 732 _computeResult(source, LIBRARY_ELEMENT6); |
733 expect(task, new isInstanceOf<BuildLibraryConstructorsTask>()); | 733 expect(task, new isInstanceOf<BuildLibraryConstructorsTask>()); |
734 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT]; | 734 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT6]; |
735 // C1 | 735 // C1 |
736 { | 736 { |
737 ClassElement classElement = libraryElement.getType('C2'); | 737 ClassElement classElement = libraryElement.getType('C2'); |
738 List<ConstructorElement> constructors = classElement.constructors; | 738 List<ConstructorElement> constructors = classElement.constructors; |
739 expect(constructors, hasLength(1)); | 739 expect(constructors, hasLength(1)); |
740 expect(constructors[0].parameters, hasLength(1)); | 740 expect(constructors[0].parameters, hasLength(1)); |
741 } | 741 } |
742 // C3 | 742 // C3 |
743 { | 743 { |
744 ClassElement classElement = libraryElement.getType('C3'); | 744 ClassElement classElement = libraryElement.getType('C3'); |
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2384 '''); | 2384 '''); |
2385 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2385 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
2386 // prepare unit and "a.m()" invocation | 2386 // prepare unit and "a.m()" invocation |
2387 _computeResult(target, RESOLVED_UNIT6); | 2387 _computeResult(target, RESOLVED_UNIT6); |
2388 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2388 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
2389 // walk the AST | 2389 // walk the AST |
2390 FunctionDeclaration function = unit.declarations[1]; | 2390 FunctionDeclaration function = unit.declarations[1]; |
2391 BlockFunctionBody body = function.functionExpression.body; | 2391 BlockFunctionBody body = function.functionExpression.body; |
2392 ExpressionStatement statement = body.block.statements[0]; | 2392 ExpressionStatement statement = body.block.statements[0]; |
2393 MethodInvocation invocation = statement.expression; | 2393 MethodInvocation invocation = statement.expression; |
2394 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 2394 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
2395 expect(unit, same(outputs[RESOLVED_UNIT6])); | 2395 expect(unit, same(outputs[RESOLVED_UNIT6])); |
2396 // a.m() is resolved now | 2396 // a.m() is resolved now |
2397 expect(invocation.methodName.staticElement, isNotNull); | 2397 expect(invocation.methodName.staticElement, isNotNull); |
2398 } | 2398 } |
2399 | 2399 |
2400 test_perform_errors() { | 2400 test_perform_errors() { |
2401 Source source = newSource('/test.dart', ''' | 2401 Source source = newSource('/test.dart', ''' |
2402 class A { | 2402 class A { |
2403 } | 2403 } |
2404 main(A a) { | 2404 main(A a) { |
2405 a.unknownMethod(); | 2405 a.unknownMethod(); |
2406 } | 2406 } |
2407 '''); | 2407 '''); |
2408 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2408 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
2409 _computeResult(target, RESOLVED_UNIT6); | 2409 _computeResult(target, RESOLVED_UNIT6); |
2410 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 2410 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
2411 // validate | 2411 // validate |
2412 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | 2412 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
2413 errorListener.assertErrorsWithCodes( | 2413 errorListener.assertErrorsWithCodes( |
2414 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | 2414 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
2415 } | 2415 } |
2416 | 2416 |
2417 test_perform_importExport() { | 2417 test_perform_importExport() { |
2418 newSource('/a.dart', ''' | 2418 newSource('/a.dart', ''' |
2419 library a; | 2419 library a; |
2420 class A<T> { | 2420 class A<T> { |
2421 T m() {} | 2421 T m() {} |
2422 } | 2422 } |
2423 '''); | 2423 '''); |
2424 newSource('/b.dart', ''' | 2424 newSource('/b.dart', ''' |
2425 library b; | 2425 library b; |
2426 export 'a.dart'; | 2426 export 'a.dart'; |
2427 '''); | 2427 '''); |
2428 Source sourceC = newSource('/c.dart', ''' | 2428 Source sourceC = newSource('/c.dart', ''' |
2429 library c; | 2429 library c; |
2430 import 'b.dart'; | 2430 import 'b.dart'; |
2431 main() { | 2431 main() { |
2432 new A<int>().m(); | 2432 new A<int>().m(); |
2433 } | 2433 } |
2434 '''); | 2434 '''); |
2435 _computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6); | 2435 _computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6); |
2436 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 2436 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
2437 // validate | 2437 // validate |
2438 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2438 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
2439 expect(unit, isNotNull); | 2439 expect(unit, isNotNull); |
2440 { | 2440 { |
2441 FunctionDeclaration functionDeclaration = unit.declarations[0]; | 2441 FunctionDeclaration functionDeclaration = unit.declarations[0]; |
2442 BlockFunctionBody body = functionDeclaration.functionExpression.body; | 2442 BlockFunctionBody body = functionDeclaration.functionExpression.body; |
2443 List<Statement> statements = body.block.statements; | 2443 List<Statement> statements = body.block.statements; |
2444 ExpressionStatement statement = statements[0]; | 2444 ExpressionStatement statement = statements[0]; |
2445 MethodInvocation invocation = statement.expression; | 2445 MethodInvocation invocation = statement.expression; |
2446 MethodElement methodElement = invocation.methodName.staticElement; | 2446 MethodElement methodElement = invocation.methodName.staticElement; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2507 } | 2507 } |
2508 | 2508 |
2509 test_perform_buildClosureLibraryElements() { | 2509 test_perform_buildClosureLibraryElements() { |
2510 Source source = newSource('/test.dart', ''' | 2510 Source source = newSource('/test.dart', ''' |
2511 main() { | 2511 main() { |
2512 } | 2512 } |
2513 '''); | 2513 '''); |
2514 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2514 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
2515 _computeResult(target, RESOLVED_UNIT5); | 2515 _computeResult(target, RESOLVED_UNIT5); |
2516 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2516 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
2517 // dart:core LIBRARY_ELEMENT is built | |
2518 expect(analysisCache.getState( | |
2519 context.sourceFactory.resolveUri(null, 'dart:core'), | |
2520 LIBRARY_ELEMENT), CacheState.VALID); | |
2521 } | 2517 } |
2522 | 2518 |
2523 test_perform_local() { | 2519 test_perform_local() { |
2524 Source source = newSource('/test.dart', ''' | 2520 Source source = newSource('/test.dart', ''' |
2525 main() { | 2521 main() { |
2526 var v1 = 1; | 2522 var v1 = 1; |
2527 var v2 = 1; | 2523 var v2 = 1; |
2528 var v3 = 1; | 2524 var v3 = 1; |
2529 var v4 = 1; | 2525 var v4 = 1; |
2530 v2 = 2; | 2526 v2 = 2; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2717 /** | 2713 /** |
2718 * Fill [errorListener] with [result] errors in the current [task]. | 2714 * Fill [errorListener] with [result] errors in the current [task]. |
2719 */ | 2715 */ |
2720 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2716 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
2721 List<AnalysisError> errors = task.outputs[result]; | 2717 List<AnalysisError> errors = task.outputs[result]; |
2722 expect(errors, isNotNull, reason: result.name); | 2718 expect(errors, isNotNull, reason: result.name); |
2723 errorListener = new GatheringErrorListener(); | 2719 errorListener = new GatheringErrorListener(); |
2724 errorListener.addAll(errors); | 2720 errorListener.addAll(errors); |
2725 } | 2721 } |
2726 } | 2722 } |
OLD | NEW |