| 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 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 | 1277 |
| 1278 void _checkCircularities( | 1278 void _checkCircularities( |
| 1279 String variableName, List<String> otherVariables, String content) { | 1279 String variableName, List<String> otherVariables, String content) { |
| 1280 // Evaluating the first constant should produce an error. | 1280 // Evaluating the first constant should produce an error. |
| 1281 CompilationUnit unit = _resolveUnit(content); | 1281 CompilationUnit unit = _resolveUnit(content); |
| 1282 _expectCircularityError(_evaluateConstant(unit, variableName)); | 1282 _expectCircularityError(_evaluateConstant(unit, variableName)); |
| 1283 // And all the other constants involved in the strongly connected component | 1283 // And all the other constants involved in the strongly connected component |
| 1284 // should be set to the same error state. | 1284 // should be set to the same error state. |
| 1285 for (String otherVariableName in otherVariables) { | 1285 for (String otherVariableName in otherVariables) { |
| 1286 PropertyInducingElement otherVariableElement = | 1286 PropertyInducingElement otherVariableElement = |
| 1287 getTopLevelVariableElement(unit, otherVariableName); | 1287 AstFinder.getTopLevelVariableElement(unit, otherVariableName); |
| 1288 _expectCircularityError((otherVariableElement | 1288 _expectCircularityError((otherVariableElement |
| 1289 as TopLevelVariableElementImpl).evaluationResult); | 1289 as TopLevelVariableElementImpl).evaluationResult); |
| 1290 } | 1290 } |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 EvaluationResultImpl _computeTopLevelVariableConstValue( | 1293 EvaluationResultImpl _computeTopLevelVariableConstValue( |
| 1294 String variableName, String content) { | 1294 String variableName, String content) { |
| 1295 return _evaluateConstant(_resolveUnit(content), variableName); | 1295 return _evaluateConstant(_resolveUnit(content), variableName); |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 EvaluationResultImpl _evaluateConstant( | 1298 EvaluationResultImpl _evaluateConstant( |
| 1299 CompilationUnit unit, String variableName) { | 1299 CompilationUnit unit, String variableName) { |
| 1300 // Find the element for the given constant. | 1300 // Find the element for the given constant. |
| 1301 PropertyInducingElement variableElement = | 1301 PropertyInducingElement variableElement = |
| 1302 getTopLevelVariableElement(unit, variableName); | 1302 AstFinder.getTopLevelVariableElement(unit, variableName); |
| 1303 // Now compute the value of the constant. | 1303 // Now compute the value of the constant. |
| 1304 computeResult(variableElement, CONSTANT_VALUE, | 1304 computeResult(variableElement, CONSTANT_VALUE, |
| 1305 matcher: isComputeConstantValueTask); | 1305 matcher: isComputeConstantValueTask); |
| 1306 expect(outputs[CONSTANT_VALUE], same(variableElement)); | 1306 expect(outputs[CONSTANT_VALUE], same(variableElement)); |
| 1307 EvaluationResultImpl evaluationResult = | 1307 EvaluationResultImpl evaluationResult = |
| 1308 (variableElement as TopLevelVariableElementImpl).evaluationResult; | 1308 (variableElement as TopLevelVariableElementImpl).evaluationResult; |
| 1309 return evaluationResult; | 1309 return evaluationResult; |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 void _expectCircularityError(EvaluationResultImpl evaluationResult) { | 1312 void _expectCircularityError(EvaluationResultImpl evaluationResult) { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 class B { | 1780 class B { |
| 1781 static const b1 = 1; | 1781 static const b1 = 1; |
| 1782 static final b2 = 2; | 1782 static final b2 = 2; |
| 1783 static final b3; | 1783 static final b3; |
| 1784 static var b4 = 4; | 1784 static var b4 = 4; |
| 1785 } | 1785 } |
| 1786 '''); | 1786 '''); |
| 1787 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1787 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1788 computeResult(target, RESOLVED_UNIT5); | 1788 computeResult(target, RESOLVED_UNIT5); |
| 1789 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1789 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1790 FieldElement elementA = getFieldInClassElement(unit, 'A', 'a'); | 1790 FieldElement elementA = AstFinder.getFieldInClassElement(unit, 'A', 'a'); |
| 1791 // compute | 1791 // compute |
| 1792 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, | 1792 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, |
| 1793 matcher: isComputePropagableVariableDependenciesTask); | 1793 matcher: isComputePropagableVariableDependenciesTask); |
| 1794 // verify | 1794 // verify |
| 1795 expect(outputs, hasLength(1)); | 1795 expect(outputs, hasLength(1)); |
| 1796 List<VariableElement> dependencies = | 1796 List<VariableElement> dependencies = |
| 1797 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; | 1797 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; |
| 1798 expect( | 1798 expect( |
| 1799 dependencies, | 1799 dependencies, |
| 1800 unorderedEquals([ | 1800 unorderedEquals([ |
| 1801 getFieldInClassElement(unit, 'A', 'a1'), | 1801 AstFinder.getFieldInClassElement(unit, 'A', 'a1'), |
| 1802 getFieldInClassElement(unit, 'A', 'a2'), | 1802 AstFinder.getFieldInClassElement(unit, 'A', 'a2'), |
| 1803 getFieldInClassElement(unit, 'B', 'b1'), | 1803 AstFinder.getFieldInClassElement(unit, 'B', 'b1'), |
| 1804 getFieldInClassElement(unit, 'B', 'b2') | 1804 AstFinder.getFieldInClassElement(unit, 'B', 'b2') |
| 1805 ])); | 1805 ])); |
| 1806 } | 1806 } |
| 1807 | 1807 |
| 1808 test_perform_topLevel() { | 1808 test_perform_topLevel() { |
| 1809 AnalysisTarget source = newSource( | 1809 AnalysisTarget source = newSource( |
| 1810 '/test.dart', | 1810 '/test.dart', |
| 1811 ''' | 1811 ''' |
| 1812 const a = d1 + d2 + d3 + d4; | 1812 const a = d1 + d2 + d3 + d4; |
| 1813 const d1 = 1; | 1813 const d1 = 1; |
| 1814 final d2 = 2; | 1814 final d2 = 2; |
| 1815 final d3; | 1815 final d3; |
| 1816 var d4 = 4; | 1816 var d4 = 4; |
| 1817 '''); | 1817 '''); |
| 1818 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1818 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1819 computeResult(target, RESOLVED_UNIT5); | 1819 computeResult(target, RESOLVED_UNIT5); |
| 1820 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1820 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1821 TopLevelVariableElement elementA = getTopLevelVariableElement(unit, 'a'); | 1821 TopLevelVariableElement elementA = |
| 1822 AstFinder.getTopLevelVariableElement(unit, 'a'); |
| 1822 // compute | 1823 // compute |
| 1823 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, | 1824 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, |
| 1824 matcher: isComputePropagableVariableDependenciesTask); | 1825 matcher: isComputePropagableVariableDependenciesTask); |
| 1825 // verify | 1826 // verify |
| 1826 expect(outputs, hasLength(1)); | 1827 expect(outputs, hasLength(1)); |
| 1827 List<VariableElement> dependencies = | 1828 List<VariableElement> dependencies = |
| 1828 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; | 1829 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; |
| 1829 expect( | 1830 expect( |
| 1830 dependencies, | 1831 dependencies, |
| 1831 unorderedEquals([ | 1832 unorderedEquals([ |
| 1832 getTopLevelVariableElement(unit, 'd1'), | 1833 AstFinder.getTopLevelVariableElement(unit, 'd1'), |
| 1833 getTopLevelVariableElement(unit, 'd2') | 1834 AstFinder.getTopLevelVariableElement(unit, 'd2') |
| 1834 ])); | 1835 ])); |
| 1835 } | 1836 } |
| 1836 | 1837 |
| 1837 test_perform_topLevel_ignoreLocal() { | 1838 test_perform_topLevel_ignoreLocal() { |
| 1838 AnalysisTarget source = newSource( | 1839 AnalysisTarget source = newSource( |
| 1839 '/test.dart', | 1840 '/test.dart', |
| 1840 ''' | 1841 ''' |
| 1841 final a = () { | 1842 final a = () { |
| 1842 const b = 2; | 1843 const b = 2; |
| 1843 const c = 3; | 1844 const c = 3; |
| 1844 return b + c; | 1845 return b + c; |
| 1845 }() + d; | 1846 }() + d; |
| 1846 final d = 4; | 1847 final d = 4; |
| 1847 '''); | 1848 '''); |
| 1848 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1849 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1849 computeResult(target, RESOLVED_UNIT5); | 1850 computeResult(target, RESOLVED_UNIT5); |
| 1850 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1851 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1851 TopLevelVariableElement elementA = getTopLevelVariableElement(unit, 'a'); | 1852 TopLevelVariableElement elementA = |
| 1853 AstFinder.getTopLevelVariableElement(unit, 'a'); |
| 1852 // compute | 1854 // compute |
| 1853 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, | 1855 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, |
| 1854 matcher: isComputePropagableVariableDependenciesTask); | 1856 matcher: isComputePropagableVariableDependenciesTask); |
| 1855 // verify | 1857 // verify |
| 1856 expect(outputs, hasLength(1)); | 1858 expect(outputs, hasLength(1)); |
| 1857 List<VariableElement> dependencies = | 1859 List<VariableElement> dependencies = |
| 1858 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; | 1860 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; |
| 1859 expect( | 1861 expect(dependencies, |
| 1860 dependencies, unorderedEquals([getTopLevelVariableElement(unit, 'd')])); | 1862 unorderedEquals([AstFinder.getTopLevelVariableElement(unit, 'd')])); |
| 1861 } | 1863 } |
| 1862 | 1864 |
| 1863 test_perform_topLevel_withoutSpaceAfterType() { | 1865 test_perform_topLevel_withoutSpaceAfterType() { |
| 1864 AnalysisTarget source = newSource( | 1866 AnalysisTarget source = newSource( |
| 1865 '/test.dart', | 1867 '/test.dart', |
| 1866 ''' | 1868 ''' |
| 1867 const List<int>a=[b, c]; | 1869 const List<int>a=[b, c]; |
| 1868 const b = 1; | 1870 const b = 1; |
| 1869 const c = 2; | 1871 const c = 2; |
| 1870 '''); | 1872 '''); |
| 1871 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1873 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1872 computeResult(target, RESOLVED_UNIT5); | 1874 computeResult(target, RESOLVED_UNIT5); |
| 1873 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1875 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1874 TopLevelVariableElement elementA = getTopLevelVariableElement(unit, 'a'); | 1876 TopLevelVariableElement elementA = |
| 1877 AstFinder.getTopLevelVariableElement(unit, 'a'); |
| 1875 // compute | 1878 // compute |
| 1876 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, | 1879 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, |
| 1877 matcher: isComputePropagableVariableDependenciesTask); | 1880 matcher: isComputePropagableVariableDependenciesTask); |
| 1878 // verify | 1881 // verify |
| 1879 expect(outputs, hasLength(1)); | 1882 expect(outputs, hasLength(1)); |
| 1880 List<VariableElement> dependencies = | 1883 List<VariableElement> dependencies = |
| 1881 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; | 1884 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; |
| 1882 expect( | 1885 expect( |
| 1883 dependencies, | 1886 dependencies, |
| 1884 unorderedEquals([ | 1887 unorderedEquals([ |
| 1885 getTopLevelVariableElement(unit, 'b'), | 1888 AstFinder.getTopLevelVariableElement(unit, 'b'), |
| 1886 getTopLevelVariableElement(unit, 'c') | 1889 AstFinder.getTopLevelVariableElement(unit, 'c') |
| 1887 ])); | 1890 ])); |
| 1888 } | 1891 } |
| 1889 } | 1892 } |
| 1890 | 1893 |
| 1891 @reflectiveTest | 1894 @reflectiveTest |
| 1892 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { | 1895 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { |
| 1893 test_perform_definingCompilationUnit() { | 1896 test_perform_definingCompilationUnit() { |
| 1894 AnalysisTarget library = newSource('/test.dart', 'library test;'); | 1897 AnalysisTarget library = newSource('/test.dart', 'library test;'); |
| 1895 computeResult(library, INCLUDED_PARTS); | 1898 computeResult(library, INCLUDED_PARTS); |
| 1896 computeResult(library, CONTAINING_LIBRARIES, | 1899 computeResult(library, CONTAINING_LIBRARIES, |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2463 var f; | 2466 var f; |
| 2464 m(x) {} | 2467 m(x) {} |
| 2465 } | 2468 } |
| 2466 class X {} | 2469 class X {} |
| 2467 class Y {} | 2470 class Y {} |
| 2468 class Z {} | 2471 class Z {} |
| 2469 '''); | 2472 '''); |
| 2470 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9, | 2473 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9, |
| 2471 matcher: isInferInstanceMembersInUnitTask); | 2474 matcher: isInferInstanceMembersInUnitTask); |
| 2472 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 2475 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
| 2473 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); | 2476 VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f'); |
| 2474 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); | 2477 MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm'); |
| 2475 DartType typeX = getClass(unit, 'X').element.type; | 2478 DartType typeX = AstFinder.getClass(unit, 'X').element.type; |
| 2476 DartType typeY = getClass(unit, 'Y').element.type; | 2479 DartType typeY = AstFinder.getClass(unit, 'Y').element.type; |
| 2477 DartType typeZ = getClass(unit, 'Z').element.type; | 2480 DartType typeZ = AstFinder.getClass(unit, 'Z').element.type; |
| 2478 | 2481 |
| 2479 expect(field.element.type, typeX); | 2482 expect(field.element.type, typeX); |
| 2480 expect(method.element.returnType, typeY); | 2483 expect(method.element.returnType, typeY); |
| 2481 expect(method.element.parameters[0].type, typeZ); | 2484 expect(method.element.parameters[0].type, typeZ); |
| 2482 } | 2485 } |
| 2483 | 2486 |
| 2484 void test_perform_cross_library_const() { | 2487 void test_perform_cross_library_const() { |
| 2485 enableStrongMode(); | 2488 enableStrongMode(); |
| 2486 AnalysisTarget firstSource = newSource( | 2489 AnalysisTarget firstSource = newSource( |
| 2487 '/first.dart', | 2490 '/first.dart', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2501 } | 2504 } |
| 2502 '''); | 2505 '''); |
| 2503 computeResult( | 2506 computeResult( |
| 2504 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9, | 2507 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9, |
| 2505 matcher: isInferInstanceMembersInUnitTask); | 2508 matcher: isInferInstanceMembersInUnitTask); |
| 2506 CompilationUnit firstUnit = outputs[RESOLVED_UNIT9]; | 2509 CompilationUnit firstUnit = outputs[RESOLVED_UNIT9]; |
| 2507 computeResult( | 2510 computeResult( |
| 2508 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); | 2511 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); |
| 2509 CompilationUnit secondUnit = outputs[RESOLVED_UNIT9]; | 2512 CompilationUnit secondUnit = outputs[RESOLVED_UNIT9]; |
| 2510 | 2513 |
| 2511 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); | 2514 VariableDeclaration variableA = |
| 2512 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); | 2515 AstFinder.getTopLevelVariable(firstUnit, 'a'); |
| 2513 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c'); | 2516 VariableDeclaration variableB = |
| 2517 AstFinder.getTopLevelVariable(secondUnit, 'b'); |
| 2518 VariableDeclaration variableC = |
| 2519 AstFinder.getFieldInClass(secondUnit, 'M', 'c'); |
| 2514 InterfaceType stringType = context.typeProvider.stringType; | 2520 InterfaceType stringType = context.typeProvider.stringType; |
| 2515 | 2521 |
| 2516 expect(variableA.element.type, stringType); | 2522 expect(variableA.element.type, stringType); |
| 2517 expect(variableB.element.type, stringType); | 2523 expect(variableB.element.type, stringType); |
| 2518 expect(variableB.initializer.staticType, stringType); | 2524 expect(variableB.initializer.staticType, stringType); |
| 2519 expect(variableC.element.type, stringType); | 2525 expect(variableC.element.type, stringType); |
| 2520 expect(variableC.initializer.staticType, stringType); | 2526 expect(variableC.initializer.staticType, stringType); |
| 2521 } | 2527 } |
| 2522 | 2528 |
| 2523 void test_perform_reresolution() { | 2529 void test_perform_reresolution() { |
| 2524 enableStrongMode(); | 2530 enableStrongMode(); |
| 2525 AnalysisTarget source = newSource( | 2531 AnalysisTarget source = newSource( |
| 2526 '/test.dart', | 2532 '/test.dart', |
| 2527 ''' | 2533 ''' |
| 2528 const topLevel = ''; | 2534 const topLevel = ''; |
| 2529 class C { | 2535 class C { |
| 2530 String field = topLevel; | 2536 String field = topLevel; |
| 2531 } | 2537 } |
| 2532 '''); | 2538 '''); |
| 2533 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 2539 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); |
| 2534 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 2540 CompilationUnit unit = outputs[RESOLVED_UNIT9]; |
| 2535 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); | 2541 VariableDeclaration topLevelDecl = |
| 2536 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); | 2542 AstFinder.getTopLevelVariable(unit, 'topLevel'); |
| 2543 VariableDeclaration fieldDecl = |
| 2544 AstFinder.getFieldInClass(unit, 'C', 'field'); |
| 2537 VariableElement topLevel = topLevelDecl.name.staticElement; | 2545 VariableElement topLevel = topLevelDecl.name.staticElement; |
| 2538 VariableElement field = fieldDecl.name.staticElement; | 2546 VariableElement field = fieldDecl.name.staticElement; |
| 2539 | 2547 |
| 2540 InterfaceType stringType = context.typeProvider.stringType; | 2548 InterfaceType stringType = context.typeProvider.stringType; |
| 2541 expect(topLevel.type, stringType); | 2549 expect(topLevel.type, stringType); |
| 2542 expect(field.type, stringType); | 2550 expect(field.type, stringType); |
| 2543 expect(fieldDecl.initializer.staticType, stringType); | 2551 expect(fieldDecl.initializer.staticType, stringType); |
| 2544 } | 2552 } |
| 2545 } | 2553 } |
| 2546 | 2554 |
| 2547 @reflectiveTest | 2555 @reflectiveTest |
| 2548 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { | 2556 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { |
| 2549 void test_perform_const_field() { | 2557 void test_perform_const_field() { |
| 2550 enableStrongMode(); | 2558 enableStrongMode(); |
| 2551 AnalysisTarget source = newSource( | 2559 AnalysisTarget source = newSource( |
| 2552 '/test.dart', | 2560 '/test.dart', |
| 2553 ''' | 2561 ''' |
| 2554 class M { | 2562 class M { |
| 2555 static const X = ""; | 2563 static const X = ""; |
| 2556 } | 2564 } |
| 2557 '''); | 2565 '''); |
| 2558 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, | 2566 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, |
| 2559 matcher: isInferStaticVariableTypesInUnitTask); | 2567 matcher: isInferStaticVariableTypesInUnitTask); |
| 2560 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2568 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2561 VariableDeclaration declaration = getFieldInClass(unit, 'M', 'X'); | 2569 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X'); |
| 2562 InterfaceType stringType = context.typeProvider.stringType; | 2570 InterfaceType stringType = context.typeProvider.stringType; |
| 2563 expect(declaration.element.type, stringType); | 2571 expect(declaration.element.type, stringType); |
| 2564 } | 2572 } |
| 2565 | 2573 |
| 2566 void test_perform_nestedDeclarations() { | 2574 void test_perform_nestedDeclarations() { |
| 2567 enableStrongMode(); | 2575 enableStrongMode(); |
| 2568 AnalysisTarget source = newSource( | 2576 AnalysisTarget source = newSource( |
| 2569 '/test.dart', | 2577 '/test.dart', |
| 2570 ''' | 2578 ''' |
| 2571 var f = (int x) { | 2579 var f = (int x) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2597 class M {} | 2605 class M {} |
| 2598 '''); | 2606 '''); |
| 2599 computeResult( | 2607 computeResult( |
| 2600 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT7, | 2608 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT7, |
| 2601 matcher: isInferStaticVariableTypesInUnitTask); | 2609 matcher: isInferStaticVariableTypesInUnitTask); |
| 2602 CompilationUnit firstUnit = outputs[RESOLVED_UNIT7]; | 2610 CompilationUnit firstUnit = outputs[RESOLVED_UNIT7]; |
| 2603 computeResult( | 2611 computeResult( |
| 2604 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT7); | 2612 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT7); |
| 2605 CompilationUnit secondUnit = outputs[RESOLVED_UNIT7]; | 2613 CompilationUnit secondUnit = outputs[RESOLVED_UNIT7]; |
| 2606 | 2614 |
| 2607 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); | 2615 VariableDeclaration variableA = |
| 2608 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); | 2616 AstFinder.getTopLevelVariable(firstUnit, 'a'); |
| 2609 VariableDeclaration variableC = getTopLevelVariable(firstUnit, 'c'); | 2617 VariableDeclaration variableB = |
| 2610 ClassDeclaration classM = getClass(secondUnit, 'M'); | 2618 AstFinder.getTopLevelVariable(secondUnit, 'b'); |
| 2619 VariableDeclaration variableC = |
| 2620 AstFinder.getTopLevelVariable(firstUnit, 'c'); |
| 2621 ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M'); |
| 2611 DartType typeM = classM.element.type; | 2622 DartType typeM = classM.element.type; |
| 2612 | 2623 |
| 2613 expect(variableA.element.type, typeM); | 2624 expect(variableA.element.type, typeM); |
| 2614 expect(variableB.element.type, typeM); | 2625 expect(variableB.element.type, typeM); |
| 2615 expect(variableB.initializer.staticType, typeM); | 2626 expect(variableB.initializer.staticType, typeM); |
| 2616 expect(variableC.element.type, typeM); | 2627 expect(variableC.element.type, typeM); |
| 2617 expect(variableC.initializer.staticType, typeM); | 2628 expect(variableC.initializer.staticType, typeM); |
| 2618 } | 2629 } |
| 2619 | 2630 |
| 2620 void test_perform_simple() { | 2631 void test_perform_simple() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2647 void test_getDeclaration_staticField() { | 2658 void test_getDeclaration_staticField() { |
| 2648 AnalysisTarget source = newSource( | 2659 AnalysisTarget source = newSource( |
| 2649 '/test.dart', | 2660 '/test.dart', |
| 2650 ''' | 2661 ''' |
| 2651 class C { | 2662 class C { |
| 2652 var field = ''; | 2663 var field = ''; |
| 2653 } | 2664 } |
| 2654 '''); | 2665 '''); |
| 2655 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2666 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2656 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2667 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2657 VariableDeclaration declaration = getFieldInClass(unit, 'C', 'field'); | 2668 VariableDeclaration declaration = |
| 2669 AstFinder.getFieldInClass(unit, 'C', 'field'); |
| 2658 VariableElement variable = declaration.name.staticElement; | 2670 VariableElement variable = declaration.name.staticElement; |
| 2659 InferStaticVariableTypeTask inferTask = | 2671 InferStaticVariableTypeTask inferTask = |
| 2660 new InferStaticVariableTypeTask(task.context, variable); | 2672 new InferStaticVariableTypeTask(task.context, variable); |
| 2661 expect(inferTask.getDeclaration(unit), declaration); | 2673 expect(inferTask.getDeclaration(unit), declaration); |
| 2662 } | 2674 } |
| 2663 | 2675 |
| 2664 void test_getDeclaration_topLevel() { | 2676 void test_getDeclaration_topLevel() { |
| 2665 AnalysisTarget source = newSource( | 2677 AnalysisTarget source = newSource( |
| 2666 '/test.dart', | 2678 '/test.dart', |
| 2667 ''' | 2679 ''' |
| 2668 var topLevel = ''; | 2680 var topLevel = ''; |
| 2669 '''); | 2681 '''); |
| 2670 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2682 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2671 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2683 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2672 VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel'); | 2684 VariableDeclaration declaration = |
| 2685 AstFinder.getTopLevelVariable(unit, 'topLevel'); |
| 2673 VariableElement variable = declaration.name.staticElement; | 2686 VariableElement variable = declaration.name.staticElement; |
| 2674 InferStaticVariableTypeTask inferTask = | 2687 InferStaticVariableTypeTask inferTask = |
| 2675 new InferStaticVariableTypeTask(task.context, variable); | 2688 new InferStaticVariableTypeTask(task.context, variable); |
| 2676 expect(inferTask.getDeclaration(unit), declaration); | 2689 expect(inferTask.getDeclaration(unit), declaration); |
| 2677 } | 2690 } |
| 2678 | 2691 |
| 2679 void test_perform() { | 2692 void test_perform() { |
| 2680 enableStrongMode(); | 2693 enableStrongMode(); |
| 2681 AnalysisTarget source = newSource( | 2694 AnalysisTarget source = newSource( |
| 2682 '/test3.dart', | 2695 '/test3.dart', |
| 2683 ''' | 2696 ''' |
| 2684 var topLevel3 = ''; | 2697 var topLevel3 = ''; |
| 2685 class C { | 2698 class C { |
| 2686 var field3 = topLevel3; | 2699 var field3 = topLevel3; |
| 2687 } | 2700 } |
| 2688 '''); | 2701 '''); |
| 2689 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2702 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2690 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2703 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2691 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3'); | 2704 VariableDeclaration topLevelDecl = |
| 2692 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3'); | 2705 AstFinder.getTopLevelVariable(unit, 'topLevel3'); |
| 2706 VariableDeclaration fieldDecl = |
| 2707 AstFinder.getFieldInClass(unit, 'C', 'field3'); |
| 2693 VariableElement topLevel = topLevelDecl.name.staticElement; | 2708 VariableElement topLevel = topLevelDecl.name.staticElement; |
| 2694 VariableElement field = fieldDecl.name.staticElement; | 2709 VariableElement field = fieldDecl.name.staticElement; |
| 2695 | 2710 |
| 2696 computeResult(field, INFERRED_STATIC_VARIABLE, | 2711 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 2697 matcher: isInferStaticVariableTypeTask); | 2712 matcher: isInferStaticVariableTypeTask); |
| 2698 InterfaceType stringType = context.typeProvider.stringType; | 2713 InterfaceType stringType = context.typeProvider.stringType; |
| 2699 expect(topLevel.type, stringType); | 2714 expect(topLevel.type, stringType); |
| 2700 expect(field.type, stringType); | 2715 expect(field.type, stringType); |
| 2701 expect(fieldDecl.initializer.staticType, stringType); | 2716 expect(fieldDecl.initializer.staticType, stringType); |
| 2702 } | 2717 } |
| 2703 | 2718 |
| 2704 void test_perform_const() { | 2719 void test_perform_const() { |
| 2705 enableStrongMode(); | 2720 enableStrongMode(); |
| 2706 AnalysisTarget source = newSource( | 2721 AnalysisTarget source = newSource( |
| 2707 '/test.dart', | 2722 '/test.dart', |
| 2708 ''' | 2723 ''' |
| 2709 const topLevel = "hello"; | 2724 const topLevel = "hello"; |
| 2710 class C { | 2725 class C { |
| 2711 var field = topLevel; | 2726 var field = topLevel; |
| 2712 } | 2727 } |
| 2713 '''); | 2728 '''); |
| 2714 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2729 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2715 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2730 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2716 VariableElement topLevel = | 2731 VariableElement topLevel = |
| 2717 getTopLevelVariable(unit, 'topLevel').name.staticElement; | 2732 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement; |
| 2718 VariableElement field = | 2733 VariableElement field = |
| 2719 getFieldInClass(unit, 'C', 'field').name.staticElement; | 2734 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement; |
| 2720 | 2735 |
| 2721 computeResult(field, INFERRED_STATIC_VARIABLE, | 2736 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 2722 matcher: isInferStaticVariableTypeTask); | 2737 matcher: isInferStaticVariableTypeTask); |
| 2723 InterfaceType stringType = context.typeProvider.stringType; | 2738 InterfaceType stringType = context.typeProvider.stringType; |
| 2724 expect(topLevel.type, stringType); | 2739 expect(topLevel.type, stringType); |
| 2725 expect(field.type, stringType); | 2740 expect(field.type, stringType); |
| 2726 } | 2741 } |
| 2727 | 2742 |
| 2728 void test_perform_cycle() { | 2743 void test_perform_cycle() { |
| 2729 enableStrongMode(); | 2744 enableStrongMode(); |
| 2730 AnalysisTarget source = newSource( | 2745 AnalysisTarget source = newSource( |
| 2731 '/test.dart', | 2746 '/test.dart', |
| 2732 ''' | 2747 ''' |
| 2733 var piFirst = true; | 2748 var piFirst = true; |
| 2734 var pi = piFirst ? 3.14 : tau / 2; | 2749 var pi = piFirst ? 3.14 : tau / 2; |
| 2735 var tau = piFirst ? pi * 2 : 6.28; | 2750 var tau = piFirst ? pi * 2 : 6.28; |
| 2736 '''); | 2751 '''); |
| 2737 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2752 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2738 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2753 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2739 VariableElement piFirst = | 2754 VariableElement piFirst = |
| 2740 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 2755 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 2741 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 2756 VariableElement pi = |
| 2742 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 2757 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; |
| 2758 VariableElement tau = |
| 2759 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; |
| 2743 | 2760 |
| 2744 computeResult(piFirst, INFERRED_STATIC_VARIABLE, | 2761 computeResult(piFirst, INFERRED_STATIC_VARIABLE, |
| 2745 matcher: isInferStaticVariableTypeTask); | 2762 matcher: isInferStaticVariableTypeTask); |
| 2746 expect(piFirst.type, context.typeProvider.boolType); | 2763 expect(piFirst.type, context.typeProvider.boolType); |
| 2747 expect(pi.type.isDynamic, isTrue); | 2764 expect(pi.type.isDynamic, isTrue); |
| 2748 expect(tau.type.isDynamic, isTrue); | 2765 expect(tau.type.isDynamic, isTrue); |
| 2749 } | 2766 } |
| 2750 | 2767 |
| 2751 void test_perform_error() { | 2768 void test_perform_error() { |
| 2752 enableStrongMode(); | 2769 enableStrongMode(); |
| 2753 AnalysisTarget source = newSource( | 2770 AnalysisTarget source = newSource( |
| 2754 '/test.dart', | 2771 '/test.dart', |
| 2755 ''' | 2772 ''' |
| 2756 var a = '' / null; | 2773 var a = '' / null; |
| 2757 '''); | 2774 '''); |
| 2758 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2775 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2759 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2776 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2760 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 2777 VariableElement a = |
| 2778 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; |
| 2761 | 2779 |
| 2762 computeResult(a, INFERRED_STATIC_VARIABLE, | 2780 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 2763 matcher: isInferStaticVariableTypeTask); | 2781 matcher: isInferStaticVariableTypeTask); |
| 2764 expect(a.type.isDynamic, isTrue); | 2782 expect(a.type.isDynamic, isTrue); |
| 2765 } | 2783 } |
| 2766 | 2784 |
| 2767 void test_perform_null() { | 2785 void test_perform_null() { |
| 2768 enableStrongMode(); | 2786 enableStrongMode(); |
| 2769 AnalysisTarget source = newSource( | 2787 AnalysisTarget source = newSource( |
| 2770 '/test.dart', | 2788 '/test.dart', |
| 2771 ''' | 2789 ''' |
| 2772 var a = null; | 2790 var a = null; |
| 2773 '''); | 2791 '''); |
| 2774 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2792 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2775 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2793 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2776 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 2794 VariableElement a = |
| 2795 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; |
| 2777 | 2796 |
| 2778 computeResult(a, INFERRED_STATIC_VARIABLE, | 2797 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 2779 matcher: isInferStaticVariableTypeTask); | 2798 matcher: isInferStaticVariableTypeTask); |
| 2780 expect(a.type.isDynamic, isTrue); | 2799 expect(a.type.isDynamic, isTrue); |
| 2781 } | 2800 } |
| 2782 } | 2801 } |
| 2783 | 2802 |
| 2784 @reflectiveTest | 2803 @reflectiveTest |
| 2785 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { | 2804 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { |
| 2786 test_perform() { | 2805 test_perform() { |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3150 final piFirst = true; | 3169 final piFirst = true; |
| 3151 final pi = piFirst ? 3.14 : tau / 2; | 3170 final pi = piFirst ? 3.14 : tau / 2; |
| 3152 final tau = piFirst ? pi * 2 : 6.28; | 3171 final tau = piFirst ? pi * 2 : 6.28; |
| 3153 '''); | 3172 '''); |
| 3154 // compute | 3173 // compute |
| 3155 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, | 3174 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, |
| 3156 matcher: isPropagateVariableTypesInUnitTask); | 3175 matcher: isPropagateVariableTypesInUnitTask); |
| 3157 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 3176 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
| 3158 // verify | 3177 // verify |
| 3159 TopLevelVariableElement piFirst = | 3178 TopLevelVariableElement piFirst = |
| 3160 getTopLevelVariableElement(unit, 'piFirst'); | 3179 AstFinder.getTopLevelVariableElement(unit, 'piFirst'); |
| 3161 TopLevelVariableElement pi = getTopLevelVariableElement(unit, 'pi'); | 3180 TopLevelVariableElement pi = |
| 3162 TopLevelVariableElement tau = getTopLevelVariableElement(unit, 'tau'); | 3181 AstFinder.getTopLevelVariableElement(unit, 'pi'); |
| 3182 TopLevelVariableElement tau = |
| 3183 AstFinder.getTopLevelVariableElement(unit, 'tau'); |
| 3163 expect(piFirst.propagatedType, context.typeProvider.boolType); | 3184 expect(piFirst.propagatedType, context.typeProvider.boolType); |
| 3164 expect(pi.propagatedType, isNull); | 3185 expect(pi.propagatedType, isNull); |
| 3165 expect(tau.propagatedType, isNull); | 3186 expect(tau.propagatedType, isNull); |
| 3166 } | 3187 } |
| 3167 | 3188 |
| 3168 void test_perform_topLevel() { | 3189 void test_perform_topLevel() { |
| 3169 AnalysisTarget source = newSource( | 3190 AnalysisTarget source = newSource( |
| 3170 '/test.dart', | 3191 '/test.dart', |
| 3171 ''' | 3192 ''' |
| 3172 //final a = b + c.length; | 3193 //final a = b + c.length; |
| 3173 final a = b; | 3194 final a = b; |
| 3174 final b = 1; | 3195 final b = 1; |
| 3175 final c = '2'; | 3196 final c = '2'; |
| 3176 '''); | 3197 '''); |
| 3177 // compute | 3198 // compute |
| 3178 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, | 3199 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, |
| 3179 matcher: isPropagateVariableTypesInUnitTask); | 3200 matcher: isPropagateVariableTypesInUnitTask); |
| 3180 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 3201 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
| 3181 // verify | 3202 // verify |
| 3182 InterfaceType intType = context.typeProvider.intType; | 3203 InterfaceType intType = context.typeProvider.intType; |
| 3183 InterfaceType stringType = context.typeProvider.stringType; | 3204 InterfaceType stringType = context.typeProvider.stringType; |
| 3184 expect(getTopLevelVariableElement(unit, 'a').propagatedType, intType); | 3205 expect(AstFinder.getTopLevelVariableElement(unit, 'a').propagatedType, |
| 3185 expect(getTopLevelVariableElement(unit, 'b').propagatedType, intType); | 3206 intType); |
| 3186 expect(getTopLevelVariableElement(unit, 'c').propagatedType, stringType); | 3207 expect(AstFinder.getTopLevelVariableElement(unit, 'b').propagatedType, |
| 3208 intType); |
| 3209 expect(AstFinder.getTopLevelVariableElement(unit, 'c').propagatedType, |
| 3210 stringType); |
| 3187 } | 3211 } |
| 3188 } | 3212 } |
| 3189 | 3213 |
| 3190 @reflectiveTest | 3214 @reflectiveTest |
| 3191 class PropagateVariableTypeTaskTest extends _AbstractDartTaskTest { | 3215 class PropagateVariableTypeTaskTest extends _AbstractDartTaskTest { |
| 3192 void test_perform_cycle() { | 3216 void test_perform_cycle() { |
| 3193 AnalysisTarget source = newSource( | 3217 AnalysisTarget source = newSource( |
| 3194 '/test.dart', | 3218 '/test.dart', |
| 3195 ''' | 3219 ''' |
| 3196 final piFirst = true; | 3220 final piFirst = true; |
| 3197 final pi = piFirst ? 3.14 : tau / 2; | 3221 final pi = piFirst ? 3.14 : tau / 2; |
| 3198 final tau = piFirst ? pi * 2 : 6.28; | 3222 final tau = piFirst ? pi * 2 : 6.28; |
| 3199 '''); | 3223 '''); |
| 3200 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 3224 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 3201 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3225 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 3202 TopLevelVariableElement piFirst = | 3226 TopLevelVariableElement piFirst = |
| 3203 getTopLevelVariableElement(unit, 'piFirst'); | 3227 AstFinder.getTopLevelVariableElement(unit, 'piFirst'); |
| 3204 TopLevelVariableElement pi = getTopLevelVariableElement(unit, 'pi'); | 3228 TopLevelVariableElement pi = |
| 3205 TopLevelVariableElement tau = getTopLevelVariableElement(unit, 'tau'); | 3229 AstFinder.getTopLevelVariableElement(unit, 'pi'); |
| 3230 TopLevelVariableElement tau = |
| 3231 AstFinder.getTopLevelVariableElement(unit, 'tau'); |
| 3206 // compute | 3232 // compute |
| 3207 computeResult(piFirst, PROPAGATED_VARIABLE, | 3233 computeResult(piFirst, PROPAGATED_VARIABLE, |
| 3208 matcher: isPropagateVariableTypeTask); | 3234 matcher: isPropagateVariableTypeTask); |
| 3209 expect(piFirst.propagatedType, context.typeProvider.boolType); | 3235 expect(piFirst.propagatedType, context.typeProvider.boolType); |
| 3210 expect(pi.propagatedType, isNull); | 3236 expect(pi.propagatedType, isNull); |
| 3211 expect(tau.propagatedType, isNull); | 3237 expect(tau.propagatedType, isNull); |
| 3212 } | 3238 } |
| 3213 | 3239 |
| 3214 void test_perform_null() { | 3240 void test_perform_null() { |
| 3215 enableStrongMode(); | 3241 enableStrongMode(); |
| 3216 AnalysisTarget source = newSource( | 3242 AnalysisTarget source = newSource( |
| 3217 '/test.dart', | 3243 '/test.dart', |
| 3218 ''' | 3244 ''' |
| 3219 var a = null; | 3245 var a = null; |
| 3220 '''); | 3246 '''); |
| 3221 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 3247 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 3222 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3248 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 3223 TopLevelVariableElement a = getTopLevelVariableElement(unit, 'a'); | 3249 TopLevelVariableElement a = AstFinder.getTopLevelVariableElement(unit, 'a'); |
| 3224 // compute | 3250 // compute |
| 3225 computeResult(a, PROPAGATED_VARIABLE, matcher: isPropagateVariableTypeTask); | 3251 computeResult(a, PROPAGATED_VARIABLE, matcher: isPropagateVariableTypeTask); |
| 3226 expect(a.propagatedType, isNull); | 3252 expect(a.propagatedType, isNull); |
| 3227 } | 3253 } |
| 3228 | 3254 |
| 3229 void test_perform_topLevel() { | 3255 void test_perform_topLevel() { |
| 3230 AnalysisTarget source = newSource( | 3256 AnalysisTarget source = newSource( |
| 3231 '/test.dart', | 3257 '/test.dart', |
| 3232 ''' | 3258 ''' |
| 3233 final a = b + c.length; | 3259 final a = b + c.length; |
| 3234 final b = 1; | 3260 final b = 1; |
| 3235 final c = '2'; | 3261 final c = '2'; |
| 3236 '''); | 3262 '''); |
| 3237 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 3263 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 3238 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3264 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 3239 TopLevelVariableElement elementA = getTopLevelVariableElement(unit, 'a'); | 3265 TopLevelVariableElement elementA = |
| 3240 TopLevelVariableElement elementB = getTopLevelVariableElement(unit, 'b'); | 3266 AstFinder.getTopLevelVariableElement(unit, 'a'); |
| 3241 TopLevelVariableElement elementC = getTopLevelVariableElement(unit, 'c'); | 3267 TopLevelVariableElement elementB = |
| 3268 AstFinder.getTopLevelVariableElement(unit, 'b'); |
| 3269 TopLevelVariableElement elementC = |
| 3270 AstFinder.getTopLevelVariableElement(unit, 'c'); |
| 3242 // compute | 3271 // compute |
| 3243 computeResult(elementA, PROPAGATED_VARIABLE, | 3272 computeResult(elementA, PROPAGATED_VARIABLE, |
| 3244 matcher: isPropagateVariableTypeTask); | 3273 matcher: isPropagateVariableTypeTask); |
| 3245 InterfaceType intType = context.typeProvider.intType; | 3274 InterfaceType intType = context.typeProvider.intType; |
| 3246 InterfaceType stringType = context.typeProvider.stringType; | 3275 InterfaceType stringType = context.typeProvider.stringType; |
| 3247 expect(elementA.propagatedType, intType); | 3276 expect(elementA.propagatedType, intType); |
| 3248 expect(elementB.propagatedType, intType); | 3277 expect(elementB.propagatedType, intType); |
| 3249 expect(elementC.propagatedType, stringType); | 3278 expect(elementC.propagatedType, stringType); |
| 3250 } | 3279 } |
| 3251 } | 3280 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3283 }); | 3312 }); |
| 3284 InterfaceType intType = context.typeProvider.intType; | 3313 InterfaceType intType = context.typeProvider.intType; |
| 3285 DartType dynamicType = context.typeProvider.dynamicType; | 3314 DartType dynamicType = context.typeProvider.dynamicType; |
| 3286 | 3315 |
| 3287 computeResult( | 3316 computeResult( |
| 3288 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); | 3317 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); |
| 3289 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; | 3318 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; |
| 3290 | 3319 |
| 3291 // B.b2 shoud be resolved on the rhs, but not yet inferred. | 3320 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 3292 assertVariableDeclarationTypes( | 3321 assertVariableDeclarationTypes( |
| 3293 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); | 3322 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType); |
| 3294 | 3323 |
| 3295 computeResult( | 3324 computeResult( |
| 3296 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); | 3325 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); |
| 3297 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; | 3326 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; |
| 3298 | 3327 |
| 3299 // B.b2 should now be fully resolved and inferred. | 3328 // B.b2 should now be fully resolved and inferred. |
| 3300 assertVariableDeclarationTypes( | 3329 assertVariableDeclarationTypes( |
| 3301 getFieldInClass(unit1, "B", "b2"), intType, intType); | 3330 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3302 | 3331 |
| 3303 // A.a2 should now be resolved on the rhs, but not yet inferred. | 3332 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3304 assertVariableDeclarationTypes( | 3333 assertVariableDeclarationTypes( |
| 3305 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 3334 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3306 | 3335 |
| 3307 computeResult( | 3336 computeResult( |
| 3308 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); | 3337 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); |
| 3309 | 3338 |
| 3310 // A.a2 should now be fully resolved and inferred. | 3339 // A.a2 should now be fully resolved and inferred. |
| 3311 assertVariableDeclarationTypes( | 3340 assertVariableDeclarationTypes( |
| 3312 getFieldInClass(unit0, "A", "a2"), intType, intType); | 3341 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3313 | 3342 |
| 3314 assertVariableDeclarationTypes( | 3343 assertVariableDeclarationTypes( |
| 3315 getFieldInClass(unit1, "B", "b2"), intType, intType); | 3344 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3316 } | 3345 } |
| 3317 | 3346 |
| 3318 // Test inference of instance fields across units | 3347 // Test inference of instance fields across units |
| 3319 void test_perform_inference_cross_unit_instance_cyclic() { | 3348 void test_perform_inference_cross_unit_instance_cyclic() { |
| 3320 List<Source> sources = newSources({ | 3349 List<Source> sources = newSources({ |
| 3321 '/a.dart': ''' | 3350 '/a.dart': ''' |
| 3322 import 'b.dart'; | 3351 import 'b.dart'; |
| 3323 class A { | 3352 class A { |
| 3324 final a2 = new B().b2; | 3353 final a2 = new B().b2; |
| 3325 } | 3354 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3340 ''' | 3369 ''' |
| 3341 }); | 3370 }); |
| 3342 DartType dynamicType = context.typeProvider.dynamicType; | 3371 DartType dynamicType = context.typeProvider.dynamicType; |
| 3343 | 3372 |
| 3344 computeResult( | 3373 computeResult( |
| 3345 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); | 3374 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); |
| 3346 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; | 3375 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; |
| 3347 | 3376 |
| 3348 // A.a2 should now be resolved on the rhs, but not yet inferred. | 3377 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3349 assertVariableDeclarationTypes( | 3378 assertVariableDeclarationTypes( |
| 3350 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3379 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3351 | 3380 |
| 3352 computeResult( | 3381 computeResult( |
| 3353 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); | 3382 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); |
| 3354 | 3383 |
| 3355 // A.a2 should now be fully resolved and inferred. | 3384 // A.a2 should now be fully resolved and inferred. |
| 3356 assertVariableDeclarationTypes( | 3385 assertVariableDeclarationTypes( |
| 3357 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3386 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3358 } | 3387 } |
| 3359 | 3388 |
| 3360 // Test inference of instance fields across units with cycles | 3389 // Test inference of instance fields across units with cycles |
| 3361 void test_perform_inference_cross_unit_static_instance() { | 3390 void test_perform_inference_cross_unit_static_instance() { |
| 3362 List<Source> sources = newSources({ | 3391 List<Source> sources = newSources({ |
| 3363 '/a.dart': ''' | 3392 '/a.dart': ''' |
| 3364 import 'b.dart'; | 3393 import 'b.dart'; |
| 3365 class A { | 3394 class A { |
| 3366 static final a1 = B.b1; | 3395 static final a1 = B.b1; |
| 3367 final a2 = new B().b2; | 3396 final a2 = new B().b2; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3385 ''' | 3414 ''' |
| 3386 }); | 3415 }); |
| 3387 InterfaceType intType = context.typeProvider.intType; | 3416 InterfaceType intType = context.typeProvider.intType; |
| 3388 DartType dynamicType = context.typeProvider.dynamicType; | 3417 DartType dynamicType = context.typeProvider.dynamicType; |
| 3389 | 3418 |
| 3390 computeResult( | 3419 computeResult( |
| 3391 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); | 3420 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); |
| 3392 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; | 3421 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; |
| 3393 | 3422 |
| 3394 assertVariableDeclarationTypes( | 3423 assertVariableDeclarationTypes( |
| 3395 getFieldInClass(unit1, "B", "b1"), intType, intType); | 3424 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3396 assertVariableDeclarationTypes( | 3425 assertVariableDeclarationTypes( |
| 3397 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); | 3426 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType); |
| 3398 | 3427 |
| 3399 computeResult( | 3428 computeResult( |
| 3400 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); | 3429 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); |
| 3401 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; | 3430 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; |
| 3402 | 3431 |
| 3403 assertVariableDeclarationTypes( | 3432 assertVariableDeclarationTypes( |
| 3404 getFieldInClass(unit0, "A", "a1"), intType, intType); | 3433 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3405 assertVariableDeclarationTypes( | 3434 assertVariableDeclarationTypes( |
| 3406 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 3435 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3407 | 3436 |
| 3408 assertVariableDeclarationTypes( | 3437 assertVariableDeclarationTypes( |
| 3409 getFieldInClass(unit1, "B", "b1"), intType, intType); | 3438 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3410 assertVariableDeclarationTypes( | 3439 assertVariableDeclarationTypes( |
| 3411 getFieldInClass(unit1, "B", "b2"), intType, intType); | 3440 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3412 | 3441 |
| 3413 computeResult( | 3442 computeResult( |
| 3414 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); | 3443 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); |
| 3415 | 3444 |
| 3416 assertVariableDeclarationTypes( | 3445 assertVariableDeclarationTypes( |
| 3417 getFieldInClass(unit0, "A", "a1"), intType, intType); | 3446 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3418 assertVariableDeclarationTypes( | 3447 assertVariableDeclarationTypes( |
| 3419 getFieldInClass(unit0, "A", "a2"), intType, intType); | 3448 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3420 | 3449 |
| 3421 assertVariableDeclarationTypes( | 3450 assertVariableDeclarationTypes( |
| 3422 getFieldInClass(unit1, "B", "b1"), intType, intType); | 3451 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3423 assertVariableDeclarationTypes( | 3452 assertVariableDeclarationTypes( |
| 3424 getFieldInClass(unit1, "B", "b2"), intType, intType); | 3453 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3425 } | 3454 } |
| 3426 | 3455 |
| 3427 // Test inference between static and instance fields | 3456 // Test inference between static and instance fields |
| 3428 void test_perform_inference_instance() { | 3457 void test_perform_inference_instance() { |
| 3429 List<Source> sources = newSources({ | 3458 List<Source> sources = newSources({ |
| 3430 '/a.dart': ''' | 3459 '/a.dart': ''' |
| 3431 import 'b.dart'; | 3460 import 'b.dart'; |
| 3432 class A { | 3461 class A { |
| 3433 final a2 = new B().b2; | 3462 final a2 = new B().b2; |
| 3434 } | 3463 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3448 }); | 3477 }); |
| 3449 InterfaceType intType = context.typeProvider.intType; | 3478 InterfaceType intType = context.typeProvider.intType; |
| 3450 DartType dynamicType = context.typeProvider.dynamicType; | 3479 DartType dynamicType = context.typeProvider.dynamicType; |
| 3451 | 3480 |
| 3452 computeResult( | 3481 computeResult( |
| 3453 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); | 3482 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); |
| 3454 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; | 3483 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; |
| 3455 | 3484 |
| 3456 // A.a2 should now be resolved on the rhs, but not yet inferred. | 3485 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3457 assertVariableDeclarationTypes( | 3486 assertVariableDeclarationTypes( |
| 3458 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3487 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3459 | 3488 |
| 3460 // B.b2 shoud be resolved on the rhs, but not yet inferred. | 3489 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 3461 assertVariableDeclarationTypes( | 3490 assertVariableDeclarationTypes( |
| 3462 getFieldInClass(unit0, "B", "b2"), dynamicType, intType); | 3491 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType); |
| 3463 | 3492 |
| 3464 computeResult( | 3493 computeResult( |
| 3465 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); | 3494 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); |
| 3466 | 3495 |
| 3467 // A.a2 should now be fully resolved and inferred. | 3496 // A.a2 should now be fully resolved and inferred. |
| 3468 assertVariableDeclarationTypes( | 3497 assertVariableDeclarationTypes( |
| 3469 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3498 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3470 | 3499 |
| 3471 // B.b2 should now be fully resolved and inferred. | 3500 // B.b2 should now be fully resolved and inferred. |
| 3472 assertVariableDeclarationTypes( | 3501 assertVariableDeclarationTypes( |
| 3473 getFieldInClass(unit0, "B", "b2"), intType, intType); | 3502 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 3474 } | 3503 } |
| 3475 } | 3504 } |
| 3476 | 3505 |
| 3477 @reflectiveTest | 3506 @reflectiveTest |
| 3478 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { | 3507 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 3479 test_perform() { | 3508 test_perform() { |
| 3480 Source sourceLib = newSource( | 3509 Source sourceLib = newSource( |
| 3481 '/my_lib.dart', | 3510 '/my_lib.dart', |
| 3482 ''' | 3511 ''' |
| 3483 library my_lib; | 3512 library my_lib; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3830 AnalysisTarget source = newSource( | 3859 AnalysisTarget source = newSource( |
| 3831 '/test.dart', | 3860 '/test.dart', |
| 3832 ''' | 3861 ''' |
| 3833 var piFirst = true; | 3862 var piFirst = true; |
| 3834 var pi = piFirst ? 3.14 : tau / 2; | 3863 var pi = piFirst ? 3.14 : tau / 2; |
| 3835 var tau = piFirst ? pi * 2 : 6.28; | 3864 var tau = piFirst ? pi * 2 : 6.28; |
| 3836 '''); | 3865 '''); |
| 3837 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 3866 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 3838 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 3867 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 3839 VariableElement piFirst = | 3868 VariableElement piFirst = |
| 3840 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 3869 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 3841 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 3870 VariableElement pi = |
| 3842 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 3871 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; |
| 3843 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer | 3872 VariableElement tau = |
| 3844 as ConditionalExpression).condition; | 3873 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; |
| 3874 Expression piFirstUse = (AstFinder |
| 3875 .getTopLevelVariable(unit, 'tau') |
| 3876 .initializer as ConditionalExpression).condition; |
| 3845 | 3877 |
| 3846 expect(piFirstUse.staticType, context.typeProvider.boolType); | 3878 expect(piFirstUse.staticType, context.typeProvider.boolType); |
| 3847 expect(piFirst.type, context.typeProvider.boolType); | 3879 expect(piFirst.type, context.typeProvider.boolType); |
| 3848 expect(pi.type.isDynamic, isTrue); | 3880 expect(pi.type.isDynamic, isTrue); |
| 3849 expect(tau.type.isDynamic, isTrue); | 3881 expect(tau.type.isDynamic, isTrue); |
| 3850 } | 3882 } |
| 3851 | 3883 |
| 3852 void test_perform_inference_cross_unit_cyclic() { | 3884 void test_perform_inference_cross_unit_cyclic() { |
| 3853 AnalysisTarget firstSource = newSource( | 3885 AnalysisTarget firstSource = newSource( |
| 3854 '/a.dart', | 3886 '/a.dart', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3875 computeResult( | 3907 computeResult( |
| 3876 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10); | 3908 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10); |
| 3877 CompilationUnit unit1 = outputs[RESOLVED_UNIT10]; | 3909 CompilationUnit unit1 = outputs[RESOLVED_UNIT10]; |
| 3878 computeResult( | 3910 computeResult( |
| 3879 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); | 3911 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); |
| 3880 CompilationUnit unit2 = outputs[RESOLVED_UNIT10]; | 3912 CompilationUnit unit2 = outputs[RESOLVED_UNIT10]; |
| 3881 | 3913 |
| 3882 InterfaceType intType = context.typeProvider.intType; | 3914 InterfaceType intType = context.typeProvider.intType; |
| 3883 | 3915 |
| 3884 assertVariableDeclarationTypes( | 3916 assertVariableDeclarationTypes( |
| 3885 getTopLevelVariable(unit1, "x"), intType, intType); | 3917 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType); |
| 3886 assertVariableDeclarationTypes( | 3918 assertVariableDeclarationTypes( |
| 3887 getFieldInClass(unit1, "A", "x"), intType, intType); | 3919 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType); |
| 3888 | 3920 |
| 3889 assertVariableDeclarationTypes( | 3921 assertVariableDeclarationTypes( |
| 3890 getTopLevelVariable(unit2, "y"), intType, intType); | 3922 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType); |
| 3891 assertVariableDeclarationTypes( | 3923 assertVariableDeclarationTypes( |
| 3892 getFieldInClass(unit2, "B", "y"), intType, intType); | 3924 AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType); |
| 3893 | 3925 |
| 3894 List<Statement> statements = | 3926 List<Statement> statements = |
| 3895 getStatementsInTopLevelFunction(unit2, "test1"); | 3927 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 3896 | 3928 |
| 3897 assertAssignmentStatementTypes(statements[1], intType, intType); | 3929 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3898 assertAssignmentStatementTypes(statements[2], intType, intType); | 3930 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3899 assertAssignmentStatementTypes(statements[3], intType, intType); | 3931 assertAssignmentStatementTypes(statements[3], intType, intType); |
| 3900 assertAssignmentStatementTypes(statements[4], intType, intType); | 3932 assertAssignmentStatementTypes(statements[4], intType, intType); |
| 3901 } | 3933 } |
| 3902 | 3934 |
| 3903 // Test that local variables in method bodies are inferred appropriately | 3935 // Test that local variables in method bodies are inferred appropriately |
| 3904 void test_perform_inference_cross_unit_instance() { | 3936 void test_perform_inference_cross_unit_instance() { |
| 3905 List<Source> sources = newSources({ | 3937 List<Source> sources = newSources({ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3925 }); | 3957 }); |
| 3926 List<dynamic> units = | 3958 List<dynamic> units = |
| 3927 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); | 3959 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); |
| 3928 CompilationUnit unit0 = units[0]; | 3960 CompilationUnit unit0 = units[0]; |
| 3929 CompilationUnit unit1 = units[1]; | 3961 CompilationUnit unit1 = units[1]; |
| 3930 CompilationUnit unit2 = units[2]; | 3962 CompilationUnit unit2 = units[2]; |
| 3931 | 3963 |
| 3932 InterfaceType intType = context.typeProvider.intType; | 3964 InterfaceType intType = context.typeProvider.intType; |
| 3933 | 3965 |
| 3934 assertVariableDeclarationTypes( | 3966 assertVariableDeclarationTypes( |
| 3935 getFieldInClass(unit0, "A", "a2"), intType, intType); | 3967 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3936 | 3968 |
| 3937 assertVariableDeclarationTypes( | 3969 assertVariableDeclarationTypes( |
| 3938 getFieldInClass(unit1, "B", "b2"), intType, intType); | 3970 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3939 | 3971 |
| 3940 List<Statement> statements = | 3972 List<Statement> statements = |
| 3941 getStatementsInTopLevelFunction(unit2, "test1"); | 3973 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 3942 | 3974 |
| 3943 assertAssignmentStatementTypes(statements[1], intType, intType); | 3975 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3944 } | 3976 } |
| 3945 | 3977 |
| 3946 // Test inference interactions between local variables and fields | 3978 // Test inference interactions between local variables and fields |
| 3947 void test_perform_inference_cross_unit_instance_member() { | 3979 void test_perform_inference_cross_unit_instance_member() { |
| 3948 List<Source> sources = newSources({ | 3980 List<Source> sources = newSources({ |
| 3949 '/a.dart': ''' | 3981 '/a.dart': ''' |
| 3950 import 'b.dart'; | 3982 import 'b.dart'; |
| 3951 var bar = new B(); | 3983 var bar = new B(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3972 }); | 4004 }); |
| 3973 List<dynamic> units = | 4005 List<dynamic> units = |
| 3974 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); | 4006 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); |
| 3975 CompilationUnit unit0 = units[0]; | 4007 CompilationUnit unit0 = units[0]; |
| 3976 CompilationUnit unit2 = units[2]; | 4008 CompilationUnit unit2 = units[2]; |
| 3977 | 4009 |
| 3978 InterfaceType intType = context.typeProvider.intType; | 4010 InterfaceType intType = context.typeProvider.intType; |
| 3979 InterfaceType stringType = context.typeProvider.stringType; | 4011 InterfaceType stringType = context.typeProvider.stringType; |
| 3980 | 4012 |
| 3981 assertVariableDeclarationStatementTypes( | 4013 assertVariableDeclarationStatementTypes( |
| 3982 getStatementsInTopLevelFunction(unit0, "foo")[0], stringType, intType); | 4014 AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0], |
| 4015 stringType, |
| 4016 intType); |
| 3983 assertVariableDeclarationStatementTypes( | 4017 assertVariableDeclarationStatementTypes( |
| 3984 getStatementsInTopLevelFunction(unit2, "foo")[0], stringType, intType); | 4018 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0], |
| 4019 stringType, |
| 4020 intType); |
| 3985 } | 4021 } |
| 3986 | 4022 |
| 3987 // Test inference interactions between local variables and top level | 4023 // Test inference interactions between local variables and top level |
| 3988 // variables | 4024 // variables |
| 3989 void test_perform_inference_cross_unit_non_cyclic() { | 4025 void test_perform_inference_cross_unit_non_cyclic() { |
| 3990 AnalysisTarget firstSource = newSource( | 4026 AnalysisTarget firstSource = newSource( |
| 3991 '/a.dart', | 4027 '/a.dart', |
| 3992 ''' | 4028 ''' |
| 3993 var x = 2; | 4029 var x = 2; |
| 3994 class A { static var x = 2; } | 4030 class A { static var x = 2; } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4011 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10); | 4047 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10); |
| 4012 CompilationUnit unit1 = outputs[RESOLVED_UNIT10]; | 4048 CompilationUnit unit1 = outputs[RESOLVED_UNIT10]; |
| 4013 computeResult( | 4049 computeResult( |
| 4014 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); | 4050 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); |
| 4015 CompilationUnit unit2 = outputs[RESOLVED_UNIT10]; | 4051 CompilationUnit unit2 = outputs[RESOLVED_UNIT10]; |
| 4016 | 4052 |
| 4017 InterfaceType intType = context.typeProvider.intType; | 4053 InterfaceType intType = context.typeProvider.intType; |
| 4018 InterfaceType stringType = context.typeProvider.stringType; | 4054 InterfaceType stringType = context.typeProvider.stringType; |
| 4019 | 4055 |
| 4020 assertVariableDeclarationTypes( | 4056 assertVariableDeclarationTypes( |
| 4021 getTopLevelVariable(unit1, "x"), intType, intType); | 4057 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType); |
| 4022 assertVariableDeclarationTypes( | 4058 assertVariableDeclarationTypes( |
| 4023 getFieldInClass(unit1, "A", "x"), intType, intType); | 4059 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType); |
| 4024 | 4060 |
| 4025 assertVariableDeclarationTypes( | 4061 assertVariableDeclarationTypes( |
| 4026 getTopLevelVariable(unit2, "y"), intType, intType); | 4062 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType); |
| 4027 assertVariableDeclarationTypes( | 4063 assertVariableDeclarationTypes( |
| 4028 getFieldInClass(unit2, "B", "y"), intType, intType); | 4064 AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType); |
| 4029 | 4065 |
| 4030 List<Statement> statements = | 4066 List<Statement> statements = |
| 4031 getStatementsInTopLevelFunction(unit2, "test1"); | 4067 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 4032 | 4068 |
| 4033 assertAssignmentStatementTypes(statements[0], intType, stringType); | 4069 assertAssignmentStatementTypes(statements[0], intType, stringType); |
| 4034 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4070 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4035 } | 4071 } |
| 4036 | 4072 |
| 4037 // Test that inference does not propagate from null | 4073 // Test that inference does not propagate from null |
| 4038 void test_perform_inference_cross_unit_static_instance() { | 4074 void test_perform_inference_cross_unit_static_instance() { |
| 4039 List<Source> sources = newSources({ | 4075 List<Source> sources = newSources({ |
| 4040 '/a.dart': ''' | 4076 '/a.dart': ''' |
| 4041 import 'b.dart'; | 4077 import 'b.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4063 }); | 4099 }); |
| 4064 List<dynamic> units = | 4100 List<dynamic> units = |
| 4065 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); | 4101 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); |
| 4066 CompilationUnit unit0 = units[0]; | 4102 CompilationUnit unit0 = units[0]; |
| 4067 CompilationUnit unit1 = units[1]; | 4103 CompilationUnit unit1 = units[1]; |
| 4068 CompilationUnit unit2 = units[2]; | 4104 CompilationUnit unit2 = units[2]; |
| 4069 | 4105 |
| 4070 InterfaceType intType = context.typeProvider.intType; | 4106 InterfaceType intType = context.typeProvider.intType; |
| 4071 | 4107 |
| 4072 assertVariableDeclarationTypes( | 4108 assertVariableDeclarationTypes( |
| 4073 getFieldInClass(unit0, "A", "a1"), intType, intType); | 4109 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 4074 assertVariableDeclarationTypes( | 4110 assertVariableDeclarationTypes( |
| 4075 getFieldInClass(unit0, "A", "a2"), intType, intType); | 4111 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 4076 | 4112 |
| 4077 assertVariableDeclarationTypes( | 4113 assertVariableDeclarationTypes( |
| 4078 getFieldInClass(unit1, "B", "b1"), intType, intType); | 4114 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 4079 assertVariableDeclarationTypes( | 4115 assertVariableDeclarationTypes( |
| 4080 getFieldInClass(unit1, "B", "b2"), intType, intType); | 4116 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 4081 | 4117 |
| 4082 List<Statement> statements = | 4118 List<Statement> statements = |
| 4083 getStatementsInTopLevelFunction(unit2, "test1"); | 4119 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 4084 | 4120 |
| 4085 assertAssignmentStatementTypes(statements[1], intType, intType); | 4121 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 4086 assertAssignmentStatementTypes(statements[2], intType, intType); | 4122 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 4087 } | 4123 } |
| 4088 | 4124 |
| 4089 // Test inference across units (non-cyclic) | 4125 // Test inference across units (non-cyclic) |
| 4090 void test_perform_inference_local_variables() { | 4126 void test_perform_inference_local_variables() { |
| 4091 AnalysisTarget source = newSource( | 4127 AnalysisTarget source = newSource( |
| 4092 '/test.dart', | 4128 '/test.dart', |
| 4093 ''' | 4129 ''' |
| 4094 test() { | 4130 test() { |
| 4095 int x = 3; | 4131 int x = 3; |
| 4096 x = "hi"; | 4132 x = "hi"; |
| 4097 var y = 3; | 4133 var y = 3; |
| 4098 y = "hi"; | 4134 y = "hi"; |
| 4099 } | 4135 } |
| 4100 '''); | 4136 '''); |
| 4101 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 4137 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 4102 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 4138 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 4103 | 4139 |
| 4104 InterfaceType intType = context.typeProvider.intType; | 4140 InterfaceType intType = context.typeProvider.intType; |
| 4105 InterfaceType stringType = context.typeProvider.stringType; | 4141 InterfaceType stringType = context.typeProvider.stringType; |
| 4106 | 4142 |
| 4107 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 4143 List<Statement> statements = |
| 4144 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 4108 | 4145 |
| 4109 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 4146 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 4110 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4147 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4111 assertVariableDeclarationStatementTypes(statements[2], intType, intType); | 4148 assertVariableDeclarationStatementTypes(statements[2], intType, intType); |
| 4112 assertAssignmentStatementTypes(statements[3], intType, stringType); | 4149 assertAssignmentStatementTypes(statements[3], intType, stringType); |
| 4113 } | 4150 } |
| 4114 | 4151 |
| 4115 // Test inference across units (cyclic) | 4152 // Test inference across units (cyclic) |
| 4116 void test_perform_inference_local_variables_fields() { | 4153 void test_perform_inference_local_variables_fields() { |
| 4117 AnalysisTarget source = newSource( | 4154 AnalysisTarget source = newSource( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4135 int y; // field def after use | 4172 int y; // field def after use |
| 4136 final z = 42; // should infer `int` | 4173 final z = 42; // should infer `int` |
| 4137 } | 4174 } |
| 4138 '''); | 4175 '''); |
| 4139 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 4176 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 4140 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 4177 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 4141 | 4178 |
| 4142 InterfaceType intType = context.typeProvider.intType; | 4179 InterfaceType intType = context.typeProvider.intType; |
| 4143 InterfaceType stringType = context.typeProvider.stringType; | 4180 InterfaceType stringType = context.typeProvider.stringType; |
| 4144 | 4181 |
| 4145 List<Statement> statements = getStatementsInMethod(unit, "A", "test1"); | 4182 List<Statement> statements = |
| 4183 AstFinder.getStatementsInMethod(unit, "A", "test1"); |
| 4146 | 4184 |
| 4147 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 4185 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 4148 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4186 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4149 assertAssignmentStatementTypes(statements[2], intType, intType); | 4187 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 4150 | 4188 |
| 4151 assertVariableDeclarationStatementTypes(statements[3], intType, intType); | 4189 assertVariableDeclarationStatementTypes(statements[3], intType, intType); |
| 4152 assertAssignmentStatementTypes(statements[4], intType, stringType); | 4190 assertAssignmentStatementTypes(statements[4], intType, stringType); |
| 4153 assertAssignmentStatementTypes(statements[5], intType, intType); | 4191 assertAssignmentStatementTypes(statements[5], intType, intType); |
| 4154 | 4192 |
| 4155 assertVariableDeclarationStatementTypes(statements[6], intType, intType); | 4193 assertVariableDeclarationStatementTypes(statements[6], intType, intType); |
| 4156 assertAssignmentStatementTypes(statements[7], intType, stringType); | 4194 assertAssignmentStatementTypes(statements[7], intType, stringType); |
| 4157 assertAssignmentStatementTypes(statements[8], intType, intType); | 4195 assertAssignmentStatementTypes(statements[8], intType, intType); |
| 4158 | 4196 |
| 4159 assertVariableDeclarationTypes( | 4197 assertVariableDeclarationTypes( |
| 4160 getFieldInClass(unit, "A", "x"), intType, intType); | 4198 AstFinder.getFieldInClass(unit, "A", "x"), intType, intType); |
| 4161 assertVariableDeclarationTypes( | 4199 assertVariableDeclarationTypes( |
| 4162 getFieldInClass(unit, "A", "z"), intType, intType); | 4200 AstFinder.getFieldInClass(unit, "A", "z"), intType, intType); |
| 4163 } | 4201 } |
| 4164 | 4202 |
| 4165 // Test inference of instance fields across units | 4203 // Test inference of instance fields across units |
| 4166 void test_perform_inference_local_variables_topLevel() { | 4204 void test_perform_inference_local_variables_topLevel() { |
| 4167 AnalysisTarget source = newSource( | 4205 AnalysisTarget source = newSource( |
| 4168 '/test.dart', | 4206 '/test.dart', |
| 4169 ''' | 4207 ''' |
| 4170 int x = 0; | 4208 int x = 0; |
| 4171 | 4209 |
| 4172 test1() { | 4210 test1() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4183 | 4221 |
| 4184 int y = 0; // field def after use | 4222 int y = 0; // field def after use |
| 4185 final z = 42; // should infer `int` | 4223 final z = 42; // should infer `int` |
| 4186 '''); | 4224 '''); |
| 4187 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 4225 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 4188 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 4226 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 4189 | 4227 |
| 4190 InterfaceType intType = context.typeProvider.intType; | 4228 InterfaceType intType = context.typeProvider.intType; |
| 4191 InterfaceType stringType = context.typeProvider.stringType; | 4229 InterfaceType stringType = context.typeProvider.stringType; |
| 4192 | 4230 |
| 4193 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1"); | 4231 List<Statement> statements = |
| 4232 AstFinder.getStatementsInTopLevelFunction(unit, "test1"); |
| 4194 | 4233 |
| 4195 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 4234 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 4196 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4235 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4197 assertAssignmentStatementTypes(statements[2], intType, intType); | 4236 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 4198 | 4237 |
| 4199 assertVariableDeclarationStatementTypes(statements[3], intType, intType); | 4238 assertVariableDeclarationStatementTypes(statements[3], intType, intType); |
| 4200 assertAssignmentStatementTypes(statements[4], intType, stringType); | 4239 assertAssignmentStatementTypes(statements[4], intType, stringType); |
| 4201 assertAssignmentStatementTypes(statements[5], intType, intType); | 4240 assertAssignmentStatementTypes(statements[5], intType, intType); |
| 4202 | 4241 |
| 4203 assertVariableDeclarationStatementTypes(statements[6], intType, intType); | 4242 assertVariableDeclarationStatementTypes(statements[6], intType, intType); |
| 4204 assertAssignmentStatementTypes(statements[7], intType, stringType); | 4243 assertAssignmentStatementTypes(statements[7], intType, stringType); |
| 4205 assertAssignmentStatementTypes(statements[8], intType, intType); | 4244 assertAssignmentStatementTypes(statements[8], intType, intType); |
| 4206 | 4245 |
| 4207 assertVariableDeclarationTypes( | 4246 assertVariableDeclarationTypes( |
| 4208 getTopLevelVariable(unit, "x"), intType, intType); | 4247 AstFinder.getTopLevelVariable(unit, "x"), intType, intType); |
| 4209 assertVariableDeclarationTypes( | 4248 assertVariableDeclarationTypes( |
| 4210 getTopLevelVariable(unit, "y"), intType, intType); | 4249 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); |
| 4211 assertVariableDeclarationTypes( | 4250 assertVariableDeclarationTypes( |
| 4212 getTopLevelVariable(unit, "z"), intType, intType); | 4251 AstFinder.getTopLevelVariable(unit, "z"), intType, intType); |
| 4213 } | 4252 } |
| 4214 | 4253 |
| 4215 // Test inference between static and instance fields | 4254 // Test inference between static and instance fields |
| 4216 void test_perform_inference_null() { | 4255 void test_perform_inference_null() { |
| 4217 AnalysisTarget source = newSource( | 4256 AnalysisTarget source = newSource( |
| 4218 '/test.dart', | 4257 '/test.dart', |
| 4219 ''' | 4258 ''' |
| 4220 var x = null; | 4259 var x = null; |
| 4221 var y = 3; | 4260 var y = 3; |
| 4222 class A { | 4261 class A { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4238 '''); | 4277 '''); |
| 4239 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 4278 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 4240 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 4279 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 4241 | 4280 |
| 4242 InterfaceType intType = context.typeProvider.intType; | 4281 InterfaceType intType = context.typeProvider.intType; |
| 4243 InterfaceType stringType = context.typeProvider.stringType; | 4282 InterfaceType stringType = context.typeProvider.stringType; |
| 4244 DartType bottomType = context.typeProvider.bottomType; | 4283 DartType bottomType = context.typeProvider.bottomType; |
| 4245 DartType dynamicType = context.typeProvider.dynamicType; | 4284 DartType dynamicType = context.typeProvider.dynamicType; |
| 4246 | 4285 |
| 4247 assertVariableDeclarationTypes( | 4286 assertVariableDeclarationTypes( |
| 4248 getTopLevelVariable(unit, "x"), dynamicType, bottomType); | 4287 AstFinder.getTopLevelVariable(unit, "x"), dynamicType, bottomType); |
| 4249 assertVariableDeclarationTypes( | 4288 assertVariableDeclarationTypes( |
| 4250 getTopLevelVariable(unit, "y"), intType, intType); | 4289 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); |
| 4251 assertVariableDeclarationTypes( | 4290 assertVariableDeclarationTypes( |
| 4252 getFieldInClass(unit, "A", "x"), dynamicType, bottomType); | 4291 AstFinder.getFieldInClass(unit, "A", "x"), dynamicType, bottomType); |
| 4253 assertVariableDeclarationTypes( | 4292 assertVariableDeclarationTypes( |
| 4254 getFieldInClass(unit, "A", "y"), intType, intType); | 4293 AstFinder.getFieldInClass(unit, "A", "y"), intType, intType); |
| 4255 assertVariableDeclarationTypes( | 4294 assertVariableDeclarationTypes( |
| 4256 getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); | 4295 AstFinder.getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); |
| 4257 assertVariableDeclarationTypes( | 4296 assertVariableDeclarationTypes( |
| 4258 getFieldInClass(unit, "A", "y2"), intType, intType); | 4297 AstFinder.getFieldInClass(unit, "A", "y2"), intType, intType); |
| 4259 | 4298 |
| 4260 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 4299 List<Statement> statements = |
| 4300 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 4261 | 4301 |
| 4262 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); | 4302 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); |
| 4263 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4303 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4264 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); | 4304 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); |
| 4265 assertAssignmentStatementTypes(statements[3], intType, stringType); | 4305 assertAssignmentStatementTypes(statements[3], intType, stringType); |
| 4266 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); | 4306 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); |
| 4267 assertAssignmentStatementTypes(statements[5], intType, stringType); | 4307 assertAssignmentStatementTypes(statements[5], intType, stringType); |
| 4268 } | 4308 } |
| 4269 | 4309 |
| 4270 // Test inference between fields and method bodies | 4310 // Test inference between fields and method bodies |
| 4271 void test_perform_local_explicit_disabled() { | 4311 void test_perform_local_explicit_disabled() { |
| 4272 AnalysisTarget source = newSource( | 4312 AnalysisTarget source = newSource( |
| 4273 '/test.dart', | 4313 '/test.dart', |
| 4274 ''' | 4314 ''' |
| 4275 test() { | 4315 test() { |
| 4276 int x = 3; | 4316 int x = 3; |
| 4277 x = "hi"; | 4317 x = "hi"; |
| 4278 } | 4318 } |
| 4279 '''); | 4319 '''); |
| 4280 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 4320 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 4281 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 4321 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 4282 | 4322 |
| 4283 InterfaceType intType = context.typeProvider.intType; | 4323 InterfaceType intType = context.typeProvider.intType; |
| 4284 InterfaceType stringType = context.typeProvider.stringType; | 4324 InterfaceType stringType = context.typeProvider.stringType; |
| 4285 | 4325 |
| 4286 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 4326 List<Statement> statements = |
| 4327 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 4287 VariableDeclaration decl = | 4328 VariableDeclaration decl = |
| 4288 (statements[0] as VariableDeclarationStatement).variables.variables[0]; | 4329 (statements[0] as VariableDeclarationStatement).variables.variables[0]; |
| 4289 expect(decl.element.type, intType); | 4330 expect(decl.element.type, intType); |
| 4290 expect(decl.initializer.staticType, intType); | 4331 expect(decl.initializer.staticType, intType); |
| 4291 | 4332 |
| 4292 ExpressionStatement statement = statements[1]; | 4333 ExpressionStatement statement = statements[1]; |
| 4293 AssignmentExpression assgn = statement.expression; | 4334 AssignmentExpression assgn = statement.expression; |
| 4294 expect(assgn.leftHandSide.staticType, intType); | 4335 expect(assgn.leftHandSide.staticType, intType); |
| 4295 expect(assgn.rightHandSide.staticType, stringType); | 4336 expect(assgn.rightHandSide.staticType, stringType); |
| 4296 } | 4337 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4314 a[0]; | 4355 a[0]; |
| 4315 } | 4356 } |
| 4316 '''); | 4357 '''); |
| 4317 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); | 4358 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 4318 CompilationUnit unit = outputs[RESOLVED_UNIT]; | 4359 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 4319 | 4360 |
| 4320 // validate | 4361 // validate |
| 4321 _fillErrorListener(STRONG_MODE_ERRORS); | 4362 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4322 expect(errorListener.errors, isEmpty); | 4363 expect(errorListener.errors, isEmpty); |
| 4323 | 4364 |
| 4324 List<Statement> statements = getStatementsInTopLevelFunction(unit, "main"); | 4365 List<Statement> statements = |
| 4366 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 4325 ExpressionStatement statement = statements[1]; | 4367 ExpressionStatement statement = statements[1]; |
| 4326 IndexExpression idx = statement.expression; | 4368 IndexExpression idx = statement.expression; |
| 4327 expect(DynamicInvoke.get(idx.target), isNotNull); | 4369 expect(DynamicInvoke.get(idx.target), isNotNull); |
| 4328 expect(DynamicInvoke.get(idx.target), isNotNull); | 4370 expect(DynamicInvoke.get(idx.target), isNotNull); |
| 4329 expect(DynamicInvoke.get(idx.target), isTrue); | 4371 expect(DynamicInvoke.get(idx.target), isTrue); |
| 4330 } | 4372 } |
| 4331 | 4373 |
| 4332 void test_perform_verifyError() { | 4374 void test_perform_verifyError() { |
| 4333 enableStrongMode(); | 4375 enableStrongMode(); |
| 4334 AnalysisTarget source = newSource( | 4376 AnalysisTarget source = newSource( |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4507 | 4549 |
| 4508 /** | 4550 /** |
| 4509 * Enable strong mode in the current analysis context. | 4551 * Enable strong mode in the current analysis context. |
| 4510 */ | 4552 */ |
| 4511 void enableStrongMode() { | 4553 void enableStrongMode() { |
| 4512 AnalysisOptionsImpl options = context.analysisOptions; | 4554 AnalysisOptionsImpl options = context.analysisOptions; |
| 4513 options.strongMode = true; | 4555 options.strongMode = true; |
| 4514 context.analysisOptions = options; | 4556 context.analysisOptions = options; |
| 4515 } | 4557 } |
| 4516 | 4558 |
| 4517 /** | |
| 4518 * Return the declaration of the class with the given [className] in the given | |
| 4519 * compilation [unit]. | |
| 4520 */ | |
| 4521 ClassDeclaration getClass(CompilationUnit unit, String className) { | |
| 4522 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | |
| 4523 for (CompilationUnitMember unitMember in unitMembers) { | |
| 4524 if (unitMember is ClassDeclaration && unitMember.name.name == className) { | |
| 4525 return unitMember; | |
| 4526 } | |
| 4527 } | |
| 4528 fail('No class named $className in ${unit.element.source}'); | |
| 4529 return null; | |
| 4530 } | |
| 4531 | |
| 4532 /** | |
| 4533 * Return the declaration of the field with the given [fieldName] in the class | |
| 4534 * with the given [className] in the given compilation [unit]. | |
| 4535 */ | |
| 4536 VariableDeclaration getFieldInClass( | |
| 4537 CompilationUnit unit, String className, String fieldName) { | |
| 4538 ClassDeclaration unitMember = getClass(unit, className); | |
| 4539 NodeList<ClassMember> classMembers = unitMember.members; | |
| 4540 for (ClassMember classMember in classMembers) { | |
| 4541 if (classMember is FieldDeclaration) { | |
| 4542 NodeList<VariableDeclaration> fields = classMember.fields.variables; | |
| 4543 for (VariableDeclaration field in fields) { | |
| 4544 if (field.name.name == fieldName) { | |
| 4545 return field; | |
| 4546 } | |
| 4547 } | |
| 4548 } | |
| 4549 } | |
| 4550 fail('No field named $fieldName in $className'); | |
| 4551 return null; | |
| 4552 } | |
| 4553 | |
| 4554 /** | |
| 4555 * Return the element of the field with the given [fieldName] in the class | |
| 4556 * with the given [className] in the given compilation [unit]. | |
| 4557 */ | |
| 4558 FieldElement getFieldInClassElement( | |
| 4559 CompilationUnit unit, String className, String fieldName) { | |
| 4560 return getFieldInClass(unit, className, fieldName)?.name?.staticElement; | |
| 4561 } | |
| 4562 | |
| 4563 /** | |
| 4564 * Return the declaration of the method with the given [methodName] in the | |
| 4565 * class with the given [className] in the given compilation [unit]. | |
| 4566 */ | |
| 4567 MethodDeclaration getMethodInClass( | |
| 4568 CompilationUnit unit, String className, String methodName) { | |
| 4569 ClassDeclaration unitMember = getClass(unit, className); | |
| 4570 NodeList<ClassMember> classMembers = unitMember.members; | |
| 4571 for (ClassMember classMember in classMembers) { | |
| 4572 if (classMember is MethodDeclaration) { | |
| 4573 if (classMember.name.name == methodName) { | |
| 4574 return classMember; | |
| 4575 } | |
| 4576 } | |
| 4577 } | |
| 4578 fail('No method named $methodName in $className'); | |
| 4579 return null; | |
| 4580 } | |
| 4581 | |
| 4582 List<Statement> getStatementsInMethod( | |
| 4583 CompilationUnit unit, String className, String methodName) { | |
| 4584 MethodDeclaration method = getMethodInClass(unit, className, methodName); | |
| 4585 BlockFunctionBody body = method.body; | |
| 4586 return body.block.statements; | |
| 4587 } | |
| 4588 | |
| 4589 List<Statement> getStatementsInTopLevelFunction( | |
| 4590 CompilationUnit unit, String functionName) { | |
| 4591 FunctionDeclaration function = getTopLevelFunction(unit, functionName); | |
| 4592 BlockFunctionBody body = function.functionExpression.body; | |
| 4593 return body.block.statements; | |
| 4594 } | |
| 4595 | |
| 4596 /** | |
| 4597 * Return the declaration of the top-level function with the given | |
| 4598 * [functionName] in the given compilation [unit]. | |
| 4599 */ | |
| 4600 FunctionDeclaration getTopLevelFunction( | |
| 4601 CompilationUnit unit, String functionName) { | |
| 4602 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | |
| 4603 for (CompilationUnitMember unitMember in unitMembers) { | |
| 4604 if (unitMember is FunctionDeclaration) { | |
| 4605 if (unitMember.name.name == functionName) { | |
| 4606 return unitMember; | |
| 4607 } | |
| 4608 } | |
| 4609 } | |
| 4610 return null; | |
| 4611 } | |
| 4612 | |
| 4613 /** | |
| 4614 * Return the declaration of the top-level variable with the given | |
| 4615 * [variableName] in the given compilation [unit]. | |
| 4616 */ | |
| 4617 VariableDeclaration getTopLevelVariable( | |
| 4618 CompilationUnit unit, String variableName) { | |
| 4619 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | |
| 4620 for (CompilationUnitMember unitMember in unitMembers) { | |
| 4621 if (unitMember is TopLevelVariableDeclaration) { | |
| 4622 NodeList<VariableDeclaration> variables = | |
| 4623 unitMember.variables.variables; | |
| 4624 for (VariableDeclaration variable in variables) { | |
| 4625 if (variable.name.name == variableName) { | |
| 4626 return variable; | |
| 4627 } | |
| 4628 } | |
| 4629 } | |
| 4630 } | |
| 4631 return null; | |
| 4632 } | |
| 4633 | |
| 4634 /** | |
| 4635 * Return the top-level variable element with the given [name]. | |
| 4636 */ | |
| 4637 TopLevelVariableElement getTopLevelVariableElement( | |
| 4638 CompilationUnit unit, String name) { | |
| 4639 return getTopLevelVariable(unit, name)?.name?.staticElement; | |
| 4640 } | |
| 4641 | |
| 4642 void setUp() { | 4559 void setUp() { |
| 4643 super.setUp(); | 4560 super.setUp(); |
| 4644 emptySource = newSource('/test.dart'); | 4561 emptySource = newSource('/test.dart'); |
| 4645 } | 4562 } |
| 4646 | 4563 |
| 4647 /** | 4564 /** |
| 4648 * Fill [errorListener] with [result] errors in the current [task]. | 4565 * Fill [errorListener] with [result] errors in the current [task]. |
| 4649 */ | 4566 */ |
| 4650 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4567 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4651 List<AnalysisError> errors = task.outputs[result]; | 4568 List<AnalysisError> errors = task.outputs[result]; |
| 4652 expect(errors, isNotNull, reason: result.name); | 4569 expect(errors, isNotNull, reason: result.name); |
| 4653 errorListener = new GatheringErrorListener(); | 4570 errorListener = new GatheringErrorListener(); |
| 4654 errorListener.addAll(errors); | 4571 errorListener.addAll(errors); |
| 4655 } | 4572 } |
| 4656 } | 4573 } |
| OLD | NEW |