| 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 2373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2384 Source source = newSource('/test.dart', ''' | 2384 Source source = newSource('/test.dart', ''' |
| 2385 class A { | 2385 class A { |
| 2386 m() {} | 2386 m() {} |
| 2387 } | 2387 } |
| 2388 main(A a) { | 2388 main(A a) { |
| 2389 a.m(); | 2389 a.m(); |
| 2390 } | 2390 } |
| 2391 '''); | 2391 '''); |
| 2392 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2392 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2393 // prepare unit and "a.m()" invocation | 2393 // prepare unit and "a.m()" invocation |
| 2394 computeResult(target, RESOLVED_UNIT6); | 2394 computeResult(target, RESOLVED_UNIT5); |
| 2395 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2395 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2396 // walk the AST | 2396 // walk the AST |
| 2397 FunctionDeclaration function = unit.declarations[1]; | 2397 FunctionDeclaration function = unit.declarations[1]; |
| 2398 BlockFunctionBody body = function.functionExpression.body; | 2398 BlockFunctionBody body = function.functionExpression.body; |
| 2399 ExpressionStatement statement = body.block.statements[0]; | 2399 ExpressionStatement statement = body.block.statements[0]; |
| 2400 MethodInvocation invocation = statement.expression; | 2400 MethodInvocation invocation = statement.expression; |
| 2401 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | 2401 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
| 2402 expect(unit, same(outputs[RESOLVED_UNIT6])); | 2402 expect(unit, same(outputs[RESOLVED_UNIT5])); |
| 2403 // a.m() is resolved now | 2403 // a.m() is resolved now |
| 2404 expect(invocation.methodName.staticElement, isNotNull); | 2404 expect(invocation.methodName.staticElement, isNotNull); |
| 2405 } | 2405 } |
| 2406 | 2406 |
| 2407 test_perform_errors() { | 2407 test_perform_errors() { |
| 2408 Source source = newSource('/test.dart', ''' | 2408 Source source = newSource('/test.dart', ''' |
| 2409 class A { | 2409 class A { |
| 2410 } | 2410 } |
| 2411 main(A a) { | 2411 main(A a) { |
| 2412 a.unknownMethod(); | 2412 a.unknownMethod(); |
| 2413 } | 2413 } |
| 2414 '''); | 2414 '''); |
| 2415 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2415 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2416 computeResult(target, RESOLVED_UNIT6); | 2416 computeResult(target, RESOLVED_UNIT5); |
| 2417 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | 2417 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
| 2418 // validate | 2418 // validate |
| 2419 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | 2419 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
| 2420 errorListener.assertErrorsWithCodes( | 2420 errorListener.assertErrorsWithCodes( |
| 2421 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | 2421 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 2422 } | 2422 } |
| 2423 | 2423 |
| 2424 test_perform_importExport() { | 2424 test_perform_importExport() { |
| 2425 newSource('/a.dart', ''' | 2425 newSource('/a.dart', ''' |
| 2426 library a; | 2426 library a; |
| 2427 class A<T> { | 2427 class A<T> { |
| 2428 T m() {} | 2428 T m() {} |
| 2429 } | 2429 } |
| 2430 '''); | 2430 '''); |
| 2431 newSource('/b.dart', ''' | 2431 newSource('/b.dart', ''' |
| 2432 library b; | 2432 library b; |
| 2433 export 'a.dart'; | 2433 export 'a.dart'; |
| 2434 '''); | 2434 '''); |
| 2435 Source sourceC = newSource('/c.dart', ''' | 2435 Source sourceC = newSource('/c.dart', ''' |
| 2436 library c; | 2436 library c; |
| 2437 import 'b.dart'; | 2437 import 'b.dart'; |
| 2438 main() { | 2438 main() { |
| 2439 new A<int>().m(); | 2439 new A<int>().m(); |
| 2440 } | 2440 } |
| 2441 '''); | 2441 '''); |
| 2442 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6); | 2442 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5); |
| 2443 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | 2443 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); |
| 2444 // validate | 2444 // validate |
| 2445 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2445 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2446 expect(unit, isNotNull); | 2446 expect(unit, isNotNull); |
| 2447 { | 2447 { |
| 2448 FunctionDeclaration functionDeclaration = unit.declarations[0]; | 2448 FunctionDeclaration functionDeclaration = unit.declarations[0]; |
| 2449 BlockFunctionBody body = functionDeclaration.functionExpression.body; | 2449 BlockFunctionBody body = functionDeclaration.functionExpression.body; |
| 2450 List<Statement> statements = body.block.statements; | 2450 List<Statement> statements = body.block.statements; |
| 2451 ExpressionStatement statement = statements[0]; | 2451 ExpressionStatement statement = statements[0]; |
| 2452 MethodInvocation invocation = statement.expression; | 2452 MethodInvocation invocation = statement.expression; |
| 2453 MethodElement methodElement = invocation.methodName.staticElement; | 2453 MethodElement methodElement = invocation.methodName.staticElement; |
| 2454 expect(methodElement, isNotNull); | 2454 expect(methodElement, isNotNull); |
| 2455 expect(methodElement.type, isNotNull); | 2455 expect(methodElement.type, isNotNull); |
| 2456 expect(methodElement.returnType.toString(), 'int'); | 2456 expect(methodElement.returnType.toString(), 'int'); |
| 2457 } | 2457 } |
| 2458 } | 2458 } |
| 2459 } | 2459 } |
| 2460 | 2460 |
| 2461 @reflectiveTest | 2461 @reflectiveTest |
| 2462 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 2462 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 2463 test_perform() { | 2463 test_perform() { |
| 2464 Source source = newSource('/test.dart', ''' | 2464 Source source = newSource('/test.dart', ''' |
| 2465 class A {} | 2465 class A {} |
| 2466 class B extends A {} | 2466 class B extends A {} |
| 2467 int f(String p) => p.length; | 2467 int f(String p) => p.length; |
| 2468 '''); | 2468 '''); |
| 2469 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2469 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2470 computeResult(target, RESOLVED_UNIT4); | 2470 computeResult(target, RESOLVED_UNIT3); |
| 2471 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 2471 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 2472 // validate | 2472 // validate |
| 2473 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 2473 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 2474 { | 2474 { |
| 2475 ClassDeclaration nodeA = unit.declarations[0]; | 2475 ClassDeclaration nodeA = unit.declarations[0]; |
| 2476 ClassDeclaration nodeB = unit.declarations[1]; | 2476 ClassDeclaration nodeB = unit.declarations[1]; |
| 2477 DartType extendsType = nodeB.extendsClause.superclass.type; | 2477 DartType extendsType = nodeB.extendsClause.superclass.type; |
| 2478 expect(extendsType, nodeA.element.type); | 2478 expect(extendsType, nodeA.element.type); |
| 2479 } | 2479 } |
| 2480 { | 2480 { |
| 2481 FunctionDeclaration functionNode = unit.declarations[2]; | 2481 FunctionDeclaration functionNode = unit.declarations[2]; |
| 2482 DartType returnType = functionNode.returnType.type; | 2482 DartType returnType = functionNode.returnType.type; |
| 2483 List<FormalParameter> parameters = | 2483 List<FormalParameter> parameters = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2499 errorListener | 2499 errorListener |
| 2500 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 2500 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 2501 } | 2501 } |
| 2502 | 2502 |
| 2503 test_perform_typedef() { | 2503 test_perform_typedef() { |
| 2504 Source source = newSource('/test.dart', ''' | 2504 Source source = newSource('/test.dart', ''' |
| 2505 typedef int F(G g); | 2505 typedef int F(G g); |
| 2506 typedef String G(int p); | 2506 typedef String G(int p); |
| 2507 '''); | 2507 '''); |
| 2508 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2508 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2509 computeResult(target, RESOLVED_UNIT4); | 2509 computeResult(target, RESOLVED_UNIT3); |
| 2510 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 2510 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 2511 // validate | 2511 // validate |
| 2512 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 2512 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 2513 FunctionTypeAlias nodeF = unit.declarations[0]; | 2513 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 2514 FunctionTypeAlias nodeG = unit.declarations[1]; | 2514 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 2515 { | 2515 { |
| 2516 FormalParameter parameter = nodeF.parameters.parameters[0]; | 2516 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 2517 DartType parameterType = parameter.element.type; | 2517 DartType parameterType = parameter.element.type; |
| 2518 Element returnTypeElement = nodeF.returnType.type.element; | 2518 Element returnTypeElement = nodeF.returnType.type.element; |
| 2519 expect(returnTypeElement.displayName, 'int'); | 2519 expect(returnTypeElement.displayName, 'int'); |
| 2520 expect(parameterType.element, nodeG.element); | 2520 expect(parameterType.element, nodeG.element); |
| 2521 } | 2521 } |
| 2522 { | 2522 { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2552 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); | 2552 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); |
| 2553 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); | 2553 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); |
| 2554 } | 2554 } |
| 2555 | 2555 |
| 2556 test_perform_buildClosureLibraryElements() { | 2556 test_perform_buildClosureLibraryElements() { |
| 2557 Source source = newSource('/test.dart', ''' | 2557 Source source = newSource('/test.dart', ''' |
| 2558 main() { | 2558 main() { |
| 2559 } | 2559 } |
| 2560 '''); | 2560 '''); |
| 2561 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2561 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2562 computeResult(target, RESOLVED_UNIT5); | 2562 computeResult(target, RESOLVED_UNIT4); |
| 2563 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2563 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 2564 } | 2564 } |
| 2565 | 2565 |
| 2566 test_perform_local() { | 2566 test_perform_local() { |
| 2567 Source source = newSource('/test.dart', ''' | 2567 Source source = newSource('/test.dart', ''' |
| 2568 main() { | 2568 main() { |
| 2569 var v1 = 1; | 2569 var v1 = 1; |
| 2570 var v2 = 1; | 2570 var v2 = 1; |
| 2571 var v3 = 1; | 2571 var v3 = 1; |
| 2572 var v4 = 1; | 2572 var v4 = 1; |
| 2573 v2 = 2; | 2573 v2 = 2; |
| 2574 v4 = 2; | 2574 v4 = 2; |
| 2575 localFunction() { | 2575 localFunction() { |
| 2576 v3 = 3; | 2576 v3 = 3; |
| 2577 v4 = 3; | 2577 v4 = 3; |
| 2578 } | 2578 } |
| 2579 } | 2579 } |
| 2580 '''); | 2580 '''); |
| 2581 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2581 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2582 computeResult(target, RESOLVED_UNIT5); | 2582 computeResult(target, RESOLVED_UNIT4); |
| 2583 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2583 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 2584 // validate | 2584 // validate |
| 2585 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2585 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 2586 FunctionElement main = unit.element.functions[0]; | 2586 FunctionElement main = unit.element.functions[0]; |
| 2587 expectMutated(main.localVariables[0], isFalse, isFalse); | 2587 expectMutated(main.localVariables[0], isFalse, isFalse); |
| 2588 expectMutated(main.localVariables[1], isFalse, isTrue); | 2588 expectMutated(main.localVariables[1], isFalse, isTrue); |
| 2589 expectMutated(main.localVariables[2], isTrue, isTrue); | 2589 expectMutated(main.localVariables[2], isTrue, isTrue); |
| 2590 expectMutated(main.localVariables[3], isTrue, isTrue); | 2590 expectMutated(main.localVariables[3], isTrue, isTrue); |
| 2591 } | 2591 } |
| 2592 | 2592 |
| 2593 test_perform_parameter() { | 2593 test_perform_parameter() { |
| 2594 Source source = newSource('/test.dart', ''' | 2594 Source source = newSource('/test.dart', ''' |
| 2595 main(p1, p2, p3, p4) { | 2595 main(p1, p2, p3, p4) { |
| 2596 p2 = 2; | 2596 p2 = 2; |
| 2597 p4 = 2; | 2597 p4 = 2; |
| 2598 localFunction() { | 2598 localFunction() { |
| 2599 p3 = 3; | 2599 p3 = 3; |
| 2600 p4 = 3; | 2600 p4 = 3; |
| 2601 } | 2601 } |
| 2602 } | 2602 } |
| 2603 '''); | 2603 '''); |
| 2604 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2604 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2605 computeResult(target, RESOLVED_UNIT5); | 2605 computeResult(target, RESOLVED_UNIT4); |
| 2606 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2606 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 2607 // validate | 2607 // validate |
| 2608 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2608 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 2609 FunctionElement main = unit.element.functions[0]; | 2609 FunctionElement main = unit.element.functions[0]; |
| 2610 expectMutated(main.parameters[0], isFalse, isFalse); | 2610 expectMutated(main.parameters[0], isFalse, isFalse); |
| 2611 expectMutated(main.parameters[1], isFalse, isTrue); | 2611 expectMutated(main.parameters[1], isFalse, isTrue); |
| 2612 expectMutated(main.parameters[2], isTrue, isTrue); | 2612 expectMutated(main.parameters[2], isTrue, isTrue); |
| 2613 expectMutated(main.parameters[3], isTrue, isTrue); | 2613 expectMutated(main.parameters[3], isTrue, isTrue); |
| 2614 } | 2614 } |
| 2615 } | 2615 } |
| 2616 | 2616 |
| 2617 @reflectiveTest | 2617 @reflectiveTest |
| 2618 class ScanDartTaskTest extends _AbstractDartTaskTest { | 2618 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2796 /** | 2796 /** |
| 2797 * Fill [errorListener] with [result] errors in the current [task]. | 2797 * Fill [errorListener] with [result] errors in the current [task]. |
| 2798 */ | 2798 */ |
| 2799 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2799 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2800 List<AnalysisError> errors = task.outputs[result]; | 2800 List<AnalysisError> errors = task.outputs[result]; |
| 2801 expect(errors, isNotNull, reason: result.name); | 2801 expect(errors, isNotNull, reason: result.name); |
| 2802 errorListener = new GatheringErrorListener(); | 2802 errorListener = new GatheringErrorListener(); |
| 2803 errorListener.addAll(errors); | 2803 errorListener.addAll(errors); |
| 2804 } | 2804 } |
| 2805 } | 2805 } |
| OLD | NEW |