| Index: pkg/analyzer/test/src/task/dart_test.dart
|
| diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart
|
| index c0ad43b2f2a4de147c3b58ecaf00e3129ee2bfb8..29a1878d858016eff0bdba160ad4fb19a02af063 100644
|
| --- a/pkg/analyzer/test/src/task/dart_test.dart
|
| +++ b/pkg/analyzer/test/src/task/dart_test.dart
|
| @@ -1831,6 +1831,32 @@ class DartErrorsTaskTest extends _AbstractDartTaskTest {
|
| }
|
|
|
| @reflectiveTest
|
| +class ErrorFilterTest extends _AbstractDartTaskTest {
|
| + @override
|
| + setUp() {
|
| + super.setUp();
|
| + context.setConfigurationData(CONFIGURED_ERROR_FILTERS, [
|
| + (AnalysisError error) => error.errorCode.name == 'INVALID_ASSIGNMENT'
|
| + ]);
|
| + }
|
| +
|
| + test_error_filters() {
|
| + AnalysisTarget library = newSource(
|
| + '/test.dart',
|
| + '''
|
| +main() {
|
| + int x = ""; // INVALID_ASSIGNMENT (suppressed)
|
| + // UNUSED_LOCAL_VARIABLE
|
| +}''');
|
| + computeResult(library, DART_ERRORS, matcher: isDartErrorsTask);
|
| + expect(outputs, hasLength(1));
|
| + List<AnalysisError> errors = outputs[DART_ERRORS];
|
| + expect(errors, hasLength(1));
|
| + expect(errors.first.errorCode, HintCode.UNUSED_LOCAL_VARIABLE);
|
| + }
|
| +}
|
| +
|
| +@reflectiveTest
|
| class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest {
|
| test_perform() {
|
| Source source = newSource(
|
| @@ -2241,30 +2267,6 @@ f(A a) {
|
| }
|
|
|
| @reflectiveTest
|
| -class ErrorFilterTest extends _AbstractDartTaskTest {
|
| - @override
|
| - setUp() {
|
| - super.setUp();
|
| - context.setConfigurationData(CONFIGURED_ERROR_FILTERS, [
|
| - (AnalysisError error) => error.errorCode.name == 'INVALID_ASSIGNMENT'
|
| - ]);
|
| - }
|
| -
|
| - test_error_filters() {
|
| - AnalysisTarget library = newSource('/test.dart', '''
|
| -main() {
|
| - int x = ""; // INVALID_ASSIGNMENT (suppressed)
|
| - // UNUSED_LOCAL_VARIABLE
|
| -}''');
|
| - computeResult(library, DART_ERRORS, matcher: isDartErrorsTask);
|
| - expect(outputs, hasLength(1));
|
| - List<AnalysisError> errors = outputs[DART_ERRORS];
|
| - expect(errors, hasLength(1));
|
| - expect(errors.first.errorCode, HintCode.UNUSED_LOCAL_VARIABLE);
|
| - }
|
| -}
|
| -
|
| -@reflectiveTest
|
| class GenerateLintsTaskTest extends _AbstractDartTaskTest {
|
| void enableLints() {
|
| AnalysisOptionsImpl options = context.analysisOptions;
|
| @@ -2340,11 +2342,11 @@ class Z {}
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
|
| matcher: isInferInstanceMembersInUnitTask);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT8];
|
| - VariableDeclaration field = getFieldInClass(unit, 'B', 'f');
|
| - MethodDeclaration method = getMethodInClass(unit, 'B', 'm');
|
| - DartType typeX = getClass(unit, 'X').element.type;
|
| - DartType typeY = getClass(unit, 'Y').element.type;
|
| - DartType typeZ = getClass(unit, 'Z').element.type;
|
| + VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f');
|
| + MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm');
|
| + DartType typeX = AstFinder.getClass(unit, 'X').element.type;
|
| + DartType typeY = AstFinder.getClass(unit, 'Y').element.type;
|
| + DartType typeZ = AstFinder.getClass(unit, 'Z').element.type;
|
|
|
| expect(field.element.type, typeX);
|
| expect(method.element.returnType, typeY);
|
| @@ -2378,9 +2380,12 @@ class M {
|
| new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8);
|
| CompilationUnit secondUnit = outputs[RESOLVED_UNIT8];
|
|
|
| - VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a');
|
| - VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b');
|
| - VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c');
|
| + VariableDeclaration variableA =
|
| + AstFinder.getTopLevelVariable(firstUnit, 'a');
|
| + VariableDeclaration variableB =
|
| + AstFinder.getTopLevelVariable(secondUnit, 'b');
|
| + VariableDeclaration variableC =
|
| + AstFinder.getFieldInClass(secondUnit, 'M', 'c');
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| expect(variableA.element.type, stringType);
|
| @@ -2402,8 +2407,10 @@ class C {
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT8];
|
| - VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel');
|
| - VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field');
|
| + VariableDeclaration topLevelDecl =
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel');
|
| + VariableDeclaration fieldDecl =
|
| + AstFinder.getFieldInClass(unit, 'C', 'field');
|
| VariableElement topLevel = topLevelDecl.name.staticElement;
|
| VariableElement field = fieldDecl.name.staticElement;
|
|
|
| @@ -2428,7 +2435,7 @@ class M {
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
|
| matcher: isInferStaticVariableTypesInUnitTask);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
| - VariableDeclaration declaration = getFieldInClass(unit, 'M', 'X');
|
| + VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X');
|
| InterfaceType stringType = context.typeProvider.stringType;
|
| expect(declaration.element.type, stringType);
|
| }
|
| @@ -2474,10 +2481,13 @@ class M {}
|
| new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6);
|
| CompilationUnit secondUnit = outputs[RESOLVED_UNIT6];
|
|
|
| - VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a');
|
| - VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b');
|
| - VariableDeclaration variableC = getTopLevelVariable(firstUnit, 'c');
|
| - ClassDeclaration classM = getClass(secondUnit, 'M');
|
| + VariableDeclaration variableA =
|
| + AstFinder.getTopLevelVariable(firstUnit, 'a');
|
| + VariableDeclaration variableB =
|
| + AstFinder.getTopLevelVariable(secondUnit, 'b');
|
| + VariableDeclaration variableC =
|
| + AstFinder.getTopLevelVariable(firstUnit, 'c');
|
| + ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M');
|
| DartType typeM = classM.element.type;
|
|
|
| expect(variableA.element.type, typeM);
|
| @@ -2524,7 +2534,8 @@ class C {
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableDeclaration declaration = getFieldInClass(unit, 'C', 'field');
|
| + VariableDeclaration declaration =
|
| + AstFinder.getFieldInClass(unit, 'C', 'field');
|
| VariableElement variable = declaration.name.staticElement;
|
| InferStaticVariableTypeTask inferTask =
|
| new InferStaticVariableTypeTask(task.context, variable);
|
| @@ -2539,7 +2550,8 @@ var topLevel = '';
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel');
|
| + VariableDeclaration declaration =
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel');
|
| VariableElement variable = declaration.name.staticElement;
|
| InferStaticVariableTypeTask inferTask =
|
| new InferStaticVariableTypeTask(task.context, variable);
|
| @@ -2558,8 +2570,10 @@ class C {
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3');
|
| - VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3');
|
| + VariableDeclaration topLevelDecl =
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel3');
|
| + VariableDeclaration fieldDecl =
|
| + AstFinder.getFieldInClass(unit, 'C', 'field3');
|
| VariableElement topLevel = topLevelDecl.name.staticElement;
|
| VariableElement field = fieldDecl.name.staticElement;
|
|
|
| @@ -2584,9 +2598,9 @@ class C {
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| VariableElement topLevel =
|
| - getTopLevelVariable(unit, 'topLevel').name.staticElement;
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement;
|
| VariableElement field =
|
| - getFieldInClass(unit, 'C', 'field').name.staticElement;
|
| + AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement;
|
|
|
| computeResult(field, INFERRED_STATIC_VARIABLE,
|
| matcher: isInferStaticVariableTypeTask);
|
| @@ -2607,9 +2621,11 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| VariableElement piFirst =
|
| - getTopLevelVariable(unit, 'piFirst').name.staticElement;
|
| - VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement;
|
| - VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement;
|
| + AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement;
|
| + VariableElement pi =
|
| + AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement;
|
| + VariableElement tau =
|
| + AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement;
|
|
|
| computeResult(piFirst, INFERRED_STATIC_VARIABLE,
|
| matcher: isInferStaticVariableTypeTask);
|
| @@ -2627,7 +2643,8 @@ var a = '' / null;
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
|
| + VariableElement a =
|
| + AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
|
|
|
| computeResult(a, INFERRED_STATIC_VARIABLE,
|
| matcher: isInferStaticVariableTypeTask);
|
| @@ -2643,7 +2660,8 @@ var a = null;
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
|
| + VariableElement a =
|
| + AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
|
|
|
| computeResult(a, INFERRED_STATIC_VARIABLE,
|
| matcher: isInferStaticVariableTypeTask);
|
| @@ -3017,7 +3035,7 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
|
|
| // B.b2 shoud be resolved on the rhs, but not yet inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
|
|
|
| computeResult(
|
| new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
|
| @@ -3025,21 +3043,21 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
|
|
| // B.b2 should now be fully resolved and inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
|
|
|
| // A.a2 should now be resolved on the rhs, but not yet inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
|
|
|
| computeResult(
|
| new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7);
|
|
|
| // A.a2 should now be fully resolved and inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| }
|
|
|
| // Test inference of instance fields across units
|
| @@ -3074,14 +3092,14 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
|
|
| // A.a2 should now be resolved on the rhs, but not yet inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
|
|
| computeResult(
|
| new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7);
|
|
|
| // A.a2 should now be fully resolved and inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| }
|
|
|
| // Test inference of instance fields across units with cycles
|
| @@ -3119,36 +3137,36 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| CompilationUnit unit1 = outputs[RESOLVED_UNIT7];
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
|
|
|
| computeResult(
|
| new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
|
| CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
|
|
|
| computeResult(
|
| new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| }
|
|
|
| // Test inference between static and instance fields
|
| @@ -3182,22 +3200,22 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
|
|
| // A.a2 should now be resolved on the rhs, but not yet inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
|
|
| // B.b2 shoud be resolved on the rhs, but not yet inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "B", "b2"), dynamicType, intType);
|
| + AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType);
|
|
|
| computeResult(
|
| new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7);
|
|
|
| // A.a2 should now be fully resolved and inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
|
|
| // B.b2 should now be fully resolved and inferred.
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType);
|
| }
|
| }
|
|
|
| @@ -3537,11 +3555,14 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| VariableElement piFirst =
|
| - getTopLevelVariable(unit, 'piFirst').name.staticElement;
|
| - VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement;
|
| - VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement;
|
| - Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer
|
| - as ConditionalExpression).condition;
|
| + AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement;
|
| + VariableElement pi =
|
| + AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement;
|
| + VariableElement tau =
|
| + AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement;
|
| + Expression piFirstUse = (AstFinder
|
| + .getTopLevelVariable(unit, 'tau')
|
| + .initializer as ConditionalExpression).condition;
|
|
|
| expect(piFirstUse.staticType, context.typeProvider.boolType);
|
| expect(piFirst.type, context.typeProvider.boolType);
|
| @@ -3582,17 +3603,17 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
|
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit1, "x"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit1, "x"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "A", "x"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit2, "y"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit2, "y"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit2, "B", "y"), intType, intType);
|
| + AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType);
|
|
|
| List<Statement> statements =
|
| - getStatementsInTopLevelFunction(unit2, "test1");
|
| + AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
|
|
|
| assertAssignmentStatementTypes(statements[1], intType, intType);
|
| assertAssignmentStatementTypes(statements[2], intType, intType);
|
| @@ -3632,13 +3653,13 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
|
|
|
| List<Statement> statements =
|
| - getStatementsInTopLevelFunction(unit2, "test1");
|
| + AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
|
|
|
| assertAssignmentStatementTypes(statements[1], intType, intType);
|
| }
|
| @@ -3679,9 +3700,13 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| assertVariableDeclarationStatementTypes(
|
| - getStatementsInTopLevelFunction(unit0, "foo")[0], stringType, intType);
|
| + AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0],
|
| + stringType,
|
| + intType);
|
| assertVariableDeclarationStatementTypes(
|
| - getStatementsInTopLevelFunction(unit2, "foo")[0], stringType, intType);
|
| + AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0],
|
| + stringType,
|
| + intType);
|
| }
|
|
|
| // Test inference interactions between local variables and top level
|
| @@ -3718,17 +3743,17 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit1, "x"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit1, "x"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "A", "x"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit2, "y"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit2, "y"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit2, "B", "y"), intType, intType);
|
| + AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType);
|
|
|
| List<Statement> statements =
|
| - getStatementsInTopLevelFunction(unit2, "test1");
|
| + AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
|
|
|
| assertAssignmentStatementTypes(statements[0], intType, stringType);
|
| assertAssignmentStatementTypes(statements[1], intType, stringType);
|
| @@ -3770,17 +3795,17 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit1, "B", "b2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
|
|
|
| List<Statement> statements =
|
| - getStatementsInTopLevelFunction(unit2, "test1");
|
| + AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
|
|
|
| assertAssignmentStatementTypes(statements[1], intType, intType);
|
| assertAssignmentStatementTypes(statements[2], intType, intType);
|
| @@ -3804,7 +3829,8 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| - List<Statement> statements = getStatementsInTopLevelFunction(unit, "test");
|
| + List<Statement> statements =
|
| + AstFinder.getStatementsInTopLevelFunction(unit, "test");
|
|
|
| assertVariableDeclarationStatementTypes(statements[0], intType, intType);
|
| assertAssignmentStatementTypes(statements[1], intType, stringType);
|
| @@ -3842,7 +3868,8 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| - List<Statement> statements = getStatementsInMethod(unit, "A", "test1");
|
| + List<Statement> statements =
|
| + AstFinder.getStatementsInMethod(unit, "A", "test1");
|
|
|
| assertVariableDeclarationStatementTypes(statements[0], intType, intType);
|
| assertAssignmentStatementTypes(statements[1], intType, stringType);
|
| @@ -3857,9 +3884,9 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| assertAssignmentStatementTypes(statements[8], intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit, "A", "x"), intType, intType);
|
| + AstFinder.getFieldInClass(unit, "A", "x"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit, "A", "z"), intType, intType);
|
| + AstFinder.getFieldInClass(unit, "A", "z"), intType, intType);
|
| }
|
|
|
| // Test inference of instance fields across units
|
| @@ -3890,7 +3917,8 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| - List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1");
|
| + List<Statement> statements =
|
| + AstFinder.getStatementsInTopLevelFunction(unit, "test1");
|
|
|
| assertVariableDeclarationStatementTypes(statements[0], intType, intType);
|
| assertAssignmentStatementTypes(statements[1], intType, stringType);
|
| @@ -3905,11 +3933,11 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| assertAssignmentStatementTypes(statements[8], intType, intType);
|
|
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit, "x"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit, "x"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit, "y"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit, "y"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit, "z"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit, "z"), intType, intType);
|
| }
|
|
|
| // Test inference between static and instance fields
|
| @@ -3945,19 +3973,20 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| DartType dynamicType = context.typeProvider.dynamicType;
|
|
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit, "x"), dynamicType, bottomType);
|
| + AstFinder.getTopLevelVariable(unit, "x"), dynamicType, bottomType);
|
| assertVariableDeclarationTypes(
|
| - getTopLevelVariable(unit, "y"), intType, intType);
|
| + AstFinder.getTopLevelVariable(unit, "y"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit, "A", "x"), dynamicType, bottomType);
|
| + AstFinder.getFieldInClass(unit, "A", "x"), dynamicType, bottomType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit, "A", "y"), intType, intType);
|
| + AstFinder.getFieldInClass(unit, "A", "y"), intType, intType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit, "A", "x2"), dynamicType, bottomType);
|
| + AstFinder.getFieldInClass(unit, "A", "x2"), dynamicType, bottomType);
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit, "A", "y2"), intType, intType);
|
| + AstFinder.getFieldInClass(unit, "A", "y2"), intType, intType);
|
|
|
| - List<Statement> statements = getStatementsInTopLevelFunction(unit, "test");
|
| + List<Statement> statements =
|
| + AstFinder.getStatementsInTopLevelFunction(unit, "test");
|
|
|
| assertAssignmentStatementTypes(statements[0], dynamicType, stringType);
|
| assertAssignmentStatementTypes(statements[1], intType, stringType);
|
| @@ -3983,7 +4012,8 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| InterfaceType intType = context.typeProvider.intType;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
|
|
| - List<Statement> statements = getStatementsInTopLevelFunction(unit, "test");
|
| + List<Statement> statements =
|
| + AstFinder.getStatementsInTopLevelFunction(unit, "test");
|
| VariableDeclaration decl =
|
| (statements[0] as VariableDeclarationStatement).variables.variables[0];
|
| expect(decl.element.type, intType);
|
| @@ -4021,7 +4051,8 @@ void main() {
|
| _fillErrorListener(STRONG_MODE_ERRORS);
|
| expect(errorListener.errors, isEmpty);
|
|
|
| - List<Statement> statements = getStatementsInTopLevelFunction(unit, "main");
|
| + List<Statement> statements =
|
| + AstFinder.getStatementsInTopLevelFunction(unit, "main");
|
| ExpressionStatement statement = statements[1];
|
| IndexExpression idx = statement.expression;
|
| expect(DynamicInvoke.get(idx.target), isNotNull);
|
| @@ -4214,114 +4245,6 @@ class _AbstractDartTaskTest extends AbstractContextTest {
|
| context.analysisOptions = options;
|
| }
|
|
|
| - /**
|
| - * Return the declaration of the class with the given [className] in the given
|
| - * compilation [unit].
|
| - */
|
| - ClassDeclaration getClass(CompilationUnit unit, String className) {
|
| - NodeList<CompilationUnitMember> unitMembers = unit.declarations;
|
| - for (CompilationUnitMember unitMember in unitMembers) {
|
| - if (unitMember is ClassDeclaration && unitMember.name.name == className) {
|
| - return unitMember;
|
| - }
|
| - }
|
| - fail('No class named $className in ${unit.element.source}');
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Return the declaration of the field with the given [fieldName] in the class
|
| - * with the given [className] in the given compilation [unit].
|
| - */
|
| - VariableDeclaration getFieldInClass(
|
| - CompilationUnit unit, String className, String fieldName) {
|
| - ClassDeclaration unitMember = getClass(unit, className);
|
| - NodeList<ClassMember> classMembers = unitMember.members;
|
| - for (ClassMember classMember in classMembers) {
|
| - if (classMember is FieldDeclaration) {
|
| - NodeList<VariableDeclaration> fields = classMember.fields.variables;
|
| - for (VariableDeclaration field in fields) {
|
| - if (field.name.name == fieldName) {
|
| - return field;
|
| - }
|
| - }
|
| - }
|
| - }
|
| - fail('No field named $fieldName in $className');
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Return the declaration of the method with the given [methodName] in the
|
| - * class with the given [className] in the given compilation [unit].
|
| - */
|
| - MethodDeclaration getMethodInClass(
|
| - CompilationUnit unit, String className, String methodName) {
|
| - ClassDeclaration unitMember = getClass(unit, className);
|
| - NodeList<ClassMember> classMembers = unitMember.members;
|
| - for (ClassMember classMember in classMembers) {
|
| - if (classMember is MethodDeclaration) {
|
| - if (classMember.name.name == methodName) {
|
| - return classMember;
|
| - }
|
| - }
|
| - }
|
| - fail('No method named $methodName in $className');
|
| - return null;
|
| - }
|
| -
|
| - List<Statement> getStatementsInMethod(
|
| - CompilationUnit unit, String className, String methodName) {
|
| - MethodDeclaration method = getMethodInClass(unit, className, methodName);
|
| - BlockFunctionBody body = method.body;
|
| - return body.block.statements;
|
| - }
|
| -
|
| - List<Statement> getStatementsInTopLevelFunction(
|
| - CompilationUnit unit, String functionName) {
|
| - FunctionDeclaration function = getTopLevelFunction(unit, functionName);
|
| - BlockFunctionBody body = function.functionExpression.body;
|
| - return body.block.statements;
|
| - }
|
| -
|
| - /**
|
| - * Return the declaration of the top-level function with the given
|
| - * [functionName] in the given compilation [unit].
|
| - */
|
| - FunctionDeclaration getTopLevelFunction(
|
| - CompilationUnit unit, String functionName) {
|
| - NodeList<CompilationUnitMember> unitMembers = unit.declarations;
|
| - for (CompilationUnitMember unitMember in unitMembers) {
|
| - if (unitMember is FunctionDeclaration) {
|
| - if (unitMember.name.name == functionName) {
|
| - return unitMember;
|
| - }
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Return the declaration of the top-level variable with the given
|
| - * [variableName] in the given compilation [unit].
|
| - */
|
| - VariableDeclaration getTopLevelVariable(
|
| - CompilationUnit unit, String variableName) {
|
| - NodeList<CompilationUnitMember> unitMembers = unit.declarations;
|
| - for (CompilationUnitMember unitMember in unitMembers) {
|
| - if (unitMember is TopLevelVariableDeclaration) {
|
| - NodeList<VariableDeclaration> variables =
|
| - unitMember.variables.variables;
|
| - for (VariableDeclaration variable in variables) {
|
| - if (variable.name.name == variableName) {
|
| - return variable;
|
| - }
|
| - }
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| void setUp() {
|
| super.setUp();
|
| emptySource = newSource('/test.dart');
|
|
|