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 2366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 Source source = newSource('/test.dart', ''' | 2377 Source source = newSource('/test.dart', ''' |
2378 class A { | 2378 class A { |
2379 m() {} | 2379 m() {} |
2380 } | 2380 } |
2381 main(A a) { | 2381 main(A a) { |
2382 a.m(); | 2382 a.m(); |
2383 } | 2383 } |
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_UNIT_NO_CONSTANTS); |
2388 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2388 CompilationUnit unit = outputs[RESOLVED_UNIT_NO_CONSTANTS]; |
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<ResolveUnitReferencesTask>()); | 2394 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
2395 expect(unit, same(outputs[RESOLVED_UNIT6])); | 2395 expect(unit, same(outputs[RESOLVED_UNIT_NO_CONSTANTS])); |
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_UNIT_NO_CONSTANTS); |
2410 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | 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( |
| 2436 new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT_NO_CONSTANTS); |
2436 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | 2437 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
2437 // validate | 2438 // validate |
2438 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2439 CompilationUnit unit = outputs[RESOLVED_UNIT_NO_CONSTANTS]; |
2439 expect(unit, isNotNull); | 2440 expect(unit, isNotNull); |
2440 { | 2441 { |
2441 FunctionDeclaration functionDeclaration = unit.declarations[0]; | 2442 FunctionDeclaration functionDeclaration = unit.declarations[0]; |
2442 BlockFunctionBody body = functionDeclaration.functionExpression.body; | 2443 BlockFunctionBody body = functionDeclaration.functionExpression.body; |
2443 List<Statement> statements = body.block.statements; | 2444 List<Statement> statements = body.block.statements; |
2444 ExpressionStatement statement = statements[0]; | 2445 ExpressionStatement statement = statements[0]; |
2445 MethodInvocation invocation = statement.expression; | 2446 MethodInvocation invocation = statement.expression; |
2446 MethodElement methodElement = invocation.methodName.staticElement; | 2447 MethodElement methodElement = invocation.methodName.staticElement; |
2447 expect(methodElement, isNotNull); | 2448 expect(methodElement, isNotNull); |
2448 expect(methodElement.type, isNotNull); | 2449 expect(methodElement.type, isNotNull); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2713 /** | 2714 /** |
2714 * Fill [errorListener] with [result] errors in the current [task]. | 2715 * Fill [errorListener] with [result] errors in the current [task]. |
2715 */ | 2716 */ |
2716 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2717 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
2717 List<AnalysisError> errors = task.outputs[result]; | 2718 List<AnalysisError> errors = task.outputs[result]; |
2718 expect(errors, isNotNull, reason: result.name); | 2719 expect(errors, isNotNull, reason: result.name); |
2719 errorListener = new GatheringErrorListener(); | 2720 errorListener = new GatheringErrorListener(); |
2720 errorListener.addAll(errors); | 2721 errorListener.addAll(errors); |
2721 } | 2722 } |
2722 } | 2723 } |
OLD | NEW |