33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:analyzer/dart/ast/ast.dart' ;
6- import 'package:analyzer/dart/element/element.dart' ;
7- import 'package:analyzer/dart/element/type.dart' ;
8- import 'package:analyzer/src/dart/resolver/flow_analysis.dart' ;
96import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart' ;
107import 'package:test/test.dart' ;
118import 'package:test_reflective_loader/test_reflective_loader.dart' ;
@@ -23,7 +20,7 @@ main() {
2320
2421@reflectiveTest
2522class DefiniteAssignmentFlowTest extends DriverResolutionTest {
26- final List < LocalVariableElement > readBeforeWritten = [] ;
23+ FlowAnalysisResult flowResult ;
2724
2825 /// Assert that only local variables with the given names are marked as read
2926 /// before being written. All the other local variables are implicitly
@@ -34,7 +31,7 @@ class DefiniteAssignmentFlowTest extends DriverResolutionTest {
3431 .where ((i) => i != null )
3532 .map ((name) => findElement.localVar (name))
3633 .toList ();
37- expect (readBeforeWritten, unorderedEquals (expected));
34+ expect (flowResult. readBeforeWritten, unorderedEquals (expected));
3835 }
3936
4037 test_assignment_leftExpression () async {
@@ -613,7 +610,7 @@ void f() {
613610}
614611''' );
615612 var localV = findNode.simple ('v; // 1' ).staticElement;
616- expect (readBeforeWritten, unorderedEquals ([localV]));
613+ expect (flowResult. readBeforeWritten, unorderedEquals ([localV]));
617614 }
618615
619616 test_functionExpression_localFunction_local2 () async {
@@ -1306,15 +1303,13 @@ void f() {
13061303 var unit = result.unit;
13071304 var typeSystem = result.typeSystem;
13081305
1309- var flowAnalysisResult = performFlowAnalysis (typeSystem, unit);
1310- readBeforeWritten.addAll (flowAnalysisResult.readBeforeWritten);
1306+ flowResult = performFlowAnalysis (typeSystem, unit);
13111307 }
13121308}
13131309
13141310@reflectiveTest
13151311class NullableFlowTest extends DriverResolutionTest {
1316- final List <AstNode > nullableNodes = [];
1317- final List <AstNode > nonNullableNodes = [];
1312+ FlowAnalysisResult flowResult;
13181313
13191314 void assertNonNullable ([
13201315 String search1,
@@ -1327,7 +1322,7 @@ class NullableFlowTest extends DriverResolutionTest {
13271322 .where ((i) => i != null )
13281323 .map ((search) => findNode.simple (search))
13291324 .toList ();
1330- expect (nonNullableNodes, unorderedEquals (expected));
1325+ expect (flowResult. nonNullableNodes, unorderedEquals (expected));
13311326 }
13321327
13331328 void assertNullable ([
@@ -1341,7 +1336,7 @@ class NullableFlowTest extends DriverResolutionTest {
13411336 .where ((i) => i != null )
13421337 .map ((search) => findNode.simple (search))
13431338 .toList ();
1344- expect (nullableNodes, unorderedEquals (expected));
1339+ expect (flowResult. nullableNodes, unorderedEquals (expected));
13451340 }
13461341
13471342 test_assign_toNonNull () async {
@@ -1608,28 +1603,15 @@ void f(int x) {
16081603 await resolveTestFile ();
16091604
16101605 var unit = result.unit;
1606+ var typeSystem = result.typeSystem;
16111607
1612- var assignedVariables = AssignedVariables <Statement , VariableElement >();
1613- unit.accept (AssignedVariablesVisitor (assignedVariables));
1614-
1615- var typeSystem = unit.declaredElement.context.typeSystem;
1616- unit.accept (FlowAnalysisVisitor (
1617- typeSystem,
1618- assignedVariables,
1619- {},
1620- [],
1621- nullableNodes,
1622- nonNullableNodes,
1623- [],
1624- [],
1625- ));
1608+ flowResult = performFlowAnalysis (typeSystem, unit);
16261609 }
16271610}
16281611
16291612@reflectiveTest
16301613class ReachableFlowTest extends DriverResolutionTest {
1631- final List <AstNode > unreachableNodes = [];
1632- final List <FunctionBody > functionBodiesThatDontComplete = [];
1614+ FlowAnalysisResult flowResult;
16331615
16341616 test_conditional_false () async {
16351617 await trackCode (r'''
@@ -2055,21 +2037,9 @@ void f() { // f
20552037 await resolveTestFile ();
20562038
20572039 var unit = result.unit;
2040+ var typeSystem = result.typeSystem;
20582041
2059- var assignedVariables = AssignedVariables <Statement , VariableElement >();
2060- unit.accept (AssignedVariablesVisitor (assignedVariables));
2061-
2062- var typeSystem = unit.declaredElement.context.typeSystem;
2063- unit.accept (FlowAnalysisVisitor (
2064- typeSystem,
2065- assignedVariables,
2066- {},
2067- [],
2068- [],
2069- [],
2070- unreachableNodes,
2071- functionBodiesThatDontComplete,
2072- ));
2042+ flowResult = performFlowAnalysis (typeSystem, unit);
20732043 }
20742044
20752045 void verify ({
@@ -2086,11 +2056,11 @@ void f() { // f
20862056 );
20872057
20882058 expect (
2089- this .unreachableNodes,
2059+ flowResult .unreachableNodes,
20902060 unorderedEquals (expectedUnreachableNodes),
20912061 );
20922062 expect (
2093- this .functionBodiesThatDontComplete,
2063+ flowResult .functionBodiesThatDontComplete,
20942064 unorderedEquals (
20952065 functionBodiesThatDontComplete
20962066 .map ((search) => findNode.functionBody (search))
@@ -2102,17 +2072,17 @@ void f() { // f
21022072
21032073@reflectiveTest
21042074class TypePromotionFlowTest extends DriverResolutionTest {
2105- final Map < AstNode , DartType > promotedTypes = {} ;
2075+ FlowAnalysisResult flowResult ;
21062076
21072077 void assertNotPromoted (String search) {
21082078 var node = findNode.simple (search);
2109- var actualType = promotedTypes[node];
2079+ var actualType = flowResult. promotedTypes[node];
21102080 expect (actualType, isNull, reason: search);
21112081 }
21122082
21132083 void assertPromoted (String search, String expectedType) {
21142084 var node = findNode.simple (search);
2115- var actualType = promotedTypes[node];
2085+ var actualType = flowResult. promotedTypes[node];
21162086 if (actualType == null ) {
21172087 fail ('$expectedType expected, but actually not promoted\n $search ' );
21182088 }
@@ -2888,20 +2858,8 @@ void f(bool b, Object x) {
28882858 await resolveTestFile ();
28892859
28902860 var unit = result.unit;
2861+ var typeSystem = result.typeSystem;
28912862
2892- var assignedVariables = AssignedVariables <Statement , VariableElement >();
2893- unit.accept (AssignedVariablesVisitor (assignedVariables));
2894-
2895- var typeSystem = unit.declaredElement.context.typeSystem;
2896- unit.accept (FlowAnalysisVisitor (
2897- typeSystem,
2898- assignedVariables,
2899- promotedTypes,
2900- [],
2901- [],
2902- [],
2903- [],
2904- [],
2905- ));
2863+ flowResult = performFlowAnalysis (typeSystem, unit);
29062864 }
29072865}
0 commit comments