| Index: packages/analyzer/test/src/task/dart_test.dart
|
| diff --git a/packages/analyzer/test/src/task/dart_test.dart b/packages/analyzer/test/src/task/dart_test.dart
|
| index 547df9709239495ccbf46d3b3713c666a5c8ac90..403467e587812e4c462e3fff40ab096c0222c945 100644
|
| --- a/packages/analyzer/test/src/task/dart_test.dart
|
| +++ b/packages/analyzer/test/src/task/dart_test.dart
|
| @@ -2,72 +2,79 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -library test.src.task.dart_test;
|
| -
|
| +library analyzer.test.src.task.dart_test;
|
| +
|
| +import 'package:analyzer/dart/ast/ast.dart';
|
| +import 'package:analyzer/dart/ast/token.dart';
|
| +import 'package:analyzer/dart/ast/visitor.dart';
|
| +import 'package:analyzer/dart/element/element.dart';
|
| +import 'package:analyzer/dart/element/type.dart';
|
| +import 'package:analyzer/error/error.dart';
|
| import 'package:analyzer/src/context/cache.dart';
|
| -import 'package:analyzer/src/generated/ast.dart';
|
| +import 'package:analyzer/src/dart/element/element.dart';
|
| +import 'package:analyzer/src/error/codes.dart';
|
| import 'package:analyzer/src/generated/constant.dart';
|
| -import 'package:analyzer/src/generated/element.dart';
|
| import 'package:analyzer/src/generated/engine.dart'
|
| show AnalysisOptionsImpl, CacheState;
|
| -import 'package:analyzer/src/generated/error.dart';
|
| import 'package:analyzer/src/generated/resolver.dart';
|
| -import 'package:analyzer/src/generated/scanner.dart';
|
| import 'package:analyzer/src/generated/sdk.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
| import 'package:analyzer/src/services/lint.dart';
|
| import 'package:analyzer/src/task/dart.dart';
|
| import 'package:analyzer/src/task/html.dart';
|
| -import 'package:analyzer/src/task/strong/info.dart';
|
| +import 'package:analyzer/src/task/strong/ast_properties.dart' as strong_ast;
|
| import 'package:analyzer/task/dart.dart';
|
| import 'package:analyzer/task/general.dart';
|
| import 'package:analyzer/task/model.dart';
|
| +import 'package:test_reflective_loader/test_reflective_loader.dart';
|
| import 'package:unittest/unittest.dart';
|
|
|
| -import '../../generated/resolver_test.dart';
|
| +import '../../generated/resolver_test_case.dart';
|
| import '../../generated/test_support.dart';
|
| -import '../../reflective_tests.dart';
|
| import '../../utils.dart';
|
| import '../context/abstract_context.dart';
|
|
|
| main() {
|
| initializeTestEnvironment();
|
| - runReflectiveTests(BuildCompilationUnitElementTaskTest);
|
| - runReflectiveTests(BuildDirectiveElementsTaskTest);
|
| - runReflectiveTests(BuildEnumMemberElementsTaskTest);
|
| - runReflectiveTests(BuildExportNamespaceTaskTest);
|
| - runReflectiveTests(BuildLibraryElementTaskTest);
|
| - runReflectiveTests(BuildPublicNamespaceTaskTest);
|
| - runReflectiveTests(BuildSourceExportClosureTaskTest);
|
| - runReflectiveTests(BuildSourceImportExportClosureTaskTest);
|
| - runReflectiveTests(BuildTypeProviderTaskTest);
|
| - runReflectiveTests(ComputeConstantDependenciesTaskTest);
|
| - runReflectiveTests(ComputeConstantValueTaskTest);
|
| - runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest);
|
| - runReflectiveTests(ComputeLibraryCycleTaskTest);
|
| - runReflectiveTests(ContainingLibrariesTaskTest);
|
| - runReflectiveTests(DartErrorsTaskTest);
|
| - runReflectiveTests(EvaluateUnitConstantsTaskTest);
|
| - runReflectiveTests(GatherUsedImportedElementsTaskTest);
|
| - runReflectiveTests(GatherUsedLocalElementsTaskTest);
|
| - runReflectiveTests(GenerateHintsTaskTest);
|
| - runReflectiveTests(GenerateLintsTaskTest);
|
| - runReflectiveTests(InferInstanceMembersInUnitTaskTest);
|
| - runReflectiveTests(InferStaticVariableTypesInUnitTaskTest);
|
| - runReflectiveTests(InferStaticVariableTypeTaskTest);
|
| - runReflectiveTests(LibraryErrorsReadyTaskTest);
|
| - runReflectiveTests(LibraryUnitErrorsTaskTest);
|
| - runReflectiveTests(ParseDartTaskTest);
|
| - runReflectiveTests(PartiallyResolveUnitReferencesTaskTest);
|
| - runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest);
|
| - runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
|
| - runReflectiveTests(ResolveUnitTaskTest);
|
| - runReflectiveTests(ResolveUnitTypeNamesTaskTest);
|
| - runReflectiveTests(ResolveVariableReferencesTaskTest);
|
| - runReflectiveTests(ScanDartTaskTest);
|
| - runReflectiveTests(StrongModeInferenceTest);
|
| - runReflectiveTests(StrongModeVerifyUnitTaskTest);
|
| - runReflectiveTests(VerifyUnitTaskTest);
|
| + defineReflectiveTests(BuildCompilationUnitElementTaskTest);
|
| + defineReflectiveTests(BuildDirectiveElementsTaskTest);
|
| + defineReflectiveTests(BuildEnumMemberElementsTaskTest);
|
| + defineReflectiveTests(BuildExportNamespaceTaskTest);
|
| + defineReflectiveTests(BuildLibraryElementTaskTest);
|
| + defineReflectiveTests(BuildPublicNamespaceTaskTest);
|
| + defineReflectiveTests(BuildSourceExportClosureTaskTest);
|
| + defineReflectiveTests(BuildTypeProviderTaskTest);
|
| + defineReflectiveTests(ComputeConstantDependenciesTaskTest);
|
| + defineReflectiveTests(ComputeConstantValueTaskTest);
|
| + defineReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest);
|
| + defineReflectiveTests(ComputeLibraryCycleTaskTest);
|
| + defineReflectiveTests(ContainingLibrariesTaskTest);
|
| + defineReflectiveTests(DartErrorsTaskTest);
|
| + defineReflectiveTests(EvaluateUnitConstantsTaskTest);
|
| + defineReflectiveTests(GatherUsedImportedElementsTaskTest);
|
| + defineReflectiveTests(GatherUsedLocalElementsTaskTest);
|
| + defineReflectiveTests(GenerateHintsTaskTest);
|
| + defineReflectiveTests(GenerateLintsTaskTest);
|
| + defineReflectiveTests(InferInstanceMembersInUnitTaskTest);
|
| + defineReflectiveTests(InferStaticVariableTypesInUnitTaskTest);
|
| + defineReflectiveTests(InferStaticVariableTypeTaskTest);
|
| + defineReflectiveTests(LibraryErrorsReadyTaskTest);
|
| + defineReflectiveTests(LibraryUnitErrorsTaskTest);
|
| + defineReflectiveTests(ParseDartTaskTest);
|
| + defineReflectiveTests(PartiallyResolveUnitReferencesTaskTest);
|
| + defineReflectiveTests(ReferencedNamesBuilderTest);
|
| + defineReflectiveTests(ResolveDirectiveElementsTaskTest);
|
| + defineReflectiveTests(ResolveInstanceFieldsInUnitTaskTest);
|
| + defineReflectiveTests(ResolveLibraryTaskTest);
|
| + defineReflectiveTests(ResolveLibraryTypeNamesTaskTest);
|
| + defineReflectiveTests(ResolveTopLevelUnitTypeBoundsTaskTest);
|
| + defineReflectiveTests(ResolveUnitTaskTest);
|
| + defineReflectiveTests(ResolveUnitTypeNamesTaskTest);
|
| + defineReflectiveTests(ResolveVariableReferencesTaskTest);
|
| + defineReflectiveTests(ScanDartTaskTest);
|
| + defineReflectiveTests(StrongModeInferenceTest);
|
| + defineReflectiveTests(StrongModeVerifyUnitTaskTest);
|
| + defineReflectiveTests(VerifyUnitTaskTest);
|
| }
|
|
|
| isInstanceOf isBuildCompilationUnitElementTask =
|
| @@ -84,8 +91,6 @@ isInstanceOf isBuildPublicNamespaceTask =
|
| new isInstanceOf<BuildPublicNamespaceTask>();
|
| isInstanceOf isBuildSourceExportClosureTask =
|
| new isInstanceOf<BuildSourceExportClosureTask>();
|
| -isInstanceOf isBuildSourceImportExportClosureTask =
|
| - new isInstanceOf<BuildSourceImportExportClosureTask>();
|
| isInstanceOf isBuildTypeProviderTask =
|
| new isInstanceOf<BuildTypeProviderTask>();
|
| isInstanceOf isComputeConstantDependenciesTask =
|
| @@ -118,8 +123,15 @@ isInstanceOf isLibraryUnitErrorsTask =
|
| isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>();
|
| isInstanceOf isPartiallyResolveUnitReferencesTask =
|
| new isInstanceOf<PartiallyResolveUnitReferencesTask>();
|
| +isInstanceOf isResolveDirectiveElementsTask =
|
| + new isInstanceOf<ResolveDirectiveElementsTask>();
|
| +isInstanceOf isResolveLibraryReferencesTask =
|
| + new isInstanceOf<ResolveLibraryReferencesTask>();
|
| +isInstanceOf isResolveLibraryTask = new isInstanceOf<ResolveLibraryTask>();
|
| isInstanceOf isResolveLibraryTypeNamesTask =
|
| new isInstanceOf<ResolveLibraryTypeNamesTask>();
|
| +isInstanceOf isResolveTopLevelUnitTypeBoundsTask =
|
| + new isInstanceOf<ResolveTopLevelUnitTypeBoundsTask>();
|
| isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>();
|
| isInstanceOf isResolveUnitTypeNamesTask =
|
| new isInstanceOf<ResolveUnitTypeNamesTask>();
|
| @@ -137,6 +149,19 @@ class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest {
|
| Source source;
|
| LibrarySpecificUnit target;
|
|
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT1);
|
| + expect(outputs[RESOLVED_UNIT1], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT1], isTrue);
|
| + }
|
| +
|
| test_perform_find_constants() {
|
| _performBuildTask('''
|
| const x = 1;
|
| @@ -154,13 +179,13 @@ f() {
|
| Annotation annotation = unit.declarations
|
| .firstWhere((m) => m is FunctionDeclaration)
|
| .metadata[0];
|
| - List<ConstantEvaluationTarget> expectedConstants = [
|
| + List<ConstantEvaluationTarget> expectedConstants =
|
| + <ConstantEvaluationTarget>[
|
| unitElement.accessors.firstWhere((e) => e.isGetter).variable,
|
| unitElement.types[0].fields[0],
|
| unitElement.functions[0].localVariables[0],
|
| unitElement.types[0].constructors[0],
|
| - new ConstantEvaluationTarget_Annotation(
|
| - context, source, source, annotation),
|
| + annotation.elementAnnotation,
|
| unitElement.types[0].constructors[0].parameters[0]
|
| ];
|
| expect(
|
| @@ -179,10 +204,11 @@ class A {
|
| }
|
| class B = Object with A;
|
| ''');
|
| - expect(outputs, hasLength(3));
|
| + expect(outputs, hasLength(4));
|
| expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull);
|
| expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull);
|
| expect(outputs[RESOLVED_UNIT1], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT1], isTrue);
|
| }
|
|
|
| test_perform_reuseElement() {
|
| @@ -215,6 +241,22 @@ class B = Object with A;
|
|
|
| @reflectiveTest
|
| class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest {
|
| + /**
|
| + * Verify that the given [element] has exactly one annotation, and that its
|
| + * [ElementAnnotationImpl] is unresolved and points back to [element].
|
| + *
|
| + * The compilation unit stored in the [ElementAnnotationImpl] should be
|
| + * [compilationUnit].
|
| + */
|
| + void checkMetadata(Element element, CompilationUnitElement compilationUnit) {
|
| + expect(element.metadata, hasLength(1));
|
| + expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>());
|
| + ElementAnnotationImpl elementAnnotation = element.metadata[0];
|
| + expect(elementAnnotation.element, isNull); // Not yet resolved
|
| + expect(elementAnnotation.compilationUnit, isNotNull);
|
| + expect(elementAnnotation.compilationUnit, compilationUnit);
|
| + }
|
| +
|
| test_perform() {
|
| List<Source> sources = newSources({
|
| '/libA.dart': '''
|
| @@ -312,6 +354,52 @@ library libB;
|
| }
|
| }
|
|
|
| + test_perform_configurations_export() {
|
| + context.declaredVariables.define('dart.library.io', 'true');
|
| + context.declaredVariables.define('dart.library.html', 'true');
|
| + newSource('/foo.dart', '');
|
| + var foo_io = newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + var testSource = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +export 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| + // Perform the task.
|
| + computeResult(testSource, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2];
|
| + // Validate the export element.
|
| + ExportElement export = testLibrary.exports[0];
|
| + expect(export.exportedLibrary.source, foo_io);
|
| + expect(export.uri, 'foo_io.dart');
|
| + }
|
| +
|
| + test_perform_configurations_import() {
|
| + context.declaredVariables.define('dart.library.io', 'true');
|
| + context.declaredVariables.define('dart.library.html', 'true');
|
| + newSource('/foo.dart', '');
|
| + var foo_io = newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + var testSource = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| + // Perform the task.
|
| + computeResult(testSource, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2];
|
| + // Validate the import element.
|
| + ImportElement import = testLibrary.imports[0];
|
| + expect(import.importedLibrary.source, foo_io);
|
| + expect(import.uri, 'foo_io.dart');
|
| + }
|
| +
|
| test_perform_dartCoreContext() {
|
| List<Source> sources = newSources({'/libA.dart': ''});
|
| Source source = sources[0];
|
| @@ -442,6 +530,58 @@ library libC;
|
| expect(importElementC.prefix, prefixElement);
|
| }
|
|
|
| + test_perform_metadata() {
|
| + List<Source> sources = newSources({
|
| + '/libA.dart': '''
|
| +@a library libA;
|
| +@b import 'libB.dart';
|
| +@c export 'libC.dart';
|
| +@d part 'part.dart';''',
|
| + '/libB.dart': 'library libB;',
|
| + '/libC.dart': 'library libC;',
|
| + '/part.dart': 'part of libA;'
|
| + });
|
| + Source sourceA = sources[0];
|
| + // perform task
|
| + computeResult(sourceA, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + // Get outputs
|
| + LibraryElement libraryA =
|
| + context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2);
|
| + // Validate metadata
|
| + checkMetadata(libraryA, libraryA.definingCompilationUnit);
|
| + checkMetadata(libraryA.imports[0], libraryA.definingCompilationUnit);
|
| + checkMetadata(libraryA.exports[0], libraryA.definingCompilationUnit);
|
| + checkMetadata(libraryA.parts[0], libraryA.definingCompilationUnit);
|
| + }
|
| +
|
| + test_perform_metadata_partOf() {
|
| + // We don't record annotations on `part of` directives because the element
|
| + // associated with a `part of` directive is the library, and the convention
|
| + // is to annotate the library at the site of the `library` declaration.
|
| + List<Source> sources = newSources({
|
| + '/libA.dart': '''
|
| +library libA;
|
| +part 'part.dart';''',
|
| + '/part.dart': '@a part of libA;'
|
| + });
|
| + Source sourceA = sources[0];
|
| + Source sourcePart = sources[1];
|
| + // perform task
|
| + computeResult(sourceA, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + // Get outputs
|
| + LibraryElement libraryA =
|
| + context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2);
|
| + CompilationUnit part = context
|
| + .getCacheEntry(new LibrarySpecificUnit(sourceA, sourcePart))
|
| + .getValue(RESOLVED_UNIT1);
|
| + // Validate metadata
|
| + expect(part.directives[0], new isInstanceOf<PartOfDirective>());
|
| + expect(part.directives[0].element, same(libraryA));
|
| + expect(part.directives[0].element.metadata, isEmpty);
|
| + }
|
| +
|
| void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) {
|
| _fillErrorListener(BUILD_DIRECTIVES_ERRORS);
|
| errorListener.assertErrorsWithCodes(expectedErrorCodes);
|
| @@ -460,6 +600,19 @@ library libC;
|
|
|
| @reflectiveTest
|
| class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest {
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT3);
|
| + expect(outputs[RESOLVED_UNIT3], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT3], isTrue);
|
| + }
|
| +
|
| test_perform() {
|
| Source source = newSource(
|
| '/test.dart',
|
| @@ -468,9 +621,9 @@ enum MyEnum {
|
| A, B
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2,
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT3,
|
| matcher: isBuildEnumMemberElementsTask);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT2];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT3];
|
| // validate Element
|
| ClassElement enumElement = unit.element.getEnum('MyEnum');
|
| List<FieldElement> fields = enumElement.fields;
|
| @@ -841,8 +994,12 @@ part of lib;
|
| void set test(_) {}
|
| '''
|
| });
|
| - CompilationUnitElement unitElement1 = partUnits[0].element;
|
| - CompilationUnitElement unitElement2 = partUnits[1].element;
|
| + CompilationUnitElement unitElement1 = partUnits
|
| + .singleWhere((u) => u.element.name.endsWith('part1.dart'))
|
| + .element;
|
| + CompilationUnitElement unitElement2 = partUnits
|
| + .singleWhere((u) => u.element.name.endsWith('part2.dart'))
|
| + .element;
|
| PropertyAccessorElement getter = unitElement1.accessors[0];
|
| PropertyAccessorElement setter = unitElement2.accessors[0];
|
| PropertyInducingElement variable = getter.variable;
|
| @@ -870,7 +1027,8 @@ void set test(_) {}
|
| libraryUnitElement = libraryUnit.element;
|
| librarySource = libraryUnitElement.source;
|
| libraryElement = outputs[LIBRARY_ELEMENT1];
|
| - partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT];
|
| + partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]
|
| + as List<CompilationUnit>;
|
| }
|
| }
|
|
|
| @@ -901,6 +1059,10 @@ d() {}
|
|
|
| @reflectiveTest
|
| class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest {
|
| + List<Source> getExportSourceClosure(Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[EXPORT_SOURCE_CLOSURE] as List<Source>;
|
| + }
|
| +
|
| test_perform_exportClosure() {
|
| Source sourceA = newSource(
|
| '/a.dart',
|
| @@ -929,133 +1091,26 @@ library lib_d;
|
| {
|
| computeResult(sourceA, EXPORT_SOURCE_CLOSURE,
|
| matcher: isBuildSourceExportClosureTask);
|
| - List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE];
|
| + List<Source> closure = getExportSourceClosure(outputs);
|
| expect(closure, unorderedEquals([sourceA, sourceB, sourceC]));
|
| }
|
| // c.dart
|
| {
|
| computeResult(sourceC, EXPORT_SOURCE_CLOSURE,
|
| matcher: isBuildSourceExportClosureTask);
|
| - List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE];
|
| + List<Source> closure = getExportSourceClosure(outputs);
|
| expect(closure, unorderedEquals([sourceA, sourceB, sourceC]));
|
| }
|
| // d.dart
|
| {
|
| computeResult(sourceD, EXPORT_SOURCE_CLOSURE,
|
| matcher: isBuildSourceExportClosureTask);
|
| - List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE];
|
| + List<Source> closure = getExportSourceClosure(outputs);
|
| expect(closure, unorderedEquals([sourceD]));
|
| }
|
| }
|
| }
|
|
|
| -@reflectiveTest
|
| -class BuildSourceImportExportClosureTaskTest extends _AbstractDartTaskTest {
|
| - test_perform_importExportClosure() {
|
| - Source sourceA = newSource(
|
| - '/a.dart',
|
| - '''
|
| -library lib_a;
|
| -''');
|
| - Source sourceB = newSource(
|
| - '/b.dart',
|
| - '''
|
| -library lib_b;
|
| -export 'a.dart';
|
| -''');
|
| - Source sourceC = newSource(
|
| - '/c.dart',
|
| - '''
|
| -library lib_c;
|
| -import 'b.dart';
|
| -''');
|
| - Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core');
|
| - // c.dart
|
| - {
|
| - computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE,
|
| - matcher: isBuildSourceImportExportClosureTask);
|
| - List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE];
|
| - expect(closure, contains(sourceA));
|
| - expect(closure, contains(sourceB));
|
| - expect(closure, contains(sourceC));
|
| - expect(closure, contains(coreSource));
|
| - }
|
| - // b.dart
|
| - {
|
| - computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE,
|
| - matcher: isBuildSourceImportExportClosureTask);
|
| - List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE];
|
| - expect(closure, contains(sourceA));
|
| - expect(closure, contains(sourceB));
|
| - expect(closure, contains(coreSource));
|
| - }
|
| - }
|
| -
|
| - test_perform_isClient_false() {
|
| - Source sourceA = newSource(
|
| - '/a.dart',
|
| - '''
|
| -library lib_a;
|
| -import 'b.dart';
|
| -''');
|
| - newSource(
|
| - '/b.dart',
|
| - '''
|
| -library lib_b;
|
| -''');
|
| - computeResult(sourceA, IS_CLIENT,
|
| - matcher: isBuildSourceImportExportClosureTask);
|
| - expect(outputs[IS_CLIENT], isFalse);
|
| - }
|
| -
|
| - test_perform_isClient_true_export_indirect() {
|
| - newSource(
|
| - '/exports_html.dart',
|
| - '''
|
| -library lib_exports_html;
|
| -export 'dart:html';
|
| -''');
|
| - Source source = newSource(
|
| - '/test.dart',
|
| - '''
|
| -import 'exports_html.dart';
|
| -''');
|
| - computeResult(source, IS_CLIENT,
|
| - matcher: isBuildSourceImportExportClosureTask);
|
| - expect(outputs[IS_CLIENT], isTrue);
|
| - }
|
| -
|
| - test_perform_isClient_true_import_direct() {
|
| - Source sourceA = newSource(
|
| - '/a.dart',
|
| - '''
|
| -library lib_a;
|
| -import 'dart:html';
|
| -''');
|
| - computeResult(sourceA, IS_CLIENT,
|
| - matcher: isBuildSourceImportExportClosureTask);
|
| - expect(outputs[IS_CLIENT], isTrue);
|
| - }
|
| -
|
| - test_perform_isClient_true_import_indirect() {
|
| - Source sourceA = newSource(
|
| - '/a.dart',
|
| - '''
|
| -library lib_a;
|
| -import 'b.dart';
|
| -''');
|
| - newSource(
|
| - '/b.dart',
|
| - '''
|
| -library lib_b;
|
| -import 'dart:html';
|
| -''');
|
| - computeResult(sourceA, IS_CLIENT,
|
| - matcher: isBuildSourceImportExportClosureTask);
|
| - expect(outputs[IS_CLIENT], isTrue);
|
| - }
|
| -}
|
| -
|
| @reflectiveTest
|
| class BuildTypeProviderTaskTest extends _AbstractDartTaskTest {
|
| test_perform() {
|
| @@ -1109,15 +1164,39 @@ class D { const D(value); }
|
| // Now compute the dependencies for the annotation, and check that it is
|
| // the set [x, constructorForD].
|
| // TODO(paulberry): test librarySource != source
|
| - computeResult(
|
| - new ConstantEvaluationTarget_Annotation(
|
| - context, source, source, annotation),
|
| - CONSTANT_DEPENDENCIES,
|
| + computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES,
|
| matcher: isComputeConstantDependenciesTask);
|
| expect(
|
| outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet());
|
| }
|
|
|
| + test_annotation_with_nonConstArg() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class A {
|
| + const A(x);
|
| +}
|
| +class C {
|
| + @A(const [(_) => null])
|
| + String s;
|
| +}
|
| +''');
|
| + // First compute the resolved unit for the source.
|
| + LibrarySpecificUnit librarySpecificUnit =
|
| + new LibrarySpecificUnit(source, source);
|
| + computeResult(librarySpecificUnit, RESOLVED_UNIT1);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT1];
|
| + // Find the annotation on the field.
|
| + ClassDeclaration classC = unit.declarations[1];
|
| + Annotation annotation = classC.members[0].metadata[0];
|
| + // Now compute the dependencies for the annotation, and check that it is
|
| + // the right size.
|
| + computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES,
|
| + matcher: isComputeConstantDependenciesTask);
|
| + expect(outputs[CONSTANT_DEPENDENCIES], hasLength(1));
|
| + }
|
| +
|
| test_annotation_without_args() {
|
| Source source = newSource(
|
| '/test.dart',
|
| @@ -1139,10 +1218,7 @@ const x = 1;
|
| Annotation annotation = findClassAnnotation(unit, 'C');
|
| // Now compute the dependencies for the annotation, and check that it is
|
| // the list [x].
|
| - computeResult(
|
| - new ConstantEvaluationTarget_Annotation(
|
| - context, source, source, annotation),
|
| - CONSTANT_DEPENDENCIES,
|
| + computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES,
|
| matcher: isComputeConstantDependenciesTask);
|
| expect(outputs[CONSTANT_DEPENDENCIES], [x]);
|
| }
|
| @@ -1156,8 +1232,8 @@ enum E {A, B, C}
|
| // First compute the resolved unit for the source.
|
| LibrarySpecificUnit librarySpecificUnit =
|
| new LibrarySpecificUnit(source, source);
|
| - computeResult(librarySpecificUnit, RESOLVED_UNIT2);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT2];
|
| + computeResult(librarySpecificUnit, RESOLVED_UNIT3);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT3];
|
| // Find the element for 'A'
|
| EnumDeclaration enumDeclaration = unit.declarations[0];
|
| EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0];
|
| @@ -1206,14 +1282,13 @@ class ComputeConstantValueTaskTest extends _AbstractDartTaskTest {
|
| if (member is ClassDeclaration && member.name.name == className) {
|
| expect(member.metadata, hasLength(1));
|
| Annotation annotation = member.metadata[0];
|
| - ConstantEvaluationTarget_Annotation target =
|
| - new ConstantEvaluationTarget_Annotation(
|
| - context, source, source, annotation);
|
| + ElementAnnotationImpl target = annotation.elementAnnotation;
|
| computeResult(target, CONSTANT_VALUE,
|
| matcher: isComputeConstantValueTask);
|
| expect(outputs[CONSTANT_VALUE], same(target));
|
| - EvaluationResultImpl evaluationResult = (annotation.elementAnnotation
|
| - as ElementAnnotationImpl).evaluationResult;
|
| + EvaluationResultImpl evaluationResult =
|
| + (annotation.elementAnnotation as ElementAnnotationImpl)
|
| + .evaluationResult;
|
| return evaluationResult;
|
| }
|
| }
|
| @@ -1380,9 +1455,10 @@ const x = 1;
|
| // should be set to the same error state.
|
| for (String otherVariableName in otherVariables) {
|
| PropertyInducingElement otherVariableElement =
|
| - _findVariable(unit, otherVariableName);
|
| - _expectCircularityError((otherVariableElement
|
| - as TopLevelVariableElementImpl).evaluationResult);
|
| + AstFinder.getTopLevelVariableElement(unit, otherVariableName);
|
| + _expectCircularityError(
|
| + (otherVariableElement as TopLevelVariableElementImpl)
|
| + .evaluationResult);
|
| }
|
| }
|
|
|
| @@ -1394,7 +1470,8 @@ const x = 1;
|
| EvaluationResultImpl _evaluateConstant(
|
| CompilationUnit unit, String variableName) {
|
| // Find the element for the given constant.
|
| - PropertyInducingElement variableElement = _findVariable(unit, variableName);
|
| + PropertyInducingElement variableElement =
|
| + AstFinder.getTopLevelVariableElement(unit, variableName);
|
| // Now compute the value of the constant.
|
| computeResult(variableElement, CONSTANT_VALUE,
|
| matcher: isComputeConstantValueTask);
|
| @@ -1412,13 +1489,6 @@ const x = 1;
|
| CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
|
| }
|
|
|
| - PropertyInducingElement _findVariable(
|
| - CompilationUnit unit, String variableName) {
|
| - // Find the element for the given constant.
|
| - return unit.element.topLevelVariables.firstWhere(
|
| - (TopLevelVariableElement variable) => variable.name == variableName);
|
| - }
|
| -
|
| CompilationUnit _resolveSource(Source source) {
|
| LibrarySpecificUnit librarySpecificUnit =
|
| new LibrarySpecificUnit(source, source);
|
| @@ -1441,6 +1511,19 @@ class ComputeInferableStaticVariableDependenciesTaskTest
|
| enableStrongMode();
|
| }
|
|
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT7);
|
| + expect(outputs[RESOLVED_UNIT7], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT7], isTrue);
|
| + }
|
| +
|
| test_perform() {
|
| AnalysisTarget source = newSource(
|
| '/test.dart',
|
| @@ -1449,28 +1532,183 @@ const a = b;
|
| const b = 0;
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| + computeResult(target, RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| TopLevelVariableElement elementA = unit.element.topLevelVariables[0];
|
| TopLevelVariableElement elementB = unit.element.topLevelVariables[1];
|
|
|
| computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES,
|
| matcher: isComputeInferableStaticVariableDependenciesTask);
|
| expect(outputs, hasLength(1));
|
| - List<VariableElement> dependencies =
|
| - outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES];
|
| + List<VariableElement> dependencies = outputs[
|
| + INFERABLE_STATIC_VARIABLE_DEPENDENCIES] as List<VariableElement>;
|
| expect(dependencies, unorderedEquals([elementB]));
|
| }
|
| }
|
|
|
| @reflectiveTest
|
| class ComputeLibraryCycleTaskTest extends _AbstractDartTaskTest {
|
| + List<LibraryElement> getLibraryCycle(Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[LIBRARY_CYCLE] as List<LibraryElement>;
|
| + }
|
| +
|
| + List<LibrarySpecificUnit> getLibraryCycleDependencies(
|
| + Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[LIBRARY_CYCLE_DEPENDENCIES] as List<LibrarySpecificUnit>;
|
| + }
|
| +
|
| + List<LibrarySpecificUnit> getLibraryCycleUnits(
|
| + Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[LIBRARY_CYCLE_UNITS] as List<LibrarySpecificUnit>;
|
| + }
|
| +
|
| @override
|
| void setUp() {
|
| super.setUp();
|
| enableStrongMode();
|
| }
|
|
|
| + void test_library_cycle_incremental() {
|
| + enableStrongMode();
|
| + Source a = newSource(
|
| + '/a.dart',
|
| + '''
|
| +library a;
|
| +''');
|
| + Source b = newSource(
|
| + '/b.dart',
|
| + '''
|
| +library b;
|
| +import 'a.dart';
|
| +''');
|
| + Source c = newSource(
|
| + '/c.dart',
|
| + '''
|
| +library c;
|
| +import 'b.dart';
|
| +''');
|
| +
|
| + _assertLibraryCycle(a, [a]);
|
| + _assertLibraryCycle(b, [b]);
|
| + _assertLibraryCycle(c, [c]);
|
| +
|
| + // Create a cycle.
|
| + context.setContents(
|
| + a,
|
| + '''
|
| +library a;
|
| +import 'c.dart';
|
| +''');
|
| + _expectInvalid(a);
|
| + _expectInvalid(b);
|
| + _expectInvalid(c);
|
| +
|
| + _assertLibraryCycle(a, [a, b, c]);
|
| + _assertLibraryCycle(b, [a, b, c]);
|
| + _assertLibraryCycle(c, [a, b, c]);
|
| +
|
| + // Break the cycle again.
|
| + context.setContents(
|
| + a,
|
| + '''
|
| +library a;
|
| +''');
|
| + _expectInvalid(a);
|
| + _expectInvalid(b);
|
| + _expectInvalid(c);
|
| +
|
| + _assertLibraryCycle(a, [a]);
|
| + _assertLibraryCycle(b, [b]);
|
| + _assertLibraryCycle(c, [c]);
|
| + }
|
| +
|
| + void test_library_cycle_incremental_partial() {
|
| + enableStrongMode();
|
| + Source a = newSource(
|
| + '/a.dart',
|
| + r'''
|
| +library a;
|
| +''');
|
| + Source b = newSource(
|
| + '/b.dart',
|
| + r'''
|
| +library b;
|
| +import 'a.dart';
|
| +''');
|
| + Source c = newSource(
|
| + '/c.dart',
|
| + r'''
|
| +library c;
|
| +import 'b.dart';
|
| +''');
|
| +
|
| + _assertLibraryCycle(a, [a]);
|
| + _assertLibraryCycle(b, [b]);
|
| + // 'c' is not reachable, so we have not yet computed its library cycles.
|
| +
|
| + // Complete the cycle, via 'c'.
|
| + context.setContents(
|
| + a,
|
| + r'''
|
| +library a;
|
| +import 'c.dart';
|
| +''');
|
| + _expectInvalid(a);
|
| + _expectInvalid(b);
|
| + _expectInvalid(c);
|
| +
|
| + // Ensure that everything reachable through 'c' was invalidated,
|
| + // and recomputed to include all three sources.
|
| + _assertLibraryCycle(a, [a, b, c]);
|
| + _assertLibraryCycle(b, [a, b, c]);
|
| + _assertLibraryCycle(c, [a, b, c]);
|
| + }
|
| +
|
| + void test_library_cycle_incremental_partial2() {
|
| + enableStrongMode();
|
| + Source a = newSource(
|
| + '/a.dart',
|
| + r'''
|
| +library a;
|
| +import 'b.dart';
|
| +''');
|
| + Source b = newSource(
|
| + '/b.dart',
|
| + r'''
|
| +library b;
|
| +import 'a.dart';
|
| +''');
|
| + Source c = newSource(
|
| + '/c.dart',
|
| + r'''
|
| +library c;
|
| +import 'b.dart';
|
| +''');
|
| +
|
| + _assertLibraryCycle(a, [a, b]);
|
| + _assertLibraryCycle(b, [a, b]);
|
| + _assertLibraryCycle(c, [c]);
|
| +
|
| + // Include 'c' into the cycle.
|
| + context.setContents(
|
| + a,
|
| + r'''
|
| +library a;
|
| +import 'b.dart';
|
| +import 'c.dart';
|
| +''');
|
| + _expectInvalid(a);
|
| + _expectInvalid(b);
|
| + _expectInvalid(c);
|
| +
|
| + // Start processing with 'b', so that when we resolve 'b' directives,
|
| + // and invalidate library cycles, the 'a' directives are not resolved yet,
|
| + // so we don't know that the cycle must include 'c'.
|
| + _assertLibraryCycle(b, [a, b, c]);
|
| + _assertLibraryCycle(a, [a, b, c]);
|
| + _assertLibraryCycle(c, [a, b, c]);
|
| + }
|
| +
|
| void test_library_cycle_linear() {
|
| List<Source> sources = newSources({
|
| '/a.dart': '''
|
| @@ -1481,18 +1719,18 @@ import 'a.dart';
|
| });
|
| List<Map<ResultDescriptor, dynamic>> results =
|
| computeLibraryResultsMap(sources, LIBRARY_CYCLE);
|
| - List<LibraryElement> component0 = results[0][LIBRARY_CYCLE];
|
| - List<LibraryElement> component1 = results[1][LIBRARY_CYCLE];
|
| + List<LibraryElement> component0 = getLibraryCycle(results[0]);
|
| + List<LibraryElement> component1 = getLibraryCycle(results[1]);
|
| expect(component0, hasLength(1));
|
| expect(component1, hasLength(1));
|
|
|
| - List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS];
|
| + List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]);
|
| + List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]);
|
| expect(units0, hasLength(1));
|
| expect(units1, hasLength(1));
|
|
|
| - List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES];
|
| + List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]);
|
| + List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]);
|
| expect(dep0, hasLength(1)); // dart:core
|
| expect(dep1, hasLength(2)); // dart:core, a.dart
|
| }
|
| @@ -1511,44 +1749,103 @@ import 'a.dart';
|
| });
|
| List<Map<ResultDescriptor, dynamic>> results =
|
| computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
|
| - List<LibraryElement> component0 = results[0][LIBRARY_CYCLE];
|
| - List<LibraryElement> component1 = results[1][LIBRARY_CYCLE];
|
| - List<LibraryElement> component2 = results[2][LIBRARY_CYCLE];
|
| + List<LibraryElement> component0 = getLibraryCycle(results[0]);
|
| + List<LibraryElement> component1 = getLibraryCycle(results[1]);
|
| + List<LibraryElement> component2 = getLibraryCycle(results[2]);
|
|
|
| expect(component0, hasLength(3));
|
| expect(component1, hasLength(3));
|
| expect(component2, hasLength(3));
|
|
|
| - List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS];
|
| + List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]);
|
| + List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]);
|
| + List<LibrarySpecificUnit> units2 = getLibraryCycleUnits(results[2]);
|
| expect(units0, hasLength(3));
|
| expect(units1, hasLength(3));
|
| expect(units2, hasLength(3));
|
|
|
| - List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES];
|
| + List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]);
|
| + List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]);
|
| + List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]);
|
| expect(dep0, hasLength(1)); // dart:core
|
| expect(dep1, hasLength(1)); // dart:core
|
| expect(dep2, hasLength(1)); // dart:core
|
| }
|
|
|
| - void test_library_cycle_self_loop() {
|
| - List<Source> sources = newSources({
|
| - '/a.dart': '''
|
| - import 'a.dart';
|
| -'''
|
| - });
|
| - List<Map<ResultDescriptor, dynamic>> results =
|
| - computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
|
| - List<LibraryElement> component0 = results[0][LIBRARY_CYCLE];
|
| - expect(component0, hasLength(1));
|
| -
|
| - List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS];
|
| - expect(units0, hasLength(1));
|
| + void test_library_cycle_override_inference_incremental() {
|
| + enableStrongMode();
|
| + Source lib1Source = newSource(
|
| + '/my_lib1.dart',
|
| + '''
|
| +library my_lib1;
|
| +import 'my_lib3.dart';
|
| +''');
|
| + Source lib2Source = newSource(
|
| + '/my_lib2.dart',
|
| + '''
|
| +library my_lib2;
|
| +import 'my_lib1.dart';
|
| +''');
|
| + Source lib3Source = newSource(
|
| + '/my_lib3.dart',
|
| + '''
|
| +library my_lib3;
|
| +import 'my_lib2.dart';
|
| +
|
| +class A {
|
| + int foo(int x) => null;
|
| +}
|
| +class B extends A {
|
| + foo(x) => null;
|
| +}
|
| +''');
|
| + AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source);
|
| + AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source);
|
| + AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source);
|
| +
|
| + computeResult(lib1Target, RESOLVED_UNIT);
|
| + computeResult(lib2Target, RESOLVED_UNIT);
|
| + computeResult(lib3Target, RESOLVED_UNIT);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT];
|
| + ClassElement b = unit.declarations[1].element;
|
| + expect(b.getMethod('foo').returnType.toString(), 'int');
|
| +
|
| + // add a dummy edit.
|
| + context.setContents(
|
| + lib1Source,
|
| + '''
|
| +library my_lib1;
|
| +import 'my_lib3.dart';
|
| +var foo = 123;
|
| +''');
|
| + _expectInvalid(lib1Source);
|
| + _expectInvalid(lib2Source);
|
| + _expectInvalid(lib3Source);
|
| +
|
| + computeResult(lib1Target, RESOLVED_UNIT);
|
| + computeResult(lib2Target, RESOLVED_UNIT);
|
| + computeResult(lib3Target, RESOLVED_UNIT);
|
| + unit = outputs[RESOLVED_UNIT];
|
| + b = unit.declarations[1].element;
|
| + expect(b.getMethod('foo').returnType.toString(), 'int',
|
| + reason: 'edit should not affect member inference');
|
| + }
|
| +
|
| + void test_library_cycle_self_loop() {
|
| + List<Source> sources = newSources({
|
| + '/a.dart': '''
|
| + import 'a.dart';
|
| +'''
|
| + });
|
| + List<Map<ResultDescriptor, dynamic>> results =
|
| + computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
|
| + List<LibraryElement> component0 = getLibraryCycle(results[0]);
|
| + expect(component0, hasLength(1));
|
| +
|
| + List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]);
|
| + expect(units0, hasLength(1));
|
|
|
| - List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES];
|
| + List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]);
|
| expect(dep0, hasLength(1)); // dart:core
|
| }
|
|
|
| @@ -1558,10 +1855,10 @@ import 'a.dart';
|
| '''
|
| import 'dart:core';
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), LIBRARY_CYCLE);
|
| - List<LibraryElement> component = outputs[LIBRARY_CYCLE];
|
| - List<CompilationUnitElement> units = outputs[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> deps = outputs[LIBRARY_CYCLE_DEPENDENCIES];
|
| + computeResult(source, LIBRARY_CYCLE);
|
| + List<LibraryElement> component = getLibraryCycle(outputs);
|
| + List<LibrarySpecificUnit> units = getLibraryCycleUnits(outputs);
|
| + List<LibrarySpecificUnit> deps = getLibraryCycleDependencies(outputs);
|
| expect(component, hasLength(1));
|
| expect(units, hasLength(1));
|
| expect(deps, hasLength(1));
|
| @@ -1580,23 +1877,23 @@ import 'dart:core';
|
| });
|
| List<Map<ResultDescriptor, dynamic>> results =
|
| computeLibraryResultsMap(sources, LIBRARY_CYCLE);
|
| - List<LibraryElement> component0 = results[0][LIBRARY_CYCLE];
|
| - List<LibraryElement> component1 = results[1][LIBRARY_CYCLE];
|
| - List<LibraryElement> component2 = results[2][LIBRARY_CYCLE];
|
| + List<LibraryElement> component0 = getLibraryCycle(results[0]);
|
| + List<LibraryElement> component1 = getLibraryCycle(results[1]);
|
| + List<LibraryElement> component2 = getLibraryCycle(results[2]);
|
| expect(component0, hasLength(1));
|
| expect(component1, hasLength(1));
|
| expect(component2, hasLength(1));
|
|
|
| - List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS];
|
| + List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]);
|
| + List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]);
|
| + List<LibrarySpecificUnit> units2 = getLibraryCycleUnits(results[2]);
|
| expect(units0, hasLength(1));
|
| expect(units1, hasLength(1));
|
| expect(units2, hasLength(1));
|
|
|
| - List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES];
|
| + List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]);
|
| + List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]);
|
| + List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]);
|
| expect(dep0, hasLength(1)); // dart:core
|
| expect(dep1, hasLength(1)); // dart:core,
|
| expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart
|
| @@ -1623,32 +1920,32 @@ import 'dart:core';
|
| });
|
| List<Map<ResultDescriptor, dynamic>> results =
|
| computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
|
| - List<LibraryElement> component0 = results[0][LIBRARY_CYCLE];
|
| - List<LibraryElement> component1 = results[1][LIBRARY_CYCLE];
|
| - List<LibraryElement> component2 = results[2][LIBRARY_CYCLE];
|
| - List<LibraryElement> component3 = results[3][LIBRARY_CYCLE];
|
| + List<LibraryElement> component0 = getLibraryCycle(results[0]);
|
| + List<LibraryElement> component1 = getLibraryCycle(results[1]);
|
| + List<LibraryElement> component2 = getLibraryCycle(results[2]);
|
| + List<LibraryElement> component3 = getLibraryCycle(results[3]);
|
|
|
| expect(component0, hasLength(2));
|
| expect(component1, hasLength(2));
|
| expect(component2, hasLength(2));
|
| expect(component3, hasLength(2));
|
|
|
| - List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units3 = results[3][LIBRARY_CYCLE_UNITS];
|
| + List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]);
|
| + List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]);
|
| + List<LibrarySpecificUnit> units2 = getLibraryCycleUnits(results[2]);
|
| + List<LibrarySpecificUnit> units3 = getLibraryCycleUnits(results[3]);
|
| expect(units0, hasLength(2));
|
| expect(units1, hasLength(2));
|
| expect(units2, hasLength(2));
|
| expect(units3, hasLength(2));
|
|
|
| - List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep3 = results[3][LIBRARY_CYCLE_DEPENDENCIES];
|
| + List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]);
|
| + List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]);
|
| + List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]);
|
| + List<LibrarySpecificUnit> dep3 = getLibraryCycleDependencies(results[3]);
|
| expect(dep0, hasLength(1)); // dart:core
|
| expect(dep1, hasLength(1)); // dart:core
|
| - expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart
|
| + expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart
|
| expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart
|
| }
|
|
|
| @@ -1683,94 +1980,69 @@ import 'dart:core';
|
| '/db.dart': '''
|
| '''
|
| });
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[0], sources[0]), LIBRARY_CYCLE);
|
| + computeResult(sources[0], LIBRARY_CYCLE);
|
| Map<ResultDescriptor, dynamic> results0 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[1], sources[1]), LIBRARY_CYCLE);
|
| + computeResult(sources[1], LIBRARY_CYCLE);
|
| Map<ResultDescriptor, dynamic> results1 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[0], sources[2]), LIBRARY_CYCLE);
|
| - Map<ResultDescriptor, dynamic> results2 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[0], sources[3]), LIBRARY_CYCLE);
|
| - Map<ResultDescriptor, dynamic> results3 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[4], sources[4]), LIBRARY_CYCLE);
|
| + computeResult(sources[4], LIBRARY_CYCLE);
|
| Map<ResultDescriptor, dynamic> results4 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[5], sources[5]), LIBRARY_CYCLE);
|
| + computeResult(sources[5], LIBRARY_CYCLE);
|
| Map<ResultDescriptor, dynamic> results5 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[5], sources[6]), LIBRARY_CYCLE);
|
| - Map<ResultDescriptor, dynamic> results6 = outputs;
|
| - computeResult(
|
| - new LibrarySpecificUnit(sources[5], sources[7]), LIBRARY_CYCLE);
|
| - Map<ResultDescriptor, dynamic> results7 = outputs;
|
| -
|
| - List<LibraryElement> component0 = results0[LIBRARY_CYCLE];
|
| - List<LibraryElement> component1 = results1[LIBRARY_CYCLE];
|
| - List<LibraryElement> component2 = results2[LIBRARY_CYCLE];
|
| - List<LibraryElement> component3 = results3[LIBRARY_CYCLE];
|
| - List<LibraryElement> component4 = results4[LIBRARY_CYCLE];
|
| - List<LibraryElement> component5 = results5[LIBRARY_CYCLE];
|
| - List<LibraryElement> component6 = results6[LIBRARY_CYCLE];
|
| - List<LibraryElement> component7 = results7[LIBRARY_CYCLE];
|
| +
|
| + List<LibraryElement> component0 = getLibraryCycle(results0);
|
| + List<LibraryElement> component1 = getLibraryCycle(results1);
|
| + List<LibraryElement> component4 = getLibraryCycle(results4);
|
| + List<LibraryElement> component5 = getLibraryCycle(results5);
|
|
|
| expect(component0, hasLength(2));
|
| expect(component1, hasLength(2));
|
| - expect(component2, hasLength(2));
|
| - expect(component3, hasLength(2));
|
| expect(component4, hasLength(2));
|
| expect(component5, hasLength(2));
|
| - expect(component6, hasLength(2));
|
| - expect(component7, hasLength(2));
|
| -
|
| - List<CompilationUnitElement> units0 = results0[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units1 = results1[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units2 = results2[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units3 = results3[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units4 = results4[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units5 = results5[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units6 = results6[LIBRARY_CYCLE_UNITS];
|
| - List<CompilationUnitElement> units7 = results7[LIBRARY_CYCLE_UNITS];
|
| +
|
| + List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results0);
|
| + List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results1);
|
| + List<LibrarySpecificUnit> units4 = getLibraryCycleUnits(results4);
|
| + List<LibrarySpecificUnit> units5 = getLibraryCycleUnits(results5);
|
| expect(units0, hasLength(4));
|
| expect(units1, hasLength(4));
|
| - expect(units2, hasLength(4));
|
| - expect(units3, hasLength(4));
|
| expect(units4, hasLength(4));
|
| expect(units5, hasLength(4));
|
| - expect(units6, hasLength(4));
|
| - expect(units7, hasLength(4));
|
| -
|
| - List<CompilationUnitElement> dep0 = results0[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep1 = results1[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep2 = results2[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep3 = results3[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep4 = results4[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep5 = results5[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep6 = results6[LIBRARY_CYCLE_DEPENDENCIES];
|
| - List<CompilationUnitElement> dep7 = results7[LIBRARY_CYCLE_DEPENDENCIES];
|
| +
|
| + List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results0);
|
| + List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results1);
|
| + List<LibrarySpecificUnit> dep4 = getLibraryCycleDependencies(results4);
|
| + List<LibrarySpecificUnit> dep5 = getLibraryCycleDependencies(results5);
|
| expect(dep0, hasLength(1)); // dart:core
|
| expect(dep1, hasLength(1)); // dart:core
|
| - expect(dep2, hasLength(1)); // dart:core
|
| - expect(dep3, hasLength(1)); // dart:core
|
| expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
|
| expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
|
| - expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
|
| - expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
|
| + }
|
| +
|
| + void _assertLibraryCycle(Source source, List<Source> expected) {
|
| + computeResult(source, LIBRARY_CYCLE);
|
| + List<LibraryElement> cycle = outputs[LIBRARY_CYCLE] as List<LibraryElement>;
|
| + expect(cycle.map((e) => e.source), unorderedEquals(expected));
|
| + }
|
| +
|
| + void _expectInvalid(Source librarySource) {
|
| + CacheEntry entry = context.getCacheEntry(librarySource);
|
| + expect(entry.getState(LIBRARY_CYCLE), CacheState.INVALID);
|
| }
|
| }
|
|
|
| @reflectiveTest
|
| class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
|
| + List<Source> getContainingLibraries(Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[CONTAINING_LIBRARIES] as List<Source>;
|
| + }
|
| +
|
| test_perform_definingCompilationUnit() {
|
| AnalysisTarget library = newSource('/test.dart', 'library test;');
|
| computeResult(library, INCLUDED_PARTS);
|
| computeResult(library, CONTAINING_LIBRARIES,
|
| matcher: isContainingLibrariesTask);
|
| expect(outputs, hasLength(1));
|
| - List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
|
| + List<Source> containingLibraries = getContainingLibraries(outputs);
|
| expect(containingLibraries, unorderedEquals([library]));
|
| }
|
|
|
| @@ -1786,7 +2058,7 @@ class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
|
| computeResult(part, CONTAINING_LIBRARIES,
|
| matcher: isContainingLibrariesTask);
|
| expect(outputs, hasLength(1));
|
| - List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
|
| + List<Source> containingLibraries = getContainingLibraries(outputs);
|
| expect(containingLibraries, unorderedEquals([library1, library2]));
|
| }
|
|
|
| @@ -1799,20 +2071,24 @@ class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
|
| computeResult(part, CONTAINING_LIBRARIES,
|
| matcher: isContainingLibrariesTask);
|
| expect(outputs, hasLength(1));
|
| - List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
|
| + List<Source> containingLibraries = getContainingLibraries(outputs);
|
| expect(containingLibraries, unorderedEquals([library]));
|
| }
|
| }
|
|
|
| @reflectiveTest
|
| class DartErrorsTaskTest extends _AbstractDartTaskTest {
|
| + List<AnalysisError> getDartErrors(Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[DART_ERRORS] as List<AnalysisError>;
|
| + }
|
| +
|
| test_perform_definingCompilationUnit() {
|
| AnalysisTarget library =
|
| newSource('/test.dart', 'library test; import "dart:math";');
|
| computeResult(library, INCLUDED_PARTS);
|
| computeResult(library, DART_ERRORS, matcher: isDartErrorsTask);
|
| expect(outputs, hasLength(1));
|
| - List<AnalysisError> errors = outputs[DART_ERRORS];
|
| + List<AnalysisError> errors = getDartErrors(outputs);
|
| expect(errors, hasLength(1));
|
| }
|
|
|
| @@ -1825,7 +2101,7 @@ class DartErrorsTaskTest extends _AbstractDartTaskTest {
|
| computeResult(library, DART_ERRORS);
|
| computeResult(part, DART_ERRORS, matcher: isDartErrorsTask);
|
| expect(outputs, hasLength(1));
|
| - List<AnalysisError> errors = outputs[DART_ERRORS];
|
| + List<AnalysisError> errors = getDartErrors(outputs);
|
| // This should contain only the errors in the part file, not the ones in the
|
| // library.
|
| expect(errors, hasLength(1));
|
| @@ -1834,6 +2110,19 @@ class DartErrorsTaskTest extends _AbstractDartTaskTest {
|
|
|
| @reflectiveTest
|
| class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest {
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT12);
|
| + expect(outputs[RESOLVED_UNIT12], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT12], isTrue);
|
| + }
|
| +
|
| test_perform() {
|
| Source source = newSource(
|
| '/test.dart',
|
| @@ -1848,9 +2137,9 @@ f() {}
|
| const x = const C();
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT10,
|
| + computeResult(target, RESOLVED_UNIT12,
|
| matcher: isEvaluateUnitConstantsTask);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT10];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT12];
|
| CompilationUnitElement unitElement = unit.element;
|
| expect(
|
| (unitElement.types[0].constructors[0] as ConstructorElementImpl)
|
| @@ -1872,7 +2161,7 @@ class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest {
|
| UsedImportedElements usedElements;
|
| Set<String> usedElementNames;
|
|
|
| - test_perform() {
|
| + test_perform_inBody() {
|
| newSource(
|
| '/a.dart',
|
| r'''
|
| @@ -1898,6 +2187,54 @@ main() {
|
| expect(usedElementNames, unorderedEquals(['A']));
|
| }
|
|
|
| + test_perform_inComment_exportDirective() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +import 'dart:async';
|
| +/// Use [Future].
|
| +export 'dart:math';
|
| +''');
|
| + _computeUsedElements(source);
|
| + expect(usedElementNames, unorderedEquals(['Future']));
|
| + }
|
| +
|
| + test_perform_inComment_importDirective() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +import 'dart:async';
|
| +/// Use [Future].
|
| +import 'dart:math';
|
| +''');
|
| + _computeUsedElements(source);
|
| + expect(usedElementNames, unorderedEquals(['Future']));
|
| + }
|
| +
|
| + test_perform_inComment_libraryDirective() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +/// Use [Future].
|
| +library test;
|
| +import 'dart:async';
|
| +''');
|
| + _computeUsedElements(source);
|
| + expect(usedElementNames, unorderedEquals(['Future']));
|
| + }
|
| +
|
| + test_perform_inComment_topLevelFunction() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +import 'dart:async';
|
| +/// Use [Future].
|
| +main() {}
|
| +''');
|
| + _computeUsedElements(source);
|
| + expect(usedElementNames, unorderedEquals(['Future']));
|
| + }
|
| +
|
| void _computeUsedElements(Source source) {
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| computeResult(target, USED_IMPORTED_ELEMENTS,
|
| @@ -2292,12 +2629,28 @@ class GenerateLintsTaskTest_AstVisitor extends SimpleAstVisitor {
|
| }
|
|
|
| class GenerateLintsTaskTest_TestLinter extends Linter {
|
| + @override
|
| + String get name => 'GenerateLintsTaskTest_TestLinter';
|
| +
|
| @override
|
| AstVisitor getVisitor() => new GenerateLintsTaskTest_AstVisitor(this);
|
| }
|
|
|
| @reflectiveTest
|
| class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest {
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT10);
|
| + expect(outputs[RESOLVED_UNIT10], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT10], isTrue);
|
| + }
|
| +
|
| void test_perform() {
|
| enableStrongMode();
|
| AnalysisTarget source = newSource(
|
| @@ -2315,14 +2668,14 @@ class X {}
|
| class Y {}
|
| class Z {}
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10,
|
| 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;
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT10];
|
| + 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);
|
| @@ -2349,16 +2702,19 @@ class M {
|
| }
|
| ''');
|
| computeResult(
|
| - new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8,
|
| + new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10,
|
| matcher: isInferInstanceMembersInUnitTask);
|
| - CompilationUnit firstUnit = outputs[RESOLVED_UNIT8];
|
| + CompilationUnit firstUnit = outputs[RESOLVED_UNIT10];
|
| computeResult(
|
| - 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');
|
| + new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10);
|
| + CompilationUnit secondUnit = outputs[RESOLVED_UNIT10];
|
| +
|
| + 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);
|
| @@ -2378,10 +2734,12 @@ class C {
|
| String field = topLevel;
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT8];
|
| - VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel');
|
| - VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field');
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT10];
|
| + VariableDeclaration topLevelDecl =
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel');
|
| + VariableDeclaration fieldDecl =
|
| + AstFinder.getFieldInClass(unit, 'C', 'field');
|
| VariableElement topLevel = topLevelDecl.name.staticElement;
|
| VariableElement field = fieldDecl.name.staticElement;
|
|
|
| @@ -2394,6 +2752,25 @@ class C {
|
|
|
| @reflectiveTest
|
| class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest {
|
| + @override
|
| + void setUp() {
|
| + super.setUp();
|
| + enableStrongMode();
|
| + }
|
| +
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT8);
|
| + expect(outputs[RESOLVED_UNIT8], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT8], isTrue);
|
| + }
|
| +
|
| void test_perform_const_field() {
|
| enableStrongMode();
|
| AnalysisTarget source = newSource(
|
| @@ -2403,14 +2780,26 @@ class M {
|
| static const X = "";
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
|
| matcher: isInferStaticVariableTypesInUnitTask);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
| - VariableDeclaration declaration = getFieldInClass(unit, 'M', 'X');
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT8];
|
| + VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X');
|
| InterfaceType stringType = context.typeProvider.stringType;
|
| expect(declaration.element.type, stringType);
|
| }
|
|
|
| + test_perform_hasParseError() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +@(i $=
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT8);
|
| + expect(outputs[RESOLVED_UNIT8], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT8], isTrue);
|
| + }
|
| +
|
| void test_perform_nestedDeclarations() {
|
| enableStrongMode();
|
| AnalysisTarget source = newSource(
|
| @@ -2422,7 +2811,7 @@ var f = (int x) {
|
| return xSquared;
|
| };
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
|
| matcher: isInferStaticVariableTypesInUnitTask);
|
| }
|
|
|
| @@ -2445,17 +2834,20 @@ var b = a;
|
| class M {}
|
| ''');
|
| computeResult(
|
| - new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT6,
|
| + new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8,
|
| matcher: isInferStaticVariableTypesInUnitTask);
|
| - CompilationUnit firstUnit = outputs[RESOLVED_UNIT6];
|
| + CompilationUnit firstUnit = outputs[RESOLVED_UNIT8];
|
| computeResult(
|
| - new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6);
|
| - CompilationUnit secondUnit = outputs[RESOLVED_UNIT6];
|
| + new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8);
|
| + CompilationUnit secondUnit = outputs[RESOLVED_UNIT8];
|
|
|
| - 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);
|
| @@ -2476,9 +2868,9 @@ var Y = () {
|
| return 1 + X;
|
| };
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
|
| matcher: isInferStaticVariableTypesInUnitTask);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT8];
|
| TopLevelVariableDeclaration declaration = unit.declarations[1];
|
| FunctionExpression function =
|
| declaration.variables.variables[0].initializer;
|
| @@ -2488,6 +2880,26 @@ var Y = () {
|
| InterfaceType intType = context.typeProvider.intType;
|
| expect(expression.staticType, intType);
|
| }
|
| +
|
| + test_staticModeHints_forStaticVariableInference() {
|
| + context.analysisOptions =
|
| + new AnalysisOptionsImpl.from(context.analysisOptions)
|
| + ..strongModeHints = true;
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +var V = [42];
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT8);
|
| + expect(outputs[RESOLVED_UNIT8], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT8], isTrue);
|
| + // An INFERRED_TYPE_LITERAL error should be generated.
|
| + List<AnalysisError> errors = outputs[
|
| + STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] as List<AnalysisError>;
|
| + expect(errors, hasLength(1));
|
| + expect(errors[0].errorCode, StrongModeCode.INFERRED_TYPE_LITERAL);
|
| + }
|
| }
|
|
|
| @reflectiveTest
|
| @@ -2500,9 +2912,10 @@ class C {
|
| var field = '';
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableDeclaration declaration = getFieldInClass(unit, 'C', 'field');
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| + VariableDeclaration declaration =
|
| + AstFinder.getFieldInClass(unit, 'C', 'field');
|
| VariableElement variable = declaration.name.staticElement;
|
| InferStaticVariableTypeTask inferTask =
|
| new InferStaticVariableTypeTask(task.context, variable);
|
| @@ -2515,9 +2928,10 @@ class C {
|
| '''
|
| var topLevel = '';
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel');
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| + VariableDeclaration declaration =
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel');
|
| VariableElement variable = declaration.name.staticElement;
|
| InferStaticVariableTypeTask inferTask =
|
| new InferStaticVariableTypeTask(task.context, variable);
|
| @@ -2534,10 +2948,12 @@ class C {
|
| var field3 = topLevel3;
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3');
|
| - VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3');
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| + VariableDeclaration topLevelDecl =
|
| + AstFinder.getTopLevelVariable(unit, 'topLevel3');
|
| + VariableDeclaration fieldDecl =
|
| + AstFinder.getFieldInClass(unit, 'C', 'field3');
|
| VariableElement topLevel = topLevelDecl.name.staticElement;
|
| VariableElement field = fieldDecl.name.staticElement;
|
|
|
| @@ -2559,12 +2975,12 @@ class C {
|
| var field = topLevel;
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| 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);
|
| @@ -2582,12 +2998,14 @@ var piFirst = true;
|
| var pi = piFirst ? 3.14 : tau / 2;
|
| var tau = piFirst ? pi * 2 : 6.28;
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| 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);
|
| @@ -2603,9 +3021,10 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| '''
|
| var a = '' / null;
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| + VariableElement a =
|
| + AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
|
|
|
| computeResult(a, INFERRED_STATIC_VARIABLE,
|
| matcher: isInferStaticVariableTypeTask);
|
| @@ -2619,9 +3038,10 @@ var a = '' / null;
|
| '''
|
| var a = null;
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| + VariableElement a =
|
| + AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
|
|
|
| computeResult(a, INFERRED_STATIC_VARIABLE,
|
| matcher: isInferStaticVariableTypeTask);
|
| @@ -2665,6 +3085,11 @@ X v3;
|
|
|
| @reflectiveTest
|
| class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest {
|
| + List<AnalysisError> getLibraryUnitErrors(
|
| + Map<ResultDescriptor, dynamic> outputs) {
|
| + return outputs[LIBRARY_UNIT_ERRORS] as List<AnalysisError>;
|
| + }
|
| +
|
| test_perform_definingCompilationUnit() {
|
| AnalysisTarget library =
|
| newSource('/test.dart', 'library test; import "dart:math";');
|
| @@ -2672,7 +3097,7 @@ class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest {
|
| new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS,
|
| matcher: isLibraryUnitErrorsTask);
|
| expect(outputs, hasLength(1));
|
| - List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS];
|
| + List<AnalysisError> errors = getLibraryUnitErrors(outputs);
|
| expect(errors, hasLength(1));
|
| }
|
|
|
| @@ -2683,7 +3108,7 @@ class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest {
|
| computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS,
|
| matcher: isLibraryUnitErrorsTask);
|
| expect(outputs, hasLength(1));
|
| - List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS];
|
| + List<AnalysisError> errors = getLibraryUnitErrors(outputs);
|
| expect(errors, hasLength(0));
|
| }
|
| }
|
| @@ -2696,13 +3121,16 @@ class ParseDartTaskTest extends _AbstractDartTaskTest {
|
| _performParseTask(r'''
|
| part of lib;
|
| class B {}''');
|
| - expect(outputs, hasLength(8));
|
| + expect(outputs, hasLength(11));
|
| expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
|
| expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
|
| _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
|
| expect(outputs[INCLUDED_PARTS], hasLength(0));
|
| + expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1));
|
| expect(outputs[PARSE_ERRORS], hasLength(0));
|
| expect(outputs[PARSED_UNIT], isNotNull);
|
| + expect(outputs[REFERENCED_NAMES], isNotNull);
|
| + expect(outputs[REFERENCED_SOURCES], hasLength(2));
|
| expect(outputs[SOURCE_KIND], SourceKind.PART);
|
| expect(outputs[UNITS], hasLength(1));
|
| }
|
| @@ -2729,17 +3157,27 @@ part 'test.dart';
|
|
|
| test_perform_doesNotExist() {
|
| _performParseTask(null);
|
| - expect(outputs, hasLength(8));
|
| + expect(outputs, hasLength(11));
|
| expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
|
| expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
|
| _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
|
| expect(outputs[INCLUDED_PARTS], hasLength(0));
|
| + expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1));
|
| expect(outputs[PARSE_ERRORS], hasLength(0));
|
| expect(outputs[PARSED_UNIT], isNotNull);
|
| - expect(outputs[SOURCE_KIND], SourceKind.UNKNOWN);
|
| + expect(outputs[REFERENCED_NAMES], isNotNull);
|
| + expect(outputs[REFERENCED_SOURCES], hasLength(2));
|
| + expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
|
| expect(outputs[UNITS], hasLength(1));
|
| }
|
|
|
| + test_perform_flushTokenStream() {
|
| + _performParseTask(r'''
|
| +class Test {}
|
| +''');
|
| + expect(analysisCache.getState(source, TOKEN_STREAM), CacheState.FLUSHED);
|
| + }
|
| +
|
| test_perform_invalidDirectives() {
|
| _performParseTask(r'''
|
| library lib;
|
| @@ -2748,13 +3186,16 @@ import '://invaliduri.dart';
|
| export '${a}lib3.dart';
|
| part 'part.dart';
|
| class A {}''');
|
| - expect(outputs, hasLength(8));
|
| + expect(outputs, hasLength(11));
|
| expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1));
|
| expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
|
| _assertHasCore(outputs[IMPORTED_LIBRARIES], 2);
|
| expect(outputs[INCLUDED_PARTS], hasLength(1));
|
| + expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2));
|
| expect(outputs[PARSE_ERRORS], hasLength(2));
|
| expect(outputs[PARSED_UNIT], isNotNull);
|
| + expect(outputs[REFERENCED_NAMES], isNotNull);
|
| + expect(outputs[REFERENCED_SOURCES], hasLength(4));
|
| expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
|
| expect(outputs[UNITS], hasLength(2));
|
| }
|
| @@ -2766,17 +3207,132 @@ import 'lib2.dart';
|
| export 'lib3.dart';
|
| part 'part.dart';
|
| class A {''');
|
| - expect(outputs, hasLength(8));
|
| + expect(outputs, hasLength(11));
|
| expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1));
|
| expect(outputs[EXPORTED_LIBRARIES], hasLength(1));
|
| _assertHasCore(outputs[IMPORTED_LIBRARIES], 2);
|
| expect(outputs[INCLUDED_PARTS], hasLength(1));
|
| + expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2));
|
| expect(outputs[PARSE_ERRORS], hasLength(1));
|
| expect(outputs[PARSED_UNIT], isNotNull);
|
| + expect(outputs[REFERENCED_NAMES], isNotNull);
|
| + expect(outputs[REFERENCED_SOURCES], hasLength(5));
|
| expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
|
| expect(outputs[UNITS], hasLength(2));
|
| }
|
|
|
| + test_perform_library_configurations_bool1() {
|
| + context.declaredVariables.define('dart.library.io', 'true');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + newSource('/bar.dart', '');
|
| + newSource('/bar_io.dart', '');
|
| + newSource('/bar_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +export 'bar.dart'
|
| + if (dart.library.io) 'bar_io.dart'
|
| + if (dart.library.html) 'bar_html.dart';
|
| +''');
|
| + var unit = outputs[PARSED_UNIT] as CompilationUnit;
|
| +
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_io.dart');
|
| +
|
| + var import = unit.directives[0] as ImportDirective;
|
| + expect(import.uriSource.shortName, 'foo.dart');
|
| + expect(import.selectedSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[0].uriSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[1].uriSource.shortName, 'foo_html.dart');
|
| +
|
| + var exported = outputs[EXPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(exported, 'bar_io.dart');
|
| +
|
| + var export = unit.directives[1] as ExportDirective;
|
| + expect(export.uriSource.shortName, 'bar.dart');
|
| + expect(export.selectedSource.shortName, 'bar_io.dart');
|
| + expect(export.configurations[0].uriSource.shortName, 'bar_io.dart');
|
| + expect(export.configurations[1].uriSource.shortName, 'bar_html.dart');
|
| +
|
| + var refSources = outputs[REFERENCED_SOURCES] as List<Source>;
|
| + var refNames = refSources.map((source) => source.shortName).toList();
|
| + expect(refNames, contains('test.dart'));
|
| + expect(refNames, contains('foo.dart'));
|
| + expect(refNames, contains('foo_io.dart'));
|
| + expect(refNames, contains('foo_html.dart'));
|
| + expect(refNames, contains('bar.dart'));
|
| + expect(refNames, contains('bar_io.dart'));
|
| + expect(refNames, contains('bar_html.dart'));
|
| + }
|
| +
|
| + test_perform_library_configurations_bool2() {
|
| + context.declaredVariables.define('dart.library.html', 'true');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_html.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_default() {
|
| + context.declaredVariables.define('dart.library.io', 'false');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_preferFirst() {
|
| + context.declaredVariables.define('dart.library.io', 'true');
|
| + context.declaredVariables.define('dart.library.html', 'true');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| +
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_io.dart');
|
| +
|
| + var unit = outputs[PARSED_UNIT] as CompilationUnit;
|
| + var import = unit.directives[0] as ImportDirective;
|
| + expect(import.uriSource.shortName, 'foo.dart');
|
| + expect(import.selectedSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[0].uriSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[1].uriSource.shortName, 'foo_html.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_value() {
|
| + context.declaredVariables.define('dart.platform', 'Windows');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_posix.dart', '');
|
| + newSource('/foo_windows.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.platform == 'Posix') 'foo_posix.dart'
|
| + if (dart.platform == 'Windows') 'foo_windows.dart';
|
| +''');
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_windows.dart');
|
| + }
|
| +
|
| test_perform_library_selfReferenceAsPart() {
|
| _performParseTask(r'''
|
| library lib;
|
| @@ -2789,23 +3345,45 @@ part 'test.dart';
|
| _performParseTask(r'''
|
| part of lib;
|
| class B {}''');
|
| - expect(outputs, hasLength(8));
|
| + expect(outputs, hasLength(11));
|
| expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
|
| expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
|
| _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
|
| expect(outputs[INCLUDED_PARTS], hasLength(0));
|
| + expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1));
|
| expect(outputs[PARSE_ERRORS], hasLength(0));
|
| expect(outputs[PARSED_UNIT], isNotNull);
|
| + expect(outputs[REFERENCED_NAMES], isNotNull);
|
| + expect(outputs[REFERENCED_SOURCES], hasLength(2));
|
| expect(outputs[SOURCE_KIND], SourceKind.PART);
|
| expect(outputs[UNITS], hasLength(1));
|
| }
|
|
|
| + /**
|
| + * Assert that [sources] contains either just a source with the given
|
| + * [expectedShortName], or it and the `dart:core` source.
|
| + */
|
| + void _assertContainsOnlyShortName(
|
| + List<Source> sources, String expectedShortName) {
|
| + Iterable<String> shortNames = sources.map((s) => s.shortName);
|
| + if (shortNames.length == 2) {
|
| + expect(shortNames, unorderedEquals(['core.dart', expectedShortName]));
|
| + } else {
|
| + expect(shortNames, unorderedEquals([expectedShortName]));
|
| + }
|
| + }
|
| +
|
| void _performParseTask(String content) {
|
| - source = newSource('/test.dart', content);
|
| + if (content == null) {
|
| + source = resourceProvider.getFile('/test.dart').createSource();
|
| + } else {
|
| + source = newSource('/test.dart', content);
|
| + }
|
| computeResult(source, PARSED_UNIT, matcher: isParseDartTask);
|
| }
|
|
|
| - static void _assertHasCore(List<Source> sources, int lenght) {
|
| + static void _assertHasCore(dynamic sourceList, int lenght) {
|
| + List<Source> sources = sourceList as List<Source>;
|
| expect(sources, hasLength(lenght));
|
| expect(sources, contains(predicate((Source s) {
|
| return s.fullName.endsWith('core.dart');
|
| @@ -2815,35 +3393,7 @@ class B {}''');
|
|
|
| @reflectiveTest
|
| class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest {
|
| - test_perform() {
|
| - enableStrongMode();
|
| - Source source = newSource(
|
| - '/test.dart',
|
| - '''
|
| -int a = b;
|
| -int b = c;
|
| -var d = 0;
|
| -class A {}
|
| -class C {
|
| - static final f = '';
|
| - var g = 0;
|
| -}
|
| -''');
|
| - LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT5,
|
| - matcher: isPartiallyResolveUnitReferencesTask);
|
| - // Test the outputs
|
| - expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(4));
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| - expect(unit, same(outputs[RESOLVED_UNIT5]));
|
| - // Test the state of the AST
|
| - TopLevelVariableDeclaration a = unit.declarations[0];
|
| - VariableDeclaration variableA = a.variables.variables[0];
|
| - SimpleIdentifier initializer = variableA.initializer;
|
| - expect(initializer.staticElement, isNotNull);
|
| - }
|
| -
|
| - test_perform_importExport() {
|
| + test_perform_strong_importExport() {
|
| newSource(
|
| '/a.dart',
|
| '''
|
| @@ -2867,11 +3417,11 @@ main() {
|
| new A<int>().m();
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5,
|
| + computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT7,
|
| matcher: isPartiallyResolveUnitReferencesTask);
|
| // validate
|
| expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0));
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| expect(unit, isNotNull);
|
|
|
| FunctionDeclaration mainFunction = unit.declarations[0];
|
| @@ -2884,7 +3434,40 @@ main() {
|
| expect(methodElement, isNull);
|
| }
|
|
|
| - test_perform_notResolved() {
|
| + test_perform_strong_inferable() {
|
| + enableStrongMode();
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +int a = b;
|
| +int b = c;
|
| +var d = 0;
|
| +class A {}
|
| +class C {
|
| + static final f = '';
|
| + var g = 0;
|
| +}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT7,
|
| + matcher: isPartiallyResolveUnitReferencesTask);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| + // INFERABLE_STATIC_VARIABLES_IN_UNIT
|
| + {
|
| + List<VariableElement> variables =
|
| + outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] as List<VariableElement>;
|
| + expect(variables, hasLength(4));
|
| + expect(variables.map((v) => v.displayName),
|
| + unorderedEquals(['a', 'b', 'd', 'f']));
|
| + }
|
| + // Test the state of the AST
|
| + TopLevelVariableDeclaration a = unit.declarations[0];
|
| + VariableDeclaration variableA = a.variables.variables[0];
|
| + SimpleIdentifier initializer = variableA.initializer;
|
| + expect(initializer.staticElement, isNotNull);
|
| + }
|
| +
|
| + test_perform_strong_notResolved() {
|
| enableStrongMode();
|
| Source source = newSource(
|
| '/test.dart',
|
| @@ -2909,9 +3492,9 @@ class C {
|
| }
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT5,
|
| + computeResult(target, RESOLVED_UNIT7,
|
| matcher: isPartiallyResolveUnitReferencesTask);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT7];
|
| NodeList<CompilationUnitMember> declarations = unit.declarations;
|
|
|
| void expectReference(BlockFunctionBody body, bool isResolved) {
|
| @@ -2919,6 +3502,7 @@ class C {
|
| SimpleIdentifier reference = statement.expression;
|
| expect(reference.staticElement, isResolved ? isNotNull : isNull);
|
| }
|
| +
|
| //
|
| // The reference to 'A' in 'f1' should not be resolved.
|
| //
|
| @@ -2951,11 +3535,537 @@ class C {
|
| }
|
|
|
| @reflectiveTest
|
| -class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| - @override
|
| +class ReferencedNamesBuilderTest extends _AbstractDartTaskTest {
|
| void setUp() {
|
| super.setUp();
|
| - enableStrongMode();
|
| + context.analysisOptions = new AnalysisOptionsImpl()
|
| + ..enableGenericMethods = true
|
| + ..strongMode = true;
|
| + }
|
| +
|
| + test_class_constructor() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + U.named(A a, B b) {
|
| + C c = null;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_class_extendedUsedUnnamedConstructorNames() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U1 extends A {
|
| + U1() : super();
|
| +}
|
| +class U2 extends p.B {
|
| + U2() : super();
|
| +}
|
| +class U3 extends p.C {
|
| + U3() : super.named();
|
| +}
|
| +''');
|
| + expect(
|
| + info.extendedUsedUnnamedConstructorNames, unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_class_field() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + A f = new B();
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['B']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_class_getter() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + A get a => new B();
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['B']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_class_members() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + int a;
|
| + int get b;
|
| + set c(_) {}
|
| + m(D d) {
|
| + a;
|
| + b;
|
| + c = 1;
|
| + m();
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['int', 'D']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['int', 'D']));
|
| + }
|
| +
|
| + test_class_members_dontHideQualified() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + int a;
|
| + int get b;
|
| + set c(_) {}
|
| + m(D d) {
|
| + d.a;
|
| + d.b;
|
| + d.c;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['int', 'D', 'a', 'b', 'c']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['int', 'D']));
|
| + }
|
| +
|
| + test_class_method() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + A m(B p) {
|
| + C v = 0;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_class_method_localVariables() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + A m() {
|
| + B b = null;
|
| + b;
|
| + {
|
| + C c = null;
|
| + b;
|
| + c;
|
| + }
|
| + d;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C', 'd']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_class_method_parameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + m(A a) {
|
| + a;
|
| + b;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'b']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_class_method_typeParameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + A m<T>(B b, T t) {
|
| + C c = 0;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_class_setter() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U {
|
| + set a(A a) {
|
| + B b = null;
|
| + }
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_class_typeParameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U<T> {
|
| + T f = new A<T>();
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['A']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_instantiatedNames_importPrefix() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +import 'a.dart' as p1;
|
| +import 'b.dart' as p2;
|
| +main() {
|
| + new p1.A();
|
| + new p1.A.c1();
|
| + new p1.B();
|
| + new p2.C();
|
| + new D();
|
| + new D.c2();
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C', 'D', 'c1', 'c2']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['A', 'B', 'C', 'D']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['main']));
|
| + expect(info.userToDependsOn['main'], isEmpty);
|
| + }
|
| +
|
| + test_localFunction() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +f(A a) {
|
| + g(B b) {}
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_superToSubs_importPrefix() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +import 'a.dart' as p1;
|
| +import 'b.dart' as p2;
|
| +class U extends p1.A with p2.B implements p2.C {}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs['A'], unorderedEquals(['U']));
|
| + expect(info.superToSubs['B'], unorderedEquals(['U']));
|
| + expect(info.superToSubs['C'], unorderedEquals(['U']));
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C']));
|
| + }
|
| +
|
| + test_topLevelVariable() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A v = new B(c);
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'c']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['B']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['v']));
|
| + expect(info.userToDependsOn['v'], unorderedEquals(['A', 'B', 'c']));
|
| + }
|
| +
|
| + test_topLevelVariable_multiple() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A v1 = new B(c), v2 = new D<E>(f);
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'c', 'D', 'E', 'f']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['B', 'D']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['v1', 'v2']));
|
| + expect(info.userToDependsOn['v1'], unorderedEquals(['A', 'B', 'c']));
|
| + expect(info.userToDependsOn['v2'], unorderedEquals(['A', 'D', 'E', 'f']));
|
| + }
|
| +
|
| + test_unit_classTypeAlias() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U = A with B implements C;
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs['A'], unorderedEquals(['U']));
|
| + expect(info.superToSubs['B'], unorderedEquals(['U']));
|
| + expect(info.superToSubs['C'], unorderedEquals(['U']));
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C']));
|
| + }
|
| +
|
| + test_unit_classTypeAlias_typeParameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +class U<T1, T2 extends D> = A<T1> with B<T2> implements C<T1, T2>;
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C', 'D']));
|
| + expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs['A'], unorderedEquals(['U']));
|
| + expect(info.superToSubs['B'], unorderedEquals(['U']));
|
| + expect(info.superToSubs['C'], unorderedEquals(['U']));
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['U']));
|
| + expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C', 'D']));
|
| + }
|
| +
|
| + test_unit_function() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A f(B b) {
|
| + C c = 0;
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_unit_function_doc() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +/**
|
| + * Documentation [C.d] reference.
|
| + */
|
| +A f(B b) {}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C', 'd']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_unit_function_localFunctions() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A f() {
|
| + B b = null;
|
| + C g() {}
|
| + g();
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_unit_function_localsDontHideQualified() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +f(A a, B b) {
|
| + var v = 0;
|
| + a.v;
|
| + a.b;
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'v', 'b']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_unit_function_localVariables() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A f() {
|
| + B b = null;
|
| + b;
|
| + {
|
| + C c = null;
|
| + b;
|
| + c;
|
| + }
|
| + d;
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C', 'd']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_unit_function_parameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A f(B b) {
|
| + C c = 0;
|
| + b;
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_unit_function_typeParameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A f<T>(B b, T t) {
|
| + C c = 0;
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['f']));
|
| + expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_unit_functionTypeAlias() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +typedef A F(B B, C c(D d));
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B', 'C', 'D']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['F']));
|
| + expect(info.userToDependsOn['F'], unorderedEquals(['A', 'B', 'C', 'D']));
|
| + }
|
| +
|
| + test_unit_functionTypeAlias_typeParameters() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +typedef A F<T>(B b, T t);
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['F']));
|
| + expect(info.userToDependsOn['F'], unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_unit_getter() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +A get aaa {
|
| + return new B();
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, unorderedEquals(['B']));
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['aaa']));
|
| + expect(info.userToDependsOn['aaa'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + test_unit_setter() {
|
| + ReferencedNames info = _computeReferencedNames('''
|
| +set aaa(A a) {
|
| + B b = null;
|
| +}
|
| +''');
|
| + expect(info.names, unorderedEquals(['A', 'B']));
|
| + expect(info.superToSubs.keys, isEmpty);
|
| + expect(info.instantiatedNames, isEmpty);
|
| + expect(info.userToDependsOn.keys, unorderedEquals(['aaa']));
|
| + expect(info.userToDependsOn['aaa'], unorderedEquals(['A']));
|
| + }
|
| +
|
| + ReferencedNames _computeReferencedNames(String code) {
|
| + Source source = newSource('/test.dart', code);
|
| + computeResult(source, REFERENCED_NAMES, matcher: isParseDartTask);
|
| + return outputs[REFERENCED_NAMES];
|
| + }
|
| +}
|
| +
|
| +@reflectiveTest
|
| +class ResolveDirectiveElementsTaskTest extends _AbstractDartTaskTest {
|
| + test_perform() {
|
| + List<Source> sources = newSources({
|
| + '/libA.dart': '''
|
| +library libA;
|
| +import 'libB.dart';
|
| +export 'libC.dart';
|
| +''',
|
| + '/libB.dart': '''
|
| +library libB;
|
| +''',
|
| + '/libC.dart': '''
|
| +library libC;
|
| +'''
|
| + });
|
| + Source sourceA = sources[0];
|
| + LibrarySpecificUnit targetA = new LibrarySpecificUnit(sourceA, sourceA);
|
| + // build directive elements
|
| + computeResult(sourceA, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + // prepare outputs
|
| + LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2];
|
| + LibraryElement libraryElementB = libraryElementA.imports[0].importedLibrary;
|
| + LibraryElement libraryElementC = libraryElementA.exports[0].exportedLibrary;
|
| + // clear elements in directive ASTs
|
| + {
|
| + CompilationUnit unitA = context.getResult(targetA, RESOLVED_UNIT1);
|
| + unitA.directives[1].element = null;
|
| + unitA.directives[2].element = null;
|
| + }
|
| + // resolve directive ASTs
|
| + computeResult(targetA, RESOLVED_UNIT2,
|
| + matcher: isResolveDirectiveElementsTask);
|
| + // validate that directive ASTs have elements
|
| + CompilationUnit unitA = context.getResult(targetA, RESOLVED_UNIT2);
|
| + {
|
| + ImportDirective importNode = unitA.directives[1];
|
| + ImportElement importElement = importNode.element;
|
| + expect(importElement, isNotNull);
|
| + expect(importElement.importedLibrary, libraryElementB);
|
| + }
|
| + {
|
| + ExportDirective exportNode = unitA.directives[2];
|
| + ExportElement exportElement = exportNode.element;
|
| + expect(exportElement, isNotNull);
|
| + expect(exportElement.exportedLibrary, libraryElementC);
|
| + }
|
| + }
|
| +}
|
| +
|
| +@reflectiveTest
|
| +class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| + @override
|
| + void setUp() {
|
| + super.setUp();
|
| + enableStrongMode();
|
| + }
|
| +
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT9);
|
| + expect(outputs[RESOLVED_UNIT9], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT9], isTrue);
|
| }
|
|
|
| // Test inference of instance fields across units
|
| @@ -2985,35 +4095,34 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| DartType dynamicType = context.typeProvider.dynamicType;
|
|
|
| computeResult(
|
| - new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7);
|
| - CompilationUnit unit1 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9);
|
| + CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
|
|
|
| // 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);
|
| - CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
|
| + CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
|
|
|
| // 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);
|
| - CompilationUnit unit2 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9);
|
|
|
| // 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
|
| @@ -3040,24 +4149,22 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| }
|
| '''
|
| });
|
| - InterfaceType intType = context.typeProvider.intType;
|
| DartType dynamicType = context.typeProvider.dynamicType;
|
|
|
| computeResult(
|
| - new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
|
| - CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
|
| + CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
|
|
|
| // 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);
|
| - CompilationUnit unit2 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9);
|
|
|
| - // A.a2 should now be fully resolved and inferred.
|
| + // A.a2 should now be fully resolved and inferred (but not re-resolved).
|
| assertVariableDeclarationTypes(
|
| - getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| + AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
|
| }
|
|
|
| // Test inference of instance fields across units with cycles
|
| @@ -3091,41 +4198,40 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| DartType dynamicType = context.typeProvider.dynamicType;
|
|
|
| computeResult(
|
| - new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7);
|
| - CompilationUnit unit1 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9);
|
| + CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
|
|
|
| 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];
|
| + new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
|
| + CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
|
|
|
| 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);
|
| - CompilationUnit unit2 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9);
|
|
|
| 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
|
| @@ -3154,28 +4260,53 @@ class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
|
| DartType dynamicType = context.typeProvider.dynamicType;
|
|
|
| computeResult(
|
| - new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
|
| - CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
|
| + CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
|
|
|
| // 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);
|
| - CompilationUnit unit1 = outputs[RESOLVED_UNIT7];
|
| + new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9);
|
|
|
| - // A.a2 should now be fully resolved and inferred.
|
| + // A.a2 should now be fully resolved and inferred (but not re-resolved).
|
| 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);
|
| + }
|
| +}
|
| +
|
| +@reflectiveTest
|
| +class ResolveLibraryTaskTest extends _AbstractDartTaskTest {
|
| + test_perform() {
|
| + Source sourceLib = newSource(
|
| + '/my_lib.dart',
|
| + '''
|
| +library my_lib;
|
| +const a = new A();
|
| +class A {
|
| + const A();
|
| +}
|
| +@a
|
| +class C {}
|
| +''');
|
| + computeResult(sourceLib, LIBRARY_ELEMENT, matcher: isResolveLibraryTask);
|
| + // validate
|
| + LibraryElement library = outputs[LIBRARY_ELEMENT];
|
| + ClassElement classC = library.getType('C');
|
| + List<ElementAnnotation> metadata = classC.metadata;
|
| + expect(metadata, hasLength(1));
|
| + ElementAnnotation annotation = metadata[0];
|
| + expect(annotation, isNotNull);
|
| + expect((annotation as ElementAnnotationImpl).evaluationResult, isNotNull);
|
| }
|
| }
|
|
|
| @@ -3196,10 +4327,10 @@ class B extends A {}
|
| part of my_lib;
|
| class C extends A {}
|
| ''');
|
| - computeResult(sourceLib, LIBRARY_ELEMENT5,
|
| + computeResult(sourceLib, LIBRARY_ELEMENT6,
|
| matcher: isResolveLibraryTypeNamesTask);
|
| // validate
|
| - LibraryElement library = outputs[LIBRARY_ELEMENT5];
|
| + LibraryElement library = outputs[LIBRARY_ELEMENT6];
|
| {
|
| ClassElement classB = library.getType('B');
|
| expect(classB.supertype.displayName, 'A');
|
| @@ -3208,6 +4339,7 @@ class C extends A {}
|
| ClassElement classC = library.getType('C');
|
| expect(classC.supertype.displayName, 'A');
|
| }
|
| + expect(library.loadLibraryFunction, isNotNull);
|
| }
|
|
|
| test_perform_external() {
|
| @@ -3226,10 +4358,10 @@ class B {}
|
| ''');
|
| // The reference A to B should be resolved, but there's no requirement that
|
| // the full class hierarchy be resolved.
|
| - computeResult(sourceA, LIBRARY_ELEMENT5,
|
| + computeResult(sourceA, LIBRARY_ELEMENT6,
|
| matcher: isResolveLibraryTypeNamesTask);
|
| // validate
|
| - LibraryElement library = outputs[LIBRARY_ELEMENT5];
|
| + LibraryElement library = outputs[LIBRARY_ELEMENT6];
|
| {
|
| ClassElement clazz = library.getType('A');
|
| expect(clazz.displayName, 'A');
|
| @@ -3239,8 +4371,149 @@ class B {}
|
| }
|
| }
|
|
|
| +@reflectiveTest
|
| +class ResolveTopLevelUnitTypeBoundsTaskTest extends _AbstractDartTaskTest {
|
| + test_perform_boundIsGenericType() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class C<T extends Map<String, List<int>>> {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT4,
|
| + matcher: isResolveTopLevelUnitTypeBoundsTask);
|
| + // validate
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| + ClassDeclaration nodeC = unit.declarations[0];
|
| + _assertTypeParameterBound(nodeC.typeParameters.typeParameters[0],
|
| + 'Map<String, List<int>>', 'Map');
|
| + }
|
| +
|
| + test_perform_errors() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class C<T extends NoSuchClass> {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVE_TYPE_BOUNDS_ERRORS,
|
| + matcher: isResolveTopLevelUnitTypeBoundsTask);
|
| + // validate
|
| + _fillErrorListener(RESOLVE_TYPE_BOUNDS_ERRORS);
|
| + errorListener
|
| + .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]);
|
| + }
|
| +
|
| + test_perform_ignoreBoundsOfBounds() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class A<T1 extends num> {}
|
| +class B<T2 extends A> {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT4,
|
| + matcher: isResolveTopLevelUnitTypeBoundsTask);
|
| + // validate
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| + ClassDeclaration nodeB = unit.declarations[1];
|
| + _assertTypeParameterBound(
|
| + nodeB.typeParameters.typeParameters[0], 'A<dynamic>', 'A');
|
| + }
|
| +
|
| + test_perform_outputs() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +class C<T extends int> {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT4);
|
| + expect(outputs[RESOLVED_UNIT4], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT4], isTrue);
|
| + expect(outputs[RESOLVE_TYPE_BOUNDS_ERRORS], isNotNull);
|
| + }
|
| +
|
| + test_perform_unitMember_ClassDeclaration() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class C<T extends int> extends Object {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT4,
|
| + matcher: isResolveTopLevelUnitTypeBoundsTask);
|
| + // validate
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| + ClassDeclaration nodeC = unit.declarations[0];
|
| + // 'extends Object' is not resolved
|
| + expect(nodeC.extendsClause.superclass.name.staticElement, isNull);
|
| + // but 'T extends int' is resolved
|
| + _assertTypeParameterBound(
|
| + nodeC.typeParameters.typeParameters[0], 'int', 'int');
|
| + }
|
| +
|
| + test_perform_unitMember_ClassTypeAlias() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class C<T extends double> = Object;
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT4,
|
| + matcher: isResolveTopLevelUnitTypeBoundsTask);
|
| + // validate
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| + ClassTypeAlias nodeC = unit.declarations[0];
|
| + // '= Object' is not resolved
|
| + expect(nodeC.superclass.name.staticElement, isNull);
|
| + // but 'T extends int' is resolved
|
| + _assertTypeParameterBound(
|
| + nodeC.typeParameters.typeParameters[0], 'double', 'double');
|
| + }
|
| +
|
| + test_perform_unitMember_FunctionTypeAlias() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +typedef F<T extends String>();
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT4,
|
| + matcher: isResolveTopLevelUnitTypeBoundsTask);
|
| + // validate
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| + FunctionTypeAlias nodeF = unit.declarations[0];
|
| + // but 'T extends String' is resolved
|
| + _assertTypeParameterBound(
|
| + nodeF.typeParameters.typeParameters[0], 'String', 'String');
|
| + }
|
| +
|
| + void _assertTypeParameterBound(TypeParameter typeParameter,
|
| + String expectedBoundTypeString, String expectedBoundElementName) {
|
| + TypeName boundNode = typeParameter.bound;
|
| + Identifier boundName = boundNode.name;
|
| + expect(boundNode.type.toString(), expectedBoundTypeString);
|
| + expect(boundName.staticType.toString(), expectedBoundTypeString);
|
| + expect(boundName.staticElement.displayName, expectedBoundElementName);
|
| + }
|
| +}
|
| +
|
| @reflectiveTest
|
| class ResolveUnitTaskTest extends _AbstractDartTaskTest {
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT11);
|
| + expect(outputs[RESOLVED_UNIT11], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT11], isTrue);
|
| + }
|
| +
|
| void test_perform() {
|
| AnalysisTarget source = newSource(
|
| '/test.dart',
|
| @@ -3255,9 +4528,9 @@ class C {
|
| }
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9,
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11,
|
| matcher: isResolveUnitTask);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
|
|
| FunctionDeclaration f = unit.declarations[0];
|
| _assertResolved(f.functionExpression.body);
|
| @@ -3277,6 +4550,19 @@ class C {
|
|
|
| @reflectiveTest
|
| class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest {
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT5);
|
| + expect(outputs[RESOLVED_UNIT5], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT5], isTrue);
|
| + }
|
| +
|
| test_perform() {
|
| Source source = newSource(
|
| '/test.dart',
|
| @@ -3286,9 +4572,9 @@ class B extends A {}
|
| int f(String p) => p.length;
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask);
|
| + computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask);
|
| // validate
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT3];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| {
|
| ClassDeclaration nodeA = unit.declarations[0];
|
| ClassDeclaration nodeB = unit.declarations[1];
|
| @@ -3328,9 +4614,9 @@ typedef int F(G g);
|
| typedef String G(int p);
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask);
|
| + computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask);
|
| // validate
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT3];
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT5];
|
| FunctionTypeAlias nodeF = unit.declarations[0];
|
| FunctionTypeAlias nodeG = unit.declarations[1];
|
| {
|
| @@ -3370,10 +4656,23 @@ class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest {
|
| * Verify that the mutated states of the given [variable] correspond to the
|
| * [mutatedInClosure] and [mutatedInScope] matchers.
|
| */
|
| - void expectMutated(VariableElement variable, Matcher mutatedInClosure,
|
| - Matcher mutatedInScope) {
|
| - expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure);
|
| - expect(variable.isPotentiallyMutatedInScope, mutatedInScope);
|
| + void expectMutated(FunctionBody body, VariableElement variable,
|
| + bool mutatedInClosure, bool mutatedInScope) {
|
| + expect(body.isPotentiallyMutatedInClosure(variable), mutatedInClosure);
|
| + expect(body.isPotentiallyMutatedInScope(variable), mutatedInScope);
|
| + }
|
| +
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT6);
|
| + expect(outputs[RESOLVED_UNIT6], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT6], isTrue);
|
| }
|
|
|
| test_perform_buildClosureLibraryElements() {
|
| @@ -3384,7 +4683,7 @@ main() {
|
| }
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT4,
|
| + computeResult(target, RESOLVED_UNIT6,
|
| matcher: isResolveVariableReferencesTask);
|
| }
|
|
|
| @@ -3406,15 +4705,17 @@ main() {
|
| }
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT4,
|
| + computeResult(target, RESOLVED_UNIT6,
|
| matcher: isResolveVariableReferencesTask);
|
| // validate
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| - FunctionElement main = unit.element.functions[0];
|
| - expectMutated(main.localVariables[0], isFalse, isFalse);
|
| - expectMutated(main.localVariables[1], isFalse, isTrue);
|
| - expectMutated(main.localVariables[2], isTrue, isTrue);
|
| - expectMutated(main.localVariables[3], isTrue, isTrue);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
| + FunctionDeclaration mainDeclaration = unit.declarations[0];
|
| + FunctionBody body = mainDeclaration.functionExpression.body;
|
| + FunctionElement main = mainDeclaration.element;
|
| + expectMutated(body, main.localVariables[0], false, false);
|
| + expectMutated(body, main.localVariables[1], false, true);
|
| + expectMutated(body, main.localVariables[2], true, true);
|
| + expectMutated(body, main.localVariables[3], true, true);
|
| }
|
|
|
| test_perform_parameter() {
|
| @@ -3431,34 +4732,57 @@ main(p1, p2, p3, p4) {
|
| }
|
| ''');
|
| LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| - computeResult(target, RESOLVED_UNIT4,
|
| + computeResult(target, RESOLVED_UNIT6,
|
| matcher: isResolveVariableReferencesTask);
|
| // validate
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT4];
|
| - FunctionElement main = unit.element.functions[0];
|
| - expectMutated(main.parameters[0], isFalse, isFalse);
|
| - expectMutated(main.parameters[1], isFalse, isTrue);
|
| - expectMutated(main.parameters[2], isTrue, isTrue);
|
| - expectMutated(main.parameters[3], isTrue, isTrue);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
| + FunctionDeclaration mainDeclaration = unit.declarations[0];
|
| + FunctionBody body = mainDeclaration.functionExpression.body;
|
| + FunctionElement main = mainDeclaration.element;
|
| + expectMutated(body, main.parameters[0], false, false);
|
| + expectMutated(body, main.parameters[1], false, true);
|
| + expectMutated(body, main.parameters[2], true, true);
|
| + expectMutated(body, main.parameters[3], true, true);
|
| }
|
| }
|
|
|
| @reflectiveTest
|
| class ScanDartTaskTest extends _AbstractDartTaskTest {
|
| + test_ignore_info() {
|
| + _performScanTask('''
|
| +//ignore: error_code
|
| +var x = '';
|
| +foo(); // ignore: error_code_2
|
| +bar(); //ignore: error_code, error_code_2
|
| +''');
|
| +
|
| + IgnoreInfo info = outputs[IGNORE_INFO];
|
| + expect(info.ignores.keys, hasLength(3));
|
| + expect(info.ignores[1].first, 'error_code');
|
| + expect(info.ignores[3].first, 'error_code_2');
|
| + expect(info.ignores[4], unorderedEquals(['error_code', 'error_code_2']));
|
| + }
|
| +
|
| test_perform_errors() {
|
| _performScanTask('import "');
|
| - expect(outputs, hasLength(3));
|
| + expect(outputs, hasLength(4));
|
| expect(outputs[LINE_INFO], isNotNull);
|
| expect(outputs[SCAN_ERRORS], hasLength(1));
|
| expect(outputs[TOKEN_STREAM], isNotNull);
|
| + IgnoreInfo ignoreInfo = outputs[IGNORE_INFO];
|
| + expect(ignoreInfo, isNotNull);
|
| + expect(ignoreInfo.hasIgnores, isFalse);
|
| }
|
|
|
| test_perform_noErrors() {
|
| _performScanTask('class A {}');
|
| - expect(outputs, hasLength(3));
|
| + expect(outputs, hasLength(4));
|
| expect(outputs[LINE_INFO], isNotNull);
|
| expect(outputs[SCAN_ERRORS], hasLength(0));
|
| expect(outputs[TOKEN_STREAM], isNotNull);
|
| + IgnoreInfo ignoreInfo = outputs[IGNORE_INFO];
|
| + expect(ignoreInfo, isNotNull);
|
| + expect(ignoreInfo.hasIgnores, isFalse);
|
| }
|
|
|
| test_perform_script() {
|
| @@ -3511,14 +4835,18 @@ var piFirst = true;
|
| var pi = piFirst ? 3.14 : tau / 2;
|
| var tau = piFirst ? pi * 2 : 6.28;
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
| 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);
|
| @@ -3550,26 +4878,26 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| }
|
| ''');
|
| computeResult(
|
| - new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9);
|
| - CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
|
| + new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT11);
|
| + CompilationUnit unit1 = outputs[RESOLVED_UNIT11];
|
| computeResult(
|
| - new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9);
|
| - CompilationUnit unit2 = outputs[RESOLVED_UNIT9];
|
| + new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT11);
|
| + CompilationUnit unit2 = outputs[RESOLVED_UNIT11];
|
|
|
| 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);
|
| @@ -3601,7 +4929,7 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| '''
|
| });
|
| List<dynamic> units =
|
| - computeLibraryResults(sources, RESOLVED_UNIT9).toList();
|
| + computeLibraryResults(sources, RESOLVED_UNIT11).toList();
|
| CompilationUnit unit0 = units[0];
|
| CompilationUnit unit1 = units[1];
|
| CompilationUnit unit2 = units[2];
|
| @@ -3609,13 +4937,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);
|
| }
|
| @@ -3648,18 +4976,21 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| '''
|
| });
|
| List<dynamic> units =
|
| - computeLibraryResults(sources, RESOLVED_UNIT9).toList();
|
| + computeLibraryResults(sources, RESOLVED_UNIT11).toList();
|
| CompilationUnit unit0 = units[0];
|
| - CompilationUnit unit1 = units[1];
|
| CompilationUnit unit2 = units[2];
|
|
|
| InterfaceType intType = context.typeProvider.intType;
|
| 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
|
| @@ -3686,27 +5017,27 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| }
|
| ''');
|
| computeResult(
|
| - new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9);
|
| - CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
|
| + new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT11);
|
| + CompilationUnit unit1 = outputs[RESOLVED_UNIT11];
|
| computeResult(
|
| - new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9);
|
| - CompilationUnit unit2 = outputs[RESOLVED_UNIT9];
|
| + new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT11);
|
| + CompilationUnit unit2 = outputs[RESOLVED_UNIT11];
|
|
|
| InterfaceType intType = context.typeProvider.intType;
|
| 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);
|
| @@ -3740,7 +5071,7 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| '''
|
| });
|
| List<dynamic> units =
|
| - computeLibraryResults(sources, RESOLVED_UNIT9).toList();
|
| + computeLibraryResults(sources, RESOLVED_UNIT11).toList();
|
| CompilationUnit unit0 = units[0];
|
| CompilationUnit unit1 = units[1];
|
| CompilationUnit unit2 = units[2];
|
| @@ -3748,17 +5079,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);
|
| @@ -3776,13 +5107,14 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| y = "hi";
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
|
|
| 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);
|
| @@ -3814,13 +5146,14 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| final z = 42; // should infer `int`
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
|
|
| 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);
|
| @@ -3835,9 +5168,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
|
| @@ -3862,13 +5195,14 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| int y = 0; // field def after use
|
| final z = 42; // should infer `int`
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
|
|
| 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);
|
| @@ -3883,11 +5217,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
|
| @@ -3914,8 +5248,8 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| new A().y2 = /*severe:StaticTypeError*/"hi";
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
|
|
| InterfaceType intType = context.typeProvider.intType;
|
| InterfaceType stringType = context.typeProvider.stringType;
|
| @@ -3923,19 +5257,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);
|
| @@ -3955,13 +5290,14 @@ var tau = piFirst ? pi * 2 : 6.28;
|
| x = "hi";
|
| }
|
| ''');
|
| - computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
|
| - CompilationUnit unit = outputs[RESOLVED_UNIT9];
|
| + computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
|
| + CompilationUnit unit = outputs[RESOLVED_UNIT11];
|
|
|
| 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);
|
| @@ -3982,6 +5318,19 @@ class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest {
|
| enableStrongMode();
|
| }
|
|
|
| + test_created_resolved_unit() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + r'''
|
| +library lib;
|
| +class A {}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, RESOLVED_UNIT);
|
| + expect(outputs[RESOLVED_UNIT], isNotNull);
|
| + expect(outputs[CREATED_RESOLVED_UNIT], isTrue);
|
| + }
|
| +
|
| void test_perform_recordDynamicInvoke() {
|
| enableStrongMode();
|
| AnalysisTarget source = newSource(
|
| @@ -3999,12 +5348,11 @@ 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);
|
| - expect(DynamicInvoke.get(idx.target), isNotNull);
|
| - expect(DynamicInvoke.get(idx.target), isTrue);
|
| + expect(strong_ast.isDynamicInvoke(idx.target), isTrue);
|
| }
|
|
|
| void test_perform_verifyError() {
|
| @@ -4012,10 +5360,9 @@ void main() {
|
| AnalysisTarget source = newSource(
|
| '/test.dart',
|
| '''
|
| -int topLevel = 3;
|
| -class C {
|
| - String field = topLevel;
|
| -}
|
| +class A {}
|
| +class B extends A {}
|
| +B b = new A();
|
| ''');
|
| computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS);
|
| // validate
|
| @@ -4023,7 +5370,7 @@ class C {
|
|
|
| var errors = errorListener.errors;
|
| expect(errors.length, 1);
|
| - expect(errors[0].errorCode.name, "dev_compiler.StaticTypeError");
|
| + expect(errors[0].errorCode.name, "STRONG_MODE_STATIC_TYPE_ERROR");
|
| }
|
| }
|
|
|
| @@ -4046,7 +5393,111 @@ main(int p) {
|
| ]);
|
| }
|
|
|
| - test_perform_directiveError() {
|
| + test_perform_ConstantValidator_declaredIdentifier() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +void main() {
|
| + for (const foo in []) {
|
| + print(foo);
|
| + }
|
| +}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
|
| + // validate
|
| + _fillErrorListener(VERIFY_ERRORS);
|
| + errorListener.assertNoErrors();
|
| + }
|
| +
|
| + test_perform_ConstantValidator_dependencyCycle() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +const int a = b;
|
| +const int b = c;
|
| +const int c = a;
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
|
| + // validate
|
| + _fillErrorListener(VERIFY_ERRORS);
|
| + errorListener.assertErrorsWithCodes(<ErrorCode>[
|
| + CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
|
| + CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
|
| + CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT
|
| + ]);
|
| + }
|
| +
|
| + test_perform_ConstantValidator_duplicateFields() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +class Test {
|
| + final int x = 1;
|
| + final int x = 2;
|
| + const Test();
|
| +}
|
| +
|
| +main() {
|
| + const Test();
|
| +}
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
|
| + // validate
|
| + _fillErrorListener(VERIFY_ERRORS);
|
| + errorListener
|
| + .assertErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
|
| + }
|
| +
|
| + test_perform_ConstantValidator_noInitializer() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +const x;
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
|
| + // validate
|
| + _fillErrorListener(VERIFY_ERRORS);
|
| + errorListener.assertErrorsWithCodes(
|
| + <ErrorCode>[CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
|
| + }
|
| +
|
| + test_perform_ConstantValidator_unknownValue() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +import 'no-such-file.dart' as p;
|
| +
|
| +const int x = p.y;
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
|
| + // validate
|
| + _fillErrorListener(VERIFY_ERRORS);
|
| + errorListener.assertErrorsWithCodes(<ErrorCode>[
|
| + CompileTimeErrorCode.URI_DOES_NOT_EXIST,
|
| + CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
|
| + ]);
|
| + }
|
| +
|
| + test_perform_directiveError_generated() {
|
| + Source source = newSource(
|
| + '/test.dart',
|
| + '''
|
| +import 'generated-file.g.dart';
|
| +''');
|
| + LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
|
| + computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
|
| + // validate
|
| + _fillErrorListener(VERIFY_ERRORS);
|
| + errorListener.assertErrorsWithCodes(
|
| + <ErrorCode>[CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED]);
|
| + }
|
| +
|
| + test_perform_directiveError_nonGenerated() {
|
| Source source = newSource(
|
| '/test.dart',
|
| '''
|
| @@ -4149,6 +5600,7 @@ class _AbstractDartTaskTest extends AbstractContextTest {
|
| matcher: matcher);
|
| return outputs[result];
|
| }
|
| +
|
| return sources.map(compute).toList();
|
| }
|
|
|
| @@ -4156,10 +5608,10 @@ class _AbstractDartTaskTest extends AbstractContextTest {
|
| List<Source> sources, ResultDescriptor result,
|
| {isInstanceOf matcher: null}) {
|
| Map<ResultDescriptor, dynamic> compute(Source source) {
|
| - computeResult(new LibrarySpecificUnit(source, source), result,
|
| - matcher: matcher);
|
| + computeResult(source, result, matcher: matcher);
|
| return outputs;
|
| }
|
| +
|
| return sources.map(compute).toList();
|
| }
|
|
|
| @@ -4192,114 +5644,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');
|
| @@ -4309,7 +5653,7 @@ class _AbstractDartTaskTest extends AbstractContextTest {
|
| * Fill [errorListener] with [result] errors in the current [task].
|
| */
|
| void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
|
| - List<AnalysisError> errors = task.outputs[result];
|
| + List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>;
|
| expect(errors, isNotNull, reason: result.name);
|
| errorListener = new GatheringErrorListener();
|
| errorListener.addAll(errors);
|
|
|